create-lupine 1.0.29 → 1.0.31
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/index.js +431 -411
- package/package.json +17 -17
- package/templates/common/.env.development +7 -7
- package/templates/common/.env.mobile +9 -9
- package/templates/common/.env.production +7 -7
- package/templates/common/_env +66 -58
- package/templates/common/_gitignore +25 -25
- package/templates/common/apps/server/src/index.ts +79 -76
- package/templates/common/apps/server/src/server-env-keys.ts +0 -9
- package/templates/common/dev/cp-folder.js +45 -45
- package/templates/common/tsconfig.json +128 -128
- package/templates/lupine-template-cv-starter/api/package.json +5 -5
- package/templates/lupine-template-cv-starter/api/resources/config_default.json +6 -6
- package/templates/lupine-template-cv-starter/api/resources/install.sqlite.sql +3 -3
- package/templates/lupine-template-cv-starter/api/src/index.ts +15 -15
- package/templates/lupine-template-cv-starter/lupine.json +39 -39
- package/templates/lupine-template-cv-starter/web/markdown/en/01-experience/index.md +32 -32
- package/templates/lupine-template-cv-starter/web/markdown/en/02-projects/index.md +36 -36
- package/templates/lupine-template-cv-starter/web/markdown/en/03-skills/index.md +28 -28
- package/templates/lupine-template-cv-starter/web/markdown/en/04-education/index.md +16 -16
- package/templates/lupine-template-cv-starter/web/markdown/en/index.md +41 -41
- package/templates/lupine-template-cv-starter/web/markdown/index.md +7 -7
- package/templates/lupine-template-cv-starter/web/markdown/zh/01-experience/index.md +32 -32
- package/templates/lupine-template-cv-starter/web/markdown/zh/02-projects/index.md +36 -36
- package/templates/lupine-template-cv-starter/web/markdown/zh/03-skills/index.md +28 -28
- package/templates/lupine-template-cv-starter/web/markdown/zh/04-education/index.md +17 -17
- package/templates/lupine-template-cv-starter/web/markdown/zh/index.md +41 -41
- package/templates/lupine-template-cv-starter/web/package.json +5 -5
- package/templates/lupine-template-cv-starter/web/src/client-env-keys.ts +5 -5
- package/templates/lupine-template-cv-starter/web/src/index.html +16 -16
- package/templates/lupine-template-cv-starter/web/src/index.tsx +28 -28
- package/templates/lupine-template-cv-starter/web/src/lupine-template-cv-starter/404.html +38 -38
- package/templates/lupine-template-cv-starter/web/src/lupine-template-cv-starter/index.html +73 -73
- package/templates/lupine-template-cv-starter/web/src/lupine-template-cv-starter/index.tsx +30 -30
- package/templates/lupine-template-cv-starter/web/src/markdown-built/en/01-experience/index.html +20 -20
- package/templates/lupine-template-cv-starter/web/src/markdown-built/en/02-projects/index.html +28 -28
- package/templates/lupine-template-cv-starter/web/src/markdown-built/en/03-skills/index.html +18 -18
- package/templates/lupine-template-cv-starter/web/src/markdown-built/en/04-education/index.html +10 -10
- package/templates/lupine-template-cv-starter/web/src/markdown-built/en/index.html +20 -20
- package/templates/lupine-template-cv-starter/web/src/markdown-built/zh/01-experience/index.html +20 -20
- package/templates/lupine-template-cv-starter/web/src/markdown-built/zh/02-projects/index.html +28 -28
- package/templates/lupine-template-cv-starter/web/src/markdown-built/zh/03-skills/index.html +18 -18
- package/templates/lupine-template-cv-starter/web/src/markdown-built/zh/04-education/index.html +11 -11
- package/templates/lupine-template-cv-starter/web/src/markdown-built/zh/index.html +20 -20
- package/templates/lupine-template-cv-starter/web/src/styles/base-css.ts +15 -15
- package/templates/lupine-template-doc-starter/api/package.json +5 -5
- package/templates/lupine-template-doc-starter/api/resources/config_default.json +6 -6
- package/templates/lupine-template-doc-starter/api/resources/install.sqlite.sql +3 -3
- package/templates/lupine-template-doc-starter/api/src/index.ts +15 -15
- package/templates/lupine-template-doc-starter/api/src/resources/config_default.json +6 -6
- package/templates/lupine-template-doc-starter/api/src/resources/install.sqlite.sql +3 -3
- package/templates/lupine-template-doc-starter/lupine.json +39 -39
- package/templates/lupine-template-doc-starter/web/markdown/en/essentials/index.md +6 -6
- package/templates/lupine-template-doc-starter/web/markdown/en/essentials/list.md +18 -18
- package/templates/lupine-template-doc-starter/web/markdown/en/guide/install.md +18 -18
- package/templates/lupine-template-doc-starter/web/markdown/en/guide/started.md +22 -22
- package/templates/lupine-template-doc-starter/web/markdown/en/index.md +42 -42
- package/templates/lupine-template-doc-starter/web/markdown/index.md +7 -7
- package/templates/lupine-template-doc-starter/web/markdown/zh/essentials/index.md +6 -6
- package/templates/lupine-template-doc-starter/web/markdown/zh/essentials/list.md +18 -18
- package/templates/lupine-template-doc-starter/web/markdown/zh/guide/install.md +18 -18
- package/templates/lupine-template-doc-starter/web/markdown/zh/guide/started.md +22 -22
- package/templates/lupine-template-doc-starter/web/markdown/zh/index.md +42 -42
- package/templates/lupine-template-doc-starter/web/package.json +5 -5
- package/templates/lupine-template-doc-starter/web/src/client-env-keys.ts +5 -5
- package/templates/lupine-template-doc-starter/web/src/index.html +16 -16
- package/templates/lupine-template-doc-starter/web/src/index.tsx +28 -28
- package/templates/lupine-template-doc-starter/web/src/lupine-template-doc-starter/404.html +38 -38
- package/templates/lupine-template-doc-starter/web/src/lupine-template-doc-starter/index.html +27 -27
- package/templates/lupine-template-doc-starter/web/src/lupine-template-doc-starter/index.tsx +30 -30
- package/templates/lupine-template-doc-starter/web/src/markdown-built/en/essentials/list.html +8 -8
- package/templates/lupine-template-doc-starter/web/src/markdown-built/en/guide/install.html +8 -8
- package/templates/lupine-template-doc-starter/web/src/markdown-built/en/guide/started.html +12 -12
- package/templates/lupine-template-doc-starter/web/src/markdown-built/zh/essentials/list.html +8 -8
- package/templates/lupine-template-doc-starter/web/src/markdown-built/zh/guide/install.html +8 -8
- package/templates/lupine-template-doc-starter/web/src/markdown-built/zh/guide/started.html +12 -12
- package/templates/lupine-template-doc-starter/web/src/styles/base-css.ts +15 -15
- package/templates/lupine-template-hello-world/api/resources/install.sqlite.sql +3 -3
- package/templates/lupine-template-hello-world/api/src/index.ts +4 -4
- package/templates/lupine-template-hello-world/api/src/service/root-api.ts +18 -18
- package/templates/lupine-template-hello-world/lupine.json +22 -22
- package/templates/lupine-template-hello-world/web/package.json +6 -6
- package/templates/lupine-template-hello-world/web/src/index.html +16 -16
- package/templates/lupine-template-hello-world/web/src/index.tsx +73 -73
- package/templates/lupine-template-responsive-starter/api/resources/install.sqlite.sql +3 -3
- package/templates/lupine-template-responsive-starter/api/src/index.ts +4 -4
- package/templates/lupine-template-responsive-starter/api/src/service/root-api.ts +18 -18
- package/templates/lupine-template-responsive-starter/web/src/app-icons.ts +76 -76
- package/templates/lupine-template-responsive-starter/web/src/components/input-history-component.tsx +93 -93
- package/templates/lupine-template-responsive-starter/web/src/components/mine-about-page.tsx +86 -86
- package/templates/lupine-template-responsive-starter/web/src/components/mine-premium-page.tsx +80 -80
- package/templates/lupine-template-responsive-starter/web/src/components/mine-settings-page.tsx +220 -219
- package/templates/lupine-template-responsive-starter/web/src/components/mobile-top-search-menu.tsx +119 -119
- package/templates/lupine-template-responsive-starter/web/src/components/note-detail.tsx +116 -116
- package/templates/lupine-template-responsive-starter/web/src/components/note-edit.tsx +154 -154
- package/templates/lupine-template-responsive-starter/web/src/components/note-search-page.tsx +193 -193
- package/templates/lupine-template-responsive-starter/web/src/components/search-input.tsx +95 -95
- package/templates/lupine-template-responsive-starter/web/src/components/side-menu-content.tsx +182 -182
- package/templates/lupine-template-responsive-starter/web/src/frames/app-responsive-frame.tsx +52 -52
- package/templates/lupine-template-responsive-starter/web/src/index.html +16 -16
- package/templates/lupine-template-responsive-starter/web/src/index.tsx +39 -39
- package/templates/lupine-template-responsive-starter/web/src/lupine-template-responsive-starter/404.html +35 -35
- package/templates/lupine-template-responsive-starter/web/src/lupine-template-responsive-starter/index.html +49 -49
- package/templates/lupine-template-responsive-starter/web/src/lupine-template-responsive-starter/index.tsx +32 -32
- package/templates/lupine-template-responsive-starter/web/src/pages/about-page.tsx +43 -43
- package/templates/lupine-template-responsive-starter/web/src/pages/finance-page.tsx +46 -46
- package/templates/lupine-template-responsive-starter/web/src/pages/home-page.tsx +452 -452
- package/templates/lupine-template-responsive-starter/web/src/pages/mine-page.tsx +325 -325
- package/templates/lupine-template-responsive-starter/web/src/pages/tools-page.tsx +46 -46
- package/templates/lupine-template-responsive-starter/web/src/services/local-notes-service.ts +87 -87
- package/templates/lupine-template-responsive-starter/web/src/services/mine-service.ts +45 -45
package/index.js
CHANGED
|
@@ -1,411 +1,431 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import fs from 'node:fs';
|
|
4
|
-
import path from 'node:path';
|
|
5
|
-
import { fileURLToPath } from 'node:url';
|
|
6
|
-
import crypto from 'node:crypto';
|
|
7
|
-
import { execSync } from 'node:child_process';
|
|
8
|
-
|
|
9
|
-
function getLatestVersion(pkgName, fallback, retries = 2) {
|
|
10
|
-
for (let i = 0; i <= retries; i++) {
|
|
11
|
-
try {
|
|
12
|
-
const version = execSync(`npm view ${pkgName} version`, {
|
|
13
|
-
encoding: 'utf8',
|
|
14
|
-
stdio: ['ignore', 'pipe', 'ignore'],
|
|
15
|
-
timeout: 10000,
|
|
16
|
-
}).trim();
|
|
17
|
-
return version ? `^${version}` : fallback;
|
|
18
|
-
} catch (e) {
|
|
19
|
-
if (i === retries) {
|
|
20
|
-
throw new Error(`\x1b[31m✖ Failed to fetch latest version for ${pkgName} from npm registry after ${retries} retries. Please check your network connection.\x1b[0m`);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return fallback;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function generateRandomString(length) {
|
|
28
|
-
const chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_!@&?-#$';
|
|
29
|
-
return [...crypto.randomBytes(length)].map((x) => chars[x % chars.length]).join('');
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
const
|
|
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
|
-
|
|
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
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
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
|
-
const
|
|
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
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
'
|
|
300
|
-
'
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
'
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
'
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
fs.
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import crypto from 'node:crypto';
|
|
7
|
+
import { execSync } from 'node:child_process';
|
|
8
|
+
|
|
9
|
+
function getLatestVersion(pkgName, fallback, retries = 2) {
|
|
10
|
+
for (let i = 0; i <= retries; i++) {
|
|
11
|
+
try {
|
|
12
|
+
const version = execSync(`npm view ${pkgName} version`, {
|
|
13
|
+
encoding: 'utf8',
|
|
14
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
15
|
+
timeout: 10000,
|
|
16
|
+
}).trim();
|
|
17
|
+
return version ? `^${version}` : fallback;
|
|
18
|
+
} catch (e) {
|
|
19
|
+
if (i === retries) {
|
|
20
|
+
throw new Error(`\x1b[31m✖ Failed to fetch latest version for ${pkgName} from npm registry after ${retries} retries. Please check your network connection.\x1b[0m`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return fallback;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function generateRandomString(length) {
|
|
28
|
+
const chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_!@&?-#$';
|
|
29
|
+
return [...crypto.randomBytes(length)].map((x) => chars[x % chars.length]).join('');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function generateLayeredPasswordHash(password) {
|
|
33
|
+
const saltHex = crypto.randomBytes(16).toString('hex');
|
|
34
|
+
const keyHex = crypto
|
|
35
|
+
.scryptSync(password, Buffer.from(saltHex, 'hex'), 32, {
|
|
36
|
+
N: 16384,
|
|
37
|
+
r: 8,
|
|
38
|
+
p: 1,
|
|
39
|
+
maxmem: 64 * 1024 * 1024,
|
|
40
|
+
})
|
|
41
|
+
.toString('hex');
|
|
42
|
+
const verifierHex = crypto.createHash('sha256').update(keyHex).digest('hex');
|
|
43
|
+
return `scrypt2$${saltHex}$${verifierHex}`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const red = (str) => `\x1b[31m${str}\x1b[0m`;
|
|
47
|
+
const green = (str) => `\x1b[32m${str}\x1b[0m`;
|
|
48
|
+
const bold = (str) => `\x1b[1m${str}\x1b[0m`;
|
|
49
|
+
|
|
50
|
+
const argv = process.argv.slice(2).reduce(
|
|
51
|
+
(acc, arg) => {
|
|
52
|
+
if (arg.startsWith('--template=')) {
|
|
53
|
+
acc.template = arg.split('=')[1];
|
|
54
|
+
} else if (arg.startsWith('--')) {
|
|
55
|
+
acc[arg.slice(2)] = true;
|
|
56
|
+
} else {
|
|
57
|
+
acc._.push(arg);
|
|
58
|
+
}
|
|
59
|
+
return acc;
|
|
60
|
+
},
|
|
61
|
+
{ _: [] }
|
|
62
|
+
);
|
|
63
|
+
// Handle -t alias manually if needed, or just support --template
|
|
64
|
+
// The original code supported `argv.t`
|
|
65
|
+
const args = process.argv.slice(2);
|
|
66
|
+
for (let i = 0; i < args.length; i++) {
|
|
67
|
+
if (args[i] === '-t' && args[i + 1]) {
|
|
68
|
+
argv.template = args[i + 1];
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const cwd = process.cwd();
|
|
72
|
+
|
|
73
|
+
const TEMPLATES = [
|
|
74
|
+
{
|
|
75
|
+
name: 'hello-world',
|
|
76
|
+
dir: 'lupine-template-hello-world',
|
|
77
|
+
display: 'Hello World',
|
|
78
|
+
itemType: 'frontend',
|
|
79
|
+
color: green,
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
name: 'doc-starter',
|
|
83
|
+
dir: 'lupine-template-doc-starter',
|
|
84
|
+
display: 'Documentation Starter',
|
|
85
|
+
itemType: 'frontend',
|
|
86
|
+
color: green,
|
|
87
|
+
needsPress: true,
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
name: 'cv-starter',
|
|
91
|
+
dir: 'lupine-template-cv-starter',
|
|
92
|
+
display: 'CV Starter',
|
|
93
|
+
itemType: 'frontend',
|
|
94
|
+
color: green,
|
|
95
|
+
needsPress: true,
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
name: 'responsive-starter-tabs',
|
|
99
|
+
dir: 'lupine-template-responsive-starter',
|
|
100
|
+
layout: 'tabs',
|
|
101
|
+
display: 'Responsive Starter (tabs)',
|
|
102
|
+
itemType: 'frontend',
|
|
103
|
+
color: green,
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
name: 'responsive-starter-sidemenu',
|
|
107
|
+
dir: 'lupine-template-responsive-starter',
|
|
108
|
+
layout: 'sidemenu',
|
|
109
|
+
display: 'Responsive Starter (sidemenu)',
|
|
110
|
+
itemType: 'frontend',
|
|
111
|
+
color: green,
|
|
112
|
+
},
|
|
113
|
+
];
|
|
114
|
+
|
|
115
|
+
async function init() {
|
|
116
|
+
console.log('Fetching latest versions...');
|
|
117
|
+
const versions = {
|
|
118
|
+
'lupine.api': getLatestVersion('lupine.api', '^1.0.1'),
|
|
119
|
+
'lupine.web': getLatestVersion('lupine.web', '^1.0.1'),
|
|
120
|
+
'lupine.components': getLatestVersion('lupine.components', '^1.0.1'),
|
|
121
|
+
'lupine.press': getLatestVersion('lupine.press', '^1.0.1')
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
if (argv['update-version']) {
|
|
125
|
+
const targetPkgPath = path.join(cwd, 'package.json');
|
|
126
|
+
if (!fs.existsSync(targetPkgPath)) {
|
|
127
|
+
console.log(red('✖ No package.json found in current directory.'));
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
let pkg;
|
|
132
|
+
try {
|
|
133
|
+
pkg = JSON.parse(fs.readFileSync(targetPkgPath, 'utf-8'));
|
|
134
|
+
} catch (e) {
|
|
135
|
+
console.log(red('✖ Failed to parse package.json.'));
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
let updated = false;
|
|
140
|
+
['dependencies', 'devDependencies', 'peerDependencies'].forEach(depType => {
|
|
141
|
+
if (pkg[depType]) {
|
|
142
|
+
for (const [name, latestVer] of Object.entries(versions)) {
|
|
143
|
+
if (pkg[depType][name]) {
|
|
144
|
+
if (pkg[depType][name] !== latestVer) {
|
|
145
|
+
console.log(`${green('Upgrading')} ${name}: ${pkg[depType][name]} -> ${latestVer}`);
|
|
146
|
+
pkg[depType][name] = latestVer;
|
|
147
|
+
updated = true;
|
|
148
|
+
} else {
|
|
149
|
+
console.log(`${name} is already at latest version (${latestVer}).`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
if (updated) {
|
|
157
|
+
fs.writeFileSync(targetPkgPath, JSON.stringify(pkg, null, 2) + '\n');
|
|
158
|
+
console.log(green('\n✔ package.json updated successfully. Please run "npm install" to apply changes.'));
|
|
159
|
+
} else {
|
|
160
|
+
console.log(green('\n✔ All target packages are already up-to-date.'));
|
|
161
|
+
}
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
let targetDir = argv._[0];
|
|
166
|
+
let template = argv.template || argv.t;
|
|
167
|
+
|
|
168
|
+
const defaultTargetDir = 'lupine-project';
|
|
169
|
+
|
|
170
|
+
function isValidPackageName(projectName) {
|
|
171
|
+
return /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(projectName);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function toValidPackageName(projectName) {
|
|
175
|
+
return projectName
|
|
176
|
+
.trim()
|
|
177
|
+
.toLowerCase()
|
|
178
|
+
.replace(/\s+/g, '-')
|
|
179
|
+
.replace(/^[._]/, '')
|
|
180
|
+
.replace(/[^a-z0-9-~]+/g, '-');
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (!targetDir) {
|
|
184
|
+
targetDir = (await prompt(`Project name: (${green(defaultTargetDir)}) `)) || defaultTargetDir;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
while (!isValidPackageName(targetDir)) {
|
|
188
|
+
console.log(red(`✖ Invalid project name: "${targetDir}". Name can not contain spaces or sensitive characters.`));
|
|
189
|
+
const suggestion = toValidPackageName(targetDir);
|
|
190
|
+
targetDir = (await prompt(`Project name: (${green(suggestion)}) `)) || suggestion;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const root = path.join(cwd, targetDir);
|
|
194
|
+
|
|
195
|
+
if (fs.existsSync(root) && !isEmpty(root)) {
|
|
196
|
+
const overwrite = await prompt(
|
|
197
|
+
`Target directory "${green(targetDir)}" is not empty. Remove existing files and continue? (y/N) `
|
|
198
|
+
);
|
|
199
|
+
if (overwrite.toLowerCase() !== 'y') {
|
|
200
|
+
throw new Error(red('✖ Operation cancelled'));
|
|
201
|
+
}
|
|
202
|
+
emptyDir(root);
|
|
203
|
+
} else if (!fs.existsSync(root)) {
|
|
204
|
+
fs.mkdirSync(root, { recursive: true });
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (!template || !TEMPLATES.find((t) => t.name === template)) {
|
|
208
|
+
if (template && !TEMPLATES.find((t) => t.name === template)) {
|
|
209
|
+
console.log(`"${template}" isn't a valid template. Please choose from below:`);
|
|
210
|
+
} else {
|
|
211
|
+
console.log('Select a template:');
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
TEMPLATES.forEach((t, i) => {
|
|
215
|
+
console.log(` ${t.color(i + 1 + '. ' + (t.display || t.name))}`);
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
const templateIdx = await prompt(`Select a template (${green('1-' + TEMPLATES.length)}): `);
|
|
219
|
+
const selected = TEMPLATES[parseInt(templateIdx) - 1];
|
|
220
|
+
if (!selected) {
|
|
221
|
+
throw new Error(red('✖ Invalid template selected'));
|
|
222
|
+
}
|
|
223
|
+
template = selected.name;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const templateObj = TEMPLATES.find((t) => t.name === template);
|
|
227
|
+
const templateDirName = templateObj?.dir || template;
|
|
228
|
+
|
|
229
|
+
const templateDir = path.resolve(fileURLToPath(import.meta.url), '../templates', templateDirName);
|
|
230
|
+
const commonDir = path.resolve(fileURLToPath(import.meta.url), '../templates', 'common');
|
|
231
|
+
|
|
232
|
+
// ... (copy logic remains same)
|
|
233
|
+
|
|
234
|
+
console.log(`\nScaffolding project in ${root}...`);
|
|
235
|
+
|
|
236
|
+
copyDir(commonDir, root);
|
|
237
|
+
fs.renameSync(path.join(root, '_gitignore'), path.join(root, '.gitignore'));
|
|
238
|
+
fs.renameSync(path.join(root, '_env'), path.join(root, '.env'));
|
|
239
|
+
|
|
240
|
+
const appsDir = path.join(root, 'apps');
|
|
241
|
+
if (!fs.existsSync(appsDir)) {
|
|
242
|
+
fs.mkdirSync(appsDir);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const appName = path.basename(root);
|
|
246
|
+
const targetAppDir = path.join(appsDir, appName);
|
|
247
|
+
|
|
248
|
+
function replaceStr(filepath, fromToArr) {
|
|
249
|
+
let content = fs.readFileSync(filepath, 'utf-8');
|
|
250
|
+
for (const { from, to } of fromToArr) {
|
|
251
|
+
content = content.replace(new RegExp(from, 'g'), to);
|
|
252
|
+
}
|
|
253
|
+
fs.writeFileSync(filepath, content);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
copyDir(templateDir, targetAppDir);
|
|
257
|
+
// if templateDir\web\src\appName exists, rename it to github-pj-name
|
|
258
|
+
const githubName = path.join(targetAppDir, `web/src/${templateObj?.dir}`);
|
|
259
|
+
if (templateObj?.dir && fs.existsSync(githubName)) {
|
|
260
|
+
fs.renameSync(githubName, path.join(targetAppDir, 'web/src/github-pj-name'));
|
|
261
|
+
replaceStr(path.join(targetAppDir, 'web/src/github-pj-name/index.tsx'), [
|
|
262
|
+
{ from: `/${templateObj?.dir}`, to: '/github-pj-name' },
|
|
263
|
+
{ from: `${templateObj?.dir}/`, to: 'github-pj-name/' },
|
|
264
|
+
]);
|
|
265
|
+
replaceStr(path.join(targetAppDir, 'web/src/github-pj-name/index.html'), [
|
|
266
|
+
{ from: `/${templateObj?.dir}`, to: '/github-pj-name' },
|
|
267
|
+
{ from: `${templateObj?.dir}/`, to: 'github-pj-name/' },
|
|
268
|
+
]);
|
|
269
|
+
replaceStr(path.join(targetAppDir, 'web/src/github-pj-name/404.html'), [
|
|
270
|
+
{ from: `/${templateObj?.dir}`, to: '/github-pj-name' },
|
|
271
|
+
{ from: `${templateObj?.dir}/`, to: 'github-pj-name/' },
|
|
272
|
+
]);
|
|
273
|
+
replaceStr(path.join(targetAppDir, 'lupine.json'), [
|
|
274
|
+
{ from: `/${templateObj?.dir}`, to: '/github-pj-name' },
|
|
275
|
+
{ from: `${templateObj?.dir}/`, to: 'github-pj-name/' },
|
|
276
|
+
]);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if (templateObj?.layout) {
|
|
280
|
+
const frameFile = path.join(targetAppDir, 'web/src/frames/app-responsive-frame.tsx');
|
|
281
|
+
if (fs.existsSync(frameFile)) {
|
|
282
|
+
let content = fs.readFileSync(frameFile, 'utf-8');
|
|
283
|
+
content = content.replace(/const DEFAULT_LAYOUT = '.*';/, `const DEFAULT_LAYOUT = '${templateObj.layout}';`);
|
|
284
|
+
fs.writeFileSync(frameFile, content);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
changePkgName(path.join(targetAppDir, 'lupine.json'), appName);
|
|
289
|
+
changePkgName(path.join(targetAppDir, 'api', 'package.json'), appName + '-api');
|
|
290
|
+
changePkgName(path.join(targetAppDir, 'web', 'package.json'), appName + '-web');
|
|
291
|
+
|
|
292
|
+
const pkg = {
|
|
293
|
+
name: appName,
|
|
294
|
+
version: '0.0.0',
|
|
295
|
+
private: true,
|
|
296
|
+
workspaces: ['apps/*', 'apps/*/*', 'packages/*'],
|
|
297
|
+
'//desktop': 'If you want to build desktop applications, please run `npm run add-electron` first.',
|
|
298
|
+
scripts: {
|
|
299
|
+
'add-electron': 'npm install -D electron@^35.2.0 electron-builder@^26.0.12',
|
|
300
|
+
'app1:build-win': `electron-builder --win --config apps/${appName}/electron/builder.json`,
|
|
301
|
+
'app1:build-linux': `electron-builder --linux --config apps/${appName}/electron/builder.json`,
|
|
302
|
+
'app1:build-mac': `export CSC_IDENTITY_AUTO_DISCOVERY=true && electron-builder --mac --x64 --config apps/${appName}/electron/builder.json`,
|
|
303
|
+
'app1:unpack-mac': `npx asar extract dist/build/mac-arm64-unpacked/${appName}.app/Contents/Resources/app.asar dist/build/mac-arm64-unpacked/${appName}.app/Contents/Resources/app.asar-unpack`,
|
|
304
|
+
'app1:unpack-linux': `npx asar extract dist/build/linux-arm64-unpacked/resources/app.asar dist/build/linux-arm64-unpacked/resources/app.asar-unpack`,
|
|
305
|
+
'app1:unpack-win': `npx asar extract dist/build/win-unpacked/resources/app.asar dist/build/win-unpacked/resources/app.asar-unpack`,
|
|
306
|
+
'app1:desktop': `electron apps/${appName}/electron/main.js`,
|
|
307
|
+
'app1:sync': `npm run sync --workspace=${appName}-web`,
|
|
308
|
+
'app1:open-ios': `npm run open-ios --workspace=${appName}-web`,
|
|
309
|
+
'app1:open-android': `npm run open-android --workspace=${appName}-web`,
|
|
310
|
+
dev: 'lupine-build --env=.env.development --dev=1 --cmd=start-dev',
|
|
311
|
+
build: 'lupine-build --env=.env.production --dev=0 --obfuscate=0',
|
|
312
|
+
'build-mobile': 'lupine-build --env=.env.mobile --dev=0 --mobile=1',
|
|
313
|
+
'start-dev': 'node dist/server_root/server/server-loader.js --env=.env.development',
|
|
314
|
+
'start-production': 'node dist/server_root/server/server-loader.js --env=.env.production',
|
|
315
|
+
format: 'prettier --write "**/*.{js,json,css,scss,md,html,yaml,ts,jsx,tsx}"',
|
|
316
|
+
},
|
|
317
|
+
dependencies: {
|
|
318
|
+
'lupine.api': 'file:packages/lupine.api',
|
|
319
|
+
},
|
|
320
|
+
devDependencies: {
|
|
321
|
+
typescript: '^5.7.2',
|
|
322
|
+
'@types/node': '^22.10.5',
|
|
323
|
+
prettier: '^2.7.1',
|
|
324
|
+
},
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
pkg.dependencies = {
|
|
328
|
+
'lupine.api': versions['lupine.api'],
|
|
329
|
+
'lupine.components': versions['lupine.components'],
|
|
330
|
+
'lupine.web': versions['lupine.web'],
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
if (templateObj && templateObj.needsPress) {
|
|
334
|
+
pkg.dependencies['lupine.press'] = versions['lupine.press'];
|
|
335
|
+
pkg.devDependencies['gray-matter'] = '^4.0.3';
|
|
336
|
+
pkg.devDependencies['marked'] = '^17.0.1';
|
|
337
|
+
pkg.scripts['cp-docs'] = `node dev/cp-folder.js dist/server_root/${appName}_web/github-pj-name docs`;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
fs.writeFileSync(path.join(root, 'package.json'), JSON.stringify(pkg, null, 2));
|
|
341
|
+
|
|
342
|
+
if (fs.existsSync(path.join(root, '.env'))) {
|
|
343
|
+
let envContent = fs.readFileSync(path.join(root, '.env'), 'utf-8');
|
|
344
|
+
|
|
345
|
+
// Auto-generate keys & random layered scrypt password placeholders
|
|
346
|
+
const secretKeys = ['CRYPTO_KEY=', 'DEV_CRYPTO_KEY=', 'DEV_TOKEN='];
|
|
347
|
+
secretKeys.forEach((key) => {
|
|
348
|
+
envContent = envContent.replace(new RegExp(`^${key}.*`, 'gm'), `${key}${generateRandomString(32)}`);
|
|
349
|
+
});
|
|
350
|
+
const passwordKeys = ['ADMIN_PASS=', 'DEV_ADMIN_PASS='];
|
|
351
|
+
passwordKeys.forEach((key) => {
|
|
352
|
+
envContent = envContent.replace(
|
|
353
|
+
new RegExp(`^${key}.*`, 'gm'),
|
|
354
|
+
`${key}${generateLayeredPasswordHash(generateRandomString(32))}`
|
|
355
|
+
);
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
envContent = envContent.replace(/{APP-NAME}/g, appName);
|
|
359
|
+
fs.writeFileSync(path.join(root, '.env'), envContent);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
console.log(`\nDone. Now run:\n`);
|
|
363
|
+
console.log(` cd ${targetDir}`);
|
|
364
|
+
console.log(` npm install`);
|
|
365
|
+
console.log(` npm run dev`);
|
|
366
|
+
console.log(``);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
import readline from 'node:readline';
|
|
370
|
+
|
|
371
|
+
function prompt(question) {
|
|
372
|
+
const rl = readline.createInterface({
|
|
373
|
+
input: process.stdin,
|
|
374
|
+
output: process.stdout,
|
|
375
|
+
});
|
|
376
|
+
return new Promise((resolve) => {
|
|
377
|
+
rl.question(question, (answer) => {
|
|
378
|
+
rl.close();
|
|
379
|
+
resolve(answer.trim());
|
|
380
|
+
});
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
function copy(src, dest) {
|
|
385
|
+
const stat = fs.statSync(src);
|
|
386
|
+
if (stat.isDirectory()) {
|
|
387
|
+
copyDir(src, dest);
|
|
388
|
+
} else {
|
|
389
|
+
fs.copyFileSync(src, dest);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
function copyDir(srcDir, destDir) {
|
|
394
|
+
fs.mkdirSync(destDir, { recursive: true });
|
|
395
|
+
for (const file of fs.readdirSync(srcDir)) {
|
|
396
|
+
const srcFile = path.resolve(srcDir, file);
|
|
397
|
+
const destFile = path.resolve(destDir, file);
|
|
398
|
+
copy(srcFile, destFile);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
function changePkgName(src, name) {
|
|
403
|
+
if (fs.existsSync(src)) {
|
|
404
|
+
const pkgJson = JSON.parse(fs.readFileSync(src, 'utf-8'));
|
|
405
|
+
pkgJson.name = name;
|
|
406
|
+
fs.writeFileSync(src, JSON.stringify(pkgJson, null, 2));
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
function isEmpty(path) {
|
|
411
|
+
const files = fs.readdirSync(path);
|
|
412
|
+
return files.length === 0 || (files.length === 1 && files[0] === '.git');
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
function emptyDir(dir) {
|
|
416
|
+
if (!fs.existsSync(dir)) {
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
for (const file of fs.readdirSync(dir)) {
|
|
420
|
+
const abs = path.resolve(dir, file);
|
|
421
|
+
if (file === '.git') {
|
|
422
|
+
continue;
|
|
423
|
+
}
|
|
424
|
+
fs.rmSync(abs, { recursive: true, force: true });
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
init().catch((e) => {
|
|
429
|
+
console.error(e.message);
|
|
430
|
+
process.exit(1);
|
|
431
|
+
});
|