create-nodality 1.0.0-beta.3 → 1.0.0-beta.37

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 (3) hide show
  1. package/bin/index.js +102 -49
  2. package/package.json +3 -3
  3. package/release.sh +11 -0
package/bin/index.js CHANGED
@@ -1,19 +1,14 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { mkdirSync, copyFileSync, existsSync, writeFileSync } from "fs";
3
+ import { mkdirSync, writeFileSync, existsSync } from "fs";
4
4
  import { resolve, dirname } from "path";
5
5
  import { execSync } from "child_process";
6
6
  import { fileURLToPath } from "url";
7
7
 
8
- // Helper to get directory of current file (since using ES modules)
8
+ // Helper to get directory of current file (ESM compatible)
9
9
  const __filename = fileURLToPath(import.meta.url);
10
10
  const __dirname = dirname(__filename);
11
11
 
12
- function copyTemplateFile(src, dest) {
13
- copyFileSync(src, dest);
14
- console.log(`Created ${dest}`);
15
- }
16
-
17
12
  function createProject(projectName) {
18
13
  const projectPath = resolve(process.cwd(), projectName);
19
14
 
@@ -23,11 +18,90 @@ function createProject(projectName) {
23
18
  }
24
19
 
25
20
  mkdirSync(projectPath);
21
+ const srcPath = resolve(projectPath, "src");
22
+ mkdirSync(srcPath);
23
+
24
+ // Create index.html
25
+ const indexHtml = `
26
+ <!DOCTYPE html>
27
+ <html lang="en">
28
+ <head>
29
+ <meta charset="UTF-8">
30
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
31
+ <title>${projectName}</title>
32
+ </head>
33
+ <body>
34
+ <div id="mount"></div>
35
+ <script src="dist/bundle.js"></script>
36
+ </body>
37
+ </html>
38
+ `;
39
+ writeFileSync(resolve(projectPath, "index.html"), indexHtml.trim());
40
+
41
+ // Create index.js
42
+ const indexJs = `
43
+ import { Des } from 'nodality';
44
+
45
+ let elements = [
46
+ {
47
+ type: "h1",
48
+ text: "Hello"
49
+ }
50
+ ];
51
+
52
+ let nodes = [
53
+ {
54
+ op: "blast"
55
+ }
56
+ ];
57
+
58
+ new Des()
59
+ .nodes(nodes)
60
+ .add(elements)
61
+ .set({
62
+ mount: "#mount",
63
+ code: true
64
+ });
65
+ `;
66
+ writeFileSync(resolve(srcPath, "index.js"), indexJs.trim());
67
+
68
+ // Create webpack.config.js
69
+ const webpackConfig = `
70
+ import path from 'path';
71
+ import { fileURLToPath } from 'url';
72
+
73
+ const __filename = fileURLToPath(import.meta.url);
74
+ const __dirname = path.dirname(__filename);
26
75
 
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"));
76
+ export default {
77
+ mode: 'production',
78
+ entry: './src/index.js',
79
+ output: {
80
+ filename: 'bundle.js',
81
+ path: path.resolve(__dirname, 'dist'),
82
+ },
83
+ module: {
84
+ rules: [
85
+ {
86
+ test: /\\.js$/,
87
+ exclude: /node_modules/,
88
+ use: {
89
+ loader: 'babel-loader',
90
+ options: {
91
+ presets: ['@babel/preset-env'],
92
+ },
93
+ },
94
+ },
95
+ ],
96
+ },
97
+ resolve: {
98
+ alias: {
99
+ nodality: path.resolve(__dirname, 'node_modules/nodality/dist/index.esm.js'),
100
+ },
101
+ },
102
+ };
103
+ `;
104
+ writeFileSync(resolve(projectPath, "webpack.config.js"), webpackConfig.trim());
31
105
 
32
106
  // Create package.json
33
107
  const pkg = {
@@ -36,67 +110,45 @@ function createProject(projectName) {
36
110
  type: "module",
37
111
  scripts: {
38
112
  build: "webpack",
39
- start: "serve dist"
113
+ start: "npx serve . -l 4000",
40
114
  },
41
115
  dependencies: {
42
- nodality: "^1.0.0-beta.4"
116
+ nodality: "^1.0.0-beta.37",
43
117
  },
44
118
  devDependencies: {
45
119
  webpack: "^5.0.0",
46
120
  "webpack-cli": "^5.0.0",
47
121
  "babel-loader": "^9.0.0",
48
122
  "@babel/core": "^7.0.0",
49
- "@babel/preset-env": "^7.0.0"
50
- }
123
+ "@babel/preset-env": "^7.0.0",
124
+ },
51
125
  };
52
-
53
126
  writeFileSync(resolve(projectPath, "package.json"), JSON.stringify(pkg, null, 2));
54
- console.log("Created package.json");
55
127
 
56
128
  // Install dependencies
57
129
  console.log("Installing dependencies...");
58
130
  execSync(`npm install`, { cwd: projectPath, stdio: "inherit" });
59
131
 
60
- // Create webpack.config.js
61
- const webpackConfig = `
62
- const path = require('path');
132
+ // Build project
133
+ console.log("Building with Webpack...");
134
+ execSync(`npx webpack`, { cwd: projectPath, stdio: "inherit" });
63
135
 
64
- module.exports = {
65
- mode: 'development',
66
- entry: './main.js',
67
- output: {
68
- filename: 'bundle.js',
69
- path: path.resolve(process.cwd(), 'dist'),
70
- },
71
- module: {
72
- rules: [
73
- {
74
- test: /\\.m?js$/,
75
- exclude: /node_modules/,
76
- use: {
77
- loader: 'babel-loader',
78
- options: {
79
- presets: ['@babel/preset-env']
80
- }
81
- }
82
- }
83
- ]
84
- }
85
- };
86
- `;
87
- writeFileSync(resolve(projectPath, "webpack.config.js"), webpackConfig.trim());
88
- console.log("Created webpack.config.js");
89
136
 
90
- // Build project using webpack
91
- console.log("Building with webpack...");
92
- execSync(`npx webpack`, { cwd: projectPath, stdio: "inherit" });
137
+ // ANSI escape codes for green text and reset
138
+
139
+ const bold = '\x1b[1m';
140
+ const color1abc9c = '\x1b[38;5;37m';
141
+ const reset = '\x1b[0m';
142
+
143
+ console.log(`\n${color1abc9c}${bold}%s${reset}\n`, `Your project "${projectName}" is ready! 🎉`);
93
144
 
94
145
  console.log("\nAll done! Run:\n");
95
146
  console.log(` cd ${projectName}`);
96
147
  console.log(" npm run build # Rebuild your project");
97
- console.log(" npm start # Serve your project\n");
148
+ console.log(" npm start # Serve your project on localhost:4000\n");
98
149
  }
99
150
 
151
+ // Parse CLI arguments
100
152
  const args = process.argv.slice(2);
101
153
 
102
154
  if (!args[0]) {
@@ -104,4 +156,5 @@ if (!args[0]) {
104
156
  process.exit(1);
105
157
  }
106
158
 
159
+ // Create the project
107
160
  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",
3
+ "version": "1.0.0-beta.37",
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-beta.4"
21
+ "nodality": "^1.0.0-beta.37"
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