create-nodality 1.0.0-beta.68 → 1.0.0-beta.69
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/index.js +83 -24
- package/package.json +1 -1
package/bin/index.js
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
|
+
|
2
3
|
import { mkdirSync, writeFileSync, existsSync } from "fs";
|
3
4
|
import { resolve, dirname } from "path";
|
4
5
|
import { execSync } from "child_process";
|
@@ -19,7 +20,7 @@ function createProject(projectName) {
|
|
19
20
|
const srcPath = resolve(projectPath, "src");
|
20
21
|
mkdirSync(srcPath);
|
21
22
|
|
22
|
-
// index.html
|
23
|
+
// index.html with import map pointing "nodality" to bundled ES module
|
23
24
|
const indexHtml = `
|
24
25
|
<!DOCTYPE html>
|
25
26
|
<html lang="en">
|
@@ -27,30 +28,35 @@ function createProject(projectName) {
|
|
27
28
|
<meta charset="UTF-8" />
|
28
29
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
29
30
|
<title>${projectName}</title>
|
31
|
+
|
32
|
+
<script type="importmap">
|
33
|
+
{
|
34
|
+
"imports": {
|
35
|
+
"nodality": "/dist/lib.bundle.js"
|
36
|
+
}
|
37
|
+
}
|
38
|
+
</script>
|
30
39
|
</head>
|
31
40
|
<body>
|
32
41
|
<div id="mount"></div>
|
33
|
-
|
42
|
+
|
43
|
+
<script type="module" src="/src/app.js"></script>
|
34
44
|
</body>
|
35
45
|
</html>
|
36
46
|
`;
|
37
47
|
writeFileSync(resolve(projectPath, "index.html"), indexHtml.trim());
|
38
48
|
|
39
|
-
// app.js
|
49
|
+
// app.js stays non-bundled with import from "nodality"
|
40
50
|
const appJs = `
|
41
|
-
import { Des } from "nodality";
|
42
51
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
}
|
52
|
+
import * as Nodality from "nodality";
|
53
|
+
|
54
|
+
const elements = [
|
55
|
+
{ type: "h1", text: "Hello" }
|
48
56
|
];
|
49
57
|
|
50
|
-
|
51
|
-
{
|
52
|
-
op: "blast"
|
53
|
-
}
|
58
|
+
const nodes = [
|
59
|
+
{ op: "blast" }
|
54
60
|
];
|
55
61
|
|
56
62
|
new Des()
|
@@ -58,39 +64,92 @@ new Des()
|
|
58
64
|
.add(elements)
|
59
65
|
.set({
|
60
66
|
mount: "#mount",
|
61
|
-
code: true
|
67
|
+
code: true,
|
62
68
|
});
|
63
69
|
`;
|
64
70
|
writeFileSync(resolve(srcPath, "app.js"), appJs.trim());
|
65
71
|
|
72
|
+
// webpack.config.js outputs nodality as ES module library
|
73
|
+
const webpackConfig = `
|
74
|
+
import path from "path";
|
75
|
+
import { fileURLToPath } from "url";
|
76
|
+
|
77
|
+
const __filename = fileURLToPath(import.meta.url);
|
78
|
+
const __dirname = path.dirname(__filename);
|
79
|
+
|
80
|
+
export default {
|
81
|
+
mode: "production",
|
82
|
+
entry: "nodality",
|
83
|
+
output: {
|
84
|
+
path: path.resolve(__dirname, "dist"),
|
85
|
+
filename: "lib.bundle.js",
|
86
|
+
library: {
|
87
|
+
type: "module",
|
88
|
+
},
|
89
|
+
environment: {
|
90
|
+
module: true,
|
91
|
+
},
|
92
|
+
clean: true,
|
93
|
+
},
|
94
|
+
experiments: {
|
95
|
+
outputModule: true,
|
96
|
+
},
|
97
|
+
module: {
|
98
|
+
rules: [
|
99
|
+
{
|
100
|
+
test: /\\.m?js$/,
|
101
|
+
exclude: /node_modules/,
|
102
|
+
use: {
|
103
|
+
loader: "babel-loader",
|
104
|
+
options: {
|
105
|
+
presets: ["@babel/preset-env"],
|
106
|
+
},
|
107
|
+
},
|
108
|
+
},
|
109
|
+
],
|
110
|
+
},
|
111
|
+
};
|
112
|
+
`;
|
113
|
+
writeFileSync(resolve(projectPath, "webpack.config.js"), webpackConfig.trim());
|
114
|
+
|
66
115
|
// package.json
|
67
116
|
const pkg = {
|
68
117
|
name: projectName,
|
69
118
|
version: "1.0.0",
|
70
119
|
type: "module",
|
71
120
|
scripts: {
|
72
|
-
|
121
|
+
build: "webpack --config webpack.config.js",
|
122
|
+
start: "npx serve . -l 4000",
|
73
123
|
},
|
74
124
|
dependencies: {
|
75
|
-
nodality: "^1.0.0-beta.66"
|
125
|
+
nodality: "^1.0.0-beta.66",
|
76
126
|
},
|
77
127
|
devDependencies: {
|
78
|
-
|
79
|
-
|
128
|
+
webpack: "^5.0.0",
|
129
|
+
"webpack-cli": "^5.0.0",
|
130
|
+
"babel-loader": "^9.0.0",
|
131
|
+
"@babel/core": "^7.0.0",
|
132
|
+
"@babel/preset-env": "^7.0.0",
|
133
|
+
serve: "^14.0.0",
|
134
|
+
},
|
80
135
|
};
|
81
136
|
writeFileSync(resolve(projectPath, "package.json"), JSON.stringify(pkg, null, 2));
|
82
137
|
|
83
138
|
console.log("Installing dependencies...");
|
84
139
|
execSync(`npm install`, { cwd: projectPath, stdio: "inherit" });
|
85
140
|
|
86
|
-
|
87
|
-
|
88
|
-
|
141
|
+
console.log("Building nodality bundle as ES module...");
|
142
|
+
execSync(`npm run build`, { cwd: projectPath, stdio: "inherit" });
|
143
|
+
|
144
|
+
const bold = "\x1b[1m";
|
145
|
+
const color1abc9c = "\x1b[38;5;37m";
|
146
|
+
const reset = "\x1b[0m";
|
89
147
|
|
90
|
-
console.log(`\n${color1abc9c}${bold}%s${reset}\n`, `
|
148
|
+
console.log(`\n${color1abc9c}${bold}%s${reset}\n`, `Project "${projectName}" is ready! 🎉`);
|
91
149
|
console.log("\nUsage:\n");
|
92
150
|
console.log(` cd ${projectName}`);
|
93
|
-
console.log(" npm
|
151
|
+
console.log(" npm run build # Rebuild library bundle");
|
152
|
+
console.log(" npm start # Serve on http://localhost:4000\n");
|
94
153
|
}
|
95
154
|
|
96
155
|
const args = process.argv.slice(2);
|
@@ -99,4 +158,4 @@ if (!args[0]) {
|
|
99
158
|
process.exit(1);
|
100
159
|
}
|
101
160
|
|
102
|
-
createProject(args[0]);
|
161
|
+
createProject(args[0]);
|