nibula 1.2.4 → 1.2.6
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/.eleventy.js +81 -81
- package/.eleventyignore +3 -3
- package/.github/workflows/publish.yml +37 -0
- package/CHANGELOG.md +179 -148
- package/LICENSE +169 -169
- package/NOTICE +4 -4
- package/README.md +120 -123
- package/bin/create.js +507 -507
- package/bin/nibula.js +317 -305
- package/docs/Assistant CLI.md +65 -65
- package/docs/Backend.md +295 -295
- package/docs/Components.md +84 -84
- package/docs/Creating pages.md +64 -64
- package/docs/Deploy.md +189 -189
- package/docs/Head and SEO.md +138 -138
- package/docs/Javascript.md +50 -50
- package/docs/Styling with SCSS.md +141 -141
- package/nginx.conf +75 -75
- package/package.json +1 -1
- package/src/backend/.htaccess +6 -6
- package/src/backend/_core/composer.json +5 -5
- package/src/backend/_core/composer.lock +492 -492
- package/src/backend/_core/index.js +267 -267
- package/src/backend/_core/index.php +147 -147
- package/src/backend/_core/init.js +52 -52
- package/src/backend/_core/init.php +33 -33
- package/src/backend/_core/modules/RateLimiter.js +58 -58
- package/src/backend/_core/modules/RateLimiter.php +30 -30
- package/src/backend/_core/modules/Response.js +59 -59
- package/src/backend/_core/modules/Response.php +48 -48
- package/src/backend/api/protected/example-protected.js +23 -23
- package/src/backend/api/protected/example-protected.php +16 -16
- package/src/backend/api/public/example-public.js +24 -24
- package/src/backend/api/public/example-public.php +16 -16
- package/src/backend/backend-node.service.example +30 -30
- package/src/backend/database/Database.js +46 -46
- package/src/backend/database/Database.php +23 -23
- package/src/backend/example.config.js +37 -37
- package/src/backend/example.config.php +27 -27
- package/src/backend/package.json +18 -18
- package/src/backend/web.config +16 -16
- package/src/frontend/.htaccess +51 -51
- package/src/frontend/404.njk +17 -17
- package/src/frontend/assets/brand/favicon.svg +54 -54
- package/src/frontend/assets/brand/logo.svg +54 -54
- package/src/frontend/components/global/footer.njk +25 -25
- package/src/frontend/components/global/header.njk +6 -6
- package/src/frontend/components/welcome.njk +114 -114
- package/src/frontend/data/site.json +48 -48
- package/src/frontend/index.njk +8 -8
- package/src/frontend/js/modules/exampleModule.js +2 -2
- package/src/frontend/js/pages/404.js +6 -6
- package/src/frontend/js/pages/homepage.js +6 -6
- package/src/frontend/layouts/base.njk +132 -132
- package/src/frontend/layouts/page-components.njk +13 -13
- package/src/frontend/llms.njk +17 -17
- package/src/frontend/robots.njk +7 -7
- package/src/frontend/scss/modules/_animations.scss +24 -24
- package/src/frontend/scss/modules/_footer.scss +27 -27
- package/src/frontend/scss/modules/_global.scss +47 -47
- package/src/frontend/scss/modules/_header.scss +27 -27
- package/src/frontend/scss/modules/_mobile.scss +29 -29
- package/src/frontend/scss/modules/_root.scss +34 -34
- package/src/frontend/scss/modules/_typography.scss +14 -14
- package/src/frontend/scss/modules/frameworks/_bootstrap.scss +109 -109
- package/src/frontend/scss/modules/frameworks/_bulma.scss +108 -108
- package/src/frontend/scss/modules/frameworks/_foundation.scss +138 -139
- package/src/frontend/scss/modules/frameworks/_uikit.scss +109 -109
- package/src/frontend/scss/pages/404.scss +27 -27
- package/src/frontend/scss/pages/homepage.scss +22 -22
- package/src/frontend/sitemap.njk +17 -17
- package/src/frontend/ts/modules/exampleModule.ts +2 -2
- package/src/frontend/ts/pages/404.ts +6 -6
- package/src/frontend/ts/pages/homepage.ts +6 -6
- package/src/frontend/web.config +55 -55
- package/tools/config/messages.json +3 -1
- package/tools/res/templates/template.js +6 -6
- package/tools/res/templates/template.njk +8 -8
- package/tools/res/templates/template.scss +22 -22
- package/tools/res/templates/template.ts +6 -6
- package/tsconfig.json +24 -24
package/bin/nibula.js
CHANGED
|
@@ -1,306 +1,318 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
const path = require('path');
|
|
5
|
-
const https = require('https');
|
|
6
|
-
const readline = require('readline');
|
|
7
|
-
const { spawnSync } = require('child_process');
|
|
8
|
-
const { findProjectRoot, NOT_INSIDE_PROJECT_MESSAGE } = require('../tools/lib/paths');
|
|
9
|
-
const { color } = require('../tools/lib/colors');
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
return
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
function
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
case '
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const https = require('https');
|
|
6
|
+
const readline = require('readline');
|
|
7
|
+
const { spawnSync } = require('child_process');
|
|
8
|
+
const { findProjectRoot, NOT_INSIDE_PROJECT_MESSAGE } = require('../tools/lib/paths');
|
|
9
|
+
const { color } = require('../tools/lib/colors');
|
|
10
|
+
const { message } = require('../tools/lib/logger');
|
|
11
|
+
|
|
12
|
+
const pkg = require('../package.json');
|
|
13
|
+
|
|
14
|
+
const [, , cmd, ...rest] = process.argv;
|
|
15
|
+
|
|
16
|
+
const CREATE = path.join(__dirname, 'create.js');
|
|
17
|
+
const ASSISTANT = path.join(__dirname, '..', 'tools', 'assistant.js');
|
|
18
|
+
const BUILDJS = path.join(__dirname, '..', 'tools', 'buildJs.js');
|
|
19
|
+
const CLEAN = path.join(__dirname, '..', 'tools', 'cleanOutput.js');
|
|
20
|
+
|
|
21
|
+
const REGISTRY = 'https://registry.npmjs.org/nibula/latest';
|
|
22
|
+
const CHECK_TIMEOUT = 2500;
|
|
23
|
+
const SKIP_FLAG = '--skip-update-check';
|
|
24
|
+
|
|
25
|
+
function run(script, args) {
|
|
26
|
+
const res = spawnSync('node', [script, ...args], {
|
|
27
|
+
stdio: 'inherit',
|
|
28
|
+
cwd: process.cwd(),
|
|
29
|
+
});
|
|
30
|
+
process.exit(res.status ?? 0);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function requireProjectRoot() {
|
|
34
|
+
const root = findProjectRoot(process.cwd());
|
|
35
|
+
if (!root) {
|
|
36
|
+
console.error(NOT_INSIDE_PROJECT_MESSAGE);
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
39
|
+
return root;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function requireOutsideProject() {
|
|
43
|
+
const root = findProjectRoot(process.cwd());
|
|
44
|
+
if (!root) return;
|
|
45
|
+
|
|
46
|
+
console.error(`\n${color.red}${message('project.alreadyInside')}${color.reset}`);
|
|
47
|
+
console.error(`${color.dim}${message('project.alreadyInsideHint')}${color.reset}\n`);
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function maybeDelegateToLocal(root) {
|
|
52
|
+
const local = path.join(root, 'node_modules', 'nibula', 'bin', 'nibula.js');
|
|
53
|
+
if (!fs.existsSync(local)) return;
|
|
54
|
+
|
|
55
|
+
let localReal;
|
|
56
|
+
let selfReal;
|
|
57
|
+
try { localReal = fs.realpathSync(local); } catch { return; }
|
|
58
|
+
try { selfReal = fs.realpathSync(__filename); } catch { selfReal = __filename; }
|
|
59
|
+
|
|
60
|
+
if (localReal !== selfReal) {
|
|
61
|
+
const res = spawnSync('node', [localReal, ...process.argv.slice(2)], {
|
|
62
|
+
stdio: 'inherit',
|
|
63
|
+
cwd: process.cwd(),
|
|
64
|
+
});
|
|
65
|
+
process.exit(res.status ?? 0);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function enterProject() {
|
|
70
|
+
const root = requireProjectRoot();
|
|
71
|
+
maybeDelegateToLocal(root);
|
|
72
|
+
return root;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function runNpm(root, scriptName) {
|
|
76
|
+
const res = spawnSync('npm', ['run', scriptName], {
|
|
77
|
+
stdio: 'inherit',
|
|
78
|
+
cwd: root,
|
|
79
|
+
shell: process.platform === 'win32',
|
|
80
|
+
});
|
|
81
|
+
if (res.error) console.error(res.error.message);
|
|
82
|
+
process.exit(res.status ?? 0);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function fetchLatest() {
|
|
86
|
+
return new Promise((resolve) => {
|
|
87
|
+
const req = https.get(REGISTRY, (res) => {
|
|
88
|
+
if (res.statusCode !== 200) {
|
|
89
|
+
res.resume();
|
|
90
|
+
resolve(null);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
let data = '';
|
|
94
|
+
res.on('data', (chunk) => { data += chunk; });
|
|
95
|
+
res.on('end', () => {
|
|
96
|
+
try {
|
|
97
|
+
resolve(JSON.parse(data).version ?? null);
|
|
98
|
+
} catch {
|
|
99
|
+
resolve(null);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
req.on('error', () => resolve(null));
|
|
104
|
+
req.setTimeout(CHECK_TIMEOUT, () => {
|
|
105
|
+
req.destroy();
|
|
106
|
+
resolve(null);
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function isOlder(current, latest) {
|
|
112
|
+
const parse = (v) => String(v).split('-')[0].split('.').map(Number);
|
|
113
|
+
const a = parse(current);
|
|
114
|
+
const b = parse(latest);
|
|
115
|
+
for (let i = 0; i < 3; i++) {
|
|
116
|
+
const na = a[i] || 0;
|
|
117
|
+
const nb = b[i] || 0;
|
|
118
|
+
if (na < nb) return true;
|
|
119
|
+
if (na > nb) return false;
|
|
120
|
+
}
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
async function checkVersion() {
|
|
125
|
+
const latest = await fetchLatest();
|
|
126
|
+
return {
|
|
127
|
+
current: pkg.version,
|
|
128
|
+
latest,
|
|
129
|
+
behind: latest !== null && isOlder(pkg.version, latest),
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function ask(question) {
|
|
134
|
+
return new Promise((resolve) => {
|
|
135
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
136
|
+
rl.question(question, (answer) => {
|
|
137
|
+
rl.close();
|
|
138
|
+
resolve(answer.trim().toLowerCase());
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function updateGlobal(version) {
|
|
144
|
+
const target = version ? `nibula@${version}` : 'nibula@latest';
|
|
145
|
+
const res = spawnSync('npm', ['install', '-g', target, '--prefer-online'], {
|
|
146
|
+
stdio: 'inherit',
|
|
147
|
+
shell: process.platform === 'win32',
|
|
148
|
+
});
|
|
149
|
+
return res.status ?? 0;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function globalNibulaPath() {
|
|
153
|
+
const res = spawnSync('npm', ['root', '-g'], {
|
|
154
|
+
encoding: 'utf8',
|
|
155
|
+
shell: process.platform === 'win32',
|
|
156
|
+
});
|
|
157
|
+
if (res.status !== 0 || !res.stdout) return null;
|
|
158
|
+
const candidate = path.join(res.stdout.trim(), 'nibula', 'bin', 'nibula.js');
|
|
159
|
+
return fs.existsSync(candidate) ? candidate : null;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function reexecAfterUpdate(args) {
|
|
163
|
+
const target = globalNibulaPath();
|
|
164
|
+
if (!target) {
|
|
165
|
+
console.error(`${color.red}Could not locate the updated Nibula installation.${color.reset}`);
|
|
166
|
+
console.error(`Run "nib new ${args[1]}" again to continue.`);
|
|
167
|
+
return 1;
|
|
168
|
+
}
|
|
169
|
+
const res = spawnSync(process.execPath, [target, ...args, SKIP_FLAG], {
|
|
170
|
+
stdio: 'inherit',
|
|
171
|
+
cwd: process.cwd(),
|
|
172
|
+
});
|
|
173
|
+
return res.status ?? 0;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function findExistingProject(baseDir, projectName) {
|
|
177
|
+
let entries;
|
|
178
|
+
try {
|
|
179
|
+
entries = fs.readdirSync(baseDir, { withFileTypes: true });
|
|
180
|
+
} catch {
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
for (const entry of entries) {
|
|
184
|
+
if (!entry.isDirectory()) continue;
|
|
185
|
+
const pkgPath = path.join(baseDir, entry.name, 'package.json');
|
|
186
|
+
if (!fs.existsSync(pkgPath)) continue;
|
|
187
|
+
try {
|
|
188
|
+
const data = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
189
|
+
if (data && data.name === projectName) {
|
|
190
|
+
return path.join(baseDir, entry.name);
|
|
191
|
+
}
|
|
192
|
+
} catch {
|
|
193
|
+
// ...
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function usage(currentVersion) {
|
|
200
|
+
console.log(`
|
|
201
|
+
${color.bold}${color.cyan}Nibula (${currentVersion})${color.reset} ${color.bold}by Michele Garofalo${color.reset}
|
|
202
|
+
|
|
203
|
+
${color.yellow}nib new <project-name>${color.reset} Create your new project
|
|
204
|
+
${color.yellow}nib cli${color.reset} Open the page-management assistant
|
|
205
|
+
${color.yellow}nib run${color.reset} Start the dev server and builds out folder runtime
|
|
206
|
+
${color.yellow}nib build${color.reset} Build the site out folder to publish
|
|
207
|
+
${color.yellow}nib clean${color.reset} Remove the output directory
|
|
208
|
+
${color.yellow}nib update${color.reset} Update to the latest version
|
|
209
|
+
`);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
async function main() {
|
|
213
|
+
switch (cmd) {
|
|
214
|
+
case 'new': {
|
|
215
|
+
const args = rest.filter((a) => a !== SKIP_FLAG);
|
|
216
|
+
const skipCheck = rest.includes(SKIP_FLAG);
|
|
217
|
+
|
|
218
|
+
if (!args[0]) {
|
|
219
|
+
console.error('Missing project name. Usage: nib new <project-name>');
|
|
220
|
+
process.exit(1);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
requireOutsideProject();
|
|
224
|
+
|
|
225
|
+
if (!skipCheck) {
|
|
226
|
+
const info = await checkVersion();
|
|
227
|
+
if (info.behind) {
|
|
228
|
+
console.log(`\nA newer version of Nibula is available: ${info.current} → ${info.latest}`);
|
|
229
|
+
if (process.stdin.isTTY) {
|
|
230
|
+
const answer = await ask('Update before creating the project? [Y/n] ');
|
|
231
|
+
if (answer === '' || answer === 'y' || answer === 'yes') {
|
|
232
|
+
const code = updateGlobal(info.latest);
|
|
233
|
+
if (code !== 0) process.exit(code);
|
|
234
|
+
console.log(`\n${color.green}Updated.${color.reset} Continuing with the new version...\n`);
|
|
235
|
+
process.exit(reexecAfterUpdate(['new', args[0]]));
|
|
236
|
+
}
|
|
237
|
+
} else {
|
|
238
|
+
console.log('Run "nib update" to update.\n');
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const existing = findExistingProject(process.cwd(), args[0]);
|
|
244
|
+
if (existing) {
|
|
245
|
+
console.log(`\n${color.yellow}A project named "${args[0]}" already exists:${color.reset} ${existing}`);
|
|
246
|
+
let overwrite = false;
|
|
247
|
+
if (process.stdin.isTTY) {
|
|
248
|
+
const answer = await ask('Do you want to overwrite it? [y/N] ');
|
|
249
|
+
overwrite = (answer === 'y' || answer === 'yes');
|
|
250
|
+
} else {
|
|
251
|
+
console.log('Run in a TTY to confirm overwrite.');
|
|
252
|
+
}
|
|
253
|
+
if (!overwrite) {
|
|
254
|
+
console.log('Stopped creating the new project');
|
|
255
|
+
process.exit(0);
|
|
256
|
+
}
|
|
257
|
+
try {
|
|
258
|
+
fs.rmSync(existing, { recursive: true, force: true });
|
|
259
|
+
console.log(`${color.green}Removed existing project.${color.reset}`);
|
|
260
|
+
} catch (err) {
|
|
261
|
+
console.error(`${color.red}Failed to remove existing project:${color.reset} ${err.message}`);
|
|
262
|
+
process.exit(1);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
run(CREATE, [args[0]]);
|
|
267
|
+
break;
|
|
268
|
+
}
|
|
269
|
+
case 'cli': {
|
|
270
|
+
enterProject();
|
|
271
|
+
run(ASSISTANT, []);
|
|
272
|
+
break;
|
|
273
|
+
}
|
|
274
|
+
case 'run': {
|
|
275
|
+
const root = enterProject();
|
|
276
|
+
runNpm(root, 'serve');
|
|
277
|
+
break;
|
|
278
|
+
}
|
|
279
|
+
case 'build': {
|
|
280
|
+
const root = enterProject();
|
|
281
|
+
runNpm(root, 'build');
|
|
282
|
+
break;
|
|
283
|
+
}
|
|
284
|
+
case 'build-js': {
|
|
285
|
+
enterProject();
|
|
286
|
+
run(BUILDJS, rest);
|
|
287
|
+
break;
|
|
288
|
+
}
|
|
289
|
+
case 'clean': {
|
|
290
|
+
enterProject();
|
|
291
|
+
run(CLEAN, []);
|
|
292
|
+
break;
|
|
293
|
+
}
|
|
294
|
+
case 'update': {
|
|
295
|
+
const info = await checkVersion();
|
|
296
|
+
if (info.latest !== null && !info.behind) {
|
|
297
|
+
console.log(`Already on the latest version (${info.current}).`);
|
|
298
|
+
process.exit(0);
|
|
299
|
+
}
|
|
300
|
+
process.exit(updateGlobal(info.latest));
|
|
301
|
+
}
|
|
302
|
+
case undefined:
|
|
303
|
+
case 'help':
|
|
304
|
+
case '-help':
|
|
305
|
+
case '--help':
|
|
306
|
+
case 'h':
|
|
307
|
+
case '-h': {
|
|
308
|
+
usage(pkg.version);
|
|
309
|
+
break;
|
|
310
|
+
}
|
|
311
|
+
default:
|
|
312
|
+
console.error(`${color.red}\nUnknown command:${color.reset} ${cmd}`);
|
|
313
|
+
usage(pkg.version);
|
|
314
|
+
process.exit(1);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
306
318
|
main();
|