@lightfish/cli 0.0.1 → 0.0.3
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 +78 -17
- package/dist/lightfish.js +78 -17
- package/package.json +1 -1
package/dist/create-lightfish.js
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
import cac from "cac";
|
|
5
5
|
|
|
6
6
|
// src/commands/create.ts
|
|
7
|
-
import
|
|
7
|
+
import path4 from "path";
|
|
8
8
|
import { execa as execa2 } from "execa";
|
|
9
|
-
import
|
|
9
|
+
import fs4 from "fs-extra";
|
|
10
10
|
import prompts3 from "prompts";
|
|
11
11
|
|
|
12
12
|
// src/utils/download-template.ts
|
|
@@ -147,6 +147,63 @@ function toPackageName(projectName) {
|
|
|
147
147
|
return projectName.trim().toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
+
// src/utils/replace-token.ts
|
|
151
|
+
import path3 from "path";
|
|
152
|
+
import fs3 from "fs-extra";
|
|
153
|
+
var SKIP_DIRS = /* @__PURE__ */ new Set([
|
|
154
|
+
".git",
|
|
155
|
+
"node_modules",
|
|
156
|
+
"dist",
|
|
157
|
+
".cache",
|
|
158
|
+
"coverage"
|
|
159
|
+
]);
|
|
160
|
+
var SKIP_EXTS = /* @__PURE__ */ new Set([
|
|
161
|
+
".png",
|
|
162
|
+
".jpg",
|
|
163
|
+
".jpeg",
|
|
164
|
+
".gif",
|
|
165
|
+
".svg",
|
|
166
|
+
".ico",
|
|
167
|
+
".webp",
|
|
168
|
+
".woff",
|
|
169
|
+
".woff2",
|
|
170
|
+
".ttf",
|
|
171
|
+
".eot",
|
|
172
|
+
".otf",
|
|
173
|
+
".mp4",
|
|
174
|
+
".webm",
|
|
175
|
+
".mp3",
|
|
176
|
+
".wav",
|
|
177
|
+
".zip",
|
|
178
|
+
".gz",
|
|
179
|
+
".tar",
|
|
180
|
+
".7z",
|
|
181
|
+
".lock"
|
|
182
|
+
]);
|
|
183
|
+
async function replaceToken(targetDir, token, value) {
|
|
184
|
+
const entries = await fs3.readdir(targetDir);
|
|
185
|
+
for (const entry of entries) {
|
|
186
|
+
const fullPath = path3.join(targetDir, entry);
|
|
187
|
+
const stat = await fs3.stat(fullPath);
|
|
188
|
+
if (stat.isDirectory()) {
|
|
189
|
+
if (SKIP_DIRS.has(entry)) continue;
|
|
190
|
+
await replaceToken(fullPath, token, value);
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
const ext = path3.extname(entry).toLowerCase();
|
|
194
|
+
if (SKIP_EXTS.has(ext)) continue;
|
|
195
|
+
try {
|
|
196
|
+
const content = await fs3.readFile(fullPath, "utf8");
|
|
197
|
+
if (content.includes(token)) {
|
|
198
|
+
const replaced = content.replaceAll(token, value);
|
|
199
|
+
await fs3.writeFile(fullPath, replaced, "utf8");
|
|
200
|
+
console.log(` [replace] ${entry}`);
|
|
201
|
+
}
|
|
202
|
+
} catch {
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
150
207
|
// src/utils/resolve-template.ts
|
|
151
208
|
import prompts2 from "prompts";
|
|
152
209
|
|
|
@@ -217,17 +274,17 @@ async function resolveTemplateRepo(options) {
|
|
|
217
274
|
|
|
218
275
|
// src/commands/create.ts
|
|
219
276
|
async function patchPackageJsonName(targetDir, projectName) {
|
|
220
|
-
const packageJsonPath =
|
|
221
|
-
if (!await
|
|
277
|
+
const packageJsonPath = path4.join(targetDir, "package.json");
|
|
278
|
+
if (!await fs4.pathExists(packageJsonPath)) {
|
|
222
279
|
throw new Error("\u6A21\u677F\u7F3A\u5C11 package.json");
|
|
223
280
|
}
|
|
224
|
-
const packageJson = await
|
|
281
|
+
const packageJson = await fs4.readJson(packageJsonPath);
|
|
225
282
|
packageJson.name = toPackageName(projectName);
|
|
226
|
-
await
|
|
283
|
+
await fs4.writeJson(packageJsonPath, packageJson, { spaces: 2 });
|
|
227
284
|
}
|
|
228
285
|
async function resolveCreateOptions(options) {
|
|
229
286
|
const cwd = options.cwd ?? process.cwd();
|
|
230
|
-
const initialProjectName = options.projectName ? normalizeProjectName(options.projectName) : "";
|
|
287
|
+
const initialProjectName = options.projectName ? normalizeProjectName(options.projectName) : options.yes ? "lightfish-app" : "";
|
|
231
288
|
const answers = await prompts3(
|
|
232
289
|
[
|
|
233
290
|
{
|
|
@@ -268,14 +325,15 @@ async function resolveCreateOptions(options) {
|
|
|
268
325
|
templateRepo: options.templateRepo,
|
|
269
326
|
yes: options.yes
|
|
270
327
|
});
|
|
328
|
+
const yesMode = options.yes === true;
|
|
271
329
|
return {
|
|
272
330
|
cwd,
|
|
273
331
|
projectName,
|
|
274
332
|
targetDir: resolveTargetDir(cwd, projectName),
|
|
275
333
|
packageManager,
|
|
276
334
|
templateRepo,
|
|
277
|
-
install: options.skipInstall ? false : options.install ?? (
|
|
278
|
-
git: options.git ?? answers.git ?? false
|
|
335
|
+
install: options.skipInstall ? false : options.install ?? (yesMode ? true : answers.install ?? false),
|
|
336
|
+
git: options.git ?? (yesMode ? true : answers.git ?? false)
|
|
279
337
|
};
|
|
280
338
|
}
|
|
281
339
|
async function maybeInstall(options) {
|
|
@@ -309,6 +367,9 @@ async function createProject(options = {}) {
|
|
|
309
367
|
console.log("[create] \u5F00\u59CB\u4FEE\u6539 package.json...");
|
|
310
368
|
await patchPackageJsonName(resolvedOptions.targetDir, resolvedOptions.projectName);
|
|
311
369
|
console.log("[create] package.json \u4FEE\u6539\u5B8C\u6210");
|
|
370
|
+
console.log("[create] \u5F00\u59CB\u66FF\u6362\u9879\u76EE\u540D\u5360\u4F4D\u7B26...");
|
|
371
|
+
await replaceToken(resolvedOptions.targetDir, "__PROJECT_NAME__", resolvedOptions.projectName);
|
|
372
|
+
console.log("[create] \u5360\u4F4D\u7B26\u66FF\u6362\u5B8C\u6210");
|
|
312
373
|
console.log("[create] \u5F00\u59CB\u5B89\u88C5\u4F9D\u8D56...");
|
|
313
374
|
await maybeInstall(resolvedOptions);
|
|
314
375
|
console.log("[create] \u4F9D\u8D56\u5B89\u88C5\u5B8C\u6210");
|
|
@@ -319,28 +380,28 @@ async function createProject(options = {}) {
|
|
|
319
380
|
}
|
|
320
381
|
|
|
321
382
|
// src/utils/package-info.ts
|
|
322
|
-
import
|
|
323
|
-
import
|
|
383
|
+
import fs5 from "fs";
|
|
384
|
+
import path5 from "path";
|
|
324
385
|
import { fileURLToPath } from "url";
|
|
325
|
-
var dirname =
|
|
386
|
+
var dirname = path5.dirname(fileURLToPath(import.meta.url));
|
|
326
387
|
function readPackageVersion() {
|
|
327
388
|
const packageJsonPathCandidates = [
|
|
328
389
|
// 源码模式:src/utils/package-info.ts -> packages/cli/package.json
|
|
329
|
-
|
|
390
|
+
path5.resolve(dirname, "../../package.json"),
|
|
330
391
|
// 构建产物模式:dist/lightfish.js -> packages/cli/package.json
|
|
331
|
-
|
|
392
|
+
path5.resolve(dirname, "../package.json")
|
|
332
393
|
];
|
|
333
|
-
const packageJsonPath = packageJsonPathCandidates.find((candidate) =>
|
|
394
|
+
const packageJsonPath = packageJsonPathCandidates.find((candidate) => fs5.existsSync(candidate));
|
|
334
395
|
if (!packageJsonPath) {
|
|
335
396
|
return "0.0.0";
|
|
336
397
|
}
|
|
337
|
-
const packageJson = JSON.parse(
|
|
398
|
+
const packageJson = JSON.parse(fs5.readFileSync(packageJsonPath, "utf8"));
|
|
338
399
|
return packageJson.version ?? "0.0.0";
|
|
339
400
|
}
|
|
340
401
|
|
|
341
402
|
// src/create-lightfish.ts
|
|
342
403
|
var cli = cac("create-lightfish");
|
|
343
|
-
cli.command("[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("--template-repo <repo>", "\u76F4\u63A5\u6307\u5B9A degit \u6E90\uFF0C\u5982 QGtiger/template-vite-server#main\uFF08\u4F18\u5148\u4E8E --template\uFF09").option("--skip-install", "\u8DF3\u8FC7\u4F9D\u8D56\u5B89\u88C5").option("--git", "\u521B\u5EFA\u540E\u521D\u59CB\u5316 git").option("--yes", "\u4F7F\u7528\u9ED8\u8BA4\u9009\u9879\u5E76\u8DF3\u8FC7\u786E\u8BA4").action(async (projectName, options) => {
|
|
404
|
+
cli.command("[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("--template-repo <repo>", "\u76F4\u63A5\u6307\u5B9A degit \u6E90\uFF0C\u5982 QGtiger/template-vite-server#main\uFF08\u4F18\u5148\u4E8E --template\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) => {
|
|
344
405
|
try {
|
|
345
406
|
const packageManager = options.pm ?? "pnpm";
|
|
346
407
|
if (!isPackageManager(packageManager)) {
|
package/dist/lightfish.js
CHANGED
|
@@ -5,9 +5,9 @@ import cac from "cac";
|
|
|
5
5
|
import { execa as execa3 } from "execa";
|
|
6
6
|
|
|
7
7
|
// src/commands/create.ts
|
|
8
|
-
import
|
|
8
|
+
import path4 from "path";
|
|
9
9
|
import { execa as execa2 } from "execa";
|
|
10
|
-
import
|
|
10
|
+
import fs4 from "fs-extra";
|
|
11
11
|
import prompts3 from "prompts";
|
|
12
12
|
|
|
13
13
|
// src/utils/download-template.ts
|
|
@@ -148,6 +148,63 @@ function toPackageName(projectName) {
|
|
|
148
148
|
return projectName.trim().toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
+
// src/utils/replace-token.ts
|
|
152
|
+
import path3 from "path";
|
|
153
|
+
import fs3 from "fs-extra";
|
|
154
|
+
var SKIP_DIRS = /* @__PURE__ */ new Set([
|
|
155
|
+
".git",
|
|
156
|
+
"node_modules",
|
|
157
|
+
"dist",
|
|
158
|
+
".cache",
|
|
159
|
+
"coverage"
|
|
160
|
+
]);
|
|
161
|
+
var SKIP_EXTS = /* @__PURE__ */ new Set([
|
|
162
|
+
".png",
|
|
163
|
+
".jpg",
|
|
164
|
+
".jpeg",
|
|
165
|
+
".gif",
|
|
166
|
+
".svg",
|
|
167
|
+
".ico",
|
|
168
|
+
".webp",
|
|
169
|
+
".woff",
|
|
170
|
+
".woff2",
|
|
171
|
+
".ttf",
|
|
172
|
+
".eot",
|
|
173
|
+
".otf",
|
|
174
|
+
".mp4",
|
|
175
|
+
".webm",
|
|
176
|
+
".mp3",
|
|
177
|
+
".wav",
|
|
178
|
+
".zip",
|
|
179
|
+
".gz",
|
|
180
|
+
".tar",
|
|
181
|
+
".7z",
|
|
182
|
+
".lock"
|
|
183
|
+
]);
|
|
184
|
+
async function replaceToken(targetDir, token, value) {
|
|
185
|
+
const entries = await fs3.readdir(targetDir);
|
|
186
|
+
for (const entry of entries) {
|
|
187
|
+
const fullPath = path3.join(targetDir, entry);
|
|
188
|
+
const stat = await fs3.stat(fullPath);
|
|
189
|
+
if (stat.isDirectory()) {
|
|
190
|
+
if (SKIP_DIRS.has(entry)) continue;
|
|
191
|
+
await replaceToken(fullPath, token, value);
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
const ext = path3.extname(entry).toLowerCase();
|
|
195
|
+
if (SKIP_EXTS.has(ext)) continue;
|
|
196
|
+
try {
|
|
197
|
+
const content = await fs3.readFile(fullPath, "utf8");
|
|
198
|
+
if (content.includes(token)) {
|
|
199
|
+
const replaced = content.replaceAll(token, value);
|
|
200
|
+
await fs3.writeFile(fullPath, replaced, "utf8");
|
|
201
|
+
console.log(` [replace] ${entry}`);
|
|
202
|
+
}
|
|
203
|
+
} catch {
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
151
208
|
// src/utils/resolve-template.ts
|
|
152
209
|
import prompts2 from "prompts";
|
|
153
210
|
|
|
@@ -218,17 +275,17 @@ async function resolveTemplateRepo(options) {
|
|
|
218
275
|
|
|
219
276
|
// src/commands/create.ts
|
|
220
277
|
async function patchPackageJsonName(targetDir, projectName) {
|
|
221
|
-
const packageJsonPath =
|
|
222
|
-
if (!await
|
|
278
|
+
const packageJsonPath = path4.join(targetDir, "package.json");
|
|
279
|
+
if (!await fs4.pathExists(packageJsonPath)) {
|
|
223
280
|
throw new Error("\u6A21\u677F\u7F3A\u5C11 package.json");
|
|
224
281
|
}
|
|
225
|
-
const packageJson = await
|
|
282
|
+
const packageJson = await fs4.readJson(packageJsonPath);
|
|
226
283
|
packageJson.name = toPackageName(projectName);
|
|
227
|
-
await
|
|
284
|
+
await fs4.writeJson(packageJsonPath, packageJson, { spaces: 2 });
|
|
228
285
|
}
|
|
229
286
|
async function resolveCreateOptions(options) {
|
|
230
287
|
const cwd = options.cwd ?? process.cwd();
|
|
231
|
-
const initialProjectName = options.projectName ? normalizeProjectName(options.projectName) : "";
|
|
288
|
+
const initialProjectName = options.projectName ? normalizeProjectName(options.projectName) : options.yes ? "lightfish-app" : "";
|
|
232
289
|
const answers = await prompts3(
|
|
233
290
|
[
|
|
234
291
|
{
|
|
@@ -269,14 +326,15 @@ async function resolveCreateOptions(options) {
|
|
|
269
326
|
templateRepo: options.templateRepo,
|
|
270
327
|
yes: options.yes
|
|
271
328
|
});
|
|
329
|
+
const yesMode = options.yes === true;
|
|
272
330
|
return {
|
|
273
331
|
cwd,
|
|
274
332
|
projectName,
|
|
275
333
|
targetDir: resolveTargetDir(cwd, projectName),
|
|
276
334
|
packageManager,
|
|
277
335
|
templateRepo,
|
|
278
|
-
install: options.skipInstall ? false : options.install ?? (
|
|
279
|
-
git: options.git ?? answers.git ?? false
|
|
336
|
+
install: options.skipInstall ? false : options.install ?? (yesMode ? true : answers.install ?? false),
|
|
337
|
+
git: options.git ?? (yesMode ? true : answers.git ?? false)
|
|
280
338
|
};
|
|
281
339
|
}
|
|
282
340
|
async function maybeInstall(options) {
|
|
@@ -310,6 +368,9 @@ async function createProject(options = {}) {
|
|
|
310
368
|
console.log("[create] \u5F00\u59CB\u4FEE\u6539 package.json...");
|
|
311
369
|
await patchPackageJsonName(resolvedOptions.targetDir, resolvedOptions.projectName);
|
|
312
370
|
console.log("[create] package.json \u4FEE\u6539\u5B8C\u6210");
|
|
371
|
+
console.log("[create] \u5F00\u59CB\u66FF\u6362\u9879\u76EE\u540D\u5360\u4F4D\u7B26...");
|
|
372
|
+
await replaceToken(resolvedOptions.targetDir, "__PROJECT_NAME__", resolvedOptions.projectName);
|
|
373
|
+
console.log("[create] \u5360\u4F4D\u7B26\u66FF\u6362\u5B8C\u6210");
|
|
313
374
|
console.log("[create] \u5F00\u59CB\u5B89\u88C5\u4F9D\u8D56...");
|
|
314
375
|
await maybeInstall(resolvedOptions);
|
|
315
376
|
console.log("[create] \u4F9D\u8D56\u5B89\u88C5\u5B8C\u6210");
|
|
@@ -320,22 +381,22 @@ async function createProject(options = {}) {
|
|
|
320
381
|
}
|
|
321
382
|
|
|
322
383
|
// src/utils/package-info.ts
|
|
323
|
-
import
|
|
324
|
-
import
|
|
384
|
+
import fs5 from "fs";
|
|
385
|
+
import path5 from "path";
|
|
325
386
|
import { fileURLToPath } from "url";
|
|
326
|
-
var dirname =
|
|
387
|
+
var dirname = path5.dirname(fileURLToPath(import.meta.url));
|
|
327
388
|
function readPackageVersion() {
|
|
328
389
|
const packageJsonPathCandidates = [
|
|
329
390
|
// 源码模式:src/utils/package-info.ts -> packages/cli/package.json
|
|
330
|
-
|
|
391
|
+
path5.resolve(dirname, "../../package.json"),
|
|
331
392
|
// 构建产物模式:dist/lightfish.js -> packages/cli/package.json
|
|
332
|
-
|
|
393
|
+
path5.resolve(dirname, "../package.json")
|
|
333
394
|
];
|
|
334
|
-
const packageJsonPath = packageJsonPathCandidates.find((candidate) =>
|
|
395
|
+
const packageJsonPath = packageJsonPathCandidates.find((candidate) => fs5.existsSync(candidate));
|
|
335
396
|
if (!packageJsonPath) {
|
|
336
397
|
return "0.0.0";
|
|
337
398
|
}
|
|
338
|
-
const packageJson = JSON.parse(
|
|
399
|
+
const packageJson = JSON.parse(fs5.readFileSync(packageJsonPath, "utf8"));
|
|
339
400
|
return packageJson.version ?? "0.0.0";
|
|
340
401
|
}
|
|
341
402
|
|
|
@@ -348,7 +409,7 @@ async function runBuild() {
|
|
|
348
409
|
stdio: "inherit"
|
|
349
410
|
});
|
|
350
411
|
}
|
|
351
|
-
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("--template-repo <repo>", "\u76F4\u63A5\u6307\u5B9A degit \u6E90\uFF0C\u5982 QGtiger/template-vite-server#main\uFF08\u4F18\u5148\u4E8E --template\uFF09").option("--skip-install", "\u8DF3\u8FC7\u4F9D\u8D56\u5B89\u88C5").option("--git", "\u521B\u5EFA\u540E\u521D\u59CB\u5316 git").option("--yes", "\u4F7F\u7528\u9ED8\u8BA4\u9009\u9879\u5E76\u8DF3\u8FC7\u786E\u8BA4").action(async (projectName, options) => {
|
|
412
|
+
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("--template-repo <repo>", "\u76F4\u63A5\u6307\u5B9A degit \u6E90\uFF0C\u5982 QGtiger/template-vite-server#main\uFF08\u4F18\u5148\u4E8E --template\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) => {
|
|
352
413
|
try {
|
|
353
414
|
const packageManager = options.pm ?? "pnpm";
|
|
354
415
|
if (!isPackageManager(packageManager)) {
|