create-cubing-app 0.35.6-rc7 → 0.36.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.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # `cubing-app-template`
1
+ # `create-cubing-app`
2
2
 
3
- This is a template project for project using [`cubing.js`](https://github.com/cubing/cubing.js) with `node` and `npm`. In an editor like VSCode, this will give you nice imports, autocompletions, and other TypeScript benefits.
3
+ This is a tool to initialize apps using [`cubing.js`](https://github.com/cubing/cubing.js) with `node` and `npm`. In an editor like VS Code, this will give you nice imports, autocompletions, and other TypeScript benefits.
4
4
 
5
5
  See <https://js.cubing.net/cubing/> for (in-progress) documentation on `cubing.js`. If you think you have any issues, don't hesitate to [file an issue here](https://github.com/cubing/cubing.js/issues/new/choose).
6
6
 
@@ -9,11 +9,8 @@ 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
- # Set up the project for the first time
13
- git clone https://github.com/cubing/cubing-app-template my-app && cd my-app
14
- npm install
15
-
16
- # Start working on the project at http://localhost:1234
12
+ npm create --yes cubing-app@latest my-cubing-project
13
+ cd my-cubing-project
17
14
  npm run dev
18
15
  ```
19
16
 
@@ -25,7 +22,7 @@ npm run build
25
22
 
26
23
  The site will be built to the `dist/web` folder, ready to place onto any static web server.
27
24
 
28
- (Note: the output uses module scripts, which means you can't just open the output HTML files directly in the browser. You have to use a web server. Something like `python3 -m http.server -d dist/web` might help if you just need to test the output locally.)
25
+ (Note: the output uses module scripts, which means you can't just open the output HTML files directly in the browser. You have to use a web server. If you want to test the output of `npm run build` locally on your computer, you can run: `npx http-server ./dist/web`)
29
26
 
30
27
  ## Getting the latest version of `cubing.js`
31
28
 
@@ -1,6 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
  import { exec } from "child_process";
3
- import { mkdir, readFile, writeFile } from "fs/promises";
3
+ import { exists } from "fs";
4
+ import { mkdir, readFile, stat, writeFile } from "fs/promises";
5
+ import { join, resolve } from "path";
6
+ import { exit, stderr } from "process";
7
+ import { createInterface } from "readline";
8
+ import { promisify } from "util";
4
9
 
5
10
  function execPromise(cmd, options) {
6
11
  return new Promise((resolve, reject) => {
@@ -14,28 +19,120 @@ function execPromise(cmd, options) {
14
19
  });
15
20
  }
16
21
 
22
+ function printHelpAndExit() {
23
+ stderr.write(`Usage:
24
+
25
+ npm create cubing-app <project folder name>
26
+
27
+ The project folder name should consist of only letters, numbers, dashes, and u
28
+ nderscores.
29
+ `);
30
+ exit(1);
31
+ }
32
+
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
+ }
58
+ }
59
+
60
+ function projectPathed(path) {
61
+ return join(projectPath, path);
62
+ }
63
+
64
+ console.log(`---------------------------------
65
+ Creating a cubing project in the following folder:
66
+ ${projectPath}
67
+ `);
68
+
69
+ // We could uses `stat` from `"fs/promises"`, but I'm not too enthused about
70
+ // catching an error in the "expected" path. So we use `exists`.
71
+ if (await promisify(exists)(projectPath)) {
72
+ process.stderr.write(`Project already exists in the current folder: ${projectPath}
73
+ Please select a different name (or delete the existing project folder).
74
+ `);
75
+ exit(1);
76
+ }
77
+ await mkdir(projectPath, { recursive: true });
78
+
17
79
  const initialPackageJSON = {
80
+ type: "module",
18
81
  scripts: {
19
- build:
20
- 'node -e \'import("barely-a-dev-server").then(s => s.barelyServe({entryRoot: "src", dev: false, outDir: "dist/web"}))\'',
21
- dev: 'node -e \'import("barely-a-dev-server").then(s => s.barelyServe({entryRoot: "src"}))\'',
82
+ "build": "node script/build.js",
83
+ "dev": "node script/dev.js",
22
84
  clean: "rm -rf ./dist",
85
+ "upgrade-cubing": "npm install --save cubing@latest",
23
86
  },
24
87
  };
25
88
  await writeFile(
26
- "./package.json",
89
+ projectPathed("package.json"),
27
90
  JSON.stringify(initialPackageJSON, null, " "),
28
91
  );
29
92
 
30
- await execPromise("npm install --save cubing");
31
- await execPromise("npm install --save-dev barely-a-dev-server");
32
-
33
- await mkdir("./src", { recursive: true });
34
- async function transferFile(rootedPath) {
35
- const indexHTML = await readFile(new URL(`./${rootedPath}`, import.meta.url));
36
- await writeFile(`./${rootedPath}`, indexHTML);
93
+ const execOptions = {
94
+ cwd: projectPath,
95
+ };
96
+ await mkdir(projectPathed("script"), { recursive: true });
97
+ await mkdir(projectPathed("src"), { recursive: true });
98
+ async function transferFile(rootedPath, contents) {
99
+ contents ??= await (async () => {
100
+ const filePath = new URL(join("..", rootedPath), import.meta.url);
101
+ return readFile(filePath, "utf-8");
102
+ })();
103
+ await writeFile(projectPathed(rootedPath), contents);
37
104
  }
105
+ await transferFile("script/build.js");
106
+ await transferFile("script/dev.js");
38
107
  await transferFile("src/index.html");
39
108
  await transferFile("src/main.ts");
40
109
  await transferFile("src/index.css");
41
- await transferFile(".gitignore");
110
+ await transferFile(
111
+ ".gitignore",
112
+ `/dist
113
+ /node_modules
114
+ `,
115
+ );
116
+ await transferFile("tsconfig.json");
117
+
118
+ await execPromise("npm install --save cubing", execOptions);
119
+ await execPromise("npm install --save-dev barely-a-dev-server", execOptions);
120
+
121
+ console.log(`Your cubing app has been created.
122
+ To work on it, run:
123
+
124
+ cd \"${projectPath.replaceAll('"', '\\"')}\"
125
+ npm run dev
126
+
127
+ Edit the files in \`src\` and open the displayed URL in browser to see changes.
128
+
129
+ --------
130
+
131
+ To create an optimized build of your app that can be uploaded to a file server, run:
132
+
133
+ npm run build
134
+
135
+ When a new version of \`cubing.js\` is released in the future, you can upgrade using:
136
+
137
+ npm install --save cubing@latest
138
+ `);
package/package.json CHANGED
@@ -1,18 +1,27 @@
1
1
  {
2
2
  "name": "create-cubing-app",
3
- "version": "0.35.6-rc7",
3
+ "version": "0.36.0",
4
4
  "type": "module",
5
5
  "bin": "./bin/create-cubing-app.js",
6
6
  "scripts": {
7
- "build": "node -e 'import(\"barely-a-dev-server\").then(s => s.barelyServe({entryRoot: \"src\", dev: false, outDir: \"dist/web\"}))'",
8
- "dev": "node -e 'import(\"barely-a-dev-server\").then(s => s.barelyServe({entryRoot: \"src\"}))'",
7
+ "build": "node script/build.js",
8
+ "dev": "node script/dev.js",
9
+ "roll-cubing-commit": "./script/roll-cubing-commit.bash",
9
10
  "clean": "rm -rf ./dist"
10
11
  },
11
12
  "dependencies": {
12
- "cubing": "^0.35.6"
13
+ "cubing": "^0.43.4"
13
14
  },
14
15
  "devDependencies": {
15
- "barely-a-dev-server": "^0.4.8",
16
- "esbuild": "^0.16.16"
17
- }
16
+ "@types/validate-npm-package-name": "^4.0.0",
17
+ "barely-a-dev-server": "^0.6.0",
18
+ "esbuild": "^0.19.2",
19
+ "validate-npm-package-name": "^5.0.0"
20
+ },
21
+ "files": [
22
+ "./bin",
23
+ "./script",
24
+ "./src",
25
+ "./tsconfig.json"
26
+ ]
18
27
  }
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env node
2
+
3
+ import {barelyServe} from "barely-a-dev-server";
4
+
5
+ const outDir = "./dist/web";
6
+ export const COMMON_OPTIONS = {
7
+ entryRoot: "./src",
8
+ esbuildOptions: {chunkNames: "chunks/[name]-[hash]"}
9
+ }
10
+
11
+ await barelyServe({
12
+ ...COMMON_OPTIONS,
13
+ dev: false,
14
+ outDir,
15
+ });
16
+
17
+ console.log(`
18
+ Your app has been built in: ${outDir}
19
+ `)
package/script/dev.js ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+
3
+ import {barelyServe} from "barely-a-dev-server";
4
+ import { COMMON_OPTIONS } from "./build.js";
5
+
6
+ barelyServe(COMMON_OPTIONS);
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is simplified `bash` version of: https://github.com/lgarron/scripts/blob/9aa4a016c7853b7a7588dd11bacd327156251b1e/web/npm-roll
4
+
5
+ if [ ! -z "$(git status --porcelain)" ]
6
+ then
7
+ echo "git status must be clean"
8
+ echo ""
9
+ git status
10
+ exit 1
11
+ fi
12
+
13
+ VERSION=$(npm show cubing version)
14
+ echo "Rolling \`cubing\` to version: v${VERSION}"
15
+
16
+ npm install "cubing@v${VERSION}"
17
+ git stage package*
18
+ git commit -m "\`npm install cubing@v${VERSION}\`"
package/tsconfig.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es2022",
4
+ "module": "es2022",
5
+ "moduleResolution": "bundler",
6
+ "verbatimModuleSyntax": true, // avoids surprises with `cubing/twisty`
7
+ }
8
+ }
File without changes
File without changes
File without changes