create-nodality 1.0.13 → 1.0.14
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 +55 -73
- package/package.json +1 -1
- package/readme 10.16.21.md +0 -0
- package/templates/index.html +0 -11
- package/templates/main.js +0 -5
package/bin/index.js
CHANGED
|
@@ -1,66 +1,53 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import { mkdirSync, writeFileSync, existsSync } from "fs";
|
|
4
|
-
import { resolve
|
|
3
|
+
import { mkdirSync, writeFileSync, existsSync, copyFileSync } from "fs";
|
|
4
|
+
import { resolve } from "path";
|
|
5
5
|
import { execSync } from "child_process";
|
|
6
|
-
// import { fileURLToPath } from "url";
|
|
7
|
-
|
|
8
|
-
// path to script itself /Users/fv/create/index.js
|
|
9
|
-
// const __filename = fileURLToPath(import.meta.url);
|
|
10
|
-
// const __dirname = dirname(__filename); // create part (folder name)
|
|
11
6
|
|
|
12
7
|
function createProject(projectName) {
|
|
13
|
-
// process.cwd() = current working directory (where user is running the command from)
|
|
14
|
-
// /Users/fv/create/PROJECT_NAME
|
|
15
8
|
const projectPath = resolve(process.cwd(), projectName);
|
|
16
9
|
|
|
17
|
-
// Check if it exists
|
|
18
10
|
if (existsSync(projectPath)) {
|
|
19
11
|
console.error(`Folder ${projectName} already exists.`);
|
|
20
12
|
process.exit(1);
|
|
21
13
|
}
|
|
22
14
|
|
|
23
|
-
//
|
|
15
|
+
// Create folders
|
|
24
16
|
mkdirSync(projectPath);
|
|
25
17
|
const srcPath = resolve(projectPath, "src");
|
|
26
18
|
mkdirSync(srcPath);
|
|
27
19
|
|
|
28
|
-
// index.html
|
|
29
|
-
// module will be bundled in next steps
|
|
20
|
+
// Copy index.html
|
|
30
21
|
const indexHtml = `
|
|
31
22
|
<!DOCTYPE html>
|
|
32
23
|
<html lang="en">
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
<div id="mount"></div>
|
|
54
|
-
<script type="module" src="/src/app.js"></script>
|
|
55
|
-
</body>
|
|
24
|
+
<head>
|
|
25
|
+
<meta charset="UTF-8">
|
|
26
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
27
|
+
<title>${projectName}</title>
|
|
28
|
+
|
|
29
|
+
<!-- importmap to map "nodality" to node_modules path -->
|
|
30
|
+
<script type="importmap">
|
|
31
|
+
{
|
|
32
|
+
"imports": {
|
|
33
|
+
"nodality": "/node_modules/nodality/dist/index.esm.js"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
</script>
|
|
37
|
+
</head>
|
|
38
|
+
<body>
|
|
39
|
+
<div id="mount"></div>
|
|
40
|
+
|
|
41
|
+
<!-- User app -->
|
|
42
|
+
<script type="module" src="src/app.js"></script>
|
|
43
|
+
</body>
|
|
56
44
|
</html>
|
|
57
45
|
`;
|
|
58
46
|
writeFileSync(resolve(projectPath, "index.html"), indexHtml.trim());
|
|
59
47
|
|
|
60
|
-
// app.js
|
|
48
|
+
// Copy app.js
|
|
61
49
|
const appJs = `
|
|
62
|
-
|
|
63
|
-
import * as Nodality from "nodality";
|
|
50
|
+
import { Des } from "nodality";
|
|
64
51
|
|
|
65
52
|
const elements = [
|
|
66
53
|
{ type: "h1", text: "Hello" }
|
|
@@ -80,7 +67,7 @@ new Des()
|
|
|
80
67
|
`;
|
|
81
68
|
writeFileSync(resolve(srcPath, "app.js"), appJs.trim());
|
|
82
69
|
|
|
83
|
-
// webpack.config.js
|
|
70
|
+
// Copy webpack.config.js
|
|
84
71
|
const webpackConfig = `
|
|
85
72
|
import path from "path";
|
|
86
73
|
import { fileURLToPath } from "url";
|
|
@@ -90,32 +77,22 @@ const __dirname = path.dirname(__filename);
|
|
|
90
77
|
|
|
91
78
|
export default {
|
|
92
79
|
mode: "production",
|
|
93
|
-
entry: "nodality",
|
|
80
|
+
entry: "nodality", // bundle Nodality only
|
|
94
81
|
output: {
|
|
95
|
-
path: path.resolve(__dirname, "dist"),
|
|
96
|
-
filename: "lib.bundle.js",
|
|
97
|
-
library: {
|
|
98
|
-
|
|
99
|
-
},
|
|
100
|
-
environment: {
|
|
101
|
-
module: true,
|
|
102
|
-
},
|
|
82
|
+
path: path.resolve(__dirname, "dist"),
|
|
83
|
+
filename: "lib.bundle.js",
|
|
84
|
+
library: { type: "module" }, // ESM output
|
|
85
|
+
environment: { module: true },
|
|
103
86
|
clean: true,
|
|
87
|
+
publicPath: "/",
|
|
104
88
|
},
|
|
105
|
-
experiments: {
|
|
106
|
-
outputModule: true,
|
|
107
|
-
},
|
|
89
|
+
experiments: { outputModule: true },
|
|
108
90
|
module: {
|
|
109
91
|
rules: [
|
|
110
92
|
{
|
|
111
93
|
test: /\\.m?js$/,
|
|
112
94
|
exclude: /node_modules/,
|
|
113
|
-
use: {
|
|
114
|
-
loader: "babel-loader",
|
|
115
|
-
options: {
|
|
116
|
-
presets: ["@babel/preset-env"],
|
|
117
|
-
},
|
|
118
|
-
},
|
|
95
|
+
use: { loader: "babel-loader", options: { presets: ["@babel/preset-env"] } },
|
|
119
96
|
},
|
|
120
97
|
],
|
|
121
98
|
},
|
|
@@ -129,27 +106,32 @@ export default {
|
|
|
129
106
|
version: "1.0.0",
|
|
130
107
|
type: "module",
|
|
131
108
|
scripts: {
|
|
132
|
-
build: "webpack --config webpack.config.js",
|
|
133
|
-
|
|
109
|
+
build: "webpack --config webpack.config.js",
|
|
110
|
+
watch: "webpack --watch --config webpack.config.js",
|
|
111
|
+
start: "live-server . --port=4000 --watch=dist,src",
|
|
112
|
+
dev: "npm-run-all --parallel watch start"
|
|
134
113
|
},
|
|
135
114
|
dependencies: {
|
|
136
|
-
nodality: "^1.0.
|
|
115
|
+
nodality: "^1.0.14"
|
|
137
116
|
},
|
|
138
117
|
devDependencies: {
|
|
139
|
-
|
|
140
|
-
"
|
|
141
|
-
"babel-loader": "^9.
|
|
142
|
-
"
|
|
143
|
-
"
|
|
144
|
-
serve: "^14.0.0",
|
|
145
|
-
|
|
118
|
+
"@babel/core": "^7.28.4",
|
|
119
|
+
"@babel/preset-env": "^7.28.3",
|
|
120
|
+
"babel-loader": "^9.2.1",
|
|
121
|
+
"live-server": "^1.2.2",
|
|
122
|
+
"npm-run-all": "^4.1.5",
|
|
123
|
+
"serve": "^14.0.0",
|
|
124
|
+
"webpack": "^5.101.3",
|
|
125
|
+
"webpack-cli": "^5.1.4",
|
|
126
|
+
"webpack-dev-server": "^5.2.2"
|
|
127
|
+
}
|
|
146
128
|
};
|
|
147
129
|
writeFileSync(resolve(projectPath, "package.json"), JSON.stringify(pkg, null, 2));
|
|
148
130
|
|
|
149
131
|
console.log("Installing dependencies...");
|
|
150
132
|
execSync(`npm install`, { cwd: projectPath, stdio: "inherit" });
|
|
151
133
|
|
|
152
|
-
console.log("Building
|
|
134
|
+
console.log("Building Nodality bundle...");
|
|
153
135
|
execSync(`npm run build`, { cwd: projectPath, stdio: "inherit" });
|
|
154
136
|
|
|
155
137
|
const bold = "\x1b[1m";
|
|
@@ -160,12 +142,12 @@ export default {
|
|
|
160
142
|
console.log("\nUsage:\n");
|
|
161
143
|
console.log(` cd ${projectName}`);
|
|
162
144
|
console.log(" npm run build # Rebuild library bundle");
|
|
163
|
-
console.log(" npm
|
|
145
|
+
console.log(" npm run dev # Start dev server with live reload");
|
|
146
|
+
console.log(" npm start # Serve project without watch");
|
|
164
147
|
}
|
|
165
|
-
// copy to create-nodality folder
|
|
166
148
|
|
|
167
|
-
//
|
|
168
|
-
const args = process.argv.slice(2);
|
|
149
|
+
// Get project name from CLI args
|
|
150
|
+
const args = process.argv.slice(2);
|
|
169
151
|
if (!args[0]) {
|
|
170
152
|
console.error("Usage: npm create nodality <project-name>");
|
|
171
153
|
process.exit(1);
|
package/package.json
CHANGED
package/readme 10.16.21.md
DELETED
|
File without changes
|
package/templates/index.html
DELETED