@lightfish/cli 0.0.5 → 0.0.7
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/dist/create-lightfish.js +133 -60
- package/dist/lightfish.js +160 -87
- package/dist/templates/react-vite/.agents/skills/lightfish-server/SKILL.md +447 -0
- package/dist/templates/react-vite/.vscode/settings.json +42 -0
- package/dist/templates/react-vite/AGENTS.md +254 -0
- package/dist/templates/react-vite/README.md +150 -0
- package/dist/templates/react-vite/_gitignore +23 -0
- package/dist/templates/react-vite/eslint.config.js +25 -0
- package/dist/templates/react-vite/index.html +13 -0
- package/dist/templates/react-vite/lightfish-server.config.js +6 -0
- package/dist/templates/react-vite/package.json +41 -0
- package/dist/templates/react-vite/pnpm-lock.yaml +3649 -0
- package/dist/templates/react-vite/public/favicon.svg +1 -0
- package/dist/templates/react-vite/public/icons.svg +24 -0
- package/dist/templates/react-vite/server/router/hello/index.ts +20 -0
- package/dist/templates/react-vite/server/schema/index.ts +18 -0
- package/dist/templates/react-vite/src/assets/hero.png +0 -0
- package/dist/templates/react-vite/src/assets/react.svg +1 -0
- package/dist/templates/react-vite/src/assets/vite.svg +1 -0
- package/dist/templates/react-vite/src/main.css +1 -0
- package/dist/templates/react-vite/src/main.tsx +43 -0
- package/dist/templates/react-vite/src/pages/example/index.tsx +26 -0
- package/dist/templates/react-vite/src/pages/example/layout.tsx +31 -0
- package/dist/templates/react-vite/src/pages/example/model.ts +20 -0
- package/dist/templates/react-vite/src/pages/index.tsx +17 -0
- package/dist/templates/react-vite/src/pages/layout.tsx +15 -0
- package/dist/templates/react-vite/tsconfig.app.json +30 -0
- package/dist/templates/react-vite/tsconfig.json +7 -0
- package/dist/templates/react-vite/tsconfig.node.json +24 -0
- package/dist/templates/react-vite/vite.config.ts +61 -0
- package/package.json +3 -2
package/dist/lightfish.js
CHANGED
|
@@ -5,17 +5,46 @@ import cac from "cac";
|
|
|
5
5
|
import { execa as execa4 } from "execa";
|
|
6
6
|
|
|
7
7
|
// src/commands/create.ts
|
|
8
|
-
import
|
|
8
|
+
import path6 from "path";
|
|
9
9
|
import { execa as execa2 } from "execa";
|
|
10
|
-
import
|
|
10
|
+
import fs6 from "fs-extra";
|
|
11
11
|
import prompts3 from "prompts";
|
|
12
12
|
|
|
13
|
-
// src/utils/
|
|
13
|
+
// src/utils/copy-template.ts
|
|
14
14
|
import path from "path";
|
|
15
|
+
import fs from "fs-extra";
|
|
16
|
+
var SKIP_NAMES = /* @__PURE__ */ new Set([".git", "node_modules", "dist"]);
|
|
17
|
+
var RESTORE_MAP = {
|
|
18
|
+
_gitignore: ".gitignore",
|
|
19
|
+
_gitattributes: ".gitattributes",
|
|
20
|
+
_npmignore: ".npmignore",
|
|
21
|
+
_gitkeep: ".gitkeep"
|
|
22
|
+
};
|
|
23
|
+
async function copyLocalTemplate(srcDir, targetDir) {
|
|
24
|
+
await fs.ensureDir(targetDir);
|
|
25
|
+
const entries = await fs.readdir(srcDir, { withFileTypes: true });
|
|
26
|
+
for (const entry of entries) {
|
|
27
|
+
if (SKIP_NAMES.has(entry.name)) continue;
|
|
28
|
+
const src = path.join(srcDir, entry.name);
|
|
29
|
+
const destName = RESTORE_MAP[entry.name] ?? entry.name;
|
|
30
|
+
const dest = path.join(targetDir, destName);
|
|
31
|
+
if (entry.isDirectory()) {
|
|
32
|
+
await copyLocalTemplate(src, dest);
|
|
33
|
+
} else if (entry.isSymbolicLink()) {
|
|
34
|
+
const linkTarget = await fs.readlink(src);
|
|
35
|
+
await fs.symlink(linkTarget, dest);
|
|
36
|
+
} else {
|
|
37
|
+
await fs.copy(src, dest);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// src/utils/download-template.ts
|
|
43
|
+
import path2 from "path";
|
|
15
44
|
import { tmpdir } from "os";
|
|
16
45
|
import { randomUUID } from "crypto";
|
|
17
46
|
import { execa } from "execa";
|
|
18
|
-
import
|
|
47
|
+
import fs2 from "fs-extra";
|
|
19
48
|
function parseRepo(repo) {
|
|
20
49
|
const [repoPart, branch] = repo.split("#");
|
|
21
50
|
let url;
|
|
@@ -29,8 +58,8 @@ function parseRepo(repo) {
|
|
|
29
58
|
return { url, branch: branch || void 0 };
|
|
30
59
|
}
|
|
31
60
|
async function gitClone(url, branch, targetDir) {
|
|
32
|
-
const tmpDir =
|
|
33
|
-
await
|
|
61
|
+
const tmpDir = path2.join(tmpdir(), `lightfish-template-${randomUUID()}`);
|
|
62
|
+
await fs2.ensureDir(tmpDir);
|
|
34
63
|
const args = ["clone", "--depth", "1"];
|
|
35
64
|
if (branch) {
|
|
36
65
|
args.push("--branch", branch);
|
|
@@ -39,30 +68,30 @@ async function gitClone(url, branch, targetDir) {
|
|
|
39
68
|
try {
|
|
40
69
|
await execa("git", args, { stdio: "inherit" });
|
|
41
70
|
} catch (error) {
|
|
42
|
-
await
|
|
71
|
+
await fs2.remove(tmpDir).catch(() => {
|
|
43
72
|
});
|
|
44
73
|
const detail = error instanceof Error ? error.message : String(error);
|
|
45
74
|
throw new Error(`Git \u514B\u9686\u5931\u8D25\uFF08${url}\uFF09\uFF1A${detail}`);
|
|
46
75
|
}
|
|
47
|
-
const entries = await
|
|
76
|
+
const entries = await fs2.readdir(tmpDir);
|
|
48
77
|
for (const entry of entries) {
|
|
49
78
|
if (entry === ".git") continue;
|
|
50
|
-
const src =
|
|
51
|
-
const dest =
|
|
52
|
-
await
|
|
79
|
+
const src = path2.join(tmpDir, entry);
|
|
80
|
+
const dest = path2.join(targetDir, entry);
|
|
81
|
+
await fs2.move(src, dest, { overwrite: true });
|
|
53
82
|
}
|
|
54
|
-
await
|
|
83
|
+
await fs2.remove(tmpDir).catch(() => {
|
|
55
84
|
});
|
|
56
85
|
}
|
|
57
86
|
async function downloadTemplate(repo, targetDir) {
|
|
58
|
-
await
|
|
87
|
+
await fs2.ensureDir(targetDir);
|
|
59
88
|
const { url, branch } = parseRepo(repo);
|
|
60
89
|
console.log(`\u6B63\u5728\u62C9\u53D6\u6A21\u677F: ${url}${branch ? ` (\u5206\u652F: ${branch})` : ""}`);
|
|
61
90
|
await gitClone(url, branch, targetDir);
|
|
62
91
|
console.log("\u6A21\u677F\u62C9\u53D6\u5B8C\u6210");
|
|
63
|
-
const gitDir =
|
|
64
|
-
if (await
|
|
65
|
-
await
|
|
92
|
+
const gitDir = path2.join(targetDir, ".git");
|
|
93
|
+
if (await fs2.pathExists(gitDir)) {
|
|
94
|
+
await fs2.remove(gitDir);
|
|
66
95
|
console.log("\u5DF2\u5220\u9664 .git \u76EE\u5F55");
|
|
67
96
|
}
|
|
68
97
|
}
|
|
@@ -86,26 +115,26 @@ function installCommand(packageManager) {
|
|
|
86
115
|
}
|
|
87
116
|
|
|
88
117
|
// src/utils/project.ts
|
|
89
|
-
import
|
|
90
|
-
import
|
|
118
|
+
import path3 from "path";
|
|
119
|
+
import fs3 from "fs-extra";
|
|
91
120
|
import prompts from "prompts";
|
|
92
121
|
function normalizeProjectName(name) {
|
|
93
122
|
return name.trim();
|
|
94
123
|
}
|
|
95
124
|
function resolveTargetDir(cwd, projectName) {
|
|
96
|
-
return
|
|
125
|
+
return path3.resolve(cwd, projectName);
|
|
97
126
|
}
|
|
98
127
|
async function assertCanCreateProject(targetDir, yes) {
|
|
99
|
-
if (!await
|
|
128
|
+
if (!await fs3.pathExists(targetDir)) {
|
|
100
129
|
return true;
|
|
101
130
|
}
|
|
102
|
-
const files = await
|
|
131
|
+
const files = await fs3.readdir(targetDir);
|
|
103
132
|
if (files.length === 0) {
|
|
104
133
|
return true;
|
|
105
134
|
}
|
|
106
135
|
if (yes) {
|
|
107
|
-
await
|
|
108
|
-
await
|
|
136
|
+
await fs3.remove(targetDir);
|
|
137
|
+
await fs3.ensureDir(targetDir);
|
|
109
138
|
return true;
|
|
110
139
|
}
|
|
111
140
|
const { overwrite } = await prompts(
|
|
@@ -124,8 +153,8 @@ async function assertCanCreateProject(targetDir, yes) {
|
|
|
124
153
|
if (!overwrite) {
|
|
125
154
|
return false;
|
|
126
155
|
}
|
|
127
|
-
await
|
|
128
|
-
await
|
|
156
|
+
await fs3.remove(targetDir);
|
|
157
|
+
await fs3.ensureDir(targetDir);
|
|
129
158
|
return true;
|
|
130
159
|
}
|
|
131
160
|
function toPackageName(projectName) {
|
|
@@ -133,8 +162,8 @@ function toPackageName(projectName) {
|
|
|
133
162
|
}
|
|
134
163
|
|
|
135
164
|
// src/utils/replace-token.ts
|
|
136
|
-
import
|
|
137
|
-
import
|
|
165
|
+
import path4 from "path";
|
|
166
|
+
import fs4 from "fs-extra";
|
|
138
167
|
var SKIP_DIRS = /* @__PURE__ */ new Set([
|
|
139
168
|
".git",
|
|
140
169
|
"node_modules",
|
|
@@ -166,22 +195,22 @@ var SKIP_EXTS = /* @__PURE__ */ new Set([
|
|
|
166
195
|
".lock"
|
|
167
196
|
]);
|
|
168
197
|
async function replaceToken(targetDir, token, value) {
|
|
169
|
-
const entries = await
|
|
198
|
+
const entries = await fs4.readdir(targetDir);
|
|
170
199
|
for (const entry of entries) {
|
|
171
|
-
const fullPath =
|
|
172
|
-
const stat = await
|
|
200
|
+
const fullPath = path4.join(targetDir, entry);
|
|
201
|
+
const stat = await fs4.stat(fullPath);
|
|
173
202
|
if (stat.isDirectory()) {
|
|
174
203
|
if (SKIP_DIRS.has(entry)) continue;
|
|
175
204
|
await replaceToken(fullPath, token, value);
|
|
176
205
|
continue;
|
|
177
206
|
}
|
|
178
|
-
const ext =
|
|
207
|
+
const ext = path4.extname(entry).toLowerCase();
|
|
179
208
|
if (SKIP_EXTS.has(ext)) continue;
|
|
180
209
|
try {
|
|
181
|
-
const content = await
|
|
210
|
+
const content = await fs4.readFile(fullPath, "utf8");
|
|
182
211
|
if (content.includes(token)) {
|
|
183
212
|
const replaced = content.replaceAll(token, value);
|
|
184
|
-
await
|
|
213
|
+
await fs4.writeFile(fullPath, replaced, "utf8");
|
|
185
214
|
console.log(` [replace] ${entry}`);
|
|
186
215
|
}
|
|
187
216
|
} catch {
|
|
@@ -197,6 +226,7 @@ var BUILTIN_TEMPLATES = [
|
|
|
197
226
|
{
|
|
198
227
|
id: "react-vite",
|
|
199
228
|
label: "React + Vite",
|
|
229
|
+
localDir: "react-vite",
|
|
200
230
|
repo: "QGtiger/template-vite-server#main"
|
|
201
231
|
}
|
|
202
232
|
];
|
|
@@ -208,6 +238,21 @@ function listTemplateIds() {
|
|
|
208
238
|
return BUILTIN_TEMPLATES.map((entry) => entry.id);
|
|
209
239
|
}
|
|
210
240
|
|
|
241
|
+
// src/utils/builtin-template-dir.ts
|
|
242
|
+
import path5 from "path";
|
|
243
|
+
import fs5 from "fs";
|
|
244
|
+
import { fileURLToPath } from "url";
|
|
245
|
+
var dirname = path5.dirname(fileURLToPath(import.meta.url));
|
|
246
|
+
function resolveBuiltinTemplateDir(localDir) {
|
|
247
|
+
const candidates = [
|
|
248
|
+
// 产物模式:dirname=dist -> dist/templates/<localDir>
|
|
249
|
+
path5.resolve(dirname, "templates", localDir),
|
|
250
|
+
// 源码模式:dirname=src/utils -> packages/cli/templates/<localDir>
|
|
251
|
+
path5.resolve(dirname, "..", "..", "templates", localDir)
|
|
252
|
+
];
|
|
253
|
+
return candidates.find((candidate) => fs5.existsSync(candidate));
|
|
254
|
+
}
|
|
255
|
+
|
|
211
256
|
// src/utils/resolve-template.ts
|
|
212
257
|
async function promptTemplateId() {
|
|
213
258
|
const { templateId } = await prompts2(
|
|
@@ -231,41 +276,59 @@ async function promptTemplateId() {
|
|
|
231
276
|
}
|
|
232
277
|
return templateId;
|
|
233
278
|
}
|
|
234
|
-
async function
|
|
235
|
-
if (options.templateRepo) {
|
|
236
|
-
return options.templateRepo;
|
|
237
|
-
}
|
|
279
|
+
async function selectEntry(options) {
|
|
238
280
|
if (options.template) {
|
|
239
281
|
const entry2 = getTemplateById(options.template);
|
|
240
282
|
if (!entry2) {
|
|
241
283
|
throw new Error(`\u672A\u77E5\u6A21\u677F\uFF1A${options.template}\u3002\u53EF\u9009\uFF1A${listTemplateIds().join("\u3001")}`);
|
|
242
284
|
}
|
|
243
|
-
return entry2
|
|
285
|
+
return entry2;
|
|
286
|
+
}
|
|
287
|
+
if (BUILTIN_TEMPLATES.length === 1) {
|
|
288
|
+
const entry2 = getTemplateById(DEFAULT_TEMPLATE_ID ?? BUILTIN_TEMPLATES[0].id);
|
|
289
|
+
if (!entry2) {
|
|
290
|
+
throw new Error("\u5185\u7F6E\u6A21\u677F\u5217\u8868\u4E3A\u7A7A");
|
|
291
|
+
}
|
|
292
|
+
return entry2;
|
|
244
293
|
}
|
|
245
294
|
if (options.yes) {
|
|
246
295
|
const entry2 = getTemplateById(DEFAULT_TEMPLATE_ID ?? BUILTIN_TEMPLATES[0].id);
|
|
247
296
|
if (!entry2) {
|
|
248
297
|
throw new Error("\u5185\u7F6E\u6A21\u677F\u5217\u8868\u4E3A\u7A7A");
|
|
249
298
|
}
|
|
250
|
-
return entry2
|
|
299
|
+
return entry2;
|
|
251
300
|
}
|
|
252
301
|
const templateId = await promptTemplateId();
|
|
253
302
|
const entry = getTemplateById(templateId);
|
|
254
303
|
if (!entry) {
|
|
255
304
|
throw new Error(`\u672A\u77E5\u6A21\u677F\uFF1A${templateId}`);
|
|
256
305
|
}
|
|
257
|
-
return entry
|
|
306
|
+
return entry;
|
|
307
|
+
}
|
|
308
|
+
async function resolveTemplate(options) {
|
|
309
|
+
const entry = await selectEntry(options);
|
|
310
|
+
if (!options.remote && entry.localDir) {
|
|
311
|
+
const dir = resolveBuiltinTemplateDir(entry.localDir);
|
|
312
|
+
if (dir) {
|
|
313
|
+
return { type: "local", dir, id: entry.id };
|
|
314
|
+
}
|
|
315
|
+
console.warn(`[template] \u5185\u7F6E\u6A21\u677F\u526F\u672C\u7F3A\u5931\uFF08${entry.localDir}\uFF09\uFF0C\u56DE\u9000\u5230 git \u62C9\u53D6\u3002`);
|
|
316
|
+
}
|
|
317
|
+
if (!entry.repo) {
|
|
318
|
+
throw new Error(`\u6A21\u677F ${entry.id} \u672A\u914D\u7F6E git \u6E90\uFF0C\u4E14\u672C\u5730\u526F\u672C\u4E0D\u53EF\u7528`);
|
|
319
|
+
}
|
|
320
|
+
return { type: "git", repo: entry.repo, id: entry.id };
|
|
258
321
|
}
|
|
259
322
|
|
|
260
323
|
// src/commands/create.ts
|
|
261
324
|
async function patchPackageJsonName(targetDir, projectName) {
|
|
262
|
-
const packageJsonPath =
|
|
263
|
-
if (!await
|
|
325
|
+
const packageJsonPath = path6.join(targetDir, "package.json");
|
|
326
|
+
if (!await fs6.pathExists(packageJsonPath)) {
|
|
264
327
|
throw new Error("\u6A21\u677F\u7F3A\u5C11 package.json");
|
|
265
328
|
}
|
|
266
|
-
const packageJson = await
|
|
329
|
+
const packageJson = await fs6.readJson(packageJsonPath);
|
|
267
330
|
packageJson.name = toPackageName(projectName);
|
|
268
|
-
await
|
|
331
|
+
await fs6.writeJson(packageJsonPath, packageJson, { spaces: 2 });
|
|
269
332
|
}
|
|
270
333
|
async function resolveCreateOptions(options) {
|
|
271
334
|
const cwd = options.cwd ?? process.cwd();
|
|
@@ -305,9 +368,9 @@ async function resolveCreateOptions(options) {
|
|
|
305
368
|
if (!isPackageManager(packageManager)) {
|
|
306
369
|
throw new Error(`\u4E0D\u652F\u6301\u7684\u5305\u7BA1\u7406\u5668\uFF1A${String(packageManager)}`);
|
|
307
370
|
}
|
|
308
|
-
const
|
|
371
|
+
const template = await resolveTemplate({
|
|
309
372
|
template: options.template,
|
|
310
|
-
|
|
373
|
+
remote: options.remote,
|
|
311
374
|
yes: options.yes
|
|
312
375
|
});
|
|
313
376
|
const yesMode = options.yes === true;
|
|
@@ -316,7 +379,7 @@ async function resolveCreateOptions(options) {
|
|
|
316
379
|
projectName,
|
|
317
380
|
targetDir: resolveTargetDir(cwd, projectName),
|
|
318
381
|
packageManager,
|
|
319
|
-
|
|
382
|
+
template,
|
|
320
383
|
install: options.skipInstall ? false : options.install ?? (yesMode ? true : answers.install ?? false),
|
|
321
384
|
git: options.git ?? (yesMode ? true : answers.git ?? false)
|
|
322
385
|
};
|
|
@@ -340,15 +403,25 @@ async function maybeInitGit(options) {
|
|
|
340
403
|
stdio: "inherit"
|
|
341
404
|
});
|
|
342
405
|
}
|
|
406
|
+
async function writeTemplate(template, targetDir) {
|
|
407
|
+
if (template.type === "local") {
|
|
408
|
+
console.log(`[create] \u4F7F\u7528\u5185\u7F6E\u6A21\u677F\uFF1A${template.id}`);
|
|
409
|
+
await copyLocalTemplate(template.dir, targetDir);
|
|
410
|
+
console.log("[create] \u5185\u7F6E\u6A21\u677F\u62F7\u8D1D\u5B8C\u6210");
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
console.log(`[create] \u4F7F\u7528 git \u6A21\u677F\uFF1A${template.id}`);
|
|
414
|
+
await downloadTemplate(template.repo, targetDir);
|
|
415
|
+
}
|
|
343
416
|
async function createProject(options = {}) {
|
|
344
417
|
const resolvedOptions = await resolveCreateOptions(options);
|
|
345
418
|
const canCreate = await assertCanCreateProject(resolvedOptions.targetDir, options.yes);
|
|
346
419
|
if (!canCreate) {
|
|
347
420
|
throw new Error("\u5DF2\u53D6\u6D88\u521B\u5EFA\u9879\u76EE");
|
|
348
421
|
}
|
|
349
|
-
console.log("[create] \u5F00\u59CB\
|
|
350
|
-
await
|
|
351
|
-
console.log("[create] \u6A21\u677F\
|
|
422
|
+
console.log("[create] \u5F00\u59CB\u5199\u5165\u6A21\u677F...");
|
|
423
|
+
await writeTemplate(resolvedOptions.template, resolvedOptions.targetDir);
|
|
424
|
+
console.log("[create] \u6A21\u677F\u5199\u5165\u5B8C\u6210");
|
|
352
425
|
console.log("[create] \u5F00\u59CB\u4FEE\u6539 package.json...");
|
|
353
426
|
await patchPackageJsonName(resolvedOptions.targetDir, resolvedOptions.projectName);
|
|
354
427
|
console.log("[create] package.json \u4FEE\u6539\u5B8C\u6210");
|
|
@@ -365,21 +438,21 @@ async function createProject(options = {}) {
|
|
|
365
438
|
}
|
|
366
439
|
|
|
367
440
|
// src/commands/publish.ts
|
|
368
|
-
import
|
|
369
|
-
import
|
|
441
|
+
import fs10 from "fs";
|
|
442
|
+
import path10 from "path";
|
|
370
443
|
|
|
371
444
|
// src/utils/env.ts
|
|
372
|
-
import
|
|
373
|
-
import
|
|
445
|
+
import fs7 from "fs";
|
|
446
|
+
import path7 from "path";
|
|
374
447
|
import { parse } from "dotenv";
|
|
375
448
|
var DEFAULT_BASE_ROOT = "https://lf-frontend.oss-cn-beijing.aliyuncs.com";
|
|
376
449
|
function loadDotenv({ cwd, envPath }) {
|
|
377
450
|
let merged;
|
|
378
451
|
if (envPath) {
|
|
379
|
-
merged = readEnvFile(
|
|
452
|
+
merged = readEnvFile(path7.resolve(cwd, envPath));
|
|
380
453
|
} else {
|
|
381
|
-
const base = readEnvFile(
|
|
382
|
-
const local = readEnvFile(
|
|
454
|
+
const base = readEnvFile(path7.resolve(cwd, ".env"));
|
|
455
|
+
const local = readEnvFile(path7.resolve(cwd, ".env.local"));
|
|
383
456
|
merged = { ...base, ...local };
|
|
384
457
|
}
|
|
385
458
|
for (const [key, value] of Object.entries(merged)) {
|
|
@@ -389,8 +462,8 @@ function loadDotenv({ cwd, envPath }) {
|
|
|
389
462
|
}
|
|
390
463
|
}
|
|
391
464
|
function readEnvFile(file) {
|
|
392
|
-
if (!
|
|
393
|
-
return parse(
|
|
465
|
+
if (!fs7.existsSync(file)) return {};
|
|
466
|
+
return parse(fs7.readFileSync(file, "utf8"));
|
|
394
467
|
}
|
|
395
468
|
function getRequiredEnvNames({ notify, serverDetected }) {
|
|
396
469
|
const required = ["OSS_REGION", "OSS_BUCKET", "OSS_ACCESS_KEYID", "OSS_ACCESS_KEYSECRECT"];
|
|
@@ -419,8 +492,8 @@ function resolvePublishEnv(options, env = process.env) {
|
|
|
419
492
|
}
|
|
420
493
|
|
|
421
494
|
// src/utils/build.ts
|
|
422
|
-
import
|
|
423
|
-
import
|
|
495
|
+
import fs8 from "fs";
|
|
496
|
+
import path8 from "path";
|
|
424
497
|
import { execa as execa3 } from "execa";
|
|
425
498
|
var SERVER_CONFIG_FILES = [
|
|
426
499
|
"lightfish-server.config.js",
|
|
@@ -436,12 +509,12 @@ var VITE_CONFIG_FILES = [
|
|
|
436
509
|
"vite.config.cjs"
|
|
437
510
|
];
|
|
438
511
|
function readPackageJson(cwd) {
|
|
439
|
-
const file =
|
|
440
|
-
if (!
|
|
441
|
-
return JSON.parse(
|
|
512
|
+
const file = path8.join(cwd, "package.json");
|
|
513
|
+
if (!fs8.existsSync(file)) return void 0;
|
|
514
|
+
return JSON.parse(fs8.readFileSync(file, "utf8"));
|
|
442
515
|
}
|
|
443
516
|
function hasVite(cwd) {
|
|
444
|
-
if (VITE_CONFIG_FILES.some((f) =>
|
|
517
|
+
if (VITE_CONFIG_FILES.some((f) => fs8.existsSync(path8.join(cwd, f)))) return true;
|
|
445
518
|
const pkg = readPackageJson(cwd);
|
|
446
519
|
if (pkg) {
|
|
447
520
|
const deps = { ...pkg.dependencies ?? {}, ...pkg.devDependencies ?? {} };
|
|
@@ -452,7 +525,7 @@ function hasVite(cwd) {
|
|
|
452
525
|
function detectBuild(cwd) {
|
|
453
526
|
return {
|
|
454
527
|
vite: hasVite(cwd),
|
|
455
|
-
server: SERVER_CONFIG_FILES.some((f) =>
|
|
528
|
+
server: SERVER_CONFIG_FILES.some((f) => fs8.existsSync(path8.join(cwd, f)))
|
|
456
529
|
};
|
|
457
530
|
}
|
|
458
531
|
async function runBuildSteps(options) {
|
|
@@ -477,19 +550,19 @@ async function runBuildSteps(options) {
|
|
|
477
550
|
|
|
478
551
|
// src/utils/oss.ts
|
|
479
552
|
import OSS from "ali-oss";
|
|
480
|
-
import
|
|
481
|
-
import
|
|
553
|
+
import fs9 from "fs";
|
|
554
|
+
import path9 from "path";
|
|
482
555
|
function withPrefix(prefix, key) {
|
|
483
556
|
const normalized = prefix.replace(/^\/+/, "").replace(/\/+$/, "");
|
|
484
557
|
if (!normalized) return key;
|
|
485
558
|
return `${normalized}/${key}`;
|
|
486
559
|
}
|
|
487
560
|
function walkDir(dir, base = "") {
|
|
488
|
-
if (!
|
|
489
|
-
const entries =
|
|
561
|
+
if (!fs9.existsSync(dir)) return [];
|
|
562
|
+
const entries = fs9.readdirSync(dir, { withFileTypes: true });
|
|
490
563
|
const files = [];
|
|
491
564
|
for (const entry of entries) {
|
|
492
|
-
const fullPath =
|
|
565
|
+
const fullPath = path9.join(dir, entry.name);
|
|
493
566
|
const key = base ? `${base}/${entry.name}` : entry.name;
|
|
494
567
|
if (entry.isDirectory()) {
|
|
495
568
|
files.push(...walkDir(fullPath, key));
|
|
@@ -567,9 +640,9 @@ function generateVersion(date = /* @__PURE__ */ new Date()) {
|
|
|
567
640
|
return date.toISOString().replace(/[-T:.Z]/g, "").slice(0, 14);
|
|
568
641
|
}
|
|
569
642
|
function readPackageJsonName(cwd) {
|
|
570
|
-
const file =
|
|
571
|
-
if (!
|
|
572
|
-
const pkg = JSON.parse(
|
|
643
|
+
const file = path10.join(cwd, "package.json");
|
|
644
|
+
if (!fs10.existsSync(file)) return void 0;
|
|
645
|
+
const pkg = JSON.parse(fs10.readFileSync(file, "utf8"));
|
|
573
646
|
return pkg.name;
|
|
574
647
|
}
|
|
575
648
|
function resolveAppName(options) {
|
|
@@ -590,7 +663,7 @@ function resolveOptions(options) {
|
|
|
590
663
|
const appName = resolveAppName({ cwd, app: options.app });
|
|
591
664
|
const version = options.version ?? generateVersion();
|
|
592
665
|
assertNumericVersion(version);
|
|
593
|
-
const distDir =
|
|
666
|
+
const distDir = path10.resolve(cwd, options.dist ?? "dist");
|
|
594
667
|
const notify = !options.noNotify;
|
|
595
668
|
const baseRoot = process.env.BASE_ROOT || DEFAULT_BASE_ROOT;
|
|
596
669
|
const root = baseRoot.replace(/\/+$/, "");
|
|
@@ -648,7 +721,7 @@ function buildNotifyPayload(params) {
|
|
|
648
721
|
id: params.appName,
|
|
649
722
|
version: Number(params.version),
|
|
650
723
|
ossIndexUrl: params.ossIndexUrl,
|
|
651
|
-
domain:
|
|
724
|
+
domain: `${params.appName}.lightfish.top`
|
|
652
725
|
};
|
|
653
726
|
if (params.note) payload.note = params.note;
|
|
654
727
|
return payload;
|
|
@@ -703,7 +776,7 @@ async function runPublish(options = {}) {
|
|
|
703
776
|
console.log("[publish] (dry-run) \u5B8C\u6210,\u672A\u6267\u884C\u4EFB\u4F55\u526F\u4F5C\u7528");
|
|
704
777
|
return;
|
|
705
778
|
}
|
|
706
|
-
if (!
|
|
779
|
+
if (!fs10.existsSync(resolved.distDir)) {
|
|
707
780
|
throw new Error(`\u4EA7\u7269\u76EE\u5F55\u4E0D\u5B58\u5728:${resolved.distDir}`);
|
|
708
781
|
}
|
|
709
782
|
console.log("[publish] \u5F00\u59CB\u4E0A\u4F20 OSS...");
|
|
@@ -744,22 +817,22 @@ function softResolveEnv(notify, serverDetected) {
|
|
|
744
817
|
}
|
|
745
818
|
|
|
746
819
|
// src/utils/package-info.ts
|
|
747
|
-
import
|
|
748
|
-
import
|
|
749
|
-
import { fileURLToPath } from "url";
|
|
750
|
-
var
|
|
820
|
+
import fs11 from "fs";
|
|
821
|
+
import path11 from "path";
|
|
822
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
823
|
+
var dirname2 = path11.dirname(fileURLToPath2(import.meta.url));
|
|
751
824
|
function readPackageVersion() {
|
|
752
825
|
const packageJsonPathCandidates = [
|
|
753
826
|
// 源码模式:src/utils/package-info.ts -> packages/cli/package.json
|
|
754
|
-
|
|
827
|
+
path11.resolve(dirname2, "../../package.json"),
|
|
755
828
|
// 构建产物模式:dist/lightfish.js -> packages/cli/package.json
|
|
756
|
-
|
|
829
|
+
path11.resolve(dirname2, "../package.json")
|
|
757
830
|
];
|
|
758
|
-
const packageJsonPath = packageJsonPathCandidates.find((candidate) =>
|
|
831
|
+
const packageJsonPath = packageJsonPathCandidates.find((candidate) => fs11.existsSync(candidate));
|
|
759
832
|
if (!packageJsonPath) {
|
|
760
833
|
return "0.0.0";
|
|
761
834
|
}
|
|
762
|
-
const packageJson = JSON.parse(
|
|
835
|
+
const packageJson = JSON.parse(fs11.readFileSync(packageJsonPath, "utf8"));
|
|
763
836
|
return packageJson.version ?? "0.0.0";
|
|
764
837
|
}
|
|
765
838
|
|
|
@@ -772,7 +845,7 @@ async function runBuild() {
|
|
|
772
845
|
stdio: "inherit"
|
|
773
846
|
});
|
|
774
847
|
}
|
|
775
|
-
cli.command("create [projectName]", "\u521B\u5EFA Lightfish React Vite \u9879\u76EE").option("--pm <pm>", "\u5305\u7BA1\u7406\u5668\uFF1Anpm\u3001yarn\u3001pnpm\u3001bun", { default: "pnpm" }).option("--template <id>", "\u5185\u7F6E\u6A21\u677F id\uFF0C\u4F8B\u5982 react-vite").option("--
|
|
848
|
+
cli.command("create [projectName]", "\u521B\u5EFA Lightfish React Vite \u9879\u76EE").option("--pm <pm>", "\u5305\u7BA1\u7406\u5668\uFF1Anpm\u3001yarn\u3001pnpm\u3001bun", { default: "pnpm" }).option("--template <id>", "\u5185\u7F6E\u6A21\u677F id\uFF0C\u4F8B\u5982 react-vite").option("--remote", "\u5F3A\u5236\u8D70 git \u62C9\u53D6\u5185\u7F6E\u6A21\u677F\uFF08\u5FFD\u7565\u672C\u5730\u526F\u672C\uFF09").option("--skip-install", "\u8DF3\u8FC7\u4F9D\u8D56\u5B89\u88C5").option("--git", "\u521B\u5EFA\u540E\u521D\u59CB\u5316 git").option("-y, --yes", "\u4F7F\u7528\u9ED8\u8BA4\u9009\u9879\u5E76\u8DF3\u8FC7\u786E\u8BA4").action(async (projectName, options) => {
|
|
776
849
|
try {
|
|
777
850
|
const packageManager = options.pm ?? "pnpm";
|
|
778
851
|
if (!isPackageManager(packageManager)) {
|
|
@@ -782,7 +855,7 @@ cli.command("create [projectName]", "\u521B\u5EFA Lightfish React Vite \u9879\u7
|
|
|
782
855
|
projectName,
|
|
783
856
|
packageManager,
|
|
784
857
|
template: options.template,
|
|
785
|
-
|
|
858
|
+
remote: options.remote,
|
|
786
859
|
skipInstall: options.skipInstall,
|
|
787
860
|
git: options.git,
|
|
788
861
|
yes: options.yes
|