pl-preset 0.0.6 → 0.0.8
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/README.md +35 -1
- package/dist/cli.js +1 -1
- package/package.json +12 -4
- package/template/.changelogrc.js +21 -0
- package/template/.czrc +66 -0
- package/template/.husky/commit-msg +1 -0
- package/template/.husky/pre-commit +1 -0
- package/template/.prettierrc +1 -1
- package/template/.stylelintrc.js +14 -4
- package/template/eslint.config.js +3 -3
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# pl-preset
|
|
2
2
|
|
|
3
|
-
一键生成web
|
|
3
|
+
一键生成web项目常用设置简化配置过程
|
|
4
4
|
|
|
5
5
|
## 使用方式
|
|
6
6
|
|
|
@@ -11,3 +11,37 @@ npm install -g pl-preset
|
|
|
11
11
|
// 在项目根路径下执行
|
|
12
12
|
plp
|
|
13
13
|
```
|
|
14
|
+
|
|
15
|
+
## 主要功能
|
|
16
|
+
|
|
17
|
+
### prettier
|
|
18
|
+
|
|
19
|
+
默认以prettier作为代码格式化工具,自动生成配置信息
|
|
20
|
+
|
|
21
|
+
### Git设置
|
|
22
|
+
|
|
23
|
+
如果项目仓库是git那么会为项目配置husky进行提交前校验同时使用cz-conventional-changelog规范commit信息,通过`npm run c`进行代码提交
|
|
24
|
+
|
|
25
|
+
### 生成changelog
|
|
26
|
+
|
|
27
|
+
对于使用cz-conventional-changelog进行git提交的项目,可以选择性接入conventional-changelog-cli工具生成changelog文件,通过执行`npm run clog`生成changelog文件
|
|
28
|
+
|
|
29
|
+
### vscode设置
|
|
30
|
+
|
|
31
|
+
当前仅支持vscode编辑器相关设置,选择vscode后自动生成插件以及代码格式化相关配置信息
|
|
32
|
+
|
|
33
|
+
### 开发语言
|
|
34
|
+
|
|
35
|
+
支持选择javascript、typescript,自动生成eslint相关配置进行校验
|
|
36
|
+
|
|
37
|
+
### 样式语音
|
|
38
|
+
|
|
39
|
+
支持选择css、less、scss,自动生成stylelint配置对代码进行校验
|
|
40
|
+
|
|
41
|
+
### 框架
|
|
42
|
+
|
|
43
|
+
支持选择vue2、vue3、react,自动在eslint和stylelint中插入框架相关设置进行校验
|
|
44
|
+
|
|
45
|
+
### html文件校验
|
|
46
|
+
|
|
47
|
+
选择项目中是否包含html文件,在eslint和prettier配置中增加html相关内容
|
package/dist/cli.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";var e=require("commander"),
|
|
2
|
+
"use strict";var e=require("commander"),s=require("chalk"),t=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,g,m,y,S,h,f,v,w,j,k,F,_={};function b(){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 L(){if(g)return d;g=1;const e=t,n=s,l=r,i=o,a=c,{SupportedEditor:p,SupportedLanguage:u,SupportedStyleSheets:m,SupportedFramework:y}=b();return d={apply:s=>{console.log(n.blue("生成编辑器设置..."));const{editorType:t}=s;t!==p.others&&t===p.VSCode&&(({language:s,framework:t,styleSheets:r,includeHtml:n})=>{const o=l.resolve(__dirname,"../template/.vscode/settings.json"),c=a.render(i.readFileSync(o,"utf-8"),{supportedLanguage:u,language:s,styleSheets:r,supportedStyleSheets:m,framework:t,supportedFramework:y,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"),g=a.render(i.readFileSync(d,"utf-8"),{style:r!==m.others,vue:t===y.vue2||t===y.vue3}),S=l.resolve(process.cwd(),"./.vscode/extensions.json");e.ensureFileSync(S),i.writeFileSync(S,g,"utf-8")})(s)}}}function O(){if(v)return f;v=1;const e=c,n=r,l=o,i=t,a=s,{SupportedLanguage:p,SupportedStyleSheets:u,SupportedFramework:d}=b();return f={apply:({framework:s,styleSheets:t,language:r})=>{if(r!==p.others){console.log(a.blue("生成 ESLint 配置文件..."));try{(()=>{const t="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:s,supportedFramework:d,supportedLanguage:p}),a=n.resolve(process.cwd(),"./",t);i.ensureFileSync(a),i.writeFileSync(a,c,"utf-8")})()}catch(e){throw new Error("生成ESLint配置文件失败: ",e.message)}}if(t!==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:t,vue:s===d.vue2||s===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 x(){if(F)return k;F=1;const e=s,a=t,p=r,u=n,{SupportedEditor:d,SupportedLanguage:g,SupportedStyleSheets:f,SupportedFramework:v}=b(),{apply:_}=L(),{apply:x}=function(){if(y)return m;y=1;const e=r,s=t,{SupportedStyleSheets:n}=b();return m={apply:({styleSheets:t,isUseGit:r,isNeedChangeLog:o})=>{if(!r||!o)return;const c=e.resolve(process.cwd(),"./package.json"),l=s.readJsonSync(c);if(l.scripts=Object.assign({},l.scripts,{c:"cz"}),l.config=Object.assign({},l.config,{commitizen:{path:"cz-conventional-changelog"}}),l["lint-staged"]={"*.{js,ts,tsx,jsx}":"eslint"},t!==n.others&&(l["lint-staged"]["*.{css,less,scss}"]="stylelint"),o){l.scripts=Object.assign({},l.scripts,{clog:"conventional-changelog -n ./.changelogrc.js -p angular -i CHANGELOG.md -s"});const t=e.resolve(__dirname,"../template/.changelogrc.js");s.copyFileSync(t,e.resolve(process.cwd(),"./.changelogrc.js"))}s.writeJsonSync(c,l,{spaces:"\t"});const i=e.resolve(__dirname,"../template/.czrc");s.copyFileSync(i,e.resolve(process.cwd(),"./.czrc"));const a=e.resolve(__dirname,"../template/commitlint.config.js");s.copyFileSync(a,e.resolve(process.cwd(),"./commitlint.config.js"));const p=e.resolve(__dirname,"../template/.husky");s.copySync(p,e.resolve(process.cwd(),"./.husky"))}}}(),{apply:q}=function(){if(h)return S;h=1;const e=t,n=s,l=r,i=o,a=c,{SupportedStyleSheets:p}=b();return S={apply:({styleSheets:s})=>{console.log(n.blue("生成 Prettier 配置文件..."));const t=l.resolve(__dirname,"../template/.prettierrc"),r=a.render(i.readFileSync(t,"utf-8"),{supportedStyleSheets:p,styleSheets:s}),o=l.resolve(process.cwd(),"./.prettierrc");e.ensureFileSync(o),i.writeFileSync(o,r,"utf-8")}}}(),{apply:E}=O(),{apply:z}=function(){if(j)return w;j=1;const{exec:e}=l,n=t,o=r,c=s,a=i,{SupportedLanguage:p,SupportedFramework:u,SupportedStyleSheets:d}=b(),g=[["prettier","^3.6.2"]],m=[["@commitlint/cli","^19.8.1"],["@commitlint/config-conventional","^19.8.1"],["@commitlint/prompt-cli","^20.1.0"],["commitizen","^4.3.1"],["cz-conventional-changelog","^3.3.0"],["husky","^9.1.7"],["lint-staged","^16.1.2"]],y=[["conventional-changelog-cli","^4.1.0"]],S=[["stylelint-config-html","^1.1.0"]],h=[["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"]],f=[["@typescript-eslint/eslint-plugin","^8.46.3"],["@typescript-eslint/parser","^8.46.3"]],v=[["stylelint","^15.10.3"],["stylelint-config-recess-order","^4.6.0"],["stylelint-config-standard","^34.0.0"]],k=[["postcss-scss","^4.0.9"],["stylelint-config-recommended-scss","^12.0.0"],["stylelint-scss","^5.3.2"]],F=[["postcss-less","^6.0.0"],["stylelint-config-recommended-less","^2.0.0"],["stylelint-less","^1.0.6"]],_=[["postcss-html","^1.8.0"],["eslint-plugin-vue","^9.33.0"],["stylelint-config-html","^1.1.0"],["vue-eslint-parser","^9.4.3"]],L=[["postcss-html","^1.8.0"],["stylelint-config-html","^1.1.0"],["eslint-plugin-vue","^9.33.0"],["vue-eslint-parser","^9.4.3"]],O=[["eslint-plugin-react","^7.37.5"],["eslint-plugin-react-hooks","^5.2.0"]];return w={apply:({language:s,framework:t,styleSheets:r,includeHtml:l,isUseGit:i,isNeedChangeLog:w})=>{console.log(c.blue("安装依赖包..."));const j=g.slice();i&&(j.push(...m),w&&j.push(...y)),l&&j.push(...S),s!==p.others&&j.push(...h),s===p.typescript&&j.push(...f),t===u.vue2?j.push(..._):t===u.vue3?j.push(...L):t===u.react&&j.push(...O),r!==d.others&&(j.push(...v),r===d.scss?j.push(...k):r===d.less&&j.push(...F));const b=o.join(process.cwd(),"package.json");if(!n.existsSync(b))return void console.log(c.red("缺少package.json文件"));const x=n.readJSONSync(b),q=x.devDependencies=x.devDependencies||{},E=x.dependencies=x.dependencies||{};for(let[e,s]of j)q[e]=s,delete E[e];n.writeJSONSync(b,x,{encoding:"utf-8",spaces:"\t"});const z=["pnpm-lock.yaml","yarn.lock","package-lock.json"];let N="npm install";for(const e of z)if(n.existsSync(o.resolve(process.cwd(),`./${e}`))){"pnpm-lock.yaml"===e?N="pnpm install":"yarn.lock"===e&&(N="yarn install");break}const G=a(">>>>>> 安装依赖 >>>>>>\n").start();e(N,(e,s,t)=>{e&&(console.log(c.red(e)),G.fail("安装失败")),G.succeed("安装完成")}).on("close",e=>{0===e?G.succeed("安装完成"):G.fail("安装失败")})}},w}();return k={run:async()=>{const s=p.resolve(process.cwd(),"./package.json");if(!a.existsSync(s))return void console.log(e.red("请在工程目录下执行命令"));const t=p.resolve(process.cwd(),".editorconfig");if(a.existsSync(t)){(await u.prompt([{type:"confirm",name:"remove",message:"默认采用Prettier进行代码格式化,项目中检测到的.editorconfig文件可能会造成干扰,是否删除:",default:!1}])).remove&&a.removeSync(t)}const r=await u.prompt([{type:"confirm",name:"isUseGit",message:"是否使用git作为代码仓库:",default:!0},{type:"confirm",name:"isNeedChangeLog",message:"是否需要生成changelog:",default:!1,when:e=>!0===e.isUseGit},{type:"list",name:"editor",message:"请选择使用的编辑器:",choices:()=>Object.entries(d).map(([e,s])=>({name:e,value:s}))},{type:"list",name:"language",message:"请选择编程语音:",choices:()=>Object.entries(g).map(([e,s])=>({name:e,value:s}))},{type:"list",name:"styleSheets",message:"请选择样式语言:",choices:()=>Object.entries(f).map(([e,s])=>({name:e,value:s}))},{type:"list",name:"framework",message:"请选择编程框架:",choices:()=>Object.entries(v).map(([e,s])=>({name:e,value:s}))},{type:"confirm",name:"includeHtml",message:"是否包含html:",default:!1}]);try{_(r)}catch(s){console.log(e.red("编辑器配置生成失败:"),s)}try{x(r)}catch(s){console.log(e.red("配置git校验失败:"),s)}try{q(r)}catch(s){console.log(e.red("Prettier配置生成失败:"),s)}try{E(r)}catch(s){console.log(e.red(s))}try{z(r)}catch(s){console.log(e.red("依赖安装失败:"),s)}}}}var q,E={version:"0.0.8"};var z=a(function(){if(q)return _;q=1;const{program:s}=e,{run:t}=x(),r=E;return s.version(r.version),s.usage("<command>"),s.command("default",{isDefault:!0}).action(()=>{t()}),s.parse(process.argv),_}());module.exports=z;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pl-preset",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"bin": {
|
|
5
5
|
"plp": "dist/cli.js"
|
|
6
6
|
},
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
"beta": "run-s build publish:beta",
|
|
12
12
|
"release": "run-s build publish:prod",
|
|
13
13
|
"publish:prod": "npm publish",
|
|
14
|
-
"publish:beta": "npm publish --tag beta"
|
|
14
|
+
"publish:beta": "npm publish --tag beta",
|
|
15
|
+
"clog": "conventional-changelog -n ./.changelogrc.js -p angular -i CHANGELOG.md -s"
|
|
15
16
|
},
|
|
16
17
|
"files": [
|
|
17
18
|
"dist",
|
|
@@ -30,7 +31,7 @@
|
|
|
30
31
|
"stylelint"
|
|
31
32
|
],
|
|
32
33
|
"devDependencies": {
|
|
33
|
-
"@babel/eslint-parser": "^7.
|
|
34
|
+
"@babel/eslint-parser": "^7.12.16",
|
|
34
35
|
"@babel/preset-env": "^7.28.5",
|
|
35
36
|
"@commitlint/cli": "^19.8.1",
|
|
36
37
|
"@commitlint/config-conventional": "^19.8.1",
|
|
@@ -40,9 +41,16 @@
|
|
|
40
41
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
41
42
|
"@rollup/plugin-terser": "^0.4.4",
|
|
42
43
|
"cz-conventional-changelog": "^3.3.0",
|
|
44
|
+
"eslint": "^9.39.1",
|
|
45
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
43
46
|
"npm-run-all": "^4.1.5",
|
|
44
47
|
"prettier": "^3.6.2",
|
|
45
|
-
"rollup": "^4.52.5"
|
|
48
|
+
"rollup": "^4.52.5",
|
|
49
|
+
"commitizen": "^4.3.1",
|
|
50
|
+
"husky": "^9.1.7",
|
|
51
|
+
"lint-staged": "^16.1.2",
|
|
52
|
+
"conventional-changelog-cli": "^4.1.0",
|
|
53
|
+
"eslint-config-prettier": "^9.1.2"
|
|
46
54
|
},
|
|
47
55
|
"dependencies": {
|
|
48
56
|
"chalk": "^4.1.2",
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// 需要输出到changelog的提交类型
|
|
2
|
+
const types = ['feat', 'fix']
|
|
3
|
+
|
|
4
|
+
module.exports = {
|
|
5
|
+
writerOpts: {
|
|
6
|
+
transform: commit => {
|
|
7
|
+
if (types.includes(commit.type)) {
|
|
8
|
+
return commit
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return null
|
|
12
|
+
},
|
|
13
|
+
// 自定义分组
|
|
14
|
+
groupBy: 'type',
|
|
15
|
+
commitGroupsSort: (a, b) => {
|
|
16
|
+
return types.indexOf(a.title) - types.indexOf(b.title)
|
|
17
|
+
},
|
|
18
|
+
// 提交排序
|
|
19
|
+
commitsSort: ['scope', 'subject']
|
|
20
|
+
}
|
|
21
|
+
}
|
package/template/.czrc
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"path": "cz-conventional-changelog",
|
|
3
|
+
"disableScopeLowerCase": false,
|
|
4
|
+
"disableSubjectLowerCase": false,
|
|
5
|
+
"maxHeaderWidth": 100,
|
|
6
|
+
"maxLineWidth": 100,
|
|
7
|
+
"defaultType": "",
|
|
8
|
+
"defaultScope": "",
|
|
9
|
+
"defaultSubject": "",
|
|
10
|
+
"defaultBody": "",
|
|
11
|
+
"defaultIssues": "",
|
|
12
|
+
"types": {
|
|
13
|
+
"refactor": {
|
|
14
|
+
"description": "🤡 代码重构(常规保存性提交)",
|
|
15
|
+
"title": "Code Refactoring",
|
|
16
|
+
"hidden": true
|
|
17
|
+
},
|
|
18
|
+
"feat": {
|
|
19
|
+
"description": "✨ 新增功能",
|
|
20
|
+
"title": "Features"
|
|
21
|
+
},
|
|
22
|
+
"fix": {
|
|
23
|
+
"description": "🐛 修复bug",
|
|
24
|
+
"title": "Bug Fixes"
|
|
25
|
+
},
|
|
26
|
+
"docs": {
|
|
27
|
+
"description": "📝 文档更新",
|
|
28
|
+
"title": "Documentation",
|
|
29
|
+
"hidden": true
|
|
30
|
+
},
|
|
31
|
+
"style": {
|
|
32
|
+
"description": "💎 代码格式调整(不影响代码运行)",
|
|
33
|
+
"title": "Styles",
|
|
34
|
+
"hidden": true
|
|
35
|
+
},
|
|
36
|
+
"perf": {
|
|
37
|
+
"description": "🚀 性能优化",
|
|
38
|
+
"title": "Performance Improvements"
|
|
39
|
+
},
|
|
40
|
+
"test": {
|
|
41
|
+
"description": "✅ 测试相关",
|
|
42
|
+
"title": "Tests",
|
|
43
|
+
"hidden": true
|
|
44
|
+
},
|
|
45
|
+
"build": {
|
|
46
|
+
"description": "📦 构建系统或外部依赖的更改",
|
|
47
|
+
"title": "Build System",
|
|
48
|
+
"hidden": true
|
|
49
|
+
},
|
|
50
|
+
"ci": {
|
|
51
|
+
"description": "👷 CI配置文件和脚本的更改",
|
|
52
|
+
"title": "Continuous Integration",
|
|
53
|
+
"hidden": true
|
|
54
|
+
},
|
|
55
|
+
"chore": {
|
|
56
|
+
"description": "🔧 其他不修改src或测试文件的更改",
|
|
57
|
+
"title": "Chores",
|
|
58
|
+
"hidden": true
|
|
59
|
+
},
|
|
60
|
+
"revert": {
|
|
61
|
+
"description": "⏪ 回滚提交",
|
|
62
|
+
"title": "Reverts",
|
|
63
|
+
"hidden": true
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
commitlint --edit $1
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
lint-staged
|
package/template/.prettierrc
CHANGED
package/template/.stylelintrc.js
CHANGED
|
@@ -11,14 +11,15 @@ module.exports = {
|
|
|
11
11
|
'stylelint-config-standard',
|
|
12
12
|
'stylelint-config-recess-order'
|
|
13
13
|
],
|
|
14
|
+
<%_ if (styleSheets == supportedStyleSheets.scss || styleSheets == supportedStyleSheets.less) { _%>
|
|
14
15
|
plugins: [
|
|
15
16
|
<%_ if (styleSheets == supportedStyleSheets.scss) { _%>
|
|
16
|
-
'stylelint-scss'
|
|
17
|
-
<%_ } else
|
|
18
|
-
'stylelint-less'
|
|
17
|
+
'stylelint-scss'
|
|
18
|
+
<%_ } else { _%>
|
|
19
|
+
'stylelint-less'
|
|
19
20
|
<%_ } _%>
|
|
20
|
-
'stylelint-order'
|
|
21
21
|
],
|
|
22
|
+
<%_ } _%>
|
|
22
23
|
rules: {
|
|
23
24
|
<%_ if (styleSheets == supportedStyleSheets.scss) { _%>
|
|
24
25
|
// SCSS嵌套语法检查
|
|
@@ -36,6 +37,15 @@ module.exports = {
|
|
|
36
37
|
'less/color-no-invalid-hex': true,
|
|
37
38
|
'less/color-hex-case': 'lower',
|
|
38
39
|
<%_ } _%>
|
|
40
|
+
<%_ if (vue) {_%>
|
|
41
|
+
// 忽略:deep以及/deep/校验
|
|
42
|
+
'selector-pseudo-class-no-unknown': [
|
|
43
|
+
true,
|
|
44
|
+
{
|
|
45
|
+
ignorePseudoClasses: ['/^deep/']
|
|
46
|
+
}
|
|
47
|
+
],
|
|
48
|
+
<%_ } _%>
|
|
39
49
|
'value-keyword-case': null,
|
|
40
50
|
// 处理 Tailwind CSS 的 at-rule
|
|
41
51
|
'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) { _%>
|
|
@@ -124,7 +124,7 @@ module.exports = [
|
|
|
124
124
|
<%_ } _%>
|
|
125
125
|
// 基础 JavaScript 配置
|
|
126
126
|
{
|
|
127
|
-
files: ['**/*.js'
|
|
127
|
+
files: ['**/*.js'<%- framework == supportedFramework.react ? '\', **/*.jsx\'' : '' -%>],
|
|
128
128
|
languageOptions: {
|
|
129
129
|
ecmaVersion: 'latest',
|
|
130
130
|
sourceType: 'module',
|