@lightfish/cli 0.0.3 → 0.0.4
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 +7 -23
- package/dist/lightfish.js +7 -23
- package/package.json +1 -2
package/dist/create-lightfish.js
CHANGED
|
@@ -14,9 +14,8 @@ import path from "path";
|
|
|
14
14
|
import { tmpdir } from "os";
|
|
15
15
|
import { randomUUID } from "crypto";
|
|
16
16
|
import { execa } from "execa";
|
|
17
|
-
import degit from "degit";
|
|
18
17
|
import fs from "fs-extra";
|
|
19
|
-
function
|
|
18
|
+
function parseRepo(repo) {
|
|
20
19
|
const [repoPart, branch] = repo.split("#");
|
|
21
20
|
let url;
|
|
22
21
|
if (repoPart.startsWith("http://") || repoPart.startsWith("https://")) {
|
|
@@ -26,7 +25,7 @@ function parseDegitRepo(repo) {
|
|
|
26
25
|
} else {
|
|
27
26
|
throw new Error(`\u65E0\u6CD5\u89E3\u6790\u4ED3\u5E93\u5730\u5740: ${repo}`);
|
|
28
27
|
}
|
|
29
|
-
return { url, branch };
|
|
28
|
+
return { url, branch: branch || void 0 };
|
|
30
29
|
}
|
|
31
30
|
async function gitClone(url, branch, targetDir) {
|
|
32
31
|
const tmpDir = path.join(tmpdir(), `lightfish-template-${randomUUID()}`);
|
|
@@ -56,25 +55,10 @@ async function gitClone(url, branch, targetDir) {
|
|
|
56
55
|
}
|
|
57
56
|
async function downloadTemplate(repo, targetDir) {
|
|
58
57
|
await fs.ensureDir(targetDir);
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
verbose: true
|
|
64
|
-
// 开启详细日志,方便调试
|
|
65
|
-
});
|
|
66
|
-
try {
|
|
67
|
-
console.log(`\u6B63\u5728\u901A\u8FC7 degit \u62C9\u53D6\u6A21\u677F: ${repo}`);
|
|
68
|
-
await emitter.clone(targetDir);
|
|
69
|
-
console.log("degit \u62C9\u53D6\u5B8C\u6210");
|
|
70
|
-
} catch (error) {
|
|
71
|
-
const detail = error instanceof Error ? error.message : String(error);
|
|
72
|
-
await fs.emptyDir(targetDir);
|
|
73
|
-
const { url, branch } = parseDegitRepo(repo);
|
|
74
|
-
console.log(`\u6B63\u5728\u901A\u8FC7 git clone \u62C9\u53D6\u6A21\u677F: ${url}${branch ? ` (\u5206\u652F: ${branch})` : ""}`);
|
|
75
|
-
await gitClone(url, branch, targetDir);
|
|
76
|
-
console.log("git clone \u62C9\u53D6\u5B8C\u6210");
|
|
77
|
-
}
|
|
58
|
+
const { url, branch } = parseRepo(repo);
|
|
59
|
+
console.log(`\u6B63\u5728\u62C9\u53D6\u6A21\u677F: ${url}${branch ? ` (\u5206\u652F: ${branch})` : ""}`);
|
|
60
|
+
await gitClone(url, branch, targetDir);
|
|
61
|
+
console.log("\u6A21\u677F\u62C9\u53D6\u5B8C\u6210");
|
|
78
62
|
const gitDir = path.join(targetDir, ".git");
|
|
79
63
|
if (await fs.pathExists(gitDir)) {
|
|
80
64
|
await fs.remove(gitDir);
|
|
@@ -401,7 +385,7 @@ function readPackageVersion() {
|
|
|
401
385
|
|
|
402
386
|
// src/create-lightfish.ts
|
|
403
387
|
var cli = cac("create-lightfish");
|
|
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
|
|
388
|
+
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 git \u4ED3\u5E93\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) => {
|
|
405
389
|
try {
|
|
406
390
|
const packageManager = options.pm ?? "pnpm";
|
|
407
391
|
if (!isPackageManager(packageManager)) {
|
package/dist/lightfish.js
CHANGED
|
@@ -15,9 +15,8 @@ import path from "path";
|
|
|
15
15
|
import { tmpdir } from "os";
|
|
16
16
|
import { randomUUID } from "crypto";
|
|
17
17
|
import { execa } from "execa";
|
|
18
|
-
import degit from "degit";
|
|
19
18
|
import fs from "fs-extra";
|
|
20
|
-
function
|
|
19
|
+
function parseRepo(repo) {
|
|
21
20
|
const [repoPart, branch] = repo.split("#");
|
|
22
21
|
let url;
|
|
23
22
|
if (repoPart.startsWith("http://") || repoPart.startsWith("https://")) {
|
|
@@ -27,7 +26,7 @@ function parseDegitRepo(repo) {
|
|
|
27
26
|
} else {
|
|
28
27
|
throw new Error(`\u65E0\u6CD5\u89E3\u6790\u4ED3\u5E93\u5730\u5740: ${repo}`);
|
|
29
28
|
}
|
|
30
|
-
return { url, branch };
|
|
29
|
+
return { url, branch: branch || void 0 };
|
|
31
30
|
}
|
|
32
31
|
async function gitClone(url, branch, targetDir) {
|
|
33
32
|
const tmpDir = path.join(tmpdir(), `lightfish-template-${randomUUID()}`);
|
|
@@ -57,25 +56,10 @@ async function gitClone(url, branch, targetDir) {
|
|
|
57
56
|
}
|
|
58
57
|
async function downloadTemplate(repo, targetDir) {
|
|
59
58
|
await fs.ensureDir(targetDir);
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
verbose: true
|
|
65
|
-
// 开启详细日志,方便调试
|
|
66
|
-
});
|
|
67
|
-
try {
|
|
68
|
-
console.log(`\u6B63\u5728\u901A\u8FC7 degit \u62C9\u53D6\u6A21\u677F: ${repo}`);
|
|
69
|
-
await emitter.clone(targetDir);
|
|
70
|
-
console.log("degit \u62C9\u53D6\u5B8C\u6210");
|
|
71
|
-
} catch (error) {
|
|
72
|
-
const detail = error instanceof Error ? error.message : String(error);
|
|
73
|
-
await fs.emptyDir(targetDir);
|
|
74
|
-
const { url, branch } = parseDegitRepo(repo);
|
|
75
|
-
console.log(`\u6B63\u5728\u901A\u8FC7 git clone \u62C9\u53D6\u6A21\u677F: ${url}${branch ? ` (\u5206\u652F: ${branch})` : ""}`);
|
|
76
|
-
await gitClone(url, branch, targetDir);
|
|
77
|
-
console.log("git clone \u62C9\u53D6\u5B8C\u6210");
|
|
78
|
-
}
|
|
59
|
+
const { url, branch } = parseRepo(repo);
|
|
60
|
+
console.log(`\u6B63\u5728\u62C9\u53D6\u6A21\u677F: ${url}${branch ? ` (\u5206\u652F: ${branch})` : ""}`);
|
|
61
|
+
await gitClone(url, branch, targetDir);
|
|
62
|
+
console.log("\u6A21\u677F\u62C9\u53D6\u5B8C\u6210");
|
|
79
63
|
const gitDir = path.join(targetDir, ".git");
|
|
80
64
|
if (await fs.pathExists(gitDir)) {
|
|
81
65
|
await fs.remove(gitDir);
|
|
@@ -409,7 +393,7 @@ async function runBuild() {
|
|
|
409
393
|
stdio: "inherit"
|
|
410
394
|
});
|
|
411
395
|
}
|
|
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
|
|
396
|
+
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 git \u4ED3\u5E93\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) => {
|
|
413
397
|
try {
|
|
414
398
|
const packageManager = options.pm ?? "pnpm";
|
|
415
399
|
if (!isPackageManager(packageManager)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lightfish/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -19,7 +19,6 @@
|
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"cac": "^7.0.0",
|
|
22
|
-
"degit": "^2.8.4",
|
|
23
22
|
"execa": "^9.6.1",
|
|
24
23
|
"fs-extra": "^11.3.5",
|
|
25
24
|
"prompts": "^2.4.2"
|