create-nodality 1.0.0 → 1.0.2

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 CHANGED
@@ -1,61 +1,171 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { mkdirSync, copyFileSync, existsSync, writeFileSync } from "fs";
4
- import { resolve, dirname } from "path";
3
+ import { mkdirSync, writeFileSync, existsSync } from "fs";
4
+ import { resolve/*, dirname*/ } from "path";
5
5
  import { execSync } from "child_process";
6
- import { fileURLToPath } from "url";
7
-
8
- // Helper to get directory of current file (since using ES modules)
9
- const __filename = fileURLToPath(import.meta.url);
10
- const __dirname = dirname(__filename);
6
+ // import { fileURLToPath } from "url";
11
7
 
12
- function copyTemplateFile(src, dest) {
13
- copyFileSync(src, dest);
14
- console.log(`Created ${dest}`);
15
- }
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)
16
11
 
17
12
  function createProject(projectName) {
13
+ // process.cwd() = current working directory (where user is running the command from)
14
+ // /Users/fv/create/PROJECT_NAME
18
15
  const projectPath = resolve(process.cwd(), projectName);
19
16
 
17
+ // Check if it exists
20
18
  if (existsSync(projectPath)) {
21
19
  console.error(`Folder ${projectName} already exists.`);
22
20
  process.exit(1);
23
21
  }
24
22
 
23
+ // Make PROJECT_NAME directory
25
24
  mkdirSync(projectPath);
25
+ const srcPath = resolve(projectPath, "src");
26
+ mkdirSync(srcPath);
27
+
28
+ // index.html with import map pointing "nodality" to bundled ES module
29
+ // module will be bundled in next steps
30
+ const indexHtml = `
31
+ <!DOCTYPE html>
32
+ <html lang="en">
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>
56
+ </html>
57
+ `;
58
+ writeFileSync(resolve(projectPath, "index.html"), indexHtml.trim());
59
+
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
+ ];
68
+
69
+ const nodes = [
70
+ { op: "blast" }
71
+ ];
72
+
73
+ new Des()
74
+ .nodes(nodes)
75
+ .add(elements)
76
+ .set({
77
+ mount: "#mount",
78
+ code: true,
79
+ });
80
+ `;
81
+ writeFileSync(resolve(srcPath, "app.js"), appJs.trim());
82
+
83
+ // webpack.config.js outputs nodality as ES module library
84
+ const webpackConfig = `
85
+ import path from "path";
86
+ import { fileURLToPath } from "url";
87
+
88
+ const __filename = fileURLToPath(import.meta.url);
89
+ const __dirname = path.dirname(__filename);
26
90
 
27
- // Copy template files
28
- const templatePath = resolve(__dirname, "../templates");
29
- copyTemplateFile(resolve(templatePath, "index.html"), resolve(projectPath, "index.html"));
30
- copyTemplateFile(resolve(templatePath, "main.js"), resolve(projectPath, "main.js"));
91
+ export default {
92
+ mode: "production",
93
+ entry: "nodality",
94
+ output: {
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,
107
+ },
108
+ module: {
109
+ rules: [
110
+ {
111
+ test: /\\.m?js$/,
112
+ exclude: /node_modules/,
113
+ use: {
114
+ loader: "babel-loader",
115
+ options: {
116
+ presets: ["@babel/preset-env"],
117
+ },
118
+ },
119
+ },
120
+ ],
121
+ },
122
+ };
123
+ `;
124
+ writeFileSync(resolve(projectPath, "webpack.config.js"), webpackConfig.trim());
31
125
 
32
- // Create package.json
126
+ // package.json
33
127
  const pkg = {
34
128
  name: projectName,
35
129
  version: "1.0.0",
36
130
  type: "module",
37
131
  scripts: {
38
- start: "serve ."
132
+ build: "webpack --config webpack.config.js", // calls webpack
133
+ start: "npx serve . -l 4000",
39
134
  },
40
135
  dependencies: {
41
- nodality: "^1.0.0"
42
- }
136
+ nodality: "^1.0.0-beta.104",
137
+ },
138
+ devDependencies: {
139
+ webpack: "^5.0.0",
140
+ "webpack-cli": "^5.0.0",
141
+ "babel-loader": "^9.0.0",
142
+ "@babel/core": "^7.0.0",
143
+ "@babel/preset-env": "^7.0.0",
144
+ serve: "^14.0.0",
145
+ },
43
146
  };
44
-
45
147
  writeFileSync(resolve(projectPath, "package.json"), JSON.stringify(pkg, null, 2));
46
- console.log("Created package.json");
47
148
 
48
- // Install dependencies
49
149
  console.log("Installing dependencies...");
50
150
  execSync(`npm install`, { cwd: projectPath, stdio: "inherit" });
51
151
 
52
- console.log("\nAll done! Run:\n");
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";
158
+
159
+ console.log(`\n${color1abc9c}${bold}%s${reset}\n`, `Project "${projectName}" is ready! 🎉`);
160
+ console.log("\nUsage:\n");
53
161
  console.log(` cd ${projectName}`);
54
- console.log(" npm start\n");
162
+ console.log(" npm run build # Rebuild library bundle");
163
+ console.log(" npm start # Serve the project");
55
164
  }
165
+ // copy to create-nodality folder
56
166
 
57
- const args = process.argv.slice(2);
58
-
167
+ // get 3rd component from "args" /(<project-name>)
168
+ const args = process.argv.slice(2);
59
169
  if (!args[0]) {
60
170
  console.error("Usage: npm create nodality <project-name>");
61
171
  process.exit(1);
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "create-nodality",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Project scaffolding tool for Nodality library",
5
5
  "bin": {
6
- "create-nodality": "./bin/index.js"
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"
21
+ "nodality": "^1.0.2"
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