create-cubing-app 0.36.4 → 0.43.5-b
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/bin/create-cubing-app.js +38 -83
- package/package.json +6 -5
- package/script/roll-cubing-commit.bash +2 -0
- package/script/build.js +0 -26
- package/tsconfig.json +0 -8
package/bin/create-cubing-app.js
CHANGED
|
@@ -1,66 +1,54 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { exec } from "child_process";
|
|
3
3
|
import { exists } from "fs";
|
|
4
|
-
import { mkdir, readFile, stat, writeFile } from "fs/promises";
|
|
4
|
+
import { cp, mkdir, readFile, stat, writeFile } from "fs/promises";
|
|
5
5
|
import { join, resolve } from "path";
|
|
6
6
|
import { exit, stderr } from "process";
|
|
7
7
|
import { createInterface } from "readline";
|
|
8
8
|
import { promisify } from "util";
|
|
9
9
|
|
|
10
|
-
const CREATE_CUBING_APP_PACKAGE_JSON = JSON.parse(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (error) {
|
|
16
|
-
reject(error);
|
|
17
|
-
}
|
|
18
|
-
// console.log(stdout);
|
|
19
|
-
resolve(stdout ? stdout : stderr);
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
}
|
|
10
|
+
const CREATE_CUBING_APP_PACKAGE_JSON = JSON.parse(
|
|
11
|
+
await readFile(new URL("../package.json", import.meta.url), "utf-8"),
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
const execPromise = promisify(exec);
|
|
23
15
|
|
|
24
16
|
function printHelpAndExit() {
|
|
25
|
-
|
|
17
|
+
stderr.write(`Usage:
|
|
26
18
|
|
|
27
19
|
npm create cubing-app <project folder name>
|
|
28
20
|
|
|
29
21
|
The project folder name should consist of only letters, numbers, dashes, and u
|
|
30
22
|
nderscores.
|
|
31
23
|
`);
|
|
32
|
-
|
|
24
|
+
exit(1);
|
|
33
25
|
}
|
|
34
26
|
|
|
35
27
|
let projectPath = process.argv[2];
|
|
36
28
|
if (!projectPath) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
29
|
+
const readline = createInterface({
|
|
30
|
+
input: process.stdin,
|
|
31
|
+
output: process.stdout,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
projectPath = await new Promise((resolve, reject) => {
|
|
35
|
+
try {
|
|
36
|
+
readline.question(
|
|
37
|
+
`Where would you like to place the project?
|
|
46
38
|
(Enter a path or name for a new folder.)
|
|
47
39
|
`,
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function projectPathed(path) {
|
|
63
|
-
return join(projectPath, path);
|
|
40
|
+
resolve,
|
|
41
|
+
);
|
|
42
|
+
} catch (e) {
|
|
43
|
+
reject(e);
|
|
44
|
+
} finally {
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
readline.close();
|
|
48
|
+
if (projectPath === "") {
|
|
49
|
+
console.log("Please enter a non-empty project path.");
|
|
50
|
+
exit(1);
|
|
51
|
+
}
|
|
64
52
|
}
|
|
65
53
|
|
|
66
54
|
console.log(`---------------------------------
|
|
@@ -71,53 +59,20 @@ ${projectPath}
|
|
|
71
59
|
// We could uses `stat` from `"fs/promises"`, but I'm not too enthused about
|
|
72
60
|
// catching an error in the "expected" path. So we use `exists`.
|
|
73
61
|
if (await promisify(exists)(projectPath)) {
|
|
74
|
-
|
|
62
|
+
process.stderr.write(`Project already exists in the current folder: ${projectPath}
|
|
75
63
|
Please select a different name (or delete the existing project folder).
|
|
76
64
|
`);
|
|
77
|
-
|
|
65
|
+
exit(1);
|
|
78
66
|
}
|
|
79
67
|
await mkdir(projectPath, { recursive: true });
|
|
80
68
|
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
},
|
|
89
|
-
};
|
|
90
|
-
await writeFile(
|
|
91
|
-
projectPathed("package.json"),
|
|
92
|
-
JSON.stringify(initialPackageJSON, null, " "),
|
|
93
|
-
);
|
|
94
|
-
|
|
95
|
-
const execOptions = {
|
|
96
|
-
cwd: projectPath,
|
|
97
|
-
};
|
|
98
|
-
await mkdir(projectPathed("script"), { recursive: true });
|
|
99
|
-
await mkdir(projectPathed("src"), { recursive: true });
|
|
100
|
-
async function transferFile(rootedPath, contents) {
|
|
101
|
-
contents ??= await (async () => {
|
|
102
|
-
const filePath = new URL(join("..", rootedPath), import.meta.url);
|
|
103
|
-
return readFile(filePath, "utf-8");
|
|
104
|
-
})();
|
|
105
|
-
await writeFile(projectPathed(rootedPath), contents);
|
|
106
|
-
}
|
|
107
|
-
await transferFile("script/build.js");
|
|
108
|
-
await transferFile("src/index.html");
|
|
109
|
-
await transferFile("src/main.ts");
|
|
110
|
-
await transferFile("src/index.css");
|
|
111
|
-
await transferFile(
|
|
112
|
-
".gitignore",
|
|
113
|
-
`/dist
|
|
114
|
-
/node_modules
|
|
115
|
-
`,
|
|
116
|
-
);
|
|
117
|
-
await transferFile("tsconfig.json");
|
|
118
|
-
|
|
119
|
-
await execPromise("npm install --save cubing", execOptions);
|
|
120
|
-
await execPromise("npm install --save-dev barely-a-dev-server", execOptions);
|
|
69
|
+
const appTemplatePath = new URL("../app-template", import.meta.url).pathname;
|
|
70
|
+
await cp(appTemplatePath, projectPath, {
|
|
71
|
+
recursive: true,
|
|
72
|
+
});
|
|
73
|
+
await execPromise("npm install", {
|
|
74
|
+
cwd: projectPath,
|
|
75
|
+
});
|
|
121
76
|
|
|
122
77
|
console.log(`Your cubing app has been created.
|
|
123
78
|
To work on it, run:
|
package/package.json
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-cubing-app",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.43.5-b",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": "./bin/create-cubing-app.js",
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": ">=19"
|
|
8
|
+
},
|
|
6
9
|
"scripts": {
|
|
7
|
-
"
|
|
8
|
-
"dev": "node script/build.js -- --dev",
|
|
9
|
-
"roll-cubing-commit": "./script/roll-cubing-commit.bash",
|
|
10
|
-
"clean": "rm -rf ./dist"
|
|
10
|
+
"prepublish-only": "prepublish-only"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"cubing": "^0.43.4"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
|
+
"@biomejs/biome": "^1.2.2",
|
|
16
17
|
"@types/validate-npm-package-name": "^4.0.0",
|
|
17
18
|
"barely-a-dev-server": "^0.6.0",
|
|
18
19
|
"esbuild": "^0.19.2",
|
package/script/build.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import {barelyServe} from "barely-a-dev-server";
|
|
4
|
-
|
|
5
|
-
export const COMMON_BUILD_OPTIONS = {
|
|
6
|
-
entryRoot: "./src",
|
|
7
|
-
esbuildOptions: {chunkNames: "chunks/[name]-[hash]"}
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
if (process.argv.at(-1) === "--dev") {
|
|
11
|
-
|
|
12
|
-
barelyServe(COMMON_BUILD_OPTIONS);
|
|
13
|
-
|
|
14
|
-
} else {
|
|
15
|
-
|
|
16
|
-
const outDir = "./dist/web";
|
|
17
|
-
await barelyServe({
|
|
18
|
-
...COMMON_BUILD_OPTIONS,
|
|
19
|
-
dev: false,
|
|
20
|
-
outDir,
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
console.log(`
|
|
24
|
-
Your app has been built in: ${outDir}
|
|
25
|
-
`)
|
|
26
|
-
}
|