@lntvow/dev 5.5.0 → 5.6.0
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/cli.d.mts +1 -0
- package/dist/cli.mjs +22 -0
- package/dist/main-DFrKdbp7.mjs +211 -0
- package/package.json +28 -19
- package/dist/cli.d.ts +0 -1
- package/dist/cli.js +0 -2
package/dist/cli.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/cli.mjs
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
//#region src/cli.ts
|
|
3
|
+
const MIN_NODE_MAJOR = 20;
|
|
4
|
+
const MIN_NODE_MINOR = 19;
|
|
5
|
+
const MIN_NODE_VERSION = `${MIN_NODE_MAJOR}.${MIN_NODE_MINOR}`;
|
|
6
|
+
const parseNodeVersion = (rawVersion) => {
|
|
7
|
+
const [majorRaw = "0", minorRaw = "0"] = rawVersion.split(".");
|
|
8
|
+
return {
|
|
9
|
+
major: Number(majorRaw),
|
|
10
|
+
minor: Number(minorRaw)
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
const isSupportedNodeVersion = (version) => version.major > MIN_NODE_MAJOR || version.major === MIN_NODE_MAJOR && version.minor >= MIN_NODE_MINOR;
|
|
14
|
+
const ensureSupportedNodeVersion = () => {
|
|
15
|
+
if (isSupportedNodeVersion(parseNodeVersion(process.versions.node))) return;
|
|
16
|
+
process.stderr.write(`@lntvow/dev: Node.js v${MIN_NODE_VERSION}+ is required (current: v${process.versions.node}).\nIf you use nvm, run:\n nvm install ${MIN_NODE_MAJOR}\n nvm use ${MIN_NODE_MAJOR}\n nvm alias default ${MIN_NODE_MAJOR}\n`);
|
|
17
|
+
process.exit(1);
|
|
18
|
+
};
|
|
19
|
+
ensureSupportedNodeVersion();
|
|
20
|
+
import("./main-DFrKdbp7.mjs");
|
|
21
|
+
//#endregion
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { Option, program } from "commander";
|
|
2
|
+
import { copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { basename, resolve } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { execSync } from "node:child_process";
|
|
6
|
+
import pc from "picocolors";
|
|
7
|
+
import dayjs from "dayjs";
|
|
8
|
+
import simpleGit from "simple-git";
|
|
9
|
+
//#region package.json
|
|
10
|
+
var name = "@lntvow/dev";
|
|
11
|
+
var version = "5.6.0";
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/constants/index.ts
|
|
14
|
+
const DEFAULT_SCRIPTS = {
|
|
15
|
+
"prepare": "simple-git-hooks",
|
|
16
|
+
"rimraf": "rimraf ./node_modules/",
|
|
17
|
+
"ncu": "ncu -u --reject @types/node && pnpm install",
|
|
18
|
+
"sort:pkg": "sort-package-json",
|
|
19
|
+
"commit": "git add . && git-cz && git push",
|
|
20
|
+
"release": "git add . && bumpp package.json --all --no-tag --no-print-commits",
|
|
21
|
+
"lint:eslint": "eslint --fix --cache",
|
|
22
|
+
"lint:tsc": "tsc --noEmit",
|
|
23
|
+
"lint": "run-p lint:eslint lint:tsc"
|
|
24
|
+
};
|
|
25
|
+
const DEV_DEPENDENCIES = [
|
|
26
|
+
"@commitlint/cli",
|
|
27
|
+
"@commitlint/config-conventional",
|
|
28
|
+
"@lntvow/eslint-config",
|
|
29
|
+
"bumpp",
|
|
30
|
+
"commitizen",
|
|
31
|
+
"cz-conventional-changelog",
|
|
32
|
+
"eslint",
|
|
33
|
+
"lint-staged",
|
|
34
|
+
"npm-run-all",
|
|
35
|
+
"prettier",
|
|
36
|
+
"simple-git-hooks",
|
|
37
|
+
"typescript"
|
|
38
|
+
].sort((a, b) => a.localeCompare(b));
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region src/utils/index.ts
|
|
41
|
+
const logger = {
|
|
42
|
+
info: (msg) => console.log(pc.blue(`● ${msg}`)),
|
|
43
|
+
success: (msg) => console.log(pc.green(`✓ ${msg}`)),
|
|
44
|
+
warn: (msg) => console.log(pc.yellow(`▲ ${msg}`)),
|
|
45
|
+
error: (msg) => console.log(pc.red(`✗ ${msg}`))
|
|
46
|
+
};
|
|
47
|
+
function executeCommand(cmd, options = {}) {
|
|
48
|
+
try {
|
|
49
|
+
return execSync(cmd, {
|
|
50
|
+
stdio: "inherit",
|
|
51
|
+
...options
|
|
52
|
+
});
|
|
53
|
+
} catch (error) {
|
|
54
|
+
logger.error(`命令执行失败: ${cmd}`);
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function getPackageManager() {
|
|
59
|
+
for (const { file, manager } of [
|
|
60
|
+
{
|
|
61
|
+
file: "pnpm-lock.yaml",
|
|
62
|
+
manager: "pnpm"
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
file: "yarn.lock",
|
|
66
|
+
manager: "yarn"
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
file: "package-lock.json",
|
|
70
|
+
manager: "npm"
|
|
71
|
+
}
|
|
72
|
+
]) if (existsSync(resolve(process.cwd(), file))) return manager;
|
|
73
|
+
const userAgent = process.env.npm_config_user_agent || "";
|
|
74
|
+
if (userAgent.startsWith("pnpm")) return "pnpm";
|
|
75
|
+
if (userAgent.startsWith("yarn")) return "yarn";
|
|
76
|
+
return "npm";
|
|
77
|
+
}
|
|
78
|
+
function copyTemplateSync(source, dest) {
|
|
79
|
+
if (statSync(source).isDirectory()) {
|
|
80
|
+
if (basename(source) === "node_modules") return;
|
|
81
|
+
mkdirSync(dest, { recursive: true });
|
|
82
|
+
readdirSync(source).forEach((file) => {
|
|
83
|
+
copyTemplateSync(resolve(source, file), resolve(dest, file));
|
|
84
|
+
});
|
|
85
|
+
} else {
|
|
86
|
+
if (existsSync(dest)) return;
|
|
87
|
+
copyFileSync(source, dest);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
//#endregion
|
|
91
|
+
//#region src/commands/init.ts
|
|
92
|
+
function registerInitCommand(program) {
|
|
93
|
+
program.command("init").description("init project").option("-t, --temp", "copy template files", true).option("--no-temp", "not copy template files").option("-s, --scripts", "init scripts", true).option("--no-scripts", "not init scripts").option("-g, --git", "init simple-git-hooks", true).option("--no-git", "not init simple-git-hooks").addOption(new Option("--pm <manager>", "package manager").choices([
|
|
94
|
+
"pnpm",
|
|
95
|
+
"npm",
|
|
96
|
+
"yarn"
|
|
97
|
+
]).default(getPackageManager(), "auto-detect if not specified")).action(initCommand);
|
|
98
|
+
}
|
|
99
|
+
function initCommand(options) {
|
|
100
|
+
logger.success("Init project by @lntvow/dev");
|
|
101
|
+
logger.info(`Cwd is ${process.cwd()}`);
|
|
102
|
+
const { temp, git, scripts, pm } = options;
|
|
103
|
+
try {
|
|
104
|
+
if (temp) copyTemplateFiles();
|
|
105
|
+
installDependencies(pm);
|
|
106
|
+
if (scripts) updatePackageScripts();
|
|
107
|
+
if (git) initGitHooks();
|
|
108
|
+
logger.success("Project initialization completed successfully!");
|
|
109
|
+
} catch (error) {
|
|
110
|
+
logger.error(`Initialization failed: ${error.message}`);
|
|
111
|
+
process.exit(1);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function copyTemplateFiles() {
|
|
115
|
+
try {
|
|
116
|
+
const srcDir = fileURLToPath(new URL("./configs", import.meta.url));
|
|
117
|
+
const destDir = process.cwd();
|
|
118
|
+
logger.info(`Copying template files from "${srcDir}" to "${destDir}"`);
|
|
119
|
+
copyTemplateSync(srcDir, destDir);
|
|
120
|
+
logger.success("Template files copied successfully");
|
|
121
|
+
} catch (error) {
|
|
122
|
+
logger.error(`Failed to copy template files: ${error.message}`);
|
|
123
|
+
throw error;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function initGitHooks() {
|
|
127
|
+
try {
|
|
128
|
+
logger.info("Initializing Git hooks...");
|
|
129
|
+
executeCommand("npx simple-git-hooks");
|
|
130
|
+
logger.success("Git hooks initialized successfully");
|
|
131
|
+
} catch (error) {
|
|
132
|
+
logger.error(`Failed to initialize Git hooks: ${error.message}`);
|
|
133
|
+
throw error;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
function updatePackageScripts() {
|
|
137
|
+
let originalContent;
|
|
138
|
+
const path = resolve(process.cwd(), "package.json");
|
|
139
|
+
try {
|
|
140
|
+
logger.info("Updating package.json scripts...");
|
|
141
|
+
originalContent = readFileSync(path, "utf-8");
|
|
142
|
+
const data = JSON.parse(originalContent);
|
|
143
|
+
const updatedData = {
|
|
144
|
+
...data,
|
|
145
|
+
scripts: {
|
|
146
|
+
...DEFAULT_SCRIPTS,
|
|
147
|
+
...data.scripts
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
writeFileSync(path, JSON.stringify(updatedData, null, 2));
|
|
151
|
+
logger.success("Package.json scripts updated successfully");
|
|
152
|
+
} catch (error) {
|
|
153
|
+
if (originalContent) writeFileSync(path, originalContent);
|
|
154
|
+
logger.error(`Failed to update package.json: ${error.message}`);
|
|
155
|
+
throw error;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
function installDependencies(packageManager) {
|
|
159
|
+
try {
|
|
160
|
+
const pkgs = DEV_DEPENDENCIES.map((pkg) => `${pkg}@latest`).join(" ");
|
|
161
|
+
const pm = packageManager ?? getPackageManager();
|
|
162
|
+
const command = {
|
|
163
|
+
pnpm: `pnpm add -D ${pkgs}`,
|
|
164
|
+
yarn: `yarn add -D ${pkgs}`,
|
|
165
|
+
npm: `npm install -D ${pkgs}`
|
|
166
|
+
}[pm];
|
|
167
|
+
logger.info(`Installing dependencies: ${command}`);
|
|
168
|
+
executeCommand(command);
|
|
169
|
+
logger.success("Dependencies installed successfully");
|
|
170
|
+
} catch (error) {
|
|
171
|
+
logger.error(`Dependency installation failed: ${error.message}`);
|
|
172
|
+
throw error;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
//#endregion
|
|
176
|
+
//#region src/commands/release.ts
|
|
177
|
+
function registerReleaseCommand(program) {
|
|
178
|
+
program.command("release").description("git release").action(releaseCommand);
|
|
179
|
+
}
|
|
180
|
+
async function releaseCommand() {
|
|
181
|
+
console.log(pc.green("Release project..."));
|
|
182
|
+
try {
|
|
183
|
+
await commitChanges();
|
|
184
|
+
logger.success("Release completed successfully!");
|
|
185
|
+
} catch (error) {
|
|
186
|
+
logger.error(`Release failed: ${error.message}`);
|
|
187
|
+
process.exit(1);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
async function commitChanges() {
|
|
191
|
+
const git = simpleGit(process.cwd());
|
|
192
|
+
try {
|
|
193
|
+
const content = dayjs().format("YYYYMMDD");
|
|
194
|
+
await git.pull();
|
|
195
|
+
await git.add(".");
|
|
196
|
+
await git.commit(content, ["--no-verify"]);
|
|
197
|
+
await git.push("origin");
|
|
198
|
+
logger.success(`提交成功: ${content}`);
|
|
199
|
+
} catch (error) {
|
|
200
|
+
logger.error(`Git操作失败: ${error.message}`);
|
|
201
|
+
process.exit(1);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
//#endregion
|
|
205
|
+
//#region src/commands/main.ts
|
|
206
|
+
program.name(name).version(version, "-v, --version", "output the version number");
|
|
207
|
+
registerInitCommand(program);
|
|
208
|
+
registerReleaseCommand(program);
|
|
209
|
+
program.parse();
|
|
210
|
+
//#endregion
|
|
211
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,57 +1,66 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lntvow/dev",
|
|
3
|
-
"version": "5.
|
|
4
|
-
"type": "module",
|
|
3
|
+
"version": "5.6.0",
|
|
5
4
|
"description": "Development environment dependencies package",
|
|
6
5
|
"keywords": [
|
|
7
6
|
"dev"
|
|
8
7
|
],
|
|
9
|
-
"license": "MIT",
|
|
10
8
|
"repository": {
|
|
11
9
|
"type": "git",
|
|
12
10
|
"url": "https://github.com/lntvow/dev.git"
|
|
13
11
|
},
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"type": "module",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": "./dist/cli.mjs",
|
|
16
|
+
"./package.json": "./package.json"
|
|
17
|
+
},
|
|
18
|
+
"types": "./dist/cli.d.mts",
|
|
19
|
+
"bin": {
|
|
20
|
+
"dev": "./dist/cli.mjs",
|
|
21
|
+
"lntvow": "./dist/cli.mjs"
|
|
22
|
+
},
|
|
14
23
|
"files": [
|
|
15
24
|
"dist",
|
|
16
25
|
"dist/configs/*"
|
|
17
26
|
],
|
|
18
|
-
"bin": {
|
|
19
|
-
"dev": "./dist/cli.js",
|
|
20
|
-
"lntvow": "./dist/cli.js"
|
|
21
|
-
},
|
|
22
|
-
"types": "dist/cli.d.ts",
|
|
23
27
|
"dependencies": {
|
|
24
28
|
"commander": "^14.0.3",
|
|
25
|
-
"dayjs": "^1.11.
|
|
29
|
+
"dayjs": "^1.11.20",
|
|
26
30
|
"local-pkg": "^1.1.2",
|
|
27
31
|
"picocolors": "^1.1.1",
|
|
28
|
-
"simple-git": "^3.
|
|
32
|
+
"simple-git": "^3.33.0"
|
|
29
33
|
},
|
|
30
34
|
"devDependencies": {
|
|
31
|
-
"@commitlint/cli": "^20.
|
|
32
|
-
"@commitlint/config-conventional": "^20.
|
|
33
|
-
"@lntvow/eslint-config": "^10.1.
|
|
35
|
+
"@commitlint/cli": "^20.5.0",
|
|
36
|
+
"@commitlint/config-conventional": "^20.5.0",
|
|
37
|
+
"@lntvow/eslint-config": "^10.1.5",
|
|
34
38
|
"@types/node": "^20.19.25",
|
|
35
|
-
"bumpp": "^
|
|
39
|
+
"bumpp": "^11.0.1",
|
|
36
40
|
"commitizen": "^4.3.1",
|
|
37
41
|
"cz-conventional-changelog": "^3.3.0",
|
|
38
|
-
"eslint": "^10.0
|
|
39
|
-
"lint-staged": "^16.
|
|
42
|
+
"eslint": "^10.1.0",
|
|
43
|
+
"lint-staged": "^16.4.0",
|
|
40
44
|
"npm-run-all": "^4.1.5",
|
|
41
45
|
"prettier": "^3.8.1",
|
|
42
46
|
"simple-git-hooks": "^2.13.1",
|
|
43
|
-
"
|
|
47
|
+
"tsdown": "^0.21.4",
|
|
44
48
|
"typescript": "^5.9.3"
|
|
45
49
|
},
|
|
50
|
+
"engines": {
|
|
51
|
+
"node": ">=20.19.0",
|
|
52
|
+
"pnpm": ">=10.0.0"
|
|
53
|
+
},
|
|
46
54
|
"scripts": {
|
|
47
55
|
"rimraf": "rimraf ./node_modules/",
|
|
48
56
|
"ncu": "ncu -u --reject @types/node && pnpm install",
|
|
57
|
+
"sort:pkg": "sort-package-json",
|
|
49
58
|
"commit": "git add . && git-cz && pnpm release -y",
|
|
50
59
|
"release": "git add . && bumpp package.json --all --no-tag --no-print-commits",
|
|
51
60
|
"lint:eslint": "eslint --fix --cache",
|
|
52
61
|
"lint:tsc": "tsc --noEmit",
|
|
53
62
|
"lint": "run-p lint:eslint lint:tsc",
|
|
54
|
-
"
|
|
55
|
-
"
|
|
63
|
+
"build": "tsdown",
|
|
64
|
+
"dev": "tsx src/cli.ts"
|
|
56
65
|
}
|
|
57
66
|
}
|
package/dist/cli.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
package/dist/cli.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import{program as D}from"commander";var u="@lntvow/dev",y="5.5.0";import{Option as C,program as b}from"commander";import{readFileSync as M,writeFileSync as w}from"fs";import{resolve as z}from"path";import{fileURLToPath as I}from"url";var h={prepare:"simple-git-hooks",rimraf:"rimraf ./node_modules/",ncu:"ncu -u --reject @types/node && pnpm install",commit:"git add . && git-cz && git push",release:"git add . && bumpp package.json --all --no-tag --no-print-commits","lint:eslint":"eslint --fix --cache","lint:tsc":"tsc --noEmit",lint:"run-p lint:eslint lint:tsc"},k=["@commitlint/cli","@commitlint/config-conventional","@lntvow/eslint-config","bumpp","commitizen","cz-conventional-changelog","eslint","lint-staged","npm-run-all","prettier","simple-git-hooks","typescript"].sort((e,t)=>e.localeCompare(t));import{execSync as S}from"child_process";import{copyFileSync as $,existsSync as v,mkdirSync as x,readdirSync as j,statSync as E}from"fs";import{basename as P,resolve as l}from"path";import a from"picocolors";var n={info:e=>console.log(a.blue(`\u25CF ${e}`)),success:e=>console.log(a.green(`\u2713 ${e}`)),warn:e=>console.log(a.yellow(`\u25B2 ${e}`)),error:e=>console.log(a.red(`\u2717 ${e}`))};function m(e,t={}){try{return S(e,{stdio:"inherit",...t})}catch(i){throw n.error(`\u547D\u4EE4\u6267\u884C\u5931\u8D25: ${e}`),i}}function g(){let e=[{file:"pnpm-lock.yaml",manager:"pnpm"},{file:"yarn.lock",manager:"yarn"},{file:"package-lock.json",manager:"npm"}];for(let{file:i,manager:o}of e)if(v(l(process.cwd(),i)))return o;let t=process.env.npm_config_user_agent||"";return t.startsWith("pnpm")?"pnpm":t.startsWith("yarn")?"yarn":"npm"}function d(e,t){if(E(e).isDirectory()){if(P(e)==="node_modules")return;x(t,{recursive:!0}),j(e).forEach(o=>{d(l(e,o),l(t,o))})}else{if(v(t))return;$(e,t)}}b.command("init").description("init project").option("-t, --temp","copy template files",!0).option("--no-temp","not copy template files").option("-s, --scripts","init scripts",!0).option("--no-scripts","not init scripts").option("-g, --git","init simple-git-hooks",!0).option("--no-git","not init simple-git-hooks").addOption(new C("--pm <manager>","package manager").choices(["pnpm","npm","yarn"]).default(g(),"auto-detect if not specified")).action(F);function F(e){n.success("Init project by @lntvow/dev"),n.info(`Cwd is ${process.cwd()}`);let{temp:t,git:i,scripts:o,pm:c}=e;console.log("options: ",e)}function T(){try{let e=I(new URL("./configs",import.meta.url)),t=process.cwd();n.info(`Copying template files from "${e}" to "${t}"`),d(e,t),n.success("Template files copied successfully")}catch(e){throw n.error(`Failed to copy template files: ${e.message}`),e}}function _(){try{n.info("Initializing Git hooks..."),m("npx simple-git-hooks"),n.success("Git hooks initialized successfully")}catch(e){throw n.error(`Failed to initialize Git hooks: ${e.message}`),e}}function O(){let e,t=z(process.cwd(),"package.json");try{n.info("Updating package.json scripts..."),e=M(t,"utf-8");let i=JSON.parse(e),o={...i,scripts:{...h,...i.scripts}};w(t,JSON.stringify(o,null,2)),n.success("Package.json scripts updated successfully")}catch(i){throw e&&w(t,e),n.error(`Failed to update package.json: ${i.message}`),i}}function R(e){try{let t=k.map(p=>`${p}@latest`).join(" "),i=e??g(),c={pnpm:`pnpm add -D ${t}`,yarn:`yarn add -D ${t}`,npm:`npm install -D ${t}`}[i];n.info(`Installing dependencies: ${c}`),m(c),n.success("Dependencies installed successfully")}catch(t){throw n.error(`Dependency installation failed: ${t.message}`),t}}import{program as G}from"commander";import N from"dayjs";import U from"picocolors";import L from"simple-git";G.command("release").description("git release").action(Y);async function Y(){console.log(U.green("Release project..."));try{await A(),n.success("Release completed successfully!")}catch(e){n.error(`Release failed: ${e.message}`),process.exit(1)}}async function A(){let e=L(process.cwd());try{let t=N().format("YYYYMMDD");await e.pull(),await e.add("."),await e.commit(t,["--no-verify"]),await e.push("origin"),n.success(`\u63D0\u4EA4\u6210\u529F: ${t}`)}catch(t){n.error(`Git\u64CD\u4F5C\u5931\u8D25: ${t.message}`),process.exit(1)}}D.name(u).version(y,"-v, --version","output the version number");D.parse();
|