@dhruvinjs/appinit 1.0.1 → 1.0.2

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 +12 -0
  2. package/dist/index.js +17 -12
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -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
@@ -167,15 +168,19 @@ Examples:
167
168
  && flagConfig.language === "js") {
168
169
  console.warn("⚠️ Warning: JavaScript does not work properly with PostgreSQL (Prisma). Consider using TypeScript.");
169
170
  }
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);
171
+ const selectedProjectName = projectName
172
+ ? projectName
173
+ : (await inquirer.prompt([
174
+ {
175
+ type: "input",
176
+ name: "name",
177
+ message: "Project Name",
178
+ default: generateRandomNames(),
179
+ },
180
+ ])).name;
181
+ const normalizedProjectName = selectedProjectName.trim();
182
+ validateProjectName(normalizedProjectName);
183
+ let project_path = getSafeProjectPath(normalizedProjectName);
179
184
  // console.log(project_path);
180
185
  // Only prompt for template if not provided via flags
181
186
  const templateSelection = flagConfig.template
@@ -291,7 +296,7 @@ Examples:
291
296
  await setup_restApi_project({
292
297
  db: fullConfig.database,
293
298
  path: project_path,
294
- name: answer.name,
299
+ name: normalizedProjectName,
295
300
  language: fullConfig.language,
296
301
  template: fullConfig.template,
297
302
  websocket_package: fullConfig.websocket_package,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhruvinjs/appinit",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",