create-cubing-app 0.35.6-rc2 → 0.35.6-rc21
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 +97 -16
- package/package.json +13 -5
package/bin/create-cubing-app.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
1
2
|
import { exec } from "child_process";
|
|
2
|
-
import {
|
|
3
|
-
import { mkdir, readFile } from "fs/promises";
|
|
3
|
+
import { exists } from "fs";
|
|
4
|
+
import { mkdir, readFile, stat, writeFile } from "fs/promises";
|
|
5
|
+
import { join } from "path";
|
|
6
|
+
import { exit, stderr } from "process";
|
|
7
|
+
import { promisify } from "util";
|
|
4
8
|
|
|
5
|
-
|
|
9
|
+
function execPromise(cmd, options) {
|
|
6
10
|
return new Promise((resolve, reject) => {
|
|
7
11
|
const childProcess = exec(cmd, options, (error, stdout, stderr) => {
|
|
8
12
|
if (error) {
|
|
@@ -11,21 +15,98 @@ export function execPromise(cmd, options) {
|
|
|
11
15
|
// console.log(stdout);
|
|
12
16
|
resolve(stdout ? stdout : stderr);
|
|
13
17
|
});
|
|
14
|
-
childProcesses.push(childProcess);
|
|
15
18
|
});
|
|
16
19
|
}
|
|
17
20
|
|
|
18
|
-
execPromise("npm install
|
|
19
|
-
|
|
21
|
+
await execPromise("npm install validate-npm-package-name", {
|
|
22
|
+
cwd: new URL(".", import.meta.url),
|
|
23
|
+
});
|
|
20
24
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
function badPackageName() {
|
|
26
|
+
stderr.write(`Please specify a valid project name!
|
|
27
|
+
For example:
|
|
28
|
+
|
|
29
|
+
npm create cubing-app my-cubing-project
|
|
30
|
+
|
|
31
|
+
`);
|
|
32
|
+
exit(1);
|
|
33
|
+
}
|
|
34
|
+
const packageName = process.argv[2];
|
|
35
|
+
if (!packageName) {
|
|
36
|
+
badPackageName();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const validate = (await import("validate-npm-package-name")).default;
|
|
40
|
+
const validationResults = validate(packageName);
|
|
41
|
+
if (!validationResults.validForNewPackages) {
|
|
42
|
+
badPackageName();
|
|
28
43
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
44
|
+
|
|
45
|
+
const packageRoot = join(".", packageName);
|
|
46
|
+
function packageRooted(path) {
|
|
47
|
+
return join(packageRoot, path);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// We could uses `stat` from `"fs/promises"`, but I'm not too enthused about
|
|
51
|
+
// catching an error in the "expected" path. So we use `exists`.
|
|
52
|
+
if (await promisify(exists)(packageRoot)) {
|
|
53
|
+
process.stderr.write(`Project already exists in the current folder: ${packageRoot}
|
|
54
|
+
Please select a different name (or delete the existing project folder).
|
|
55
|
+
`);
|
|
56
|
+
exit(1);
|
|
57
|
+
}
|
|
58
|
+
await mkdir(packageRoot);
|
|
59
|
+
|
|
60
|
+
const initialPackageJSON = {
|
|
61
|
+
scripts: {
|
|
62
|
+
build:
|
|
63
|
+
"node -e 'import(\"barely-a-dev-server\").then(s => s.barelyServe({entryRoot: \"src\", dev: false, outDir: \"dist/web\"}))' && echo '' && echo 'Your app has been built in: ./dist/web' && echo ''",
|
|
64
|
+
dev: 'node -e \'import("barely-a-dev-server").then(s => s.barelyServe({entryRoot: "src"}))\'',
|
|
65
|
+
clean: "rm -rf ./dist",
|
|
66
|
+
"upgrade-cubing": "npm install cubing@latest",
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
await writeFile(
|
|
70
|
+
packageRooted("package.json"),
|
|
71
|
+
JSON.stringify(initialPackageJSON, null, " "),
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
const execOptions = {
|
|
75
|
+
cwd: packageRoot,
|
|
76
|
+
};
|
|
77
|
+
await mkdir(packageRooted("src"), { recursive: true });
|
|
78
|
+
async function transferFile(rootedPath, contents) {
|
|
79
|
+
contents ??= await (async () => {
|
|
80
|
+
const filePath = new URL(join("..", rootedPath), import.meta.url);
|
|
81
|
+
return readFile(filePath, "utf-8");
|
|
82
|
+
})();
|
|
83
|
+
await writeFile(packageRooted(rootedPath), contents);
|
|
84
|
+
}
|
|
85
|
+
await transferFile("src/index.html");
|
|
86
|
+
await transferFile("src/main.ts");
|
|
87
|
+
await transferFile("src/index.css");
|
|
88
|
+
await transferFile(
|
|
89
|
+
".gitignore",
|
|
90
|
+
`/dist
|
|
91
|
+
/node_modules
|
|
92
|
+
`,
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
await execPromise("npm install --save cubing", execOptions);
|
|
96
|
+
await execPromise("npm install --save-dev barely-a-dev-server", execOptions);
|
|
97
|
+
|
|
98
|
+
console.log(`---------------------------------
|
|
99
|
+
Your cubing app has been created.
|
|
100
|
+
To work on it, run:
|
|
101
|
+
|
|
102
|
+
cd ${packageRoot}
|
|
103
|
+
npm run dev
|
|
104
|
+
|
|
105
|
+
To create an optimized build of your app that can be uploaded to a file server, run:
|
|
106
|
+
|
|
107
|
+
npm run build
|
|
108
|
+
|
|
109
|
+
When a new version of \`cubing.js\` is released in the future, you can upgrade using:
|
|
110
|
+
|
|
111
|
+
npm install cubing@latest
|
|
112
|
+
`);
|
package/package.json
CHANGED
|
@@ -1,17 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-cubing-app",
|
|
3
|
-
"version": "0.35.6-
|
|
3
|
+
"version": "0.35.6-rc21",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"bin": "./bin/create-cubing-app.js",
|
|
5
6
|
"scripts": {
|
|
6
|
-
"build": "node -e 'import(\"barely-a-dev-server\").then(s => s.barelyServe({entryRoot: \"src\", dev: false, outDir: \"dist/web\"}))'",
|
|
7
|
-
"dev": "node -e 'import(\"barely-a-dev-server\").then(s => s.barelyServe({entryRoot: \"src\"}))'",
|
|
7
|
+
"build": "node -e 'import(\"barely-a-dev-server\").then(s => s.barelyServe({entryRoot: \"./src\", dev: false, outDir: \"dist/web\"}))' && echo '' && echo 'Your app has been built in: ./dist/web' && echo ''",
|
|
8
|
+
"dev": "node -e 'import(\"barely-a-dev-server\").then(s => s.barelyServe({entryRoot: \"./src\"}))'",
|
|
9
|
+
"upgrade-cubing": "npm install cubing@latest",
|
|
8
10
|
"clean": "rm -rf ./dist"
|
|
9
11
|
},
|
|
10
12
|
"dependencies": {
|
|
11
13
|
"cubing": "^0.35.6"
|
|
12
14
|
},
|
|
13
15
|
"devDependencies": {
|
|
16
|
+
"@types/validate-npm-package-name": "^4.0.0",
|
|
14
17
|
"barely-a-dev-server": "^0.4.8",
|
|
15
|
-
"esbuild": "^0.16.16"
|
|
16
|
-
|
|
18
|
+
"esbuild": "^0.16.16",
|
|
19
|
+
"validate-npm-package-name": "^5.0.0"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"./bin",
|
|
23
|
+
"./src"
|
|
24
|
+
]
|
|
17
25
|
}
|