create-cubing-app 0.35.6-rc23 → 0.35.6-rc24
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/README.md +1 -2
- package/bin/create-cubing-app.js +48 -30
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,8 +9,7 @@ See <https://js.cubing.net/cubing/> for (in-progress) documentation on `cubing.j
|
|
|
9
9
|
Make sure `node` is installed first (which will also install `npm`): <https://nodejs.org/en/download/>
|
|
10
10
|
|
|
11
11
|
```shell
|
|
12
|
-
npm create cubing-app my-cubing-project
|
|
13
|
-
|
|
12
|
+
npm create --yes cubing-app@latest my-cubing-project
|
|
14
13
|
cd my-cubing-project
|
|
15
14
|
npm run dev
|
|
16
15
|
```
|
package/bin/create-cubing-app.js
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
import { exec } from "child_process";
|
|
3
3
|
import { exists } from "fs";
|
|
4
4
|
import { mkdir, readFile, stat, writeFile } from "fs/promises";
|
|
5
|
-
import { join } from "path";
|
|
5
|
+
import { join, resolve } from "path";
|
|
6
6
|
import { exit, stderr } from "process";
|
|
7
|
+
import { createInterface } from "readline";
|
|
7
8
|
import { promisify } from "util";
|
|
8
9
|
|
|
9
10
|
function execPromise(cmd, options) {
|
|
@@ -18,44 +19,62 @@ function execPromise(cmd, options) {
|
|
|
18
19
|
});
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
cwd: new URL(".", import.meta.url),
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
function badPackageName() {
|
|
22
|
+
function printHelpAndExit() {
|
|
26
23
|
stderr.write(`Usage:
|
|
27
24
|
|
|
28
|
-
|
|
25
|
+
npm create cubing-app <project folder name>
|
|
29
26
|
|
|
30
|
-
The project folder name should consist of only letters, numbers, dashes, and
|
|
27
|
+
The project folder name should consist of only letters, numbers, dashes, and u
|
|
28
|
+
nderscores.
|
|
31
29
|
`);
|
|
32
|
-
exit(
|
|
33
|
-
}
|
|
34
|
-
const packageName = process.argv[2];
|
|
35
|
-
if (!packageName) {
|
|
36
|
-
badPackageName();
|
|
30
|
+
exit(1);
|
|
37
31
|
}
|
|
38
32
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
33
|
+
let projectPath = process.argv[2];
|
|
34
|
+
if (!projectPath) {
|
|
35
|
+
const readline = createInterface({
|
|
36
|
+
input: process.stdin,
|
|
37
|
+
output: process.stdout,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
projectPath = await new Promise((resolve, reject) => {
|
|
41
|
+
try {
|
|
42
|
+
readline.question(
|
|
43
|
+
`Where would you like to place the project?
|
|
44
|
+
(Enter a path or name for a new folder.)
|
|
45
|
+
`,
|
|
46
|
+
resolve,
|
|
47
|
+
);
|
|
48
|
+
} catch (e) {
|
|
49
|
+
reject(e);
|
|
50
|
+
} finally {
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
readline.close();
|
|
54
|
+
if (projectPath === "") {
|
|
55
|
+
console.log("Please enter a non-empty project path.");
|
|
56
|
+
exit(1);
|
|
57
|
+
}
|
|
43
58
|
}
|
|
44
59
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return join(packageRoot, path);
|
|
60
|
+
function projectPathed(path) {
|
|
61
|
+
return join(projectPath, path);
|
|
48
62
|
}
|
|
49
63
|
|
|
64
|
+
console.log(`---------------------------------
|
|
65
|
+
Creating a cubing project in the following folder:
|
|
66
|
+
${projectPath}
|
|
67
|
+
`);
|
|
68
|
+
|
|
50
69
|
// We could uses `stat` from `"fs/promises"`, but I'm not too enthused about
|
|
51
70
|
// catching an error in the "expected" path. So we use `exists`.
|
|
52
|
-
if (await promisify(exists)(
|
|
53
|
-
process.stderr.write(`Project already exists in the current folder: ${
|
|
71
|
+
if (await promisify(exists)(projectPath)) {
|
|
72
|
+
process.stderr.write(`Project already exists in the current folder: ${projectPath}
|
|
54
73
|
Please select a different name (or delete the existing project folder).
|
|
55
74
|
`);
|
|
56
75
|
exit(1);
|
|
57
76
|
}
|
|
58
|
-
await mkdir(
|
|
77
|
+
await mkdir(projectPath, { recursive: true });
|
|
59
78
|
|
|
60
79
|
const initialPackageJSON = {
|
|
61
80
|
scripts: {
|
|
@@ -67,20 +86,20 @@ const initialPackageJSON = {
|
|
|
67
86
|
},
|
|
68
87
|
};
|
|
69
88
|
await writeFile(
|
|
70
|
-
|
|
89
|
+
projectPathed("package.json"),
|
|
71
90
|
JSON.stringify(initialPackageJSON, null, " "),
|
|
72
91
|
);
|
|
73
92
|
|
|
74
93
|
const execOptions = {
|
|
75
|
-
cwd:
|
|
94
|
+
cwd: projectPath,
|
|
76
95
|
};
|
|
77
|
-
await mkdir(
|
|
96
|
+
await mkdir(projectPathed("src"), { recursive: true });
|
|
78
97
|
async function transferFile(rootedPath, contents) {
|
|
79
98
|
contents ??= await (async () => {
|
|
80
99
|
const filePath = new URL(join("..", rootedPath), import.meta.url);
|
|
81
100
|
return readFile(filePath, "utf-8");
|
|
82
101
|
})();
|
|
83
|
-
await writeFile(
|
|
102
|
+
await writeFile(projectPathed(rootedPath), contents);
|
|
84
103
|
}
|
|
85
104
|
await transferFile("src/index.html");
|
|
86
105
|
await transferFile("src/main.ts");
|
|
@@ -95,11 +114,10 @@ await transferFile(
|
|
|
95
114
|
await execPromise("npm install --save cubing", execOptions);
|
|
96
115
|
await execPromise("npm install --save-dev barely-a-dev-server", execOptions);
|
|
97
116
|
|
|
98
|
-
console.log(
|
|
99
|
-
Your cubing app has been created.
|
|
117
|
+
console.log(`Your cubing app has been created.
|
|
100
118
|
To work on it, run:
|
|
101
119
|
|
|
102
|
-
cd ${
|
|
120
|
+
cd \"${projectPath.replaceAll('"', '\\"')}\"
|
|
103
121
|
npm run dev
|
|
104
122
|
|
|
105
123
|
To create an optimized build of your app that can be uploaded to a file server, run:
|