cmyr-template-cli 1.45.3 → 1.45.5
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/plopfile.js +48 -18
- package/package.json +8 -7
package/dist/plopfile.js
CHANGED
|
@@ -24,7 +24,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
24
24
|
|
|
25
25
|
// src/plopfile.ts
|
|
26
26
|
var import_path11 = __toESM(require("path"));
|
|
27
|
-
var
|
|
27
|
+
var import_fs_extra12 = __toESM(require("fs-extra"));
|
|
28
28
|
var import_ora11 = __toESM(require("ora"));
|
|
29
29
|
|
|
30
30
|
// src/config/env.ts
|
|
@@ -35,8 +35,10 @@ var PACKAGE_MANAGER = "pnpm";
|
|
|
35
35
|
// src/utils/utils.ts
|
|
36
36
|
var import_path10 = __toESM(require("path"));
|
|
37
37
|
var import_colors3 = __toESM(require("@colors/colors"));
|
|
38
|
-
var import_download_git_repo = __toESM(require("download-git-repo"));
|
|
39
38
|
var import_ora10 = __toESM(require("ora"));
|
|
39
|
+
var import_axios2 = __toESM(require("axios"));
|
|
40
|
+
var import_adm_zip = __toESM(require("adm-zip"));
|
|
41
|
+
var import_fs_extra11 = __toESM(require("fs-extra"));
|
|
40
42
|
|
|
41
43
|
// src/utils/constants.ts
|
|
42
44
|
var GITHUB_API_URL = "https://api.github.com";
|
|
@@ -2321,31 +2323,59 @@ async function initCursorDirectory(projectPath) {
|
|
|
2321
2323
|
}
|
|
2322
2324
|
|
|
2323
2325
|
// src/utils/utils.ts
|
|
2324
|
-
async function downloadGitRepo(repository, destination
|
|
2326
|
+
async function downloadGitRepo(repository, destination) {
|
|
2325
2327
|
const fastRepo = await getFastGitRepo(repository);
|
|
2326
2328
|
const loading = (0, import_ora10.default)(`正在下载模板 - ${repository}`);
|
|
2327
2329
|
loading.start();
|
|
2328
2330
|
return Promise.any([
|
|
2329
|
-
|
|
2330
|
-
(0, import_download_git_repo.default)(fastRepo, destination, options, (err) => {
|
|
2331
|
-
if (err) {
|
|
2332
|
-
loading.fail("下载模板失败!");
|
|
2333
|
-
process.exit(1);
|
|
2334
|
-
}
|
|
2335
|
-
loading.succeed(`成功下载模板 - ${repository}`);
|
|
2336
|
-
resolve(true);
|
|
2337
|
-
});
|
|
2338
|
-
}),
|
|
2331
|
+
downloadAndExtractZip(fastRepo, destination, loading, repository),
|
|
2339
2332
|
new Promise((_resolve, reject) => setTimeout(reject, 60 * 1e3))
|
|
2340
2333
|
]);
|
|
2341
2334
|
}
|
|
2335
|
+
async function downloadAndExtractZip(url, destination, loading, repository) {
|
|
2336
|
+
try {
|
|
2337
|
+
const response = await import_axios2.default.get(url, { responseType: "arraybuffer" });
|
|
2338
|
+
const buffer = Buffer.from(response.data);
|
|
2339
|
+
const zip = new import_adm_zip.default(buffer);
|
|
2340
|
+
const entries = zip.getEntries();
|
|
2341
|
+
const topDir = entries[0]?.entryName.split("/")[0];
|
|
2342
|
+
if (!topDir) {
|
|
2343
|
+
throw new Error("无效的 zip 文件");
|
|
2344
|
+
}
|
|
2345
|
+
await import_fs_extra11.default.ensureDir(destination);
|
|
2346
|
+
for (const entry of entries) {
|
|
2347
|
+
if (entry.entryName.startsWith(`${topDir}/`)) {
|
|
2348
|
+
const relativePath = entry.entryName.slice(topDir.length + 1);
|
|
2349
|
+
if (!relativePath) {
|
|
2350
|
+
continue;
|
|
2351
|
+
}
|
|
2352
|
+
const targetPath = import_path10.default.join(destination, relativePath);
|
|
2353
|
+
const resolvedPath = import_path10.default.resolve(targetPath);
|
|
2354
|
+
if (!resolvedPath.startsWith(import_path10.default.resolve(destination))) {
|
|
2355
|
+
throw new Error(`路径遍历攻击检测: ${relativePath}`);
|
|
2356
|
+
}
|
|
2357
|
+
if (entry.isDirectory) {
|
|
2358
|
+
await import_fs_extra11.default.ensureDir(targetPath);
|
|
2359
|
+
} else {
|
|
2360
|
+
await import_fs_extra11.default.ensureDir(import_path10.default.dirname(targetPath));
|
|
2361
|
+
await import_fs_extra11.default.writeFile(targetPath, entry.getData());
|
|
2362
|
+
}
|
|
2363
|
+
}
|
|
2364
|
+
}
|
|
2365
|
+
loading.succeed(`成功下载模板 - ${repository}`);
|
|
2366
|
+
return true;
|
|
2367
|
+
} catch {
|
|
2368
|
+
loading.fail("下载模板失败!");
|
|
2369
|
+
process.exit(1);
|
|
2370
|
+
}
|
|
2371
|
+
}
|
|
2342
2372
|
async function getFastGitRepo(repository) {
|
|
2343
2373
|
const loading = (0, import_ora10.default)(`正在选择镜像源 - ${repository}`);
|
|
2344
2374
|
loading.start();
|
|
2345
2375
|
try {
|
|
2346
2376
|
const fastUrl = await getFastUrl(REMOTES.map((remote) => `${remote}/${repository}/archive/refs/heads/master.zip`));
|
|
2347
2377
|
loading.succeed(`成功选择了镜像源 - ${fastUrl}`);
|
|
2348
|
-
return
|
|
2378
|
+
return fastUrl;
|
|
2349
2379
|
} catch (error) {
|
|
2350
2380
|
console.error(error);
|
|
2351
2381
|
loading.fail("选择镜像源失败!");
|
|
@@ -2507,7 +2537,7 @@ async function getGitUserName() {
|
|
|
2507
2537
|
}
|
|
2508
2538
|
|
|
2509
2539
|
// src/utils/ai-api.ts
|
|
2510
|
-
var
|
|
2540
|
+
var import_axios3 = __toESM(require("axios"));
|
|
2511
2541
|
|
|
2512
2542
|
// src/pure/ai.ts
|
|
2513
2543
|
var MAX_USER_INPUT_LENGTH = 500;
|
|
@@ -2590,7 +2620,7 @@ async function chatCompletion(request) {
|
|
|
2590
2620
|
throw new Error("AI_API_BASE must use HTTPS for security (except for localhost)");
|
|
2591
2621
|
}
|
|
2592
2622
|
try {
|
|
2593
|
-
const response = await
|
|
2623
|
+
const response = await import_axios3.default.post(
|
|
2594
2624
|
endpoint,
|
|
2595
2625
|
{
|
|
2596
2626
|
model,
|
|
@@ -2616,7 +2646,7 @@ async function chatCompletion(request) {
|
|
|
2616
2646
|
}
|
|
2617
2647
|
return content;
|
|
2618
2648
|
} catch (error) {
|
|
2619
|
-
if (
|
|
2649
|
+
if (import_axios3.default.isAxiosError(error)) {
|
|
2620
2650
|
const axiosError = error;
|
|
2621
2651
|
if (axiosError.code === "ECONNABORTED" || axiosError.message.includes("timeout")) {
|
|
2622
2652
|
throw new Error(`AI API request timed out after ${AI_TIMEOUT / 1e3} seconds. Please try again.`);
|
|
@@ -2869,7 +2899,7 @@ module.exports = function(plop) {
|
|
|
2869
2899
|
name: "license",
|
|
2870
2900
|
message: "请选择开源协议",
|
|
2871
2901
|
async choices() {
|
|
2872
|
-
return
|
|
2902
|
+
return import_fs_extra12.default.readdir(import_path11.default.join(__dirname, "../templates/licenses/"));
|
|
2873
2903
|
},
|
|
2874
2904
|
default: "MIT",
|
|
2875
2905
|
when(answers2) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cmyr-template-cli",
|
|
3
|
-
"version": "1.45.
|
|
3
|
+
"version": "1.45.5",
|
|
4
4
|
"description": "草梅友仁自制的项目模板创建器",
|
|
5
5
|
"author": "CaoMeiYouRen",
|
|
6
6
|
"license": "MIT",
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
"@commitlint/cli": "^21.0.1",
|
|
39
39
|
"@semantic-release/changelog": "^6.0.3",
|
|
40
40
|
"@semantic-release/git": "^10.0.1",
|
|
41
|
+
"@types/adm-zip": "^0.5.8",
|
|
41
42
|
"@types/debug": "^4.1.13",
|
|
42
43
|
"@types/ejs": "^3.1.0",
|
|
43
44
|
"@types/fs-extra": "^11.0.0",
|
|
@@ -45,17 +46,17 @@
|
|
|
45
46
|
"@types/libsodium-wrappers": "^0.8.2",
|
|
46
47
|
"@types/lodash": "^4.17.24",
|
|
47
48
|
"@types/minimist": "^1.2.5",
|
|
48
|
-
"@types/node": "^
|
|
49
|
+
"@types/node": "^26.0.1",
|
|
49
50
|
"@vitest/coverage-v8": "^4.1.6",
|
|
50
51
|
"commitizen": "^4.3.1",
|
|
51
52
|
"commitlint-config-cmyr": "1.0.0",
|
|
52
53
|
"conventional-changelog-cmyr-config": "^3.0.0",
|
|
53
|
-
"conventional-changelog-writer": "^
|
|
54
|
+
"conventional-changelog-writer": "^9.1.0",
|
|
54
55
|
"cross-env": "^10.1.0",
|
|
55
56
|
"cz-conventional-changelog-cmyr": "2.0.0",
|
|
56
57
|
"debug": "^4.4.3",
|
|
57
58
|
"eslint": "^9.34.0",
|
|
58
|
-
"eslint-config-cmyr": "2.3.
|
|
59
|
+
"eslint-config-cmyr": "2.3.1",
|
|
59
60
|
"husky": "^9.0.5",
|
|
60
61
|
"lint-staged": "^17.0.4",
|
|
61
62
|
"rimraf": "^6.1.3",
|
|
@@ -72,11 +73,11 @@
|
|
|
72
73
|
"@lint-md/core": "^2.0.0",
|
|
73
74
|
"acorn": "^8.16.0",
|
|
74
75
|
"acorn-walk": "^8.3.5",
|
|
76
|
+
"adm-zip": "^0.6.0",
|
|
75
77
|
"axios": "^1.16.1",
|
|
76
|
-
"commander": "^
|
|
78
|
+
"commander": "^15.0.0",
|
|
77
79
|
"dayjs": "^1.11.20",
|
|
78
|
-
"
|
|
79
|
-
"ejs": "^5.0.2",
|
|
80
|
+
"ejs": "^6.0.1",
|
|
80
81
|
"fs-extra": "^11.3.5",
|
|
81
82
|
"json5": "^2.2.1",
|
|
82
83
|
"libsodium-wrappers": "0.8.4",
|