create-nodality 1.0.0-beta.4 → 1.0.0-beta.5
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 +74 -48
- package/package.json +1 -1
package/bin/index.js
CHANGED
@@ -1,19 +1,14 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
2
|
|
3
|
-
import { mkdirSync,
|
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 (
|
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,39 +18,39 @@ function createProject(projectName) {
|
|
23
18
|
}
|
24
19
|
|
25
20
|
mkdirSync(projectPath);
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
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 { Text } from 'nodality';
|
44
|
+
|
45
|
+
new Text('Hello, Nodality!')
|
46
|
+
.set({
|
47
|
+
size: 'S1',
|
48
|
+
color: '#1abc9c',
|
49
|
+
font: 'Arial',
|
50
|
+
})
|
51
|
+
.render('#mount');
|
52
|
+
`;
|
53
|
+
writeFileSync(resolve(srcPath, "index.js"), indexJs.trim());
|
59
54
|
|
60
55
|
// Create webpack.config.js
|
61
56
|
const webpackConfig = `
|
@@ -66,16 +61,16 @@ const __filename = fileURLToPath(import.meta.url);
|
|
66
61
|
const __dirname = path.dirname(__filename);
|
67
62
|
|
68
63
|
export default {
|
69
|
-
mode: '
|
70
|
-
entry: './
|
64
|
+
mode: 'production',
|
65
|
+
entry: './src/index.js',
|
71
66
|
output: {
|
72
67
|
filename: 'bundle.js',
|
73
|
-
path: path.resolve(
|
68
|
+
path: path.resolve(__dirname, 'dist'),
|
74
69
|
},
|
75
70
|
module: {
|
76
71
|
rules: [
|
77
72
|
{
|
78
|
-
test:
|
73
|
+
test: /\\.js$/,
|
79
74
|
exclude: /node_modules/,
|
80
75
|
use: {
|
81
76
|
loader: 'babel-loader',
|
@@ -86,21 +81,52 @@ export default {
|
|
86
81
|
},
|
87
82
|
],
|
88
83
|
},
|
84
|
+
resolve: {
|
85
|
+
alias: {
|
86
|
+
nodality: path.resolve(__dirname, 'node_modules/nodality/dist/index.esm.js'),
|
87
|
+
},
|
88
|
+
},
|
89
89
|
};
|
90
90
|
`;
|
91
91
|
writeFileSync(resolve(projectPath, "webpack.config.js"), webpackConfig.trim());
|
92
|
-
console.log("Created webpack.config.js");
|
93
92
|
|
94
|
-
//
|
95
|
-
|
93
|
+
// Create package.json
|
94
|
+
const pkg = {
|
95
|
+
name: projectName,
|
96
|
+
version: "1.0.0",
|
97
|
+
type: "module",
|
98
|
+
scripts: {
|
99
|
+
build: "webpack",
|
100
|
+
start: "serve . -l 4000",
|
101
|
+
},
|
102
|
+
dependencies: {
|
103
|
+
nodality: "^1.0.0-beta.4",
|
104
|
+
},
|
105
|
+
devDependencies: {
|
106
|
+
webpack: "^5.0.0",
|
107
|
+
"webpack-cli": "^5.0.0",
|
108
|
+
"babel-loader": "^9.0.0",
|
109
|
+
"@babel/core": "^7.0.0",
|
110
|
+
"@babel/preset-env": "^7.0.0",
|
111
|
+
},
|
112
|
+
};
|
113
|
+
writeFileSync(resolve(projectPath, "package.json"), JSON.stringify(pkg, null, 2));
|
114
|
+
|
115
|
+
// Install dependencies
|
116
|
+
console.log("Installing dependencies...");
|
117
|
+
execSync(`npm install`, { cwd: projectPath, stdio: "inherit" });
|
118
|
+
|
119
|
+
// Build project
|
120
|
+
console.log("Building with Webpack...");
|
96
121
|
execSync(`npx webpack`, { cwd: projectPath, stdio: "inherit" });
|
97
122
|
|
98
123
|
console.log("\nAll done! Run:\n");
|
99
124
|
console.log(` cd ${projectName}`);
|
100
125
|
console.log(" npm run build # Rebuild your project");
|
101
|
-
console.log(" npm start # Serve your project\n");
|
126
|
+
console.log(" npm start # Serve your project on localhost:4000\n");
|
102
127
|
}
|
103
128
|
|
129
|
+
// Parse CLI arguments
|
104
130
|
const args = process.argv.slice(2);
|
105
131
|
|
106
132
|
if (!args[0]) {
|