feat: initialize cli & dependency installation

This commit is contained in:
Erica Marigold 2022-11-19 12:31:57 +05:30
parent 8fda47196d
commit df5ec67c3b
No known key found for this signature in database
GPG key ID: 23CD97ABBBCC5ED2
37 changed files with 276 additions and 473 deletions

View file

@ -1 +0,0 @@
// do this someday

View file

@ -3,8 +3,7 @@
"version": "0.0.0", "version": "0.0.0",
"private": true, "private": true,
"workspaces": [ "workspaces": [
"apps/*", "libs/*",
"apps/*/*",
"packages/*/*" "packages/*/*"
], ],
"scripts": { "scripts": {

View file

@ -0,0 +1,4 @@
{
"extends": "../tsconfig.json",
}

View file

@ -0,0 +1,10 @@
export default function get(): string|null {
const userAgent = process.env.npm_config_user_agent
if (!userAgent) {
return null;
}
const manager= userAgent.split(" ")[0].split("/")[0];
return manager
}

View file

@ -0,0 +1,44 @@
import { spawn } from "child_process";
import { userInfo } from "os";
export default function install(packageManager: "npm" | "pnpm" | "yarn" | null, workingDirectory: string) {
const cmds = {
npm: {
command: "npm",
args: ["install"]
},
pnpm: {
command: "pnpm",
args: ["install"]
},
yarn: {
command: "yarn",
args: []
}
}
console.log(userInfo().shell)
switch (packageManager) {
case null:
const spawnedNPM = spawn(`${cmds.npm.command}`, cmds.npm.args, { cwd: workingDirectory, stdio: "inherit", shell: userInfo().shell })
spawnedNPM.stdout.on("data", (out) => {
console.log(`Installing dependencies using npm`)
console.log(`\rnpm :: ${out}`)
})
case "npm" || "pnpm" || "yarn":
const spawnedAny = spawn(`${cmds[packageManager].command}`, cmds[packageManager].args, { cwd: workingDirectory, stdio: "inherit", shell: userInfo().shell })
spawnedAny.stdout.on("data", (out) => {
console.log(`Installing dependencies using ${packageManager}`)
console.log(`\r${packageManager} :: ${out}`)
})
spawnedAny.stderr.on("data", (err) => {
console.error(`\r${packageManager} error: ${err}`)
})
}
}

View file

@ -8,21 +8,21 @@
"dev": "ts-node-dev src/index.ts", "dev": "ts-node-dev src/index.ts",
"start": "ts-node src/index.ts" "start": "ts-node src/index.ts"
}, },
"type": "module",
"keywords": [], "keywords": [],
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"dependencies": {
"inquirer": "8.2.3",
"kleur": "^4.1.5"
},
"devDependencies": { "devDependencies": {
"@types/inquirer": "^9.0.3", "@types/inquirer": "8.2.3",
"@types/node": "^18.11.9", "@types/node": "^18.11.9",
"@types/prompt": "^1.1.4", "@types/prompt": "^1.1.4",
"ts-node": "^10.9.1",
"ts-node-dev": "^2.0.0", "ts-node-dev": "^2.0.0",
"tsconfig": "workspace:*", "tsconfig": "workspace:*",
"tslib": "^2.4.1", "tslib": "^2.4.1",
"typescript": "^4.9.3" "typescript": "^4.9.3"
},
"dependencies": {
"inquirer": "^9.1.4",
"kleur": "^4.1.5"
} }
} }

28
packages/cli/src/index.ts Normal file
View file

@ -0,0 +1,28 @@
import * as inquirer from "inquirer";
import getPackageManager from "../lib/getPackageManager";
import install from "../lib/installDependencies";
inquirer
.prompt([
{
type: 'list',
name: 'flavor',
message: 'Which flavor?',
choices: ['TypeScript', 'JavaScript'],
filter(val) {
return val.toLowerCase();
},
},
])
.then((answers) => {
console.log(JSON.stringify(answers, null, ' '));
let packageManager = getPackageManager()
if (packageManager !== "npm"||"pnpm"||"yarn") {
packageManager = "npm"
}
install(packageManager as "npm"|"pnpm"|"yarn"|null, ".")
});

View file

@ -1,4 +0,0 @@
import * as React from "react";
export const Button = () => {
return <button>Boop</button>;
};

View file

@ -1,2 +0,0 @@
import * as React from "react";
export * from "./Button";

View file

@ -1,19 +0,0 @@
{
"name": "ui",
"version": "0.0.0",
"main": "./index.tsx",
"types": "./index.tsx",
"license": "MIT",
"scripts": {
"lint": "eslint *.ts*"
},
"devDependencies": {
"@types/react": "^18.0.17",
"@types/react-dom": "^18.0.6",
"eslint": "^7.32.0",
"eslint-config-custom": "workspace:*",
"react": "^18.2.0",
"tsconfig": "workspace:*",
"typescript": "^4.5.2"
}
}

View file

@ -1,5 +0,0 @@
{
"extends": "tsconfig/react-library.json",
"include": ["."],
"exclude": ["dist", "build", "node_modules"]
}

File diff suppressed because it is too large Load diff

View file

@ -1,4 +1,3 @@
packages: packages:
- "apps/*" - "libs/*"
- "apps/*/*"
- "packages/*" - "packages/*"