@dhruvinjs/appinit 1.0.1 → 1.0.4

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.
Files changed (3) hide show
  1. package/README.md +13 -1
  2. package/dist/index.js +51 -13
  3. package/package.json +5 -5
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @dhruvinjs/appinit
2
2
 
3
- Backend project generator CLI.
3
+ Express backend starter with optional WebSocket, DB, and Docker support.
4
4
 
5
5
  This package creates an Express-based backend starter with optional WebSocket support (`ws` or `socket.io`), optional DB setup (`mongo` or `postgresql_prisma`), and optional Dockerfile generation.
6
6
 
@@ -10,6 +10,12 @@ This package creates an Express-based backend starter with optional WebSocket su
10
10
  npx @dhruvinjs/appinit my-app
11
11
  ```
12
12
 
13
+ You can also run without a name and choose it in prompts:
14
+
15
+ ```bash
16
+ npx @dhruvinjs/appinit
17
+ ```
18
+
13
19
  or install globally:
14
20
 
15
21
  ```bash
@@ -17,6 +23,12 @@ npm i -g @dhruvinjs/appinit
17
23
  appinit my-app
18
24
  ```
19
25
 
26
+ Global command also supports no name:
27
+
28
+ ```bash
29
+ appinit
30
+ ```
31
+
20
32
  ## What this CLI actually does
21
33
 
22
34
  Source entrypoint: `src/index.ts`.
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import { Command } from "commander";
3
3
  const program = new Command();
4
4
  import inquirer from "inquirer";
5
- import { checkEnv, generateRandomNames, getSafeProjectPath, isToolInstalled, } from "./utils/utils.js";
5
+ import { checkEnv, generateRandomNames, getSafeProjectPath, isToolInstalled, validateProjectName, } from "./utils/utils.js";
6
6
  import { setup_restApi_project } from "./generator/shell.js";
7
7
  import { package_manager_env, db_deps_dev, template_flags, } from "./constants.js";
8
8
  function validateRawFlags(args) {
@@ -33,6 +33,7 @@ program
33
33
  .name("appinit")
34
34
  .description("Generate production-ready backend projects")
35
35
  .version("1.0.0")
36
+ .argument("[projectName]", "Project name (optional). Prompts if omitted.")
36
37
  // Preset flags
37
38
  .option("--ts", "TypeScript + REST API (default template)")
38
39
  .option("--js", "JavaScript + REST API (default template)")
@@ -59,7 +60,7 @@ Examples:
59
60
  $ appinit my-app --js-ws --db none --no-git
60
61
  $ appinit my-app --template rest_api --lang ts --db postgresql_prisma
61
62
  `)
62
- .action(async (options) => {
63
+ .action(async (projectName, options) => {
63
64
  try {
64
65
  // validateRawCommand(process.argv.slice(2).join(" "));
65
66
  //process.argv prints everythign you typed into the terminal like
@@ -149,6 +150,23 @@ Examples:
149
150
  console.error(`❌ Error: Invalid package manager "${options.pm}". Use: npm, pnpm, or yarn`);
150
151
  process.exit(1);
151
152
  }
153
+ // Check if the specified package manager is installed
154
+ if (!(await isToolInstalled(options.pm))) {
155
+ const fallbackPm = await inquirer.prompt([
156
+ {
157
+ type: "confirm",
158
+ name: "useFallback",
159
+ message: `⚠️ Package manager "${options.pm}" is not installed. Would you like to use npm instead?`,
160
+ default: true,
161
+ },
162
+ ]);
163
+ if (!fallbackPm.useFallback) {
164
+ console.log("❌ Cancelled: Please install the required package manager and try again.");
165
+ process.exit(0);
166
+ }
167
+ // Use npm as fallback
168
+ options.pm = "npm";
169
+ }
152
170
  }
153
171
  // Commander negated options can set defaults implicitly.
154
172
  // Only treat docker as explicitly configured when the user passed a docker flag.
@@ -167,15 +185,19 @@ Examples:
167
185
  && flagConfig.language === "js") {
168
186
  console.warn("⚠️ Warning: JavaScript does not work properly with PostgreSQL (Prisma). Consider using TypeScript.");
169
187
  }
170
- const answer = await inquirer.prompt([
171
- {
172
- type: "input",
173
- name: "name",
174
- message: "Project Name",
175
- default: generateRandomNames(),
176
- },
177
- ]);
178
- let project_path = getSafeProjectPath(answer.name);
188
+ const selectedProjectName = projectName
189
+ ? projectName
190
+ : (await inquirer.prompt([
191
+ {
192
+ type: "input",
193
+ name: "name",
194
+ message: "Project Name",
195
+ default: generateRandomNames(),
196
+ },
197
+ ])).name;
198
+ const normalizedProjectName = selectedProjectName.trim();
199
+ validateProjectName(normalizedProjectName);
200
+ let project_path = getSafeProjectPath(normalizedProjectName);
179
201
  // console.log(project_path);
180
202
  // Only prompt for template if not provided via flags
181
203
  const templateSelection = flagConfig.template
@@ -288,16 +310,32 @@ Examples:
288
310
  if (fullConfig.docker && !(await isToolInstalled("docker"))) {
289
311
  console.warn('Warning: "docker" is not installed. Dockerfile will be generated, but you cannot build/run containers until Docker is installed.');
290
312
  }
313
+ let resolvedPm = options.pm || fullConfig.packageManager || "npm";
314
+ if (!(await isToolInstalled(resolvedPm))) {
315
+ const fallbackPm = await inquirer.prompt([
316
+ {
317
+ type: "confirm",
318
+ name: "useFallback",
319
+ message: `Package manager "${resolvedPm}" is not installed. Would you like to use npm instead?`,
320
+ default: true,
321
+ },
322
+ ]);
323
+ if (!fallbackPm.useFallback) {
324
+ console.log("❌ Cancelled: Please install the required package manager and try again.");
325
+ process.exit(0);
326
+ }
327
+ resolvedPm = "npm";
328
+ }
291
329
  await setup_restApi_project({
292
330
  db: fullConfig.database,
293
331
  path: project_path,
294
- name: answer.name,
332
+ name: normalizedProjectName,
295
333
  language: fullConfig.language,
296
334
  template: fullConfig.template,
297
335
  websocket_package: fullConfig.websocket_package,
298
336
  Dockerfile: fullConfig.docker,
299
337
  skipGit: options.git === false,
300
- packageManager: options.pm || fullConfig.packageManager || "npm",
338
+ packageManager: resolvedPm,
301
339
  });
302
340
  }
303
341
  catch (error) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dhruvinjs/appinit",
3
- "version": "1.0.1",
4
- "description": "",
3
+ "version": "1.0.4",
4
+ "description": "Express backend starter with optional WebSocket, DB, and Docker support.",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
7
7
  "bin": {
@@ -23,7 +23,7 @@
23
23
  "jsonwebtoken": "^9.0.3",
24
24
  "ora": "^9.1.0",
25
25
  "unique-names-generator": "^4.7.1",
26
- "appinit-templates": "1.0.1"
26
+ "appinit-templates": "1.0.2"
27
27
  },
28
28
  "author": "dhruvinjs",
29
29
  "license": "MIT",
@@ -35,7 +35,7 @@
35
35
  },
36
36
  "scripts": {
37
37
  "test": "echo \"Error: no test specified\" && exit 1",
38
- "build": "npx tsc -b",
39
- "dev": "tsc -b && node dist/index.js"
38
+ "dev": "tsc -b && node dist/index.js",
39
+ "build": "tsc -b"
40
40
  }
41
41
  }