create-nodality 1.0.0-beta.9 → 1.0.0-beta.91
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 +90 -54
- package/package.json +3 -3
- package/release.sh +11 -0
- /package/{readme.md → readme 10.16.21.md} +0 -0
package/bin/index.js
CHANGED
|
@@ -1,106 +1,139 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import { mkdirSync, writeFileSync, existsSync } from "fs";
|
|
4
|
-
import { resolve
|
|
4
|
+
import { resolve/*, dirname*/ } from "path";
|
|
5
5
|
import { execSync } from "child_process";
|
|
6
|
-
import { fileURLToPath } from "url";
|
|
6
|
+
// import { fileURLToPath } from "url";
|
|
7
7
|
|
|
8
|
-
//
|
|
9
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
10
|
-
const __dirname = dirname(__filename);
|
|
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
11
|
|
|
12
12
|
function createProject(projectName) {
|
|
13
|
+
// process.cwd() = current working directory (where user is running the command from)
|
|
14
|
+
// /Users/fv/create/PROJECT_NAME
|
|
13
15
|
const projectPath = resolve(process.cwd(), projectName);
|
|
14
16
|
|
|
17
|
+
// Check if it exists
|
|
15
18
|
if (existsSync(projectPath)) {
|
|
16
19
|
console.error(`Folder ${projectName} already exists.`);
|
|
17
20
|
process.exit(1);
|
|
18
21
|
}
|
|
19
22
|
|
|
23
|
+
// Make PROJECT_NAME directory
|
|
20
24
|
mkdirSync(projectPath);
|
|
21
25
|
const srcPath = resolve(projectPath, "src");
|
|
22
26
|
mkdirSync(srcPath);
|
|
23
27
|
|
|
24
|
-
//
|
|
28
|
+
// index.html with import map pointing "nodality" to bundled ES module
|
|
29
|
+
// module will be bundled in next steps
|
|
25
30
|
const indexHtml = `
|
|
26
31
|
<!DOCTYPE html>
|
|
27
32
|
<html lang="en">
|
|
28
|
-
<head>
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
<head>
|
|
34
|
+
<meta charset="UTF-8" />
|
|
35
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
36
|
+
<title>${projectName}</title>
|
|
37
|
+
<script type="importmap">
|
|
38
|
+
{
|
|
39
|
+
"imports": {
|
|
40
|
+
"nodality": "/dist/lib.bundle.js"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
</script>
|
|
44
|
+
<style>
|
|
45
|
+
* {
|
|
46
|
+
margin: 0;
|
|
47
|
+
padding:0;
|
|
48
|
+
box-sizing: border-box;
|
|
49
|
+
}
|
|
50
|
+
</style>
|
|
51
|
+
</head>
|
|
52
|
+
<body>
|
|
53
|
+
<div id="mount"></div>
|
|
54
|
+
<script type="module" src="/src/app.js"></script>
|
|
55
|
+
</body>
|
|
37
56
|
</html>
|
|
38
57
|
`;
|
|
39
58
|
writeFileSync(resolve(projectPath, "index.html"), indexHtml.trim());
|
|
40
59
|
|
|
41
|
-
//
|
|
42
|
-
const
|
|
43
|
-
|
|
60
|
+
// app.js stays non-bundled with import from "nodality"
|
|
61
|
+
const appJs = `
|
|
62
|
+
|
|
63
|
+
import * as Nodality from "nodality";
|
|
64
|
+
|
|
65
|
+
const elements = [
|
|
66
|
+
{ type: "h1", text: "Hello" }
|
|
67
|
+
];
|
|
44
68
|
|
|
45
|
-
|
|
69
|
+
const nodes = [
|
|
70
|
+
{ op: "blast" }
|
|
71
|
+
];
|
|
72
|
+
|
|
73
|
+
new Des()
|
|
74
|
+
.nodes(nodes)
|
|
75
|
+
.add(elements)
|
|
46
76
|
.set({
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
})
|
|
51
|
-
.render('#mount');
|
|
77
|
+
mount: "#mount",
|
|
78
|
+
code: true,
|
|
79
|
+
});
|
|
52
80
|
`;
|
|
53
|
-
writeFileSync(resolve(srcPath, "
|
|
81
|
+
writeFileSync(resolve(srcPath, "app.js"), appJs.trim());
|
|
54
82
|
|
|
55
|
-
//
|
|
83
|
+
// webpack.config.js outputs nodality as ES module library
|
|
56
84
|
const webpackConfig = `
|
|
57
|
-
import path from
|
|
58
|
-
import { fileURLToPath } from
|
|
85
|
+
import path from "path";
|
|
86
|
+
import { fileURLToPath } from "url";
|
|
59
87
|
|
|
60
88
|
const __filename = fileURLToPath(import.meta.url);
|
|
61
89
|
const __dirname = path.dirname(__filename);
|
|
62
90
|
|
|
63
91
|
export default {
|
|
64
|
-
mode:
|
|
65
|
-
entry:
|
|
92
|
+
mode: "production",
|
|
93
|
+
entry: "nodality",
|
|
66
94
|
output: {
|
|
67
|
-
|
|
68
|
-
|
|
95
|
+
path: path.resolve(__dirname, "dist"), // get dist folder in the current directory
|
|
96
|
+
filename: "lib.bundle.js", // will produce curr_dir/dist/lib.bundle.js using webpack when run
|
|
97
|
+
library: {
|
|
98
|
+
type: "module",
|
|
99
|
+
},
|
|
100
|
+
environment: {
|
|
101
|
+
module: true,
|
|
102
|
+
},
|
|
103
|
+
clean: true,
|
|
104
|
+
},
|
|
105
|
+
experiments: {
|
|
106
|
+
outputModule: true,
|
|
69
107
|
},
|
|
70
108
|
module: {
|
|
71
109
|
rules: [
|
|
72
110
|
{
|
|
73
|
-
test: /\\.js$/,
|
|
111
|
+
test: /\\.m?js$/,
|
|
74
112
|
exclude: /node_modules/,
|
|
75
113
|
use: {
|
|
76
|
-
loader:
|
|
114
|
+
loader: "babel-loader",
|
|
77
115
|
options: {
|
|
78
|
-
presets: [
|
|
116
|
+
presets: ["@babel/preset-env"],
|
|
79
117
|
},
|
|
80
118
|
},
|
|
81
119
|
},
|
|
82
120
|
],
|
|
83
121
|
},
|
|
84
|
-
resolve: {
|
|
85
|
-
alias: {
|
|
86
|
-
nodality: path.resolve(__dirname, 'node_modules/nodality/dist/index.esm.js'),
|
|
87
|
-
},
|
|
88
|
-
},
|
|
89
122
|
};
|
|
90
123
|
`;
|
|
91
124
|
writeFileSync(resolve(projectPath, "webpack.config.js"), webpackConfig.trim());
|
|
92
125
|
|
|
93
|
-
//
|
|
126
|
+
// package.json
|
|
94
127
|
const pkg = {
|
|
95
128
|
name: projectName,
|
|
96
129
|
version: "1.0.0",
|
|
97
130
|
type: "module",
|
|
98
131
|
scripts: {
|
|
99
|
-
build: "webpack",
|
|
132
|
+
build: "webpack --config webpack.config.js", // calls webpack
|
|
100
133
|
start: "npx serve . -l 4000",
|
|
101
134
|
},
|
|
102
135
|
dependencies: {
|
|
103
|
-
nodality: "^1.0.0-beta.
|
|
136
|
+
nodality: "^1.0.0-beta.91",
|
|
104
137
|
},
|
|
105
138
|
devDependencies: {
|
|
106
139
|
webpack: "^5.0.0",
|
|
@@ -108,31 +141,34 @@ export default {
|
|
|
108
141
|
"babel-loader": "^9.0.0",
|
|
109
142
|
"@babel/core": "^7.0.0",
|
|
110
143
|
"@babel/preset-env": "^7.0.0",
|
|
144
|
+
serve: "^14.0.0",
|
|
111
145
|
},
|
|
112
146
|
};
|
|
113
147
|
writeFileSync(resolve(projectPath, "package.json"), JSON.stringify(pkg, null, 2));
|
|
114
148
|
|
|
115
|
-
// Install dependencies
|
|
116
149
|
console.log("Installing dependencies...");
|
|
117
150
|
execSync(`npm install`, { cwd: projectPath, stdio: "inherit" });
|
|
118
151
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
152
|
+
console.log("Building nodality bundle as ES module...");
|
|
153
|
+
execSync(`npm run build`, { cwd: projectPath, stdio: "inherit" });
|
|
154
|
+
|
|
155
|
+
const bold = "\x1b[1m";
|
|
156
|
+
const color1abc9c = "\x1b[38;5;37m";
|
|
157
|
+
const reset = "\x1b[0m";
|
|
122
158
|
|
|
123
|
-
console.log(
|
|
159
|
+
console.log(`\n${color1abc9c}${bold}%s${reset}\n`, `Project "${projectName}" is ready! 🎉`);
|
|
160
|
+
console.log("\nUsage:\n");
|
|
124
161
|
console.log(` cd ${projectName}`);
|
|
125
|
-
console.log(" npm run build # Rebuild
|
|
126
|
-
console.log(" npm start # Serve
|
|
162
|
+
console.log(" npm run build # Rebuild library bundle");
|
|
163
|
+
console.log(" npm start # Serve the project");
|
|
127
164
|
}
|
|
165
|
+
// copy to create-nodality folder
|
|
128
166
|
|
|
129
|
-
//
|
|
130
|
-
const args = process.argv.slice(2);
|
|
131
|
-
|
|
167
|
+
// get 3rd component from "args" /(<project-name>)
|
|
168
|
+
const args = process.argv.slice(2);
|
|
132
169
|
if (!args[0]) {
|
|
133
170
|
console.error("Usage: npm create nodality <project-name>");
|
|
134
171
|
process.exit(1);
|
|
135
172
|
}
|
|
136
173
|
|
|
137
|
-
// Create the project
|
|
138
174
|
createProject(args[0]);
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-nodality",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.91",
|
|
4
4
|
"description": "Project scaffolding tool for Nodality library",
|
|
5
5
|
"bin": {
|
|
6
|
-
"create-nodality": "
|
|
6
|
+
"create-nodality": "bin/index.js"
|
|
7
7
|
},
|
|
8
8
|
"type": "module",
|
|
9
9
|
"scripts": {
|
|
@@ -18,6 +18,6 @@
|
|
|
18
18
|
"author": "Filip Vabrousek",
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"nodality": "^1.0.0-beta.
|
|
21
|
+
"nodality": "^1.0.0-beta.91"
|
|
22
22
|
}
|
|
23
23
|
}
|
package/release.sh
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
next_version=32
|
|
2
|
+
full_version="1.0.0-beta.${next_version}"
|
|
3
|
+
|
|
4
|
+
# ✅ Update package version to full beta version
|
|
5
|
+
sed -i '' -E "s/(\"version\": \")1\.0\.0-beta\.[0-9]+\"/\1${full_version}\"/" package.json
|
|
6
|
+
|
|
7
|
+
# ✅ Update nodality dependency in package.json to ^1.0.0-beta.xx
|
|
8
|
+
sed -i '' -E "s/(\"nodality\": \")\^1\.0\.0-beta\.[0-9]+\"/\1\\^${full_version}\"/" package.json
|
|
9
|
+
|
|
10
|
+
# ✅ Update hardcoded nodality version in bin/index.js
|
|
11
|
+
sed -i '' -E "s/(nodality: \\\")\^1\.0\.0-beta\.[0-9]+(\\\")/\1\\^${full_version}\2/" bin/index.js
|
|
File without changes
|