@lntvow/dev 5.2.3 → 5.2.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.
Files changed (3) hide show
  1. package/dist/cli.cjs +1 -235
  2. package/dist/cli.mjs +1 -208
  3. package/package.json +2 -2
package/dist/cli.cjs CHANGED
@@ -1,236 +1,2 @@
1
1
  #!/usr/bin/env node
2
- "use strict";
3
- var __create = Object.create;
4
- var __defProp = Object.defineProperty;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getProtoOf = Object.getPrototypeOf;
8
- var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
18
- // If the importer is in node compatibility mode or this is not an ESM
19
- // file that has been converted to a CommonJS file using a Babel-
20
- // compatible transform (i.e. "__esModule" has not been set), then set
21
- // "default" to the CommonJS "module.exports" for node compatibility.
22
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
23
- mod
24
- ));
25
-
26
- // node_modules/.pnpm/tsup@8.5.0_@microsoft+api-extractor@7.52.8_@types+node@22.15.33__jiti@2.4.2_typescript@5.8.3_yaml@2.8.0/node_modules/tsup/assets/cjs_shims.js
27
- var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
28
- var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
29
-
30
- // src/cli.ts
31
- var import_commander3 = require("commander");
32
-
33
- // package.json
34
- var name = "@lntvow/dev";
35
- var version = "5.2.3";
36
-
37
- // src/commands/init.ts
38
- var import_node_path2 = require("path");
39
- var import_node_fs2 = require("fs");
40
- var import_node_url = require("url");
41
- var import_commander = require("commander");
42
- var import_local_pkg = require("local-pkg");
43
-
44
- // src/utils/index.ts
45
- var import_node_child_process = require("child_process");
46
- var import_node_fs = require("fs");
47
- var import_node_path = require("path");
48
- var import_picocolors = __toESM(require("picocolors"), 1);
49
- var logger = {
50
- info: (msg) => console.log(import_picocolors.default.blue(`\u25CF ${msg}`)),
51
- success: (msg) => console.log(import_picocolors.default.green(`\u2713 ${msg}`)),
52
- warn: (msg) => console.log(import_picocolors.default.yellow(`\u25B2 ${msg}`)),
53
- error: (msg) => console.log(import_picocolors.default.red(`\u2717 ${msg}`))
54
- };
55
- function executeCommand(cmd, options = {}) {
56
- try {
57
- return (0, import_node_child_process.execSync)(cmd, { stdio: "inherit", ...options });
58
- } catch (error) {
59
- logger.error(`\u547D\u4EE4\u6267\u884C\u5931\u8D25: ${cmd}`);
60
- throw error;
61
- }
62
- }
63
- function getPackageManager() {
64
- const lockFiles = [
65
- { file: "pnpm-lock.yaml", manager: "pnpm" },
66
- { file: "yarn.lock", manager: "yarn" },
67
- { file: "package-lock.json", manager: "npm" }
68
- ];
69
- for (const { file, manager } of lockFiles) {
70
- if ((0, import_node_fs.existsSync)((0, import_node_path.resolve)(process.cwd(), file))) {
71
- return manager;
72
- }
73
- }
74
- const userAgent = process.env.npm_config_user_agent || "";
75
- if (userAgent.startsWith("pnpm")) return "pnpm";
76
- if (userAgent.startsWith("yarn")) return "yarn";
77
- return "npm";
78
- }
79
- function copyTemplateSync(source, dest) {
80
- const stat = (0, import_node_fs.statSync)(source);
81
- if (stat.isDirectory()) {
82
- if ((0, import_node_path.basename)(source) === "node_modules") return;
83
- (0, import_node_fs.mkdirSync)(dest, { recursive: true });
84
- (0, import_node_fs.readdirSync)(source).forEach((file) => {
85
- copyTemplateSync((0, import_node_path.resolve)(source, file), (0, import_node_path.resolve)(dest, file));
86
- });
87
- } else {
88
- if ((0, import_node_fs.existsSync)(dest)) return;
89
- (0, import_node_fs.copyFileSync)(source, dest);
90
- }
91
- }
92
-
93
- // src/constants/index.ts
94
- var DEFAULT_SCRIPTS = {
95
- "postinstall": "simple-git-hooks",
96
- "rimraf": "rimraf ./node_modules/",
97
- "ncu": "ncu -u --reject @types/node && pnpm install",
98
- "commit": "git add . && git-cz && pnpm release -y",
99
- "release": "git add . && bumpp package.json --all --no-tag --no-print-commits",
100
- "lint:eslint": "eslint --fix --cache",
101
- "lint:tsc": "tsc --noEmit",
102
- "lint": "run-p lint:eslint lint:tsc"
103
- };
104
- var DEV_DEPENDENCIES = [
105
- "@commitlint/cli",
106
- "@commitlint/config-conventional",
107
- "@lntvow/eslint-config",
108
- "bumpp",
109
- "commitizen",
110
- "cz-conventional-changelog",
111
- "eslint",
112
- "lint-staged",
113
- "npm-run-all",
114
- "prettier",
115
- "simple-git-hooks",
116
- "typescript"
117
- ].sort((a, b) => a.localeCompare(b));
118
-
119
- // src/commands/init.ts
120
- import_commander.program.command("init").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").description("init project").action(initCommand);
121
- function initCommand(options) {
122
- logger.success("Init project by @lntvow/dev");
123
- logger.info(`Cwd is ${process.cwd()}`);
124
- const { temp, git, scripts } = options;
125
- try {
126
- installDependencies();
127
- if (temp) {
128
- copyTemplateFiles();
129
- }
130
- if (scripts) {
131
- updatePackageScripts();
132
- }
133
- if (git) {
134
- initGitHooks();
135
- }
136
- logger.success("Project initialization completed successfully!");
137
- } catch (error) {
138
- logger.error(`Initialization failed: ${error.message}`);
139
- process.exit(1);
140
- }
141
- }
142
- function copyTemplateFiles() {
143
- const srcDir = (0, import_node_path2.resolve)((0, import_node_url.fileURLToPath)(new URL("./configs", importMetaUrl)));
144
- const destDir = process.cwd();
145
- logger.info(`Copying template files from "${srcDir}" to "${destDir}"`);
146
- copyTemplateSync(srcDir, destDir);
147
- logger.success("Template files copied successfully");
148
- }
149
- function initGitHooks() {
150
- if (!(0, import_local_pkg.isPackageExists)("simple-git-hooks")) {
151
- logger.warn("simple-git-hooks not installed, skipping initialization");
152
- return;
153
- }
154
- try {
155
- logger.info("Initializing Git hooks...");
156
- executeCommand("npx simple-git-hooks");
157
- logger.success("Git hooks initialized successfully");
158
- } catch (error) {
159
- logger.error(`Failed to initialize Git hooks: ${error.message}`);
160
- }
161
- }
162
- function updatePackageScripts() {
163
- logger.info("Updating package.json scripts...");
164
- const path = (0, import_node_path2.resolve)(process.cwd(), "package.json");
165
- let originalContent;
166
- try {
167
- originalContent = (0, import_node_fs2.readFileSync)(path, "utf-8");
168
- const data = JSON.parse(originalContent);
169
- const updatedData = {
170
- ...data,
171
- scripts: {
172
- ...DEFAULT_SCRIPTS,
173
- ...data.scripts
174
- }
175
- };
176
- (0, import_node_fs2.writeFileSync)(path, JSON.stringify(updatedData, null, 2));
177
- logger.success("Package.json scripts updated successfully");
178
- } catch (error) {
179
- if (originalContent) {
180
- (0, import_node_fs2.writeFileSync)(path, originalContent);
181
- }
182
- logger.error(`Failed to update package.json: ${error.message}`);
183
- process.exit(1);
184
- }
185
- }
186
- function installDependencies() {
187
- try {
188
- const pkgs = DEV_DEPENDENCIES.map((pkg) => `${pkg}@latest`).join(" ");
189
- const pm = getPackageManager();
190
- let command = "";
191
- if (pm === "pnpm") command = `pnpm add -D ${pkgs}`;
192
- else if (pm === "yarn") command = `yarn add -D ${pkgs}`;
193
- else command = `npm install -D ${pkgs}`;
194
- logger.info(`Installing dependencies: ${command}`);
195
- executeCommand(command);
196
- logger.success("Dependencies installed successfully");
197
- } catch (error) {
198
- logger.error(`Dependency installation failed: ${error.message}`);
199
- process.exit(1);
200
- }
201
- }
202
-
203
- // src/commands/release.ts
204
- var import_commander2 = require("commander");
205
- var import_picocolors2 = __toESM(require("picocolors"), 1);
206
- var import_dayjs = __toESM(require("dayjs"), 1);
207
- var import_simple_git = __toESM(require("simple-git"), 1);
208
- import_commander2.program.command("release").description("git release").action(releaseCommand);
209
- async function releaseCommand() {
210
- console.log(import_picocolors2.default.green("Release project..."));
211
- try {
212
- await commitChanges();
213
- logger.success("Release completed successfully!");
214
- } catch (error) {
215
- logger.error(`Release failed: ${error.message}`);
216
- process.exit(1);
217
- }
218
- }
219
- async function commitChanges() {
220
- const git = (0, import_simple_git.default)(process.cwd());
221
- try {
222
- const content = (0, import_dayjs.default)().format("YYYYMMDD");
223
- await git.pull();
224
- await git.add(".");
225
- await git.commit(content, ["--no-verify"]);
226
- await git.push("origin");
227
- logger.success(`\u63D0\u4EA4\u6210\u529F: ${content}`);
228
- } catch (error) {
229
- logger.error(`Git\u64CD\u4F5C\u5931\u8D25: ${error.message}`);
230
- process.exit(1);
231
- }
232
- }
233
-
234
- // src/cli.ts
235
- import_commander3.program.name(name).version(version, "-v, --version", "output the version number");
236
- import_commander3.program.parse();
2
+ "use strict";var I=Object.create;var y=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var T=Object.getPrototypeOf,F=Object.prototype.hasOwnProperty;var U=(e,t,i,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of R(t))!F.call(e,r)&&r!==i&&y(e,r,{get:()=>t[r],enumerable:!(o=P(t,r))||o.enumerable});return e};var m=(e,t,i)=>(i=e!=null?I(T(e)):{},U(t||!e||!e.__esModule?y(i,"default",{value:e,enumerable:!0}):i,e));var G=()=>typeof document>"u"?new URL(`file:${__filename}`).href:document.currentScript&&document.currentScript.src||new URL("main.js",document.baseURI).href,c=G();var u=require("commander");var k="@lntvow/dev",v="5.2.4";var f=require("path"),l=require("fs"),$=require("url"),j=require("commander"),E=require("local-pkg");var w=require("child_process"),s=require("fs"),a=require("path"),p=m(require("picocolors"),1),n={info:e=>console.log(p.default.blue(`\u25CF ${e}`)),success:e=>console.log(p.default.green(`\u2713 ${e}`)),warn:e=>console.log(p.default.yellow(`\u25B2 ${e}`)),error:e=>console.log(p.default.red(`\u2717 ${e}`))};function g(e,t={}){try{return(0,w.execSync)(e,{stdio:"inherit",...t})}catch(i){throw n.error(`\u547D\u4EE4\u6267\u884C\u5931\u8D25: ${e}`),i}}function x(){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((0,s.existsSync)((0,a.resolve)(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((0,s.statSync)(e).isDirectory()){if((0,a.basename)(e)==="node_modules")return;(0,s.mkdirSync)(t,{recursive:!0}),(0,s.readdirSync)(e).forEach(o=>{d((0,a.resolve)(e,o),(0,a.resolve)(t,o))})}else{if((0,s.existsSync)(t))return;(0,s.copyFileSync)(e,t)}}var S={postinstall:"simple-git-hooks",rimraf:"rimraf ./node_modules/",ncu:"ncu -u --reject @types/node && pnpm install",commit:"git add . && git-cz && pnpm release -y",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"},D=["@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));j.program.command("init").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").description("init project").action(L);function L(e){n.success("Init project by @lntvow/dev"),n.info(`Cwd is ${process.cwd()}`);let{temp:t,git:i,scripts:o}=e;try{Y(),t&&M(),o&&O(),i&&N(),n.success("Project initialization completed successfully!")}catch(r){n.error(`Initialization failed: ${r.message}`),process.exit(1)}}function M(){let e=(0,f.resolve)((0,$.fileURLToPath)(new URL("./configs",c))),t=process.cwd();n.info(`Copying template files from "${e}" to "${t}"`),d(e,t),n.success("Template files copied successfully")}function N(){if(!(0,E.isPackageExists)("simple-git-hooks")){n.warn("simple-git-hooks not installed, skipping initialization");return}try{n.info("Initializing Git hooks..."),g("npx simple-git-hooks"),n.success("Git hooks initialized successfully")}catch(e){n.error(`Failed to initialize Git hooks: ${e.message}`)}}function O(){n.info("Updating package.json scripts...");let e=(0,f.resolve)(process.cwd(),"package.json"),t;try{t=(0,l.readFileSync)(e,"utf-8");let i=JSON.parse(t),o={...i,scripts:{...S,...i.scripts}};(0,l.writeFileSync)(e,JSON.stringify(o,null,2)),n.success("Package.json scripts updated successfully")}catch(i){t&&(0,l.writeFileSync)(e,t),n.error(`Failed to update package.json: ${i.message}`),process.exit(1)}}function Y(){try{let e=D.map(o=>`${o}@latest`).join(" "),t=x(),i="";t==="pnpm"?i=`pnpm add -D ${e}`:t==="yarn"?i=`yarn add -D ${e}`:i=`npm install -D ${e}`,n.info(`Installing dependencies: ${i}`),g(i),n.success("Dependencies installed successfully")}catch(e){n.error(`Dependency installation failed: ${e.message}`),process.exit(1)}}var b=require("commander"),C=m(require("picocolors"),1),z=m(require("dayjs"),1),_=m(require("simple-git"),1);b.program.command("release").description("git release").action(A);async function A(){console.log(C.default.green("Release project..."));try{await J(),n.success("Release completed successfully!")}catch(e){n.error(`Release failed: ${e.message}`),process.exit(1)}}async function J(){let e=(0,_.default)(process.cwd());try{let t=(0,z.default)().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)}}u.program.name(k).version(v,"-v, --version","output the version number");u.program.parse();
package/dist/cli.mjs CHANGED
@@ -1,209 +1,2 @@
1
1
  #!/usr/bin/env node
2
-
3
- // src/cli.ts
4
- import { program as program3 } from "commander";
5
-
6
- // package.json
7
- var name = "@lntvow/dev";
8
- var version = "5.2.3";
9
-
10
- // src/commands/init.ts
11
- import { resolve as resolve2 } from "path";
12
- import { readFileSync, writeFileSync } from "fs";
13
- import { fileURLToPath } from "url";
14
- import { program } from "commander";
15
- import { isPackageExists } from "local-pkg";
16
-
17
- // src/utils/index.ts
18
- import { execSync } from "child_process";
19
- import { statSync, mkdirSync, readdirSync, existsSync, copyFileSync } from "fs";
20
- import { basename, resolve } from "path";
21
- import pc from "picocolors";
22
- var logger = {
23
- info: (msg) => console.log(pc.blue(`\u25CF ${msg}`)),
24
- success: (msg) => console.log(pc.green(`\u2713 ${msg}`)),
25
- warn: (msg) => console.log(pc.yellow(`\u25B2 ${msg}`)),
26
- error: (msg) => console.log(pc.red(`\u2717 ${msg}`))
27
- };
28
- function executeCommand(cmd, options = {}) {
29
- try {
30
- return execSync(cmd, { stdio: "inherit", ...options });
31
- } catch (error) {
32
- logger.error(`\u547D\u4EE4\u6267\u884C\u5931\u8D25: ${cmd}`);
33
- throw error;
34
- }
35
- }
36
- function getPackageManager() {
37
- const lockFiles = [
38
- { file: "pnpm-lock.yaml", manager: "pnpm" },
39
- { file: "yarn.lock", manager: "yarn" },
40
- { file: "package-lock.json", manager: "npm" }
41
- ];
42
- for (const { file, manager } of lockFiles) {
43
- if (existsSync(resolve(process.cwd(), file))) {
44
- return manager;
45
- }
46
- }
47
- const userAgent = process.env.npm_config_user_agent || "";
48
- if (userAgent.startsWith("pnpm")) return "pnpm";
49
- if (userAgent.startsWith("yarn")) return "yarn";
50
- return "npm";
51
- }
52
- function copyTemplateSync(source, dest) {
53
- const stat = statSync(source);
54
- if (stat.isDirectory()) {
55
- if (basename(source) === "node_modules") return;
56
- mkdirSync(dest, { recursive: true });
57
- readdirSync(source).forEach((file) => {
58
- copyTemplateSync(resolve(source, file), resolve(dest, file));
59
- });
60
- } else {
61
- if (existsSync(dest)) return;
62
- copyFileSync(source, dest);
63
- }
64
- }
65
-
66
- // src/constants/index.ts
67
- var DEFAULT_SCRIPTS = {
68
- "postinstall": "simple-git-hooks",
69
- "rimraf": "rimraf ./node_modules/",
70
- "ncu": "ncu -u --reject @types/node && pnpm install",
71
- "commit": "git add . && git-cz && pnpm release -y",
72
- "release": "git add . && bumpp package.json --all --no-tag --no-print-commits",
73
- "lint:eslint": "eslint --fix --cache",
74
- "lint:tsc": "tsc --noEmit",
75
- "lint": "run-p lint:eslint lint:tsc"
76
- };
77
- var DEV_DEPENDENCIES = [
78
- "@commitlint/cli",
79
- "@commitlint/config-conventional",
80
- "@lntvow/eslint-config",
81
- "bumpp",
82
- "commitizen",
83
- "cz-conventional-changelog",
84
- "eslint",
85
- "lint-staged",
86
- "npm-run-all",
87
- "prettier",
88
- "simple-git-hooks",
89
- "typescript"
90
- ].sort((a, b) => a.localeCompare(b));
91
-
92
- // src/commands/init.ts
93
- program.command("init").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").description("init project").action(initCommand);
94
- function initCommand(options) {
95
- logger.success("Init project by @lntvow/dev");
96
- logger.info(`Cwd is ${process.cwd()}`);
97
- const { temp, git, scripts } = options;
98
- try {
99
- installDependencies();
100
- if (temp) {
101
- copyTemplateFiles();
102
- }
103
- if (scripts) {
104
- updatePackageScripts();
105
- }
106
- if (git) {
107
- initGitHooks();
108
- }
109
- logger.success("Project initialization completed successfully!");
110
- } catch (error) {
111
- logger.error(`Initialization failed: ${error.message}`);
112
- process.exit(1);
113
- }
114
- }
115
- function copyTemplateFiles() {
116
- const srcDir = resolve2(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
- }
122
- function initGitHooks() {
123
- if (!isPackageExists("simple-git-hooks")) {
124
- logger.warn("simple-git-hooks not installed, skipping initialization");
125
- return;
126
- }
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
- }
134
- }
135
- function updatePackageScripts() {
136
- logger.info("Updating package.json scripts...");
137
- const path = resolve2(process.cwd(), "package.json");
138
- let originalContent;
139
- try {
140
- originalContent = readFileSync(path, "utf-8");
141
- const data = JSON.parse(originalContent);
142
- const updatedData = {
143
- ...data,
144
- scripts: {
145
- ...DEFAULT_SCRIPTS,
146
- ...data.scripts
147
- }
148
- };
149
- writeFileSync(path, JSON.stringify(updatedData, null, 2));
150
- logger.success("Package.json scripts updated successfully");
151
- } catch (error) {
152
- if (originalContent) {
153
- writeFileSync(path, originalContent);
154
- }
155
- logger.error(`Failed to update package.json: ${error.message}`);
156
- process.exit(1);
157
- }
158
- }
159
- function installDependencies() {
160
- try {
161
- const pkgs = DEV_DEPENDENCIES.map((pkg) => `${pkg}@latest`).join(" ");
162
- const pm = getPackageManager();
163
- let command = "";
164
- if (pm === "pnpm") command = `pnpm add -D ${pkgs}`;
165
- else if (pm === "yarn") command = `yarn add -D ${pkgs}`;
166
- else command = `npm install -D ${pkgs}`;
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
- process.exit(1);
173
- }
174
- }
175
-
176
- // src/commands/release.ts
177
- import { program as program2 } from "commander";
178
- import pc2 from "picocolors";
179
- import dayjs from "dayjs";
180
- import simpleGit from "simple-git";
181
- program2.command("release").description("git release").action(releaseCommand);
182
- async function releaseCommand() {
183
- console.log(pc2.green("Release project..."));
184
- try {
185
- await commitChanges();
186
- logger.success("Release completed successfully!");
187
- } catch (error) {
188
- logger.error(`Release failed: ${error.message}`);
189
- process.exit(1);
190
- }
191
- }
192
- async function commitChanges() {
193
- const git = simpleGit(process.cwd());
194
- try {
195
- const content = dayjs().format("YYYYMMDD");
196
- await git.pull();
197
- await git.add(".");
198
- await git.commit(content, ["--no-verify"]);
199
- await git.push("origin");
200
- logger.success(`\u63D0\u4EA4\u6210\u529F: ${content}`);
201
- } catch (error) {
202
- logger.error(`Git\u64CD\u4F5C\u5931\u8D25: ${error.message}`);
203
- process.exit(1);
204
- }
205
- }
206
-
207
- // src/cli.ts
208
- program3.name(name).version(version, "-v, --version", "output the version number");
209
- program3.parse();
2
+ import{program as w}from"commander";var g="@lntvow/dev",d="5.2.4";import{resolve as v}from"path";import{readFileSync as b,writeFileSync as k}from"fs";import{fileURLToPath as z}from"url";import{program as P}from"commander";import{isPackageExists as T}from"local-pkg";import{execSync as D}from"child_process";import{statSync as S,mkdirSync as $,readdirSync as j,existsSync as f,copyFileSync as E}from"fs";import{basename as C,resolve as a}from"path";import c from"picocolors";var i={info:e=>console.log(c.blue(`\u25CF ${e}`)),success:e=>console.log(c.green(`\u2713 ${e}`)),warn:e=>console.log(c.yellow(`\u25B2 ${e}`)),error:e=>console.log(c.red(`\u2717 ${e}`))};function p(e,t={}){try{return D(e,{stdio:"inherit",...t})}catch(n){throw i.error(`\u547D\u4EE4\u6267\u884C\u5931\u8D25: ${e}`),n}}function u(){let e=[{file:"pnpm-lock.yaml",manager:"pnpm"},{file:"yarn.lock",manager:"yarn"},{file:"package-lock.json",manager:"npm"}];for(let{file:n,manager:o}of e)if(f(a(process.cwd(),n)))return o;let t=process.env.npm_config_user_agent||"";return t.startsWith("pnpm")?"pnpm":t.startsWith("yarn")?"yarn":"npm"}function l(e,t){if(S(e).isDirectory()){if(C(e)==="node_modules")return;$(t,{recursive:!0}),j(e).forEach(o=>{l(a(e,o),a(t,o))})}else{if(f(t))return;E(e,t)}}var y={postinstall:"simple-git-hooks",rimraf:"rimraf ./node_modules/",ncu:"ncu -u --reject @types/node && pnpm install",commit:"git add . && git-cz && pnpm release -y",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"},h=["@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));P.command("init").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").description("init project").action(_);function _(e){i.success("Init project by @lntvow/dev"),i.info(`Cwd is ${process.cwd()}`);let{temp:t,git:n,scripts:o}=e;try{G(),t&&F(),o&&R(),n&&I(),i.success("Project initialization completed successfully!")}catch(x){i.error(`Initialization failed: ${x.message}`),process.exit(1)}}function F(){let e=v(z(new URL("./configs",import.meta.url))),t=process.cwd();i.info(`Copying template files from "${e}" to "${t}"`),l(e,t),i.success("Template files copied successfully")}function I(){if(!T("simple-git-hooks")){i.warn("simple-git-hooks not installed, skipping initialization");return}try{i.info("Initializing Git hooks..."),p("npx simple-git-hooks"),i.success("Git hooks initialized successfully")}catch(e){i.error(`Failed to initialize Git hooks: ${e.message}`)}}function R(){i.info("Updating package.json scripts...");let e=v(process.cwd(),"package.json"),t;try{t=b(e,"utf-8");let n=JSON.parse(t),o={...n,scripts:{...y,...n.scripts}};k(e,JSON.stringify(o,null,2)),i.success("Package.json scripts updated successfully")}catch(n){t&&k(e,t),i.error(`Failed to update package.json: ${n.message}`),process.exit(1)}}function G(){try{let e=h.map(o=>`${o}@latest`).join(" "),t=u(),n="";t==="pnpm"?n=`pnpm add -D ${e}`:t==="yarn"?n=`yarn add -D ${e}`:n=`npm install -D ${e}`,i.info(`Installing dependencies: ${n}`),p(n),i.success("Dependencies installed successfully")}catch(e){i.error(`Dependency installation failed: ${e.message}`),process.exit(1)}}import{program as N}from"commander";import M from"picocolors";import U from"dayjs";import L from"simple-git";N.command("release").description("git release").action(O);async function O(){console.log(M.green("Release project..."));try{await Y(),i.success("Release completed successfully!")}catch(e){i.error(`Release failed: ${e.message}`),process.exit(1)}}async function Y(){let e=L(process.cwd());try{let t=U().format("YYYYMMDD");await e.pull(),await e.add("."),await e.commit(t,["--no-verify"]),await e.push("origin"),i.success(`\u63D0\u4EA4\u6210\u529F: ${t}`)}catch(t){i.error(`Git\u64CD\u4F5C\u5931\u8D25: ${t.message}`),process.exit(1)}}w.name(g).version(d,"-v, --version","output the version number");w.parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lntvow/dev",
3
- "version": "5.2.3",
3
+ "version": "5.2.4",
4
4
  "type": "module",
5
5
  "description": "Development environment dependencies package",
6
6
  "keywords": [
@@ -30,7 +30,7 @@
30
30
  "devDependencies": {
31
31
  "@commitlint/cli": "^19.8.1",
32
32
  "@commitlint/config-conventional": "^19.8.1",
33
- "@lntvow/eslint-config": "^9.28.4",
33
+ "@lntvow/eslint-config": "^9.28.6",
34
34
  "@types/node": "^22.15.32",
35
35
  "bumpp": "^10.2.0",
36
36
  "commitizen": "^4.3.1",