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 CHANGED
@@ -1,66 +1,53 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { mkdirSync, writeFileSync, existsSync } from "fs";
4
- import { resolve/*, dirname*/ } from "path";
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
- // Make PROJECT_NAME directory
15
+ // Create folders
24
16
  mkdirSync(projectPath);
25
17
  const srcPath = resolve(projectPath, "src");
26
18
  mkdirSync(srcPath);
27
19
 
28
- // index.html with import map pointing "nodality" to bundled ES module
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
- <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>
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 stays non-bundled with import from "nodality"
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 outputs nodality as ES module library
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"), // 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
- },
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", // calls webpack
133
- start: "npx serve . -l 4000",
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.13",
115
+ nodality: "^1.0.14"
137
116
  },
138
117
  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
- },
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 nodality bundle as ES module...");
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 start # Serve the project");
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
- // get 3rd component from "args" /(<project-name>)
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-nodality",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
4
4
  "description": "Project scaffolding tool for Nodality library",
5
5
  "bin": {
6
6
  "create-nodality": "bin/index.js"
File without changes
@@ -1,11 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8" />
5
- <title>Nodality App</title>
6
- </head>
7
- <body>
8
- <div id="mount"></div>
9
- <script type="module" src="./main.js"></script>
10
- </body>
11
- </html>
package/templates/main.js DELETED
@@ -1,5 +0,0 @@
1
- import { Text } from "nodality";
2
-
3
- new Text("Hello")
4
- .set({})
5
- .render("#mount");