create-nodality 1.0.91 → 1.0.93

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.
Files changed (2) hide show
  1. package/bin/index.js +29 -40
  2. package/package.json +1 -1
package/bin/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { mkdirSync, writeFileSync, existsSync, copyFileSync } from "fs";
3
+ import { mkdirSync, writeFileSync, existsSync } from "fs";
4
4
  import { resolve } from "path";
5
5
  import { execSync } from "child_process";
6
6
 
@@ -12,14 +12,14 @@ function createProject(projectName) {
12
12
  process.exit(1);
13
13
  }
14
14
 
15
- // Create folders
16
15
  mkdirSync(projectPath);
17
16
  const srcPath = resolve(projectPath, "src");
18
17
  mkdirSync(srcPath);
19
18
 
20
- // Copy index.html
21
- const indexHtml = `
22
- <!DOCTYPE html>
19
+ // Root dev index.html — used during `npm run dev` (live-server serves
20
+ // upload/, but the root file is also kept as a development fallback
21
+ // pointing at src/app.js via the node_modules importmap).
22
+ const indexHtml = `<!DOCTYPE html>
23
23
  <html lang="en">
24
24
  <head>
25
25
  <meta charset="UTF-8">
@@ -41,16 +41,16 @@ function createProject(projectName) {
41
41
  <!-- User app -->
42
42
  <script type="module" src="src/app.js"></script>
43
43
  </body>
44
- </html>
45
- `;
46
- writeFileSync(resolve(projectPath, "index.html"), indexHtml.trim());
44
+ </html>`;
45
+ writeFileSync(resolve(projectPath, "index.html"), indexHtml);
47
46
 
48
- // Copy app.js
49
- const appJs = `
50
- import { Des } from "nodality";
47
+ // src/app.js — the user's source. On first `npm run prerender`
48
+ // the CLI clones this into upload/pages/<name>.js as the SSG entry.
49
+ const appJs = `import { Des } from "nodality";
51
50
 
52
51
  const elements = [
53
- { type: "h1", text: "Hello" }
52
+ { type: "h1", text: "Hello" },
53
+ { type: "nav" }
54
54
  ];
55
55
 
56
56
  const nodes = [
@@ -62,14 +62,15 @@ new Des()
62
62
  .add(elements)
63
63
  .set({
64
64
  mount: "#mount",
65
- code: true,
65
+ code: false,
66
66
  });
67
- `;
68
- writeFileSync(resolve(srcPath, "app.js"), appJs.trim());
67
+ `;
68
+ writeFileSync(resolve(srcPath, "app.js"), appJs);
69
69
 
70
- // Copy webpack.config.js
71
- const webpackConfig = `
72
- import path from "path";
70
+ // webpack outputs the bundle into upload/ so dev (live-server upload)
71
+ // and prerender both see the same lib.bundle.js. clean:false so the
72
+ // build does not wipe the SSG index.html / pages/ that live alongside.
73
+ const webpackConfig = `import path from "path";
73
74
  import { fileURLToPath } from "url";
74
75
 
75
76
  const __filename = fileURLToPath(import.meta.url);
@@ -79,12 +80,12 @@ export default {
79
80
  mode: "production",
80
81
  entry: "nodality", // bundle Nodality only
81
82
  output: {
82
- path: path.resolve(__dirname, "dist"),
83
+ path: path.resolve(__dirname, "upload"),
83
84
  filename: "lib.bundle.js",
84
85
  library: { type: "module" }, // ESM output
85
86
  environment: { module: true },
86
- clean: true,
87
- publicPath: "/",
87
+ clean: false, // upload/ holds index.html + pages/ — do not wipe
88
+ publicPath: "./",
88
89
  },
89
90
  experiments: { outputModule: true },
90
91
  module: {
@@ -97,22 +98,18 @@ export default {
97
98
  ],
98
99
  },
99
100
  };
100
- `;
101
- writeFileSync(resolve(projectPath, "webpack.config.js"), webpackConfig.trim());
101
+ `;
102
+ writeFileSync(resolve(projectPath, "webpack.config.js"), webpackConfig);
102
103
 
103
- // package.json
104
104
  const pkg = {
105
105
  name: projectName,
106
106
  version: "1.0.0",
107
107
  type: "module",
108
108
  scripts: {
109
109
  build: "webpack --config webpack.config.js",
110
- // `prerender` is the SSG step — renders upload/*.html in place
111
- // from upload/pages/*.js entries. Reads nodality.config.json
112
- // (scaffolded below) for origin + optional locales/pages.
113
110
  prerender: "nodality prerender",
114
111
  watch: "webpack --watch --config webpack.config.js",
115
- start: "live-server . --port=4000 --watch=dist,src",
112
+ start: "live-server upload --port=4000 --watch=upload",
116
113
  dev: "npm-run-all --parallel watch start"
117
114
  },
118
115
  dependencies: {
@@ -132,13 +129,6 @@ export default {
132
129
  };
133
130
  writeFileSync(resolve(projectPath, "package.json"), JSON.stringify(pkg, null, 2));
134
131
 
135
- // nodality.config.json — read by `nodality prerender`. Origin is
136
- // a placeholder the user should change; everything else has a
137
- // sensible default and can stay out of the file unless overridden.
138
- // The empty `pages: []` means "auto-discover" (walk upload/*.html
139
- // and pair with upload/pages/<name>.js or upload/<name>.js). For
140
- // irregular pairs like `index.html → app.js`, fill in pages
141
- // explicitly here.
142
132
  const nodalityConfig = {
143
133
  origin: `https://${projectName}.example.com`,
144
134
  uploadDir: "upload",
@@ -162,17 +152,16 @@ export default {
162
152
  console.log(`\n${color1abc9c}${bold}%s${reset}\n`, `Project "${projectName}" is ready! 🎉`);
163
153
  console.log("\nUsage:\n");
164
154
  console.log(` cd ${projectName}`);
165
- console.log(" npm run build # Rebuild library bundle");
166
- console.log(" npm run prerender # Prerender static HTML for production (SSG)");
167
- console.log(" npm run dev # Start dev server with live reload");
168
- console.log(" npm start # Serve project without watch");
155
+ console.log(" npm run build # Rebuild library bundle into upload/");
156
+ console.log(" npm run prerender # First run bootstraps upload/, then renders static HTML");
157
+ console.log(" npm run dev # Start dev server (live-server on upload/) with watch");
158
+ console.log(" npm start # Serve upload/ without watch");
169
159
  console.log("");
170
160
  console.log(
171
161
  ` Edit ${color1abc9c}nodality.config.json${reset} to set your public origin before running prerender.`
172
162
  );
173
163
  }
174
164
 
175
- // Get project name from CLI args
176
165
  const args = process.argv.slice(2);
177
166
  if (!args[0]) {
178
167
  console.error("Usage: npm create nodality <project-name>");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-nodality",
3
- "version": "1.0.91",
3
+ "version": "1.0.93",
4
4
  "description": "Project scaffolding tool for Nodality library",
5
5
  "bin": {
6
6
  "create-nodality": "bin/index.js"