UNPKG

@lntvow/dev

Version:

Development environment dependencies package

3 lines (2 loc) 5.08 kB
#!/usr/bin/env node "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 g=(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 l=require("fs"),u=require("path"),E=require("url"),m=require("commander"),_=g(require("picocolors"),1),b=g(require("dayjs"),1),z=g(require("simple-git"),1),C=require("local-pkg");var k="@lntvow/dev",v="5.0.29";var x=require("child_process"),w=require("fs"),S=require("path"),a=g(require("picocolors"),1),n={info:e=>console.log(a.default.blue(`\u25CF ${e}`)),success:e=>console.log(a.default.green(`\u2713 ${e}`)),warn:e=>console.log(a.default.yellow(`\u25B2 ${e}`)),error:e=>console.log(a.default.red(`\u2717 ${e}`))};function d(e,t={}){try{return(0,x.execSync)(e,{stdio:"inherit",...t})}catch(i){throw n.error(`\u547D\u4EE4\u6267\u884C\u5931\u8D25: ${e}`),i}}function j(){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,w.existsSync)((0,S.resolve)(process.cwd(),i)))return o;let t=process.env.npm_config_user_agent||"";return t.startsWith("pnpm")?"pnpm":t.startsWith("yarn")?"yarn":"npm"}var D={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 "src/**/*.{js,jsx,ts,tsx,vue}" --fix',"lint:tsc":"tsc --noEmit",lint:"run-p lint:eslint lint:tsc"},$=["@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));var s=require("fs"),p=require("path");function f(e,t){if((0,s.statSync)(e).isDirectory()){if((0,p.basename)(e)==="node_modules")return;(0,s.mkdirSync)(t,{recursive:!0}),(0,s.readdirSync)(e).forEach(o=>{f((0,p.resolve)(e,o),(0,p.resolve)(t,o))})}else{if((0,s.existsSync)(t))return;(0,s.copyFileSync)(e,t)}}var L=(0,E.fileURLToPath)(new URL(".",c));m.program.name(k).version(v,"-v, --version","output the version number");m.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(async 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(){n.info("Copying template files..."),f((0,u.resolve)(L,"./configs"),process.cwd()),n.success("Template files copied successfully")}function N(){if(!(0,C.isPackageExists)("simple-git-hooks")){n.warn("simple-git-hooks not installed, skipping initialization");return}try{n.info("Initializing Git hooks..."),d("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,u.resolve)(process.cwd(),"package.json"),t;try{t=(0,l.readFileSync)(e,"utf-8");let i=JSON.parse(t),o={...i,scripts:{...D,...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=$.map(o=>`${o}@latest`).join(" "),t=j(),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}`),d(i),n.success("Dependencies installed successfully")}catch(e){n.error(`Dependency installation failed: ${e.message}`),process.exit(1)}}m.program.command("release").description("git release").action(async()=>{console.log(_.default.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=(0,z.default)(process.cwd());try{let t=(0,b.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)}}m.program.parse();