create-nodality 1.0.0-beta.67 → 1.0.0-beta.68
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 +9 -72
- package/package.json +1 -1
package/bin/index.js
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
|
-
|
3
2
|
import { mkdirSync, writeFileSync, existsSync } from "fs";
|
4
3
|
import { resolve, dirname } from "path";
|
5
4
|
import { execSync } from "child_process";
|
@@ -20,7 +19,7 @@ function createProject(projectName) {
|
|
20
19
|
const srcPath = resolve(projectPath, "src");
|
21
20
|
mkdirSync(srcPath);
|
22
21
|
|
23
|
-
// index.html
|
22
|
+
// index.html
|
24
23
|
const indexHtml = `
|
25
24
|
<!DOCTYPE html>
|
26
25
|
<html lang="en">
|
@@ -31,16 +30,15 @@ function createProject(projectName) {
|
|
31
30
|
</head>
|
32
31
|
<body>
|
33
32
|
<div id="mount"></div>
|
34
|
-
<script src="dist/bundle-library.js"></script>
|
35
33
|
<script type="module" src="src/app.js"></script>
|
36
34
|
</body>
|
37
35
|
</html>
|
38
36
|
`;
|
39
37
|
writeFileSync(resolve(projectPath, "index.html"), indexHtml.trim());
|
40
38
|
|
41
|
-
// app.js
|
39
|
+
// app.js — kept as-is, no bundling
|
42
40
|
const appJs = `
|
43
|
-
|
41
|
+
import { Des } from "nodality";
|
44
42
|
|
45
43
|
let elements = [
|
46
44
|
{
|
@@ -55,9 +53,6 @@ let nodes = [
|
|
55
53
|
}
|
56
54
|
];
|
57
55
|
|
58
|
-
// Use NodalityLib global exported by bundle-library.js
|
59
|
-
const { Des } = window.NodalityLib;
|
60
|
-
|
61
56
|
new Des()
|
62
57
|
.nodes(nodes)
|
63
58
|
.add(elements)
|
@@ -68,92 +63,34 @@ new Des()
|
|
68
63
|
`;
|
69
64
|
writeFileSync(resolve(srcPath, "app.js"), appJs.trim());
|
70
65
|
|
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
|
81
|
-
const webpackConfig = `
|
82
|
-
import path from 'path';
|
83
|
-
import { fileURLToPath } from 'url';
|
84
|
-
|
85
|
-
const __filename = fileURLToPath(import.meta.url);
|
86
|
-
const __dirname = path.dirname(__filename);
|
87
|
-
|
88
|
-
export default {
|
89
|
-
mode: 'production',
|
90
|
-
entry: './src/library.js',
|
91
|
-
output: {
|
92
|
-
filename: 'bundle-library.js',
|
93
|
-
path: path.resolve(__dirname, 'dist'),
|
94
|
-
globalObject: 'this',
|
95
|
-
library: {
|
96
|
-
name: 'NodalityLib',
|
97
|
-
type: 'umd',
|
98
|
-
},
|
99
|
-
},
|
100
|
-
module: {
|
101
|
-
rules: [
|
102
|
-
{
|
103
|
-
test: /\\.js$/,
|
104
|
-
exclude: /node_modules/,
|
105
|
-
use: {
|
106
|
-
loader: 'babel-loader',
|
107
|
-
options: {
|
108
|
-
presets: ['@babel/preset-env'],
|
109
|
-
},
|
110
|
-
},
|
111
|
-
},
|
112
|
-
],
|
113
|
-
},
|
114
|
-
};
|
115
|
-
`;
|
116
|
-
writeFileSync(resolve(projectPath, "webpack.config.js"), webpackConfig.trim());
|
117
|
-
|
118
|
-
// package.json with dependencies & scripts
|
66
|
+
// package.json
|
119
67
|
const pkg = {
|
120
68
|
name: projectName,
|
121
69
|
version: "1.0.0",
|
122
70
|
type: "module",
|
123
71
|
scripts: {
|
124
|
-
|
125
|
-
start: "npx serve . -l 4000",
|
72
|
+
start: "npx serve . -l 4000"
|
126
73
|
},
|
127
74
|
dependencies: {
|
128
|
-
nodality: "^1.0.0-beta.66"
|
75
|
+
nodality: "^1.0.0-beta.66"
|
129
76
|
},
|
130
77
|
devDependencies: {
|
131
|
-
|
132
|
-
|
133
|
-
"babel-loader": "^9.0.0",
|
134
|
-
"@babel/core": "^7.0.0",
|
135
|
-
"@babel/preset-env": "^7.0.0",
|
136
|
-
},
|
78
|
+
serve: "^14.0.0"
|
79
|
+
}
|
137
80
|
};
|
138
81
|
writeFileSync(resolve(projectPath, "package.json"), JSON.stringify(pkg, null, 2));
|
139
82
|
|
140
83
|
console.log("Installing dependencies...");
|
141
84
|
execSync(`npm install`, { cwd: projectPath, stdio: "inherit" });
|
142
85
|
|
143
|
-
console.log("Building library bundle...");
|
144
|
-
execSync(`npx webpack`, { cwd: projectPath, stdio: "inherit" });
|
145
|
-
|
146
86
|
const bold = '\x1b[1m';
|
147
87
|
const color1abc9c = '\x1b[38;5;37m';
|
148
88
|
const reset = '\x1b[0m';
|
149
89
|
|
150
90
|
console.log(`\n${color1abc9c}${bold}%s${reset}\n`, `Your project "${projectName}" is ready! 🎉`);
|
151
|
-
|
152
91
|
console.log("\nUsage:\n");
|
153
92
|
console.log(` cd ${projectName}`);
|
154
|
-
console.log(" npm run build # Rebuild Nodality library bundle");
|
155
93
|
console.log(" npm start # Serve your project on http://localhost:4000");
|
156
|
-
console.log("\nNote: Your app.js uses the global window.NodalityLib exported by the bundled library.\n");
|
157
94
|
}
|
158
95
|
|
159
96
|
const args = process.argv.slice(2);
|
@@ -162,4 +99,4 @@ if (!args[0]) {
|
|
162
99
|
process.exit(1);
|
163
100
|
}
|
164
101
|
|
165
|
-
createProject(args[0]);
|
102
|
+
createProject(args[0]);
|