@dawitworku/projectcli 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,75 @@
1
+ # projectcli
2
+
3
+ Interactive project generator.
4
+
5
+ Run it as a single command, pick language → framework, and it scaffolds the project by calling the underlying official CLIs (Vite, Next.js, Nest, etc.).
6
+
7
+ ## Run with npx (recommended)
8
+
9
+ After you publish this package to npm:
10
+
11
+ ```bash
12
+ npx projectcli@latest
13
+ ```
14
+
15
+ You can also run non-interactively:
16
+
17
+ ```bash
18
+ npx projectcli@latest --language "TypeScript" --framework "NestJS" --name my-api --pm npm
19
+ ```
20
+
21
+ ## Run (dev)
22
+
23
+ ```bash
24
+ npm install
25
+ npm start
26
+ ```
27
+
28
+ ## Install as a single-word command
29
+
30
+ From this repo folder:
31
+
32
+ ```bash
33
+ npm install
34
+ npm link
35
+ ```
36
+
37
+ Then you can run:
38
+
39
+ ```bash
40
+ projectcli
41
+ ```
42
+
43
+ ## Add libraries to an existing project
44
+
45
+ Run inside a project folder:
46
+
47
+ ```bash
48
+ projectcli add
49
+ ```
50
+
51
+ ## Notes
52
+
53
+ - If you type a project name that already exists, the CLI will ask for another name (it won’t quit).
54
+ - Some generators (like Vite/Next/etc.) can still ask their own questions — those prompts come from the underlying tool.
55
+
56
+ ## Useful flags
57
+
58
+ ```bash
59
+ projectcli --help
60
+ projectcli --version
61
+ projectcli --list
62
+ projectcli --language "JavaScript" --framework "Astro" --name myapp --pm pnpm
63
+ projectcli --language "TypeScript" --framework "TanStack Start" --name myapp --pm npm
64
+ projectcli --language "TypeScript" --framework "NestJS" --name myapi --pm pnpm
65
+ projectcli --dry-run --language "JavaScript" --framework "Vite (React)" --name demo --pm pnpm
66
+ ```
67
+
68
+ ## How it works
69
+
70
+ - Choose language
71
+ - Choose framework
72
+ - Enter project name
73
+ - CLI runs the underlying generator commands (npm/cargo/django-admin/etc.)
74
+
75
+ If a generator command is missing on your machine, install it and re-run.
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { main } = require("../src/index");
4
+
5
+ main({ argv: process.argv.slice(2) }).catch((err) => {
6
+ const message = err && err.message ? err.message : String(err);
7
+ console.error(`\nError: ${message}`);
8
+ process.exitCode = 1;
9
+ });
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@dawitworku/projectcli",
3
+ "version": "0.1.0",
4
+ "description": "Interactive project generator (language -> framework -> create).",
5
+ "license": "MIT",
6
+ "type": "commonjs",
7
+ "bin": {
8
+ "projectcli": "bin/projectcli.js"
9
+ },
10
+ "files": [
11
+ "bin",
12
+ "src",
13
+ "README.md"
14
+ ],
15
+ "engines": {
16
+ "node": ">=18"
17
+ },
18
+ "keywords": [
19
+ "cli",
20
+ "scaffold",
21
+ "generator",
22
+ "project"
23
+ ],
24
+ "scripts": {
25
+ "start": "node bin/projectcli.js",
26
+ "lint": "node -c bin/projectcli.js && node -c src/index.js && node -c src/registry.js && node -c src/run.js"
27
+ },
28
+ "dependencies": {
29
+ "inquirer": "^9.2.23",
30
+ "inquirer-autocomplete-prompt": "^3.0.1"
31
+ }
32
+ }
package/src/add.js ADDED
@@ -0,0 +1,263 @@
1
+ const fs = require("node:fs");
2
+ const path = require("node:path");
3
+
4
+ const { detectLanguage, detectPackageManager } = require("./detect");
5
+ const { getCatalog } = require("./libraries");
6
+ const { pmAddCommand, pmExecCommand } = require("./pm");
7
+ const { runSteps } = require("./run");
8
+
9
+ function uniq(arr) {
10
+ return Array.from(new Set(arr));
11
+ }
12
+
13
+ function parseAddArgs(argv) {
14
+ const out = { yes: false, dryRun: false };
15
+ const args = Array.isArray(argv) ? argv : [];
16
+ for (const a of args) {
17
+ if (a === "--yes" || a === "-y") out.yes = true;
18
+ else if (a === "--dry-run") out.dryRun = true;
19
+ }
20
+ return out;
21
+ }
22
+
23
+ function printStepsPreview(steps) {
24
+ console.log("\nPlanned actions:");
25
+ for (const step of steps) {
26
+ const type = step.type || "command";
27
+ if (type === "command") {
28
+ const where = step.cwdFromProjectRoot ? "(in project)" : "(here)";
29
+ console.log(`- ${step.program} ${step.args.join(" ")} ${where}`);
30
+ } else if (type === "mkdir") {
31
+ console.log(`- mkdir -p ${step.path}`);
32
+ } else if (type === "writeFile") {
33
+ console.log(`- write ${step.path}`);
34
+ } else {
35
+ console.log(`- ${type}`);
36
+ }
37
+ }
38
+ console.log("");
39
+ }
40
+
41
+ async function runAdd({ prompt, argv }) {
42
+ const flags = parseAddArgs(argv);
43
+ const cwd = process.cwd();
44
+ const language = detectLanguage(cwd);
45
+ const pm = detectPackageManager(cwd);
46
+
47
+ if (language === "Unknown") {
48
+ throw new Error(
49
+ "Couldn't detect project type here. Run inside a project folder (package.json, pyproject.toml, go.mod, etc.)."
50
+ );
51
+ }
52
+
53
+ console.log(`\nDetected project: ${language}`);
54
+ if (language === "JavaScript/TypeScript") {
55
+ console.log(`Detected package manager: ${pm}`);
56
+ }
57
+
58
+ const catalog = getCatalog(language);
59
+ const categories = Object.keys(catalog);
60
+ if (categories.length === 0) {
61
+ throw new Error(`No library catalog configured for: ${language}`);
62
+ }
63
+
64
+ const BACK = "__back__";
65
+ const EXIT = "__exit__";
66
+
67
+ let selectedCategory = null;
68
+ let selectedLabels = null;
69
+
70
+ while (true) {
71
+ if (!selectedCategory) {
72
+ const categoryChoices = [
73
+ ...categories.map((c) => ({
74
+ name: `${c} (${catalog[c].length})`,
75
+ value: c,
76
+ })),
77
+ new (require("inquirer").Separator)(),
78
+ { name: "Exit", value: EXIT },
79
+ ];
80
+
81
+ const { category } = await prompt([
82
+ {
83
+ type: "list",
84
+ name: "category",
85
+ message: "Category:",
86
+ choices: categoryChoices,
87
+ pageSize: 14,
88
+ },
89
+ ]);
90
+
91
+ if (category === EXIT) return;
92
+ selectedCategory = category;
93
+ continue;
94
+ }
95
+
96
+ if (!selectedLabels) {
97
+ const items = catalog[selectedCategory] || [];
98
+ const { picks } = await prompt([
99
+ {
100
+ type: "checkbox",
101
+ name: "picks",
102
+ message: "Select libraries (space to toggle):",
103
+ choices: items.map((i) => ({ name: i.label, value: i.label })),
104
+ validate: (v) =>
105
+ v && v.length ? true : "Pick at least one library.",
106
+ pageSize: 14,
107
+ },
108
+ ]);
109
+
110
+ selectedLabels = picks;
111
+
112
+ const { next } = await prompt([
113
+ {
114
+ type: "list",
115
+ name: "next",
116
+ message: "Next:",
117
+ choices: [
118
+ { name: "Continue", value: "continue" },
119
+ { name: "← Back", value: BACK },
120
+ { name: "Cancel", value: EXIT },
121
+ ],
122
+ pageSize: 8,
123
+ },
124
+ ]);
125
+
126
+ if (next === EXIT) return;
127
+ if (next === BACK) {
128
+ selectedLabels = null;
129
+ selectedCategory = null;
130
+ continue;
131
+ }
132
+
133
+ // continue
134
+ }
135
+
136
+ const items = catalog[selectedCategory] || [];
137
+ const chosen = items.filter((i) => selectedLabels.includes(i.label));
138
+
139
+ const packages = uniq(chosen.flatMap((i) => i.packages || []));
140
+ const packagesDev = uniq(chosen.flatMap((i) => i.packagesDev || []));
141
+ const posts = uniq(chosen.map((i) => i.post).filter(Boolean));
142
+
143
+ const steps = [];
144
+
145
+ if (language === "JavaScript/TypeScript") {
146
+ if (!fs.existsSync(path.join(cwd, "package.json"))) {
147
+ throw new Error(
148
+ "No package.json found; run this inside a JS/TS project."
149
+ );
150
+ }
151
+
152
+ if (packages.length) {
153
+ const cmd = pmAddCommand(pm, packages, { dev: false });
154
+ steps.push({ type: "command", ...cmd, cwdFromProjectRoot: true });
155
+ }
156
+ if (packagesDev.length) {
157
+ const cmd = pmAddCommand(pm, packagesDev, { dev: true });
158
+ steps.push({ type: "command", ...cmd, cwdFromProjectRoot: true });
159
+ }
160
+
161
+ // Optional post-steps
162
+ for (const post of posts) {
163
+ if (post === "tailwind-init") {
164
+ const cmd = pmExecCommand(pm, "tailwindcss", ["init", "-p"]);
165
+ steps.push({ type: "command", ...cmd, cwdFromProjectRoot: true });
166
+ }
167
+ if (post === "playwright-install") {
168
+ const cmd = pmExecCommand(pm, "playwright", ["install"]);
169
+ steps.push({ type: "command", ...cmd, cwdFromProjectRoot: true });
170
+ }
171
+ if (post === "shadcn-init") {
172
+ // shadcn/ui uses a CLI; keep it interactive.
173
+ const cmd = pmExecCommand(pm, "shadcn@latest", ["init"]);
174
+ steps.push({ type: "command", ...cmd, cwdFromProjectRoot: true });
175
+ }
176
+ }
177
+
178
+ if (flags.dryRun) {
179
+ printStepsPreview(steps);
180
+ console.log("Dry run: nothing executed.");
181
+ return;
182
+ }
183
+
184
+ if (!flags.yes) {
185
+ const { ok } = await prompt([
186
+ {
187
+ type: "confirm",
188
+ name: "ok",
189
+ message: "Install selected libraries now?",
190
+ default: true,
191
+ },
192
+ ]);
193
+ if (!ok) {
194
+ selectedLabels = null;
195
+ continue;
196
+ }
197
+ }
198
+
199
+ await runSteps(steps, { projectRoot: cwd });
200
+ console.log("\nDone. Libraries added.");
201
+ return;
202
+ }
203
+
204
+ if (language === "Python") {
205
+ const all = uniq([...packages, ...packagesDev]);
206
+ const { mode } = await prompt([
207
+ {
208
+ type: "list",
209
+ name: "mode",
210
+ message: "How to add Python packages?",
211
+ choices: [
212
+ {
213
+ name: "Append to requirements.txt (no install)",
214
+ value: "requirements",
215
+ },
216
+ {
217
+ name: "pip install now (and append requirements.txt)",
218
+ value: "pip",
219
+ },
220
+ ],
221
+ default: "requirements",
222
+ },
223
+ ]);
224
+
225
+ const reqPath = path.join(cwd, "requirements.txt");
226
+ const toAppend = all.map((p) => `${p}\n`).join("");
227
+
228
+ if (flags.dryRun) {
229
+ console.log("\nPlanned actions:");
230
+ if (mode === "pip") {
231
+ console.log(`- python -m pip install ${all.join(" ")} (here)`);
232
+ }
233
+ console.log(`- append requirements.txt: ${all.join(", ")}`);
234
+ console.log("\nDry run: nothing executed.");
235
+ return;
236
+ }
237
+
238
+ if (mode === "pip") {
239
+ await runSteps(
240
+ [
241
+ {
242
+ type: "command",
243
+ program: "python",
244
+ args: ["-m", "pip", "install", ...all],
245
+ cwdFromProjectRoot: true,
246
+ },
247
+ ],
248
+ { projectRoot: cwd }
249
+ );
250
+ }
251
+
252
+ fs.appendFileSync(reqPath, toAppend, "utf8");
253
+ console.log("\nDone. Updated requirements.txt");
254
+ return;
255
+ }
256
+
257
+ throw new Error(`Add mode not implemented yet for: ${language}`);
258
+ }
259
+ }
260
+
261
+ module.exports = {
262
+ runAdd,
263
+ };
package/src/detect.js ADDED
@@ -0,0 +1,44 @@
1
+ const fs = require("node:fs");
2
+ const path = require("node:path");
3
+
4
+ function exists(cwd, rel) {
5
+ return fs.existsSync(path.join(cwd, rel));
6
+ }
7
+
8
+ function detectPackageManager(cwd) {
9
+ if (exists(cwd, "pnpm-lock.yaml")) return "pnpm";
10
+ if (exists(cwd, "yarn.lock")) return "yarn";
11
+ if (exists(cwd, "bun.lockb") || exists(cwd, "bun.lock")) return "bun";
12
+ if (exists(cwd, "package-lock.json")) return "npm";
13
+ // fallback
14
+ return "npm";
15
+ }
16
+
17
+ function detectLanguage(cwd) {
18
+ if (exists(cwd, "package.json")) return "JavaScript/TypeScript";
19
+ if (exists(cwd, "pyproject.toml") || exists(cwd, "requirements.txt"))
20
+ return "Python";
21
+ if (exists(cwd, "go.mod")) return "Go";
22
+ if (exists(cwd, "Cargo.toml")) return "Rust";
23
+ if (exists(cwd, "composer.json")) return "PHP";
24
+ if (
25
+ exists(cwd, "pom.xml") ||
26
+ exists(cwd, "build.gradle") ||
27
+ exists(cwd, "build.gradle.kts")
28
+ )
29
+ return "Java/Kotlin";
30
+ if (
31
+ fs.readdirSync(cwd).some((f) => f.endsWith(".csproj") || f.endsWith(".sln"))
32
+ )
33
+ return "C#";
34
+ if (exists(cwd, "pubspec.yaml")) return "Dart";
35
+ if (exists(cwd, "Gemfile")) return "Ruby";
36
+ if (exists(cwd, "Package.swift")) return "Swift";
37
+ if (exists(cwd, "CMakeLists.txt")) return "C++";
38
+ return "Unknown";
39
+ }
40
+
41
+ module.exports = {
42
+ detectLanguage,
43
+ detectPackageManager,
44
+ };