@dhruvinjs/appinit 1.0.0 → 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 +140 -0
  2. package/dist/index.js +17 -12
  3. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,140 @@
1
+ # @dhruvinjs/appinit
2
+
3
+ Backend project generator CLI.
4
+
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
+
7
+ ## Install and run
8
+
9
+ ```bash
10
+ npx @dhruvinjs/appinit my-app
11
+ ```
12
+
13
+ You can also run without a name and choose it in prompts:
14
+
15
+ ```bash
16
+ npx @dhruvinjs/appinit
17
+ ```
18
+
19
+ or install globally:
20
+
21
+ ```bash
22
+ npm i -g @dhruvinjs/appinit
23
+ appinit my-app
24
+ ```
25
+
26
+ Global command also supports no name:
27
+
28
+ ```bash
29
+ appinit
30
+ ```
31
+
32
+ ## What this CLI actually does
33
+
34
+ Source entrypoint: `src/index.ts`.
35
+
36
+ 1. Parses flags with `commander`.
37
+ 2. Prompts with `inquirer` for missing options.
38
+ 3. Validates project name/path safety.
39
+ 4. Creates project directory and runs package-manager init.
40
+ 5. Installs runtime dependencies.
41
+ 6. Installs dev dependencies (and TypeScript setup if selected).
42
+ 7. Runs `npx prisma init` for PostgreSQL + Prisma.
43
+ 8. Optionally installs `ws` or `socket.io`.
44
+ 9. Renders EJS templates from `appinit-templates` package into your new project.
45
+ 10. Optionally initializes git.
46
+
47
+ Core implementation files:
48
+
49
+ - `src/index.ts`: CLI flags, prompts, and config assembly.
50
+ - `src/generator/shell.ts`: project setup flow and command execution.
51
+ - `src/generator/template_engine.ts`: template rendering and file mapping.
52
+ - `src/utils/utils.ts`: safety checks, package.json/tsconfig updates, cleanup.
53
+ - `src/constants.ts`: dependency lists and allowed options.
54
+
55
+ ## Templates and publishing model
56
+
57
+ This CLI resolves templates at runtime from the separate package `appinit-templates`:
58
+
59
+ - `template_engine.ts` uses `require.resolve("appinit-templates/package.json")`.
60
+ - Because of this, `appinit-templates` must be available when users install this CLI.
61
+
62
+ ## Commands this CLI runs on your machine
63
+
64
+ Depending on options, it may run:
65
+
66
+ - `<pm> init` (or `npm init -y`)
67
+ - `<pm> pkg set name=<project-name>`
68
+ - `<pm> install ...`
69
+ - `<pm> install -D ...`
70
+ - `npx tsc --init` (TypeScript path)
71
+ - `npx prisma init` (PostgreSQL + Prisma path)
72
+ - `git init` (unless `--no-git`)
73
+
74
+ It also writes files into the generated project folder and may remove that folder on setup failure/cancel.
75
+
76
+ ## Flags
77
+
78
+ Preset flags:
79
+
80
+ - `--ts`, `--js`
81
+ - `--ts-rest`, `--js-rest`
82
+ - `--ts-ws`, `--js-ws`
83
+ - `--ts-io`, `--js-io`
84
+
85
+ Granular flags:
86
+
87
+ - `--template <rest_api|websocket+rest_api>`
88
+ - `--lang <js|ts>`
89
+ - `--db <none|mongo|postgresql_prisma>`
90
+ - `--ws <ws|socket.io>`
91
+ - `--docker` / `--no-docker`
92
+ - `--pm <npm|pnpm|yarn>`
93
+ - `--no-git`
94
+
95
+ ## Dependencies and why they exist
96
+
97
+ Runtime dependencies in this package:
98
+
99
+ - `commander`: CLI argument parsing.
100
+ - `inquirer`: interactive prompts.
101
+ - `execa`: safe process spawning for package manager/git/prisma commands.
102
+ - `ora`: spinner/progress output.
103
+ - `chalk`: colored terminal output.
104
+ - `fs-extra`: file operations for templates/config updates/cleanup.
105
+ - `ejs`: template rendering engine.
106
+ - `unique-names-generator`: default project name generation.
107
+ - `appinit-templates`: source of boilerplate templates.
108
+
109
+ Direct dependencies currently listed but not used directly by CLI source:
110
+
111
+ - `express`
112
+ - `cors`
113
+ - `helmet`
114
+ - `jsonwebtoken`
115
+
116
+ These libraries are generated-project dependencies. They are installed into created apps from `src/constants.ts`, not used as runtime imports by this CLI itself.
117
+
118
+ ## Trust and safety notes
119
+
120
+ - No telemetry/analytics calls are implemented in this package.
121
+ - It executes local shell commands and installs packages from your configured registry.
122
+ - It validates project names and blocks path traversal-style names.
123
+ - On failure or Ctrl+C/Ctrl+D, it tries to clean up the generated directory.
124
+ - It warns when git/docker tools are missing (generation still continues where possible).
125
+
126
+ ## Known behavior to be aware of
127
+
128
+ - Environment check currently always verifies `npm` and `npx` are present, even if you choose `pnpm` or `yarn`.
129
+ - Template resolution requires the `appinit-templates` package to be installable.
130
+
131
+ ## Develop locally
132
+
133
+ ```bash
134
+ pnpm --filter @dhruvinjs/appinit run build
135
+ pnpm --filter @dhruvinjs/appinit run dev
136
+ ```
137
+
138
+ ## License
139
+
140
+ MIT
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.0",
3
+ "version": "1.0.2",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",