create-nxpress-app 1.0.5 → 1.0.7
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/dist/index.js +77 -38
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -6,12 +6,46 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
const prompts_1 = require("@clack/prompts");
|
|
8
8
|
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
const child_process_1 = require("child_process");
|
|
9
10
|
const commander_1 = require("commander");
|
|
10
11
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
11
12
|
const path_1 = __importDefault(require("path"));
|
|
12
|
-
const child_process_1 = require("child_process");
|
|
13
13
|
const util_1 = require("util");
|
|
14
14
|
const execAsync = (0, util_1.promisify)(child_process_1.exec);
|
|
15
|
+
const deps = ["@nxpress/core"];
|
|
16
|
+
const devDeps = ["@types/express", "@types/node", "typescript"];
|
|
17
|
+
function getInstallCommands(pm, depsList, devDepsList) {
|
|
18
|
+
const depsStr = depsList.join(" ");
|
|
19
|
+
const devDepsStr = devDepsList.join(" ");
|
|
20
|
+
switch (pm) {
|
|
21
|
+
case "npm":
|
|
22
|
+
return {
|
|
23
|
+
depsCmd: `npm install ${depsStr}`,
|
|
24
|
+
devDepsCmd: `npm install -D ${devDepsStr}`,
|
|
25
|
+
};
|
|
26
|
+
case "yarn":
|
|
27
|
+
return {
|
|
28
|
+
depsCmd: `yarn add ${depsStr}`,
|
|
29
|
+
devDepsCmd: `yarn add -D ${devDepsStr}`,
|
|
30
|
+
};
|
|
31
|
+
case "bun":
|
|
32
|
+
return {
|
|
33
|
+
depsCmd: `bun add ${depsStr}`,
|
|
34
|
+
devDepsCmd: `bun add -d ${devDepsStr}`,
|
|
35
|
+
};
|
|
36
|
+
case "deno":
|
|
37
|
+
return {
|
|
38
|
+
depsCmd: `deno add ${depsStr}`,
|
|
39
|
+
devDepsCmd: `deno add -D ${devDepsStr}`,
|
|
40
|
+
};
|
|
41
|
+
case "pnpm":
|
|
42
|
+
default:
|
|
43
|
+
return {
|
|
44
|
+
depsCmd: `pnpm add ${depsStr}`,
|
|
45
|
+
devDepsCmd: `pnpm add -D ${devDepsStr}`,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
15
49
|
const program = new commander_1.Command();
|
|
16
50
|
program
|
|
17
51
|
.name("create-nxpress-app")
|
|
@@ -23,7 +57,7 @@ program
|
|
|
23
57
|
.option("--app-dir <dir>", "Directory for application routes")
|
|
24
58
|
.option("--components-dir <dir>", "Directory for components")
|
|
25
59
|
.option("--public-dir <dir>", "Directory for static assets")
|
|
26
|
-
.option("--
|
|
60
|
+
.option("--pkg-manager <pm>", "Package manager (pnpm, npm, yarn, bun, deno)")
|
|
27
61
|
.action(async (projectDirArg, options) => {
|
|
28
62
|
console.log();
|
|
29
63
|
(0, prompts_1.intro)(chalk_1.default.bgCyan.black(" Create Nxpress App "));
|
|
@@ -135,17 +169,27 @@ program
|
|
|
135
169
|
publicDirName = pubRes;
|
|
136
170
|
}
|
|
137
171
|
}
|
|
138
|
-
let
|
|
139
|
-
if (
|
|
140
|
-
const
|
|
141
|
-
message: "
|
|
142
|
-
|
|
172
|
+
let pkgManager = options.pkgManager;
|
|
173
|
+
if (process.stdin.isTTY && !options.pkgManager) {
|
|
174
|
+
const selectedPm = await (0, prompts_1.select)({
|
|
175
|
+
message: "Which package manager do you want to use?",
|
|
176
|
+
options: [
|
|
177
|
+
{ value: "pnpm", label: "pnpm (Default)", hint: "Fast & disk space efficient" },
|
|
178
|
+
{ value: "npm", label: "npm", hint: "Default Node.js package manager" },
|
|
179
|
+
{ value: "yarn", label: "yarn", hint: "Classic/Berry package manager" },
|
|
180
|
+
{ value: "bun", label: "bun", hint: "Ultra-fast runtime & package manager" },
|
|
181
|
+
{ value: "deno", label: "deno", hint: "Modern JavaScript/TypeScript runtime" },
|
|
182
|
+
],
|
|
183
|
+
initialValue: "pnpm",
|
|
143
184
|
});
|
|
144
|
-
if ((0, prompts_1.isCancel)(
|
|
185
|
+
if ((0, prompts_1.isCancel)(selectedPm)) {
|
|
145
186
|
(0, prompts_1.cancel)("Operation cancelled.");
|
|
146
187
|
process.exit(0);
|
|
147
188
|
}
|
|
148
|
-
|
|
189
|
+
pkgManager = selectedPm;
|
|
190
|
+
}
|
|
191
|
+
if (!pkgManager) {
|
|
192
|
+
pkgManager = "pnpm";
|
|
149
193
|
}
|
|
150
194
|
const s = (0, prompts_1.spinner)();
|
|
151
195
|
s.start("Scaffolding project...");
|
|
@@ -198,7 +242,7 @@ program
|
|
|
198
242
|
// Index page
|
|
199
243
|
const indexPageContent = engine === "handlebars"
|
|
200
244
|
? `<div class="max-w-4xl mx-auto px-4 py-16 text-center">
|
|
201
|
-
<h1 class="text-5xl font-bold mb-4 bg-
|
|
245
|
+
<h1 class="text-5xl font-bold mb-4 bg-linear-to-r from-blue-400 to-indigo-500 bg-clip-text text-transparent">
|
|
202
246
|
Welcome to {{title}}
|
|
203
247
|
</h1>
|
|
204
248
|
<p class="text-xl text-slate-400 mb-8">{{description}}</p>
|
|
@@ -208,7 +252,7 @@ program
|
|
|
208
252
|
</div>`
|
|
209
253
|
: engine === "ejs"
|
|
210
254
|
? `<div class="max-w-4xl mx-auto px-4 py-16 text-center">
|
|
211
|
-
<h1 class="text-5xl font-bold mb-4 bg-
|
|
255
|
+
<h1 class="text-5xl font-bold mb-4 bg-linear-to-r from-blue-400 to-indigo-500 bg-clip-text text-transparent">
|
|
212
256
|
Welcome to <%= title %>
|
|
213
257
|
</h1>
|
|
214
258
|
<p class="text-xl text-slate-400 mb-8"><%= description %></p>
|
|
@@ -217,14 +261,14 @@ program
|
|
|
217
261
|
</div>
|
|
218
262
|
</div>`
|
|
219
263
|
: `<div class="max-w-4xl mx-auto px-4 py-16 text-center">
|
|
220
|
-
<h1 class="text-5xl font-bold mb-4 bg-
|
|
264
|
+
<h1 class="text-5xl font-bold mb-4 bg-linear-to-r from-blue-400 to-indigo-500 bg-clip-text text-transparent">
|
|
221
265
|
Welcome to Nxpress
|
|
222
266
|
</h1>
|
|
223
267
|
<p class="text-xl text-slate-400 mb-8">Express.js with Next.js developer experience</p>
|
|
224
268
|
</div>`;
|
|
225
269
|
fs_extra_1.default.writeFileSync(path_1.default.join(appDir, `index.${ext}`), indexPageContent);
|
|
226
270
|
// Data loader for index page
|
|
227
|
-
const indexTsContent = `import
|
|
271
|
+
const indexTsContent = `import { Request, Response } from "express";
|
|
228
272
|
|
|
229
273
|
export async function props(req: Request, res: Response) {
|
|
230
274
|
return {
|
|
@@ -235,7 +279,7 @@ export async function props(req: Request, res: Response) {
|
|
|
235
279
|
`;
|
|
236
280
|
fs_extra_1.default.writeFileSync(path_1.default.join(appDir, "index.ts"), indexTsContent);
|
|
237
281
|
// App CSS for Tailwind v4
|
|
238
|
-
fs_extra_1.default.writeFileSync(path_1.default.join(targetPath, "app.css"), `@import "tailwindcss";\n`);
|
|
282
|
+
fs_extra_1.default.writeFileSync(path_1.default.join(targetPath, "app.css"), `@import "tailwindcss";\n@import "tailwindcss/preflight";\n@tailwind utilities;\n`);
|
|
239
283
|
// Server file
|
|
240
284
|
const serverTsContent = `import { nxpress } from '@nxpress/core';
|
|
241
285
|
|
|
@@ -249,10 +293,9 @@ app.listen(PORT, () => {
|
|
|
249
293
|
});
|
|
250
294
|
`;
|
|
251
295
|
fs_extra_1.default.writeFileSync(path_1.default.join(targetPath, "server.ts"), serverTsContent);
|
|
252
|
-
const pkgVersion = "1.0.4";
|
|
253
296
|
// nxpress.config.json
|
|
254
297
|
const nxConfig = {
|
|
255
|
-
$schema: `https://unpkg.com/@nxpress/core
|
|
298
|
+
$schema: `https://unpkg.com/@nxpress/core@latest/schema.json`,
|
|
256
299
|
port,
|
|
257
300
|
engine: engine === "handlebars" ? "hbs" : engine,
|
|
258
301
|
appDir: appDirName,
|
|
@@ -270,26 +313,21 @@ app.listen(PORT, () => {
|
|
|
270
313
|
build: "tsc",
|
|
271
314
|
start: "nxpress start",
|
|
272
315
|
},
|
|
273
|
-
dependencies: {
|
|
274
|
-
"@nxpress/core": `^${pkgVersion}`,
|
|
275
|
-
},
|
|
276
|
-
devDependencies: {
|
|
277
|
-
typescript: "^5.3.3",
|
|
278
|
-
"@types/node": "^20.11.24",
|
|
279
|
-
},
|
|
280
316
|
};
|
|
281
317
|
fs_extra_1.default.writeFileSync(path_1.default.join(targetPath, "package.json"), JSON.stringify(projectPkgJson, null, 2));
|
|
282
318
|
// tsconfig.json for target project
|
|
283
319
|
const projectTsConfig = {
|
|
284
320
|
compilerOptions: {
|
|
285
|
-
target: "
|
|
286
|
-
module: "
|
|
287
|
-
moduleResolution: "
|
|
321
|
+
target: "esnext",
|
|
322
|
+
module: "nodenext",
|
|
323
|
+
moduleResolution: "nodenext",
|
|
288
324
|
strict: true,
|
|
289
325
|
esModuleInterop: true,
|
|
290
326
|
skipLibCheck: true,
|
|
327
|
+
types: ["node", "express"],
|
|
291
328
|
},
|
|
292
|
-
include: ["
|
|
329
|
+
include: ["**/*.ts"],
|
|
330
|
+
exclude: ["node_modules", "dist"],
|
|
293
331
|
};
|
|
294
332
|
fs_extra_1.default.writeFileSync(path_1.default.join(targetPath, "tsconfig.json"), JSON.stringify(projectTsConfig, null, 2));
|
|
295
333
|
// .gitignore
|
|
@@ -300,20 +338,21 @@ dist
|
|
|
300
338
|
`;
|
|
301
339
|
fs_extra_1.default.writeFileSync(path_1.default.join(targetPath, ".gitignore"), gitignoreContent);
|
|
302
340
|
s.stop("Project structure created successfully.");
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
341
|
+
const instSpinner = (0, prompts_1.spinner)();
|
|
342
|
+
instSpinner.start(`Installing dependencies with ${pkgManager}...`);
|
|
343
|
+
try {
|
|
344
|
+
const { depsCmd, devDepsCmd } = getInstallCommands(pkgManager, deps, devDeps);
|
|
345
|
+
await execAsync(depsCmd, { cwd: targetPath });
|
|
346
|
+
await execAsync(devDepsCmd, { cwd: targetPath });
|
|
347
|
+
instSpinner.stop("Dependencies installed successfully.");
|
|
348
|
+
}
|
|
349
|
+
catch (err) {
|
|
350
|
+
instSpinner.stop("Failed to install dependencies automatically.");
|
|
313
351
|
}
|
|
352
|
+
const devCmd = pkgManager === "npm" ? "npm run dev" : `${pkgManager} dev`;
|
|
314
353
|
(0, prompts_1.outro)(`Project created in ${chalk_1.default.cyan(projectDir)}!\n\n` +
|
|
315
354
|
`Next steps:\n` +
|
|
316
355
|
` ${chalk_1.default.cyan(`cd ${projectDir}`)}\n` +
|
|
317
|
-
` ${chalk_1.default.cyan(
|
|
356
|
+
` ${chalk_1.default.cyan(devCmd)}`);
|
|
318
357
|
});
|
|
319
358
|
program.parse(process.argv);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-nxpress-app",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "CLI tool to create Nxpress applications",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -22,15 +22,15 @@
|
|
|
22
22
|
],
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@clack/prompts": "^
|
|
26
|
-
"chalk": "^
|
|
27
|
-
"commander": "^
|
|
28
|
-
"fs-extra": "^11.
|
|
25
|
+
"@clack/prompts": "^1.7.0",
|
|
26
|
+
"chalk": "^6.0.0",
|
|
27
|
+
"commander": "^15.0.0",
|
|
28
|
+
"fs-extra": "^11.4.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@types/fs-extra": "^11.0.4",
|
|
32
|
-
"@types/node": "^
|
|
33
|
-
"typescript": "^
|
|
32
|
+
"@types/node": "^26.1.1",
|
|
33
|
+
"typescript": "^7.0.2"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
36
|
"build": "tsc",
|