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