pl-preset 0.0.5 → 0.0.7
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.js +1 -1
- package/package.json +3 -1
- package/template/.stylelintrc.js +11 -3
- package/template/eslint.config.js +2 -2
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"),
|
|
2
|
+
"use strict";var e=require("commander"),t=require("chalk"),s=require("fs-extra"),r=require("path"),n=require("inquirer"),o=require("fs"),c=require("ejs"),l=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,l=r,i=o,a=c,{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=l.resolve(__dirname,"../template/.vscode/settings.json"),c=a.render(i.readFileSync(o,"utf-8"),{supportedLanguage:u,language:t,styleSheets:r,supportedStyleSheets:m,framework:s,supportedFramework:g,html:n}),p=l.resolve(process.cwd(),"./.vscode/settings.json");e.ensureFileSync(p),i.writeFileSync(p,c,"utf-8");const d=l.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=l.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=c,n=r,l=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"),c=e.render(l.readFileSync(o,"utf-8"),{language:r,framework:t,supportedFramework:d,supportedLanguage:p}),a=n.resolve(process.cwd(),"./",s);i.ensureFileSync(a),i.writeFileSync(a,c,"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(l.readFileSync(r,"utf-8"),{supportedStyleSheets:u,styleSheets:s,vue:t===d.vue2||t===d.vue3}),c=n.resolve(process.cwd(),"./.stylelintrc.js");i.ensureFileSync(c),i.writeFileSync(c,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,l=r,i=o,a=c,{SupportedStyleSheets:p}=_();return S={apply:({styleSheets:t})=>{console.log(n.blue("生成 Prettier 配置文件..."));const s=l.resolve(__dirname,"../template/.prettierrc"),r=a.render(i.readFileSync(s,"utf-8"),{supportedStyleSheets:p,styleSheets:t}),o=l.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}=l,n=s,o=r,c=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","^4.3.8"],["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"]],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:l})=>{console.log(c.blue("安装依赖包..."));const i=y.slice();l&&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(c.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(c.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.7"};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.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"bin": {
|
|
5
5
|
"plp": "dist/cli.js"
|
|
6
6
|
},
|
|
@@ -40,6 +40,8 @@
|
|
|
40
40
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
41
41
|
"@rollup/plugin-terser": "^0.4.4",
|
|
42
42
|
"cz-conventional-changelog": "^3.3.0",
|
|
43
|
+
"eslint": "^9.39.2",
|
|
44
|
+
"eslint-plugin-prettier": "^5.5.5",
|
|
43
45
|
"npm-run-all": "^4.1.5",
|
|
44
46
|
"prettier": "^3.6.2",
|
|
45
47
|
"rollup": "^4.52.5"
|
package/template/.stylelintrc.js
CHANGED
|
@@ -13,11 +13,10 @@ module.exports = {
|
|
|
13
13
|
],
|
|
14
14
|
plugins: [
|
|
15
15
|
<%_ if (styleSheets == supportedStyleSheets.scss) { _%>
|
|
16
|
-
'stylelint-scss'
|
|
16
|
+
'stylelint-scss'
|
|
17
17
|
<%_ } else if (styleSheets == supportedStyleSheets.less) { _%>
|
|
18
|
-
'stylelint-less'
|
|
18
|
+
'stylelint-less'
|
|
19
19
|
<%_ } _%>
|
|
20
|
-
'stylelint-order'
|
|
21
20
|
],
|
|
22
21
|
rules: {
|
|
23
22
|
<%_ if (styleSheets == supportedStyleSheets.scss) { _%>
|
|
@@ -36,6 +35,15 @@ module.exports = {
|
|
|
36
35
|
'less/color-no-invalid-hex': true,
|
|
37
36
|
'less/color-hex-case': 'lower',
|
|
38
37
|
<%_ } _%>
|
|
38
|
+
<%_ if (vue) {_%>
|
|
39
|
+
// 忽略:deep以及/deep/校验
|
|
40
|
+
'selector-pseudo-class-no-unknown': [
|
|
41
|
+
true,
|
|
42
|
+
{
|
|
43
|
+
ignorePseudoClasses: ['/^deep/']
|
|
44
|
+
}
|
|
45
|
+
],
|
|
46
|
+
<%_ } _%>
|
|
39
47
|
'value-keyword-case': null,
|
|
40
48
|
// 处理 Tailwind CSS 的 at-rule
|
|
41
49
|
'at-rule-no-unknown': [
|
|
@@ -72,12 +72,12 @@ module.exports = [
|
|
|
72
72
|
ecmaVersion: 'latest',
|
|
73
73
|
sourceType: 'module'
|
|
74
74
|
},
|
|
75
|
-
globals: { ...globals.browser, ...globals.node }
|
|
76
75
|
<%_ if (language == supportedLanguage.javascript) { _%>
|
|
77
76
|
babelOptions: {
|
|
78
77
|
presets: ['@babel/preset-env']
|
|
79
|
-
}
|
|
78
|
+
},
|
|
80
79
|
<%_ } _%>
|
|
80
|
+
globals: { ...globals.browser, ...globals.node }
|
|
81
81
|
},
|
|
82
82
|
plugins: {
|
|
83
83
|
<%_ if (language == supportedLanguage.typescript) { _%>
|