create-cubing-app 0.35.6-rc1 → 0.35.6-rc10

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.
@@ -0,0 +1,137 @@
1
+ #!/usr/bin/env node
2
+ import { exec } from "child_process";
3
+ import { mkdir, writeFile } from "fs/promises";
4
+ import { join } from "path";
5
+ import { exit, stderr } from "process";
6
+ import { default as validate } from "validate-npm-package-name";
7
+
8
+ function execPromise(cmd, options) {
9
+ return new Promise((resolve, reject) => {
10
+ const childProcess = exec(cmd, options, (error, stdout, stderr) => {
11
+ if (error) {
12
+ reject(error);
13
+ }
14
+ // console.log(stdout);
15
+ resolve(stdout ? stdout : stderr);
16
+ });
17
+ });
18
+ }
19
+
20
+ function badPackageName() {
21
+ stderr.write(`Please specify a valid project name!
22
+ For example:
23
+
24
+ npm create cubing-app my-cubing-project
25
+
26
+ `);
27
+ exit(1);
28
+ }
29
+ const packageName = process.argv[2];
30
+ if (!packageName) {
31
+ badPackageName();
32
+ }
33
+ const validationResults = validate(packageName);
34
+ if (!validationResults.validForNewPackages) {
35
+ badPackageName();
36
+ }
37
+
38
+ const packageRoot = join(".", packageName);
39
+ function packageRooted(path) {
40
+ return join(packageRoot, path);
41
+ }
42
+ await mkdir(packageRoot);
43
+
44
+ const initialPackageJSON = {
45
+ scripts: {
46
+ build:
47
+ 'node -e \'import("barely-a-dev-server").then(s => s.barelyServe({entryRoot: "src", dev: false, outDir: "dist/web"}))\'',
48
+ dev: 'node -e \'import("barely-a-dev-server").then(s => s.barelyServe({entryRoot: "src"}))\'',
49
+ clean: "rm -rf ./dist",
50
+ },
51
+ };
52
+ await writeFile(
53
+ packageRooted("package.json"),
54
+ JSON.stringify(initialPackageJSON, null, " "),
55
+ );
56
+
57
+ const execOptions = {
58
+ cwd: packageRoot,
59
+ };
60
+ await mkdir(packageRooted("src"), { recursive: true });
61
+ async function transferFile(rootedPath, contents) {
62
+ await writeFile(packageRooted(rootedPath), contents);
63
+ }
64
+ await transferFile(
65
+ "src/index.html",
66
+ `<!DOCTYPE html>
67
+ <html>
68
+
69
+ <head>
70
+ <meta charset="utf8">
71
+ <title>My Cubing App</title>
72
+ <link rel="stylesheet" href="./index.css">
73
+ <!-- Note: the source file is \`main.ts\`, but here we use the transpiled file name it will have on the web server. -->
74
+ <script src="./main.js" type="module"></script>
75
+ </head>
76
+
77
+ <body>
78
+ <h1>My Cubing App</h1>
79
+ <twisty-player id="main-player"></twisty-player>
80
+ </body>
81
+
82
+ </html>
83
+ `,
84
+ );
85
+ await transferFile(
86
+ "src/main.ts",
87
+ `// Always keep the following line if you are using any twisty players on your page.
88
+ import "cubing/twisty";
89
+ // Use the following line for specific imports from \`cubing/twisty\`.
90
+ import { TwistyAlgViewer, type TwistyPlayer } from "cubing/twisty";
91
+
92
+ // Import from other modules as usual.
93
+ import { randomScrambleForEvent } from "cubing/scramble";
94
+
95
+ class App {
96
+ // Example of getting an element from the page.
97
+ twistyPlayer: TwistyPlayer = document.querySelector("#main-player")!;
98
+ // Example of creating a new element and adding it to the page.
99
+ twistyAlgViewer = document.body.appendChild(
100
+ new TwistyAlgViewer({ twistyPlayer: this.twistyPlayer })
101
+ );
102
+ constructor() {
103
+ this.updateScramble();
104
+ }
105
+
106
+ async updateScramble() {
107
+ this.twistyPlayer.alg = await randomScrambleForEvent("333");
108
+ }
109
+ }
110
+
111
+ // Make the app object available in the console for debugging.
112
+ // Try running: app.updateScramble()
113
+ globalThis.app = new App();
114
+ `,
115
+ );
116
+ await transferFile(
117
+ "src/index.css",
118
+ `/* Center everything on the page. */
119
+ html, body {
120
+ height: 100%;
121
+ margin: 0;
122
+ display: grid;
123
+ place-content: center;
124
+ gap: 1em;
125
+ font-family: sans-serif;
126
+ }
127
+ `,
128
+ );
129
+ await transferFile(
130
+ ".gitignore",
131
+ `/dist
132
+ /node_modules
133
+ `,
134
+ );
135
+
136
+ await execPromise("npm install --save cubing", execOptions);
137
+ await execPromise("npm install --save-dev barely-a-dev-server", execOptions);
File without changes
File without changes
File without changes
package/package.json CHANGED
@@ -1,6 +1,8 @@
1
1
  {
2
2
  "name": "create-cubing-app",
3
- "version": "0.35.6-rc1",
3
+ "version": "0.35.6-rc10",
4
+ "type": "module",
5
+ "bin": "./bin/create-cubing-app.js",
4
6
  "scripts": {
5
7
  "build": "node -e 'import(\"barely-a-dev-server\").then(s => s.barelyServe({entryRoot: \"src\", dev: false, outDir: \"dist/web\"}))'",
6
8
  "dev": "node -e 'import(\"barely-a-dev-server\").then(s => s.barelyServe({entryRoot: \"src\"}))'",
@@ -10,7 +12,9 @@
10
12
  "cubing": "^0.35.6"
11
13
  },
12
14
  "devDependencies": {
15
+ "@types/validate-npm-package-name": "^4.0.0",
13
16
  "barely-a-dev-server": "^0.4.8",
14
- "esbuild": "^0.16.16"
17
+ "esbuild": "^0.16.16",
18
+ "validate-npm-package-name": "^5.0.0"
15
19
  }
16
20
  }