pl-preset 0.0.5 → 0.0.6

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 (2) hide show
  1. package/dist/cli.js +1 -1
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- "use strict";var e=require("commander"),t=require("chalk"),s=require("fs-extra"),r=require("path"),n=require("inquirer"),o=require("fs"),l=require("ejs"),c=require("child_process"),i=require("ora");function a(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var p,u,d,m,y,g,S,h,f,v,w,k,j,F,b={};function _(){if(u)return p;u=1;return p={SupportedEditor:{vscode:1,others:0},SupportedLanguage:{javascript:1,typescript:2,others:0},SupportedStyleSheets:{css:1,less:2,scss:3,others:0},SupportedFramework:{vue2:1,vue3:2,react:3,others:0}}}function x(){if(m)return d;m=1;const e=s,n=t,c=r,i=o,a=l,{SupportedEditor:p,SupportedLanguage:u,SupportedStyleSheets:y,SupportedFramework:g}=_();return d={apply:t=>{console.log(n.blue("生成编辑器设置..."));const{editorType:s}=t;s!==p.others&&s===p.VSCode&&(({language:t,framework:s,styleSheets:r,includeHtml:n})=>{const o=c.resolve(__dirname,"../template/.vscode/settings.json"),l=a.render(i.readFileSync(o,"utf-8"),{supportedLanguage:u,language:t,styleSheets:r,supportedStyleSheets:y,framework:s,supportedFramework:g,html:n}),p=c.resolve(process.cwd(),"./.vscode/settings.json");e.ensureFileSync(p),i.writeFileSync(p,l,"utf-8");const d=c.resolve(__dirname,"../template/.vscode/extensions.json"),m=a.render(i.readFileSync(d,"utf-8"),{style:r!==y.others,vue:s===g.vue2||s===g.vue3}),S=c.resolve(process.cwd(),"./.vscode/extensions.json");e.ensureFileSync(S),i.writeFileSync(S,m,"utf-8")})(t)}}}function q(){if(v)return f;v=1;const e=l,n=r,c=o,i=s,a=t,{SupportedLanguage:p,SupportedStyleSheets:u,SupportedFramework:d}=_();return f={apply:({framework:t,styleSheets:s,language:r})=>{if(r!==p.others){console.log(a.blue("生成 ESLint 配置文件..."));try{(()=>{const s="module"===i.readJSONSync(n.resolve(process.cwd(),"./package.json")).type?"eslint.config.cjs":"eslint.config.js",o=n.resolve(__dirname,"../template/eslint.config.js"),l=e.render(c.readFileSync(o,"utf-8"),{language:r,framework:t,supportedFramework:d,supportedLanguage:p}),a=n.resolve(process.cwd(),"./",s);i.ensureFileSync(a),i.writeFileSync(a,l,"utf-8")})()}catch(e){throw new Error("生成ESLint配置文件失败: ",e.message)}}if(s!==u.others){console.log(a.blue("生成 Stylelint 配置文件..."));try{(()=>{const r=n.resolve(__dirname,"../template/.stylelintrc.js"),o=e.render(c.readFileSync(r,"utf-8"),{supportedStyleSheets:u,styleSheets:s,vue:t===d.vue2||t===d.vue3}),l=n.resolve(process.cwd(),"./.stylelintrc.js");i.ensureFileSync(l),i.writeFileSync(l,o,"utf-8")})()}catch(e){throw new Error("生成Stylelint配置文件失败: ",e.message)}}}}}function E(){if(F)return j;F=1;const e=t,a=s,p=r,u=n,{SupportedEditor:d,SupportedLanguage:m,SupportedStyleSheets:f,SupportedFramework:v}=_(),{apply:b}=x(),{apply:E}=function(){if(g)return y;g=1;const e=r,t=s,{SupportedStyleSheets:n}=_();return y={apply:({styleSheets:s})=>{const r=e.resolve(process.cwd(),"./package.json"),o=t.readJsonSync(r);o.scripts=Object.assign({},o.scripts,{c:"cz"}),o.husky={hooks:{"pre-commit":"lint-staged","commit-msg":"commitlint -E HUSKY_GIT_PARAMS"}},o.config=Object.assign({},o.config,{commitizen:{path:"cz-conventional-changelog"}}),o["lint-staged"]={"*.{js,ts,tsx,jsx}":"eslint"},s!==n.others&&(o["lint-staged"]["*.{css,less,scss}"]="stylelint"),t.writeJsonSync(r,o,{spaces:"\t"})}}}(),{apply:L}=function(){if(h)return S;h=1;const e=s,n=t,c=r,i=o,a=l,{SupportedStyleSheets:p}=_();return S={apply:({styleSheets:t})=>{console.log(n.blue("生成 Prettier 配置文件..."));const s=c.resolve(__dirname,"../template/.prettierrc"),r=a.render(i.readFileSync(s,"utf-8"),{supportedStyleSheets:p,styleSheets:t}),o=c.resolve(process.cwd(),"./.prettierrc");e.ensureFileSync(o),i.writeFileSync(o,r,"utf-8")}}}(),{apply:O}=q(),{apply:P}=function(){if(k)return w;k=1;const{exec:e}=c,n=s,o=r,l=t,a=i,{SupportedLanguage:p,SupportedFramework:u,SupportedStyleSheets:d}=_(),m=[["@commitlint/cli","^19.8.1"],["@commitlint/config-conventional","^19.8.1"],["@commitlint/prompt-cli","^20.1.0"],["cz-conventional-changelog","^3.3.0"],["husky","^9.1.7"],["lint-staged","^16.1.2"],["prettier","^3.6.2"]],y=[["stylelint-config-html","^1.1.0"]],g=[["eslint","^9.39.1"],["eslint-config-prettier","^9.1.2"],["eslint-plugin-prettier","^5.5.4"],["@babel/eslint-parser","^7.12.16"],["@babel/preset-env","^7.28.5"]],S=[["@typescript-eslint/eslint-plugin","^8.46.3"],["@typescript-eslint/parser","^8.46.3"]],h=[["stylelint","^15.10.3"],["stylelint-config-recess-order","^7.4.0"],["stylelint-config-standard","^34.0.0"],["stylelint-order","^6.0.4"]],f=[["postcss-scss","^4.0.9"],["stylelint-config-recommended-scss","^12.0.0"],["stylelint-scss","^5.3.2"]],v=[["postcss-less","^6.0.0"],["stylelint-config-recommended-less","^2.0.0"],["stylelint-less","^1.0.6"]],j=[["postcss-html","^1.8.0"],["eslint-plugin-vue","^9.33.0"],["stylelint-config-html","^1.1.0"],["vue-eslint-parser","^9.4.3"]],F=[["postcss-html","^1.8.0"],["stylelint-config-html","^1.1.0"],["eslint-plugin-vue","^9.33.0"],["vue-eslint-parser","^9.4.3"]],b=[["eslint-plugin-react","^7.37.5"],["eslint-plugin-react-hooks","^5.2.0"]];return w={apply:({language:t,framework:s,styleSheets:r,includeHtml:c})=>{console.log(l.blue("安装依赖包..."));const i=m.slice();c&&i.push(...y),t!==p.others&&i.push(...g),t===p.typescript&&i.push(...S),s===u.vue2?i.push(...j):s===u.vue3?i.push(...F):s===u.react&&i.push(...b),r!==d.others&&(i.push(...h),r===d.scss?i.push(...f):r===d.less&&i.push(...v));const w=["pnpm-lock.yaml","yarn.lock","package-lock.json"];let k="npm i -D";for(const e of w)if(n.existsSync(o.resolve(process.cwd(),`./${e}`))){"pnpm-lock.yaml"===e?k="pnpm add -D":"yarn.lock"===e&&(k="yarn add -D");break}const _=i.map(([t,s])=>{const r=`${t}@${s}`;return console.log(l.yellow(r)),new Promise((t,s)=>{e(k+" "+`${r} --legacy-peer-deps`,(e,t,r)=>{e&&(console.log(l.red(e)),s(new Error("安装失败: ",e)))}).on("close",e=>{0===e?t(e):s(new Error("安装失败: ",e))})})}),x=a(">>>>>> 正在安装依赖包 >>>>>>\n").start();Promise.allSettled(_).then(e=>{e.every(e=>"fulfilled"===e.status)?x.succeed("安装完成"):x.fail("安装失败"),process.exit()})}},w}();return j={run:async()=>{const t=p.resolve(process.cwd(),"./package.json");if(!a.existsSync(t))return void console.log(e.red("请在工程目录下执行命令"));const s=p.resolve(process.cwd(),".editorconfig");if(a.existsSync(s)){(await u.prompt([{type:"confirm",name:"remove",message:"默认采用Prettier进行代码格式化,项目中检测到的.editorconfig文件可能会造成干扰,是否删除:",default:!1}])).remove&&a.removeSync(s)}const r=await u.prompt([{type:"list",name:"editor",message:"请选择使用的编辑器:",choices:()=>Object.entries(d).map(([e,t])=>({name:e,value:t}))},{type:"list",name:"language",message:"请选择编程语音:",choices:()=>Object.entries(m).map(([e,t])=>({name:e,value:t}))},{type:"list",name:"styleSheets",message:"请选择样式语言:",choices:()=>Object.entries(f).map(([e,t])=>({name:e,value:t}))},{type:"list",name:"framework",message:"请选择编程框架:",choices:()=>Object.entries(v).map(([e,t])=>({name:e,value:t}))},{type:"confirm",name:"includeHtml",message:"是否包含html:",default:!1}]);try{b(r)}catch(t){console.log(e.red("编辑器配置生成失败:"),t)}try{E(r)}catch(t){console.log(e.red("package.json配置生成失败:"),t)}try{L(r)}catch(t){console.log(e.red("Prettier配置生成失败:"),t)}try{O(r)}catch(t){console.log(e.red(t))}try{P(r)}catch(t){console.log(e.red("依赖安装失败:"),t)}}}}var L,O={version:"0.0.5"};var P=function(){if(L)return b;L=1;const{program:t}=e,{run:s}=E(),r=O;return t.version(r.version),t.usage("<command>"),t.command("default",{isDefault:!0}).action(()=>{s()}),t.parse(process.argv),b}(),z=a(P);module.exports=z;
2
+ "use strict";var e=require("commander"),t=require("chalk"),s=require("fs-extra"),r=require("path"),n=require("inquirer"),o=require("fs"),l=require("ejs"),c=require("child_process"),i=require("ora");function a(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var p,u,d,y,m,g,S,f,h,v,w,k,j,F,b={};function _(){if(u)return p;u=1;return p={SupportedEditor:{vscode:1,others:0},SupportedLanguage:{javascript:1,typescript:2,others:0},SupportedStyleSheets:{css:1,less:2,scss:3,others:0},SupportedFramework:{vue2:1,vue3:2,react:3,others:0}}}function x(){if(y)return d;y=1;const e=s,n=t,c=r,i=o,a=l,{SupportedEditor:p,SupportedLanguage:u,SupportedStyleSheets:m,SupportedFramework:g}=_();return d={apply:t=>{console.log(n.blue("生成编辑器设置..."));const{editorType:s}=t;s!==p.others&&s===p.VSCode&&(({language:t,framework:s,styleSheets:r,includeHtml:n})=>{const o=c.resolve(__dirname,"../template/.vscode/settings.json"),l=a.render(i.readFileSync(o,"utf-8"),{supportedLanguage:u,language:t,styleSheets:r,supportedStyleSheets:m,framework:s,supportedFramework:g,html:n}),p=c.resolve(process.cwd(),"./.vscode/settings.json");e.ensureFileSync(p),i.writeFileSync(p,l,"utf-8");const d=c.resolve(__dirname,"../template/.vscode/extensions.json"),y=a.render(i.readFileSync(d,"utf-8"),{style:r!==m.others,vue:s===g.vue2||s===g.vue3}),S=c.resolve(process.cwd(),"./.vscode/extensions.json");e.ensureFileSync(S),i.writeFileSync(S,y,"utf-8")})(t)}}}function O(){if(v)return h;v=1;const e=l,n=r,c=o,i=s,a=t,{SupportedLanguage:p,SupportedStyleSheets:u,SupportedFramework:d}=_();return h={apply:({framework:t,styleSheets:s,language:r})=>{if(r!==p.others){console.log(a.blue("生成 ESLint 配置文件..."));try{(()=>{const s="module"===i.readJSONSync(n.resolve(process.cwd(),"./package.json")).type?"eslint.config.cjs":"eslint.config.js",o=n.resolve(__dirname,"../template/eslint.config.js"),l=e.render(c.readFileSync(o,"utf-8"),{language:r,framework:t,supportedFramework:d,supportedLanguage:p}),a=n.resolve(process.cwd(),"./",s);i.ensureFileSync(a),i.writeFileSync(a,l,"utf-8")})()}catch(e){throw new Error("生成ESLint配置文件失败: ",e.message)}}if(s!==u.others){console.log(a.blue("生成 Stylelint 配置文件..."));try{(()=>{const r=n.resolve(__dirname,"../template/.stylelintrc.js"),o=e.render(c.readFileSync(r,"utf-8"),{supportedStyleSheets:u,styleSheets:s,vue:t===d.vue2||t===d.vue3}),l=n.resolve(process.cwd(),"./.stylelintrc.js");i.ensureFileSync(l),i.writeFileSync(l,o,"utf-8")})()}catch(e){throw new Error("生成Stylelint配置文件失败: ",e.message)}}}}}function q(){if(F)return j;F=1;const e=t,a=s,p=r,u=n,{SupportedEditor:d,SupportedLanguage:y,SupportedStyleSheets:h,SupportedFramework:v}=_(),{apply:b}=x(),{apply:q}=function(){if(g)return m;g=1;const e=r,t=s,{SupportedStyleSheets:n}=_();return m={apply:({styleSheets:s})=>{const r=e.resolve(process.cwd(),"./package.json"),o=t.readJsonSync(r);o.scripts=Object.assign({},o.scripts,{c:"cz"}),o.husky={hooks:{"pre-commit":"lint-staged","commit-msg":"commitlint -E HUSKY_GIT_PARAMS"}},o.config=Object.assign({},o.config,{commitizen:{path:"cz-conventional-changelog"}}),o["lint-staged"]={"*.{js,ts,tsx,jsx}":"eslint"},s!==n.others&&(o["lint-staged"]["*.{css,less,scss}"]="stylelint"),t.writeJsonSync(r,o,{spaces:"\t"})}}}(),{apply:L}=function(){if(f)return S;f=1;const e=s,n=t,c=r,i=o,a=l,{SupportedStyleSheets:p}=_();return S={apply:({styleSheets:t})=>{console.log(n.blue("生成 Prettier 配置文件..."));const s=c.resolve(__dirname,"../template/.prettierrc"),r=a.render(i.readFileSync(s,"utf-8"),{supportedStyleSheets:p,styleSheets:t}),o=c.resolve(process.cwd(),"./.prettierrc");e.ensureFileSync(o),i.writeFileSync(o,r,"utf-8")}}}(),{apply:E}=O(),{apply:J}=function(){if(k)return w;k=1;const{exec:e}=c,n=s,o=r,l=t,a=i,{SupportedLanguage:p,SupportedFramework:u,SupportedStyleSheets:d}=_(),y=[["@commitlint/cli","^19.8.1"],["@commitlint/config-conventional","^19.8.1"],["@commitlint/prompt-cli","^20.1.0"],["cz-conventional-changelog","^3.3.0"],["husky","^9.1.7"],["lint-staged","^16.1.2"],["prettier","^3.6.2"]],m=[["stylelint-config-html","^1.1.0"]],g=[["eslint","^9.39.1"],["eslint-config-prettier","^9.1.2"],["eslint-plugin-prettier","^5.5.4"],["@babel/eslint-parser","^7.12.16"],["@babel/preset-env","^7.28.5"]],S=[["@typescript-eslint/eslint-plugin","^8.46.3"],["@typescript-eslint/parser","^8.46.3"]],f=[["stylelint","^15.10.3"],["stylelint-config-recess-order","^4.6.0"],["stylelint-config-standard","^34.0.0"],["stylelint-order","^6.0.4"]],h=[["postcss-scss","^4.0.9"],["stylelint-config-recommended-scss","^12.0.0"],["stylelint-scss","^5.3.2"]],v=[["postcss-less","^6.0.0"],["stylelint-config-recommended-less","^2.0.0"],["stylelint-less","^1.0.6"]],j=[["postcss-html","^1.8.0"],["eslint-plugin-vue","^9.33.0"],["stylelint-config-html","^1.1.0"],["vue-eslint-parser","^9.4.3"]],F=[["postcss-html","^1.8.0"],["stylelint-config-html","^1.1.0"],["eslint-plugin-vue","^9.33.0"],["vue-eslint-parser","^9.4.3"]],b=[["eslint-plugin-react","^7.37.5"],["eslint-plugin-react-hooks","^5.2.0"]];return w={apply:({language:t,framework:s,styleSheets:r,includeHtml:c})=>{console.log(l.blue("安装依赖包..."));const i=y.slice();c&&i.push(...m),t!==p.others&&i.push(...g),t===p.typescript&&i.push(...S),s===u.vue2?i.push(...j):s===u.vue3?i.push(...F):s===u.react&&i.push(...b),r!==d.others&&(i.push(...f),r===d.scss?i.push(...h):r===d.less&&i.push(...v));const w=o.join(process.cwd(),"package.json");if(!n.existsSync(w))return void console.log(l.red("缺少package.json文件"));const k=n.readJSONSync(w),_=k.devDependencies=k.devDependencies||{},x=(k.dependencies=k.dependencies)||{};for(let[e,t]of i)_[e]=t,delete x[e];n.writeJSONSync(w,k,{encoding:"utf-8",spaces:"\t"});const O=["pnpm-lock.yaml","yarn.lock","package-lock.json"];let q="npm install";for(const e of O)if(n.existsSync(o.resolve(process.cwd(),`./${e}`))){"pnpm-lock.yaml"===e?q="pnpm install":"yarn.lock"===e&&(q="yarn install");break}const L=a(">>>>>> 安装依赖 >>>>>>\n").start();e(q,(e,t,s)=>{e&&(console.log(l.red(e)),L.fail("安装失败")),L.succeed("安装完成")}).on("close",e=>{0===e?L.succeed("安装完成"):L.fail("安装失败")})}},w}();return j={run:async()=>{const t=p.resolve(process.cwd(),"./package.json");if(!a.existsSync(t))return void console.log(e.red("请在工程目录下执行命令"));const s=p.resolve(process.cwd(),".editorconfig");if(a.existsSync(s)){(await u.prompt([{type:"confirm",name:"remove",message:"默认采用Prettier进行代码格式化,项目中检测到的.editorconfig文件可能会造成干扰,是否删除:",default:!1}])).remove&&a.removeSync(s)}const r=await u.prompt([{type:"list",name:"editor",message:"请选择使用的编辑器:",choices:()=>Object.entries(d).map(([e,t])=>({name:e,value:t}))},{type:"list",name:"language",message:"请选择编程语音:",choices:()=>Object.entries(y).map(([e,t])=>({name:e,value:t}))},{type:"list",name:"styleSheets",message:"请选择样式语言:",choices:()=>Object.entries(h).map(([e,t])=>({name:e,value:t}))},{type:"list",name:"framework",message:"请选择编程框架:",choices:()=>Object.entries(v).map(([e,t])=>({name:e,value:t}))},{type:"confirm",name:"includeHtml",message:"是否包含html:",default:!1}]);try{b(r)}catch(t){console.log(e.red("编辑器配置生成失败:"),t)}try{q(r)}catch(t){console.log(e.red("package.json配置生成失败:"),t)}try{L(r)}catch(t){console.log(e.red("Prettier配置生成失败:"),t)}try{E(r)}catch(t){console.log(e.red(t))}try{J(r)}catch(t){console.log(e.red("依赖安装失败:"),t)}}}}var L,E={version:"0.0.6"};var J=function(){if(L)return b;L=1;const{program:t}=e,{run:s}=q(),r=E;return t.version(r.version),t.usage("<command>"),t.command("default",{isDefault:!0}).action(()=>{s()}),t.parse(process.argv),b}(),P=a(J);module.exports=P;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pl-preset",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "bin": {
5
5
  "plp": "dist/cli.js"
6
6
  },