create-nxpage-app 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.
Files changed (2) hide show
  1. package/index.js +76 -0
  2. package/package.json +8 -0
package/index.js ADDED
@@ -0,0 +1,76 @@
1
+ import { spawnSync } from "child_process";
2
+ import fs from "fs";
3
+ import path from "path";
4
+
5
+ const args = process.argv.slice(2);
6
+ const project = args[0];
7
+
8
+ if (!project || project === "--help" || project === "-h") {
9
+ console.log(`
10
+ Create a new NxPage app
11
+
12
+ Usage:
13
+ create-nxpage-app <project-name>
14
+
15
+ Example:
16
+ create-nxpage-app my-site
17
+ `);
18
+ process.exit(0);
19
+ }
20
+
21
+ if (fs.existsSync(project)) {
22
+ console.error(`Error: folder "${project}" already exists`);
23
+ process.exit(1);
24
+ }
25
+
26
+ console.log(`\nCreating NxPage.js project "${project}"...\n`);
27
+
28
+ const createResult = spawnSync(
29
+ "npx",
30
+ ["create-next-app@latest", project, "--use-pnpm"],
31
+ { stdio: "inherit" }
32
+ );
33
+
34
+ if (createResult.status !== 0) {
35
+ console.error("Failed to create Next.js app");
36
+ process.exit(1);
37
+ }
38
+
39
+ console.log("\nInstalling NxPage...\n");
40
+
41
+ const installResult = spawnSync(
42
+ "pnpm",
43
+ ["add", "nxpage"],
44
+ { cwd: project, stdio: "inherit" }
45
+ );
46
+
47
+ if (installResult.status !== 0) {
48
+ console.error("Failed to install nxpage");
49
+ process.exit(1);
50
+ }
51
+
52
+ const pkgPath = path.join(project, "package.json");
53
+
54
+ if (!fs.existsSync(pkgPath)) {
55
+ console.error("package.json not found");
56
+ process.exit(1);
57
+ }
58
+
59
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
60
+
61
+ pkg.scripts = {
62
+ ...pkg.scripts,
63
+ dev: "nxpage dev",
64
+ build: "nxpage build",
65
+ start: "nxpage start"
66
+ };
67
+
68
+ fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
69
+
70
+ console.log(`
71
+ NxPage project ready!
72
+
73
+ Next steps:
74
+ cd ${project}
75
+ pnpm dev
76
+ `);
package/package.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "name": "create-nxpage-app",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "bin": {
6
+ "create-nxpage-app": "./index.js"
7
+ }
8
+ }