create-cubing-app 0.35.6-rc8 → 0.36.2

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,13 @@
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";
9
+
10
+ const CREATE_CUBING_APP_PACKAGE_JSON = JSON.parse(await readFile(new URL("../package.json", import.meta.url), "utf-8"));
4
11
 
5
12
  function execPromise(cmd, options) {
6
13
  return new Promise((resolve, reject) => {
@@ -14,95 +21,120 @@ function execPromise(cmd, options) {
14
21
  });
15
22
  }
16
23
 
24
+ function printHelpAndExit() {
25
+ stderr.write(`Usage:
26
+
27
+ npm create cubing-app <project folder name>
28
+
29
+ The project folder name should consist of only letters, numbers, dashes, and u
30
+ nderscores.
31
+ `);
32
+ exit(1);
33
+ }
34
+
35
+ let projectPath = process.argv[2];
36
+ if (!projectPath) {
37
+ const readline = createInterface({
38
+ input: process.stdin,
39
+ output: process.stdout,
40
+ });
41
+
42
+ projectPath = await new Promise((resolve, reject) => {
43
+ try {
44
+ readline.question(
45
+ `Where would you like to place the project?
46
+ (Enter a path or name for a new folder.)
47
+ `,
48
+ resolve,
49
+ );
50
+ } catch (e) {
51
+ reject(e);
52
+ } finally {
53
+ }
54
+ });
55
+ readline.close();
56
+ if (projectPath === "") {
57
+ console.log("Please enter a non-empty project path.");
58
+ exit(1);
59
+ }
60
+ }
61
+
62
+ function projectPathed(path) {
63
+ return join(projectPath, path);
64
+ }
65
+
66
+ console.log(`---------------------------------
67
+ Creating a cubing project in the following folder:
68
+ ${projectPath}
69
+ `);
70
+
71
+ // We could uses `stat` from `"fs/promises"`, but I'm not too enthused about
72
+ // catching an error in the "expected" path. So we use `exists`.
73
+ if (await promisify(exists)(projectPath)) {
74
+ process.stderr.write(`Project already exists in the current folder: ${projectPath}
75
+ Please select a different name (or delete the existing project folder).
76
+ `);
77
+ exit(1);
78
+ }
79
+ await mkdir(projectPath, { recursive: true });
80
+
17
81
  const initialPackageJSON = {
82
+ type: "module",
18
83
  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"}))\'',
84
+ "build": CREATE_CUBING_APP_PACKAGE_JSON.scripts["build"],
85
+ "dev": CREATE_CUBING_APP_PACKAGE_JSON.scripts["dev"],
22
86
  clean: "rm -rf ./dist",
87
+ "upgrade-cubing": "npm install --save cubing@latest",
23
88
  },
24
89
  };
25
90
  await writeFile(
26
- "./package.json",
91
+ projectPathed("package.json"),
27
92
  JSON.stringify(initialPackageJSON, null, " "),
28
93
  );
29
94
 
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 });
95
+ const execOptions = {
96
+ cwd: projectPath,
97
+ };
98
+ await mkdir(projectPathed("script"), { recursive: true });
99
+ await mkdir(projectPathed("src"), { recursive: true });
34
100
  async function transferFile(rootedPath, contents) {
35
- const indexHTML = await readFile(new URL(`./${rootedPath}`, import.meta.url));
36
- await writeFile(`./${rootedPath}`, indexHTML);
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);
37
106
  }
38
- await transferFile(
39
- "src/index.html",
40
- `<!DOCTYPE html>
41
- <html>
42
-
43
- <head>
44
- <meta charset="utf8">
45
- <title>My Cubing App</title>
46
- <link rel="stylesheet" href="./index.css">
47
- <!-- Note: the source file is \`main.ts\`, but here we use the transpiled file name it will have on the web server. -->
48
- <script src="./main.js" type="module"></script>
49
- </head>
50
-
51
- <body>
52
- <h1>My Cubing App</h1>
53
- <twisty-player id="main-player"></twisty-player>
54
- </body>
55
-
56
- </html>
57
- `,
58
- );
59
- await transferFile(
60
- "src/main.ts",
61
- `// Always keep the following line if you are using any twisty players on your page.
62
- import "cubing/twisty";
63
- // Use the following line for specific imports from \`cubing/twisty\`.
64
- import { TwistyAlgViewer, type TwistyPlayer } from "cubing/twisty";
65
-
66
- // Import from other modules as usual.
67
- import { randomScrambleForEvent } from "cubing/scramble";
68
-
69
- class App {
70
- // Example of getting an element from the page.
71
- twistyPlayer: TwistyPlayer = document.querySelector("#main-player")!;
72
- // Example of creating a new element and adding it to the page.
73
- twistyAlgViewer = document.body.appendChild(
74
- new TwistyAlgViewer({ twistyPlayer: this.twistyPlayer })
75
- );
76
- constructor() {
77
- this.updateScramble();
78
- }
79
-
80
- async updateScramble() {
81
- this.twistyPlayer.alg = await randomScrambleForEvent("333");
82
- }
83
- }
84
-
85
- // Make the app object available in the console for debugging.
86
- // Try running: app.updateScramble()
87
- globalThis.app = new App();
88
- `,
89
- );
90
- await transferFile(
91
- "src/index.css",
92
- `/* Center everything on the page. */
93
- html, body {
94
- height: 100%;
95
- margin: 0;
96
- display: grid;
97
- place-content: center;
98
- gap: 1em;
99
- font-family: sans-serif;
100
- }
101
- `,
102
- );
107
+ await transferFile("script/build.js");
108
+ await transferFile("script/dev.js");
109
+ await transferFile("src/index.html");
110
+ await transferFile("src/main.ts");
111
+ await transferFile("src/index.css");
103
112
  await transferFile(
104
113
  ".gitignore",
105
114
  `/dist
106
115
  /node_modules
107
116
  `,
108
117
  );
118
+ await transferFile("tsconfig.json");
119
+
120
+ await execPromise("npm install --save cubing", execOptions);
121
+ await execPromise("npm install --save-dev barely-a-dev-server", execOptions);
122
+
123
+ console.log(`Your cubing app has been created.
124
+ To work on it, run:
125
+
126
+ cd \"${projectPath.replaceAll('"', '\\"')}\"
127
+ npm run dev
128
+
129
+ Edit the files in \`src\` and open the displayed URL in browser to see changes.
130
+
131
+ --------
132
+
133
+ To create an optimized build of your app that can be uploaded to a file server, run:
134
+
135
+ npm run build
136
+
137
+ When a new version of \`cubing.js\` is released in the future, you can upgrade using:
138
+
139
+ npm install --save cubing@latest
140
+ `);
package/package.json CHANGED
@@ -1,18 +1,27 @@
1
1
  {
2
2
  "name": "create-cubing-app",
3
- "version": "0.35.6-rc8",
3
+ "version": "0.36.2",
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/build.js -- --dev",
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,27 @@
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
+ `)
27
+ }
@@ -0,0 +1,4 @@
1
+ export const COMMON_BUILD_OPTIONS = {
2
+ entryRoot: "./src",
3
+ esbuildOptions: {chunkNames: "chunks/[name]-[hash]"}
4
+ }
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_BUILD_OPTIONS } from "./common-build-options.js";
5
+
6
+ barelyServe(COMMON_BUILD_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