@lntvow/dev 5.6.0 → 5.6.1

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.mjs CHANGED
@@ -1,22 +1,2 @@
1
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 {};
2
+ (e=>e.major>20||e.major===20&&e.minor>=19)((e=>{let[t=`0`,n=`0`]=e.split(`.`);return{major:Number(t),minor:Number(n)}})(process.versions.node))||(process.stderr.write(`@lntvow/dev: Node.js v20.19+ is required (current: v${process.versions.node}).\nIf you use nvm, run:\n nvm install 20\n nvm use 20\n nvm alias default 20\n`),process.exit(1)),import(`./main-BMHwzhZi.mjs`);export{};
@@ -0,0 +1 @@
1
+ import{Option as e,program as t}from"commander";import{copyFileSync as n,existsSync as r,mkdirSync as i,readFileSync as a,readdirSync as o,statSync as s,writeFileSync as c}from"node:fs";import{basename as l,resolve as u}from"node:path";import{fileURLToPath as d}from"node:url";import{execSync as f}from"node:child_process";import p from"picocolors";import m from"dayjs";import h from"simple-git";var g=`@lntvow/dev`,_=`5.6.1`;const v={prepare:`simple-git-hooks`,rimraf:`rimraf ./node_modules/`,ncu:`ncu -u --reject @types/node && pnpm install`,"sort:pkg":`sort-package-json`,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`},y=[`@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)),b={info:e=>console.log(p.blue(`● ${e}`)),success:e=>console.log(p.green(`✓ ${e}`)),warn:e=>console.log(p.yellow(`▲ ${e}`)),error:e=>console.log(p.red(`✗ ${e}`))};function x(e,t={}){try{return f(e,{stdio:`inherit`,...t})}catch(t){throw b.error(`命令执行失败: ${e}`),t}}function S(){for(let{file:e,manager:t}of[{file:`pnpm-lock.yaml`,manager:`pnpm`},{file:`yarn.lock`,manager:`yarn`},{file:`package-lock.json`,manager:`npm`}])if(r(u(process.cwd(),e)))return t;let e=process.env.npm_config_user_agent||``;return e.startsWith(`pnpm`)?`pnpm`:e.startsWith(`yarn`)?`yarn`:`npm`}function C(e,t){if(s(e).isDirectory()){if(l(e)===`node_modules`)return;i(t,{recursive:!0}),o(e).forEach(n=>{C(u(e,n),u(t,n))})}else{if(r(t))return;n(e,t)}}function w(t){t.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 e(`--pm <manager>`,`package manager`).choices([`pnpm`,`npm`,`yarn`]).default(S(),`auto-detect if not specified`)).action(T)}function T(e){b.success(`Init project by @lntvow/dev`),b.info(`Cwd is ${process.cwd()}`);let{temp:t,git:n,scripts:r,pm:i}=e;try{t&&E(),k(i),r&&O(),n&&D(),b.success(`Project initialization completed successfully!`)}catch(e){b.error(`Initialization failed: ${e.message}`),process.exit(1)}}function E(){try{let e=d(new URL(`./configs`,import.meta.url)),t=process.cwd();b.info(`Copying template files from "${e}" to "${t}"`),C(e,t),b.success(`Template files copied successfully`)}catch(e){throw b.error(`Failed to copy template files: ${e.message}`),e}}function D(){try{b.info(`Initializing Git hooks...`),x(`npx simple-git-hooks`),b.success(`Git hooks initialized successfully`)}catch(e){throw b.error(`Failed to initialize Git hooks: ${e.message}`),e}}function O(){let e,t=u(process.cwd(),`package.json`);try{b.info(`Updating package.json scripts...`),e=a(t,`utf-8`);let n=JSON.parse(e),r={...n,scripts:{...v,...n.scripts}};c(t,JSON.stringify(r,null,2)),b.success(`Package.json scripts updated successfully`)}catch(n){throw e&&c(t,e),b.error(`Failed to update package.json: ${n.message}`),n}}function k(e){try{let t=y.map(e=>`${e}@latest`).join(` `),n=e??S(),r={pnpm:`pnpm add -D ${t}`,yarn:`yarn add -D ${t}`,npm:`npm install -D ${t}`}[n];b.info(`Installing dependencies: ${r}`),x(r),b.success(`Dependencies installed successfully`)}catch(e){throw b.error(`Dependency installation failed: ${e.message}`),e}}function A(e){e.command(`release`).description(`git release`).action(j)}async function j(){console.log(p.green(`Release project...`));try{await M(),b.success(`Release completed successfully!`)}catch(e){b.error(`Release failed: ${e.message}`),process.exit(1)}}async function M(){let e=h(process.cwd());try{let t=m().format(`YYYYMMDD`);await e.pull(),await e.add(`.`),await e.commit(t,[`--no-verify`]),await e.push(`origin`),b.success(`提交成功: ${t}`)}catch(e){b.error(`Git操作失败: ${e.message}`),process.exit(1)}}t.name(g).version(_,`-v, --version`,`output the version number`),w(t),A(t),t.parse();export{};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lntvow/dev",
3
- "version": "5.6.0",
3
+ "version": "5.6.1",
4
4
  "description": "Development environment dependencies package",
5
5
  "keywords": [
6
6
  "dev"
@@ -38,6 +38,7 @@
38
38
  "@types/node": "^20.19.25",
39
39
  "bumpp": "^11.0.1",
40
40
  "commitizen": "^4.3.1",
41
+ "conventional-changelog-cli": "^5.0.0",
41
42
  "cz-conventional-changelog": "^3.3.0",
42
43
  "eslint": "^10.1.0",
43
44
  "lint-staged": "^16.4.0",
@@ -56,7 +57,7 @@
56
57
  "ncu": "ncu -u --reject @types/node && pnpm install",
57
58
  "sort:pkg": "sort-package-json",
58
59
  "commit": "git add . && git-cz && pnpm release -y",
59
- "release": "git add . && bumpp package.json --all --no-tag --no-print-commits",
60
+ "release": "git add . && bumpp package.json --all --no-print-commits",
60
61
  "lint:eslint": "eslint --fix --cache",
61
62
  "lint:tsc": "tsc --noEmit",
62
63
  "lint": "run-p lint:eslint lint:tsc",
@@ -1,211 +0,0 @@
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 {};