@cgzair/cgz-fabric 1.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 cgzjs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # cgz-fabric
2
+
3
+ fabric 是《信息技术部前端编码手册》的配套 CLI 工具,一键接入符合前端研发部门的编码规范,提高项目研发效率。
4
+
5
+ ## 使用
6
+
7
+ 安装
8
+
9
+ ```bash
10
+ yarn add @cgzair/cgz-fabric -D
11
+ ```
12
+
13
+ ### 自动配置
14
+
15
+ 1.通过 `shell` 命令
16
+
17
+ ```bash
18
+ npx fabric install
19
+ ```
20
+
21
+ 2.通过 `npm scripts`
22
+
23
+ ```json
24
+ // package.json
25
+ {
26
+ "scripts": {
27
+ "prepare": "fabric install"
28
+ }
29
+ }
30
+ ```
31
+
32
+ ## IDE 插件配套集成
33
+
34
+ 推荐使用 `vscode` 作为开发工具,然后安装以下插件:
35
+
36
+ 1. ESLint,安装地址:<https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint>
37
+
38
+ 2. Markdownlint,安装地址:<https://marketplace.visualstudio.com/items?itemName=DavidAnson.vscode-markdownlint>
39
+
40
+ 3. Prettier,安装地址:<https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode>
41
+
42
+ 4. Stylelint,安装地址:<https://marketplace.visualstudio.com/items?itemName=stylelint.vscode-stylelint>
43
+
44
+ ## 可用选项
45
+
46
+ 帮助
47
+
48
+ ``` bash
49
+ fabric -h
50
+ ```
package/lib/cli.js ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ "use strict";var __awaiter=this&&this.__awaiter||function(e,a,c,s){return new(c=c||Promise)(function(r,t){function n(e){try{o(s.next(e))}catch(e){t(e)}}function i(e){try{o(s.throw(e))}catch(e){t(e)}}function o(e){var t;e.done?r(e.value):((t=e.value)instanceof c?t:new c(function(e){e(t)})).then(n,i)}o((s=s.apply(e,a||[])).next())})},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});const path_1=__importDefault(require("path")),commander_1=require("commander"),cgz_core_1=require("cgz-core"),install_1=__importDefault(require("./scripts/install")),extension_1=__importDefault(require("./utils/extension")),cwd=process.cwd(),currentPkg=(0,cgz_core_1.getCurrentPkg)(path_1.default.resolve(__dirname,"../"));commander_1.program.version(currentPkg.version,"-v").description(currentPkg.name+" 是《信息技术部前端编码手册》的配套 CLI 工具,一键接入符合前端研发部门的编码规范,提高项目研发效率。"),commander_1.program.command("install").alias("i").description("交互式生成适用于当前项目的编码规范").option("--vsc","写入 .vscode 推荐配置").option("--ext","安装 vscode 推荐扩展").action(e=>__awaiter(void 0,void 0,void 0,function*(){e.ext?(0,extension_1.default)():yield(0,install_1.default)({cwd:cwd},e.vsc)})),commander_1.program.parse(process.argv);
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ extends: ["cgz"],
3
+ };
@@ -0,0 +1,23 @@
1
+ # http://editorconfig.org
2
+ root = true
3
+
4
+ [*]
5
+ indent_style = space
6
+ tab_width = 2
7
+ indent_size = 2
8
+ end_of_line = lf
9
+ charset = utf-8
10
+ trim_trailing_whitespace = true
11
+ insert_final_newline = true
12
+ max_line_length = 120
13
+
14
+ [*.md]
15
+ trim_trailing_whitespace = false
16
+
17
+ [*.json]
18
+ indent_style = space
19
+ indent_size = 2
20
+ tab_width = 2
21
+
22
+ [Makefile]
23
+ indent_style = tab
@@ -0,0 +1,3 @@
1
+ statics
2
+ dist
3
+ build
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ extends: ["<%= eslint === 'javascript' ? 'eslint-config-cgz' : `eslint-config-cgz/${eslint}` %>"<%_ if (prettier) { _%>, "prettier"<%_ } _%>],
3
+ };
@@ -0,0 +1,5 @@
1
+ <%_ if (markdownlint) { _%>
2
+ {
3
+ "extends": "markdownlint-config-cgz"
4
+ }
5
+ <%_ } _%>
@@ -0,0 +1,5 @@
1
+ <%_ if (markdownlint) { _%>
2
+ <%_ markdownLintIgnores.forEach((txt) => { _%>
3
+ <%= txt %>
4
+ <% }) %>
5
+ <%_ } -%>
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ ...require("prettier-config-cgz"),
3
+ };
@@ -0,0 +1,5 @@
1
+ <%_ if (stylelint) { _%>
2
+ <%_ stylelintIgnores.forEach((txt)=> { _%>
3
+ <%= txt %>
4
+ <% }) %>
5
+ <%_ } -%>
@@ -0,0 +1,5 @@
1
+ <%_ if (stylelint) { _%>
2
+ module.exports = {
3
+ extends: "stylelint-config-cgz",
4
+ };
5
+ <%_ } _%>
@@ -0,0 +1,9 @@
1
+ {
2
+ "recommendations": [
3
+ "dbaeumer.vscode-eslint",
4
+ "stylelint.vscode-stylelint",
5
+ "esbenp.prettier-vscode",
6
+ "mrmlnc.vscode-scss",
7
+ "DavidAnson.vscode-markdownlint"
8
+ ]
9
+ }
@@ -0,0 +1,52 @@
1
+ {
2
+ "eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact", "vue"],
3
+ <%_ if (stylelint) { _%>
4
+ "stylelint.validate": [<%- stylelintExt.map((ext) => `"${ext.replace(/^\./, '')}"`).join(', ') %>],
5
+ <%_ } _%>
6
+ "editor.codeActionsOnSave": {
7
+ "source.fixAll.eslint": true<%= stylelint || markdownlint ? ',' : '' %>
8
+ <%_ if (stylelint) { _%>
9
+ "source.fixAll.stylelint": true<%= markdownlint ? ',' : '' %>
10
+ <%_ } _%>
11
+ <%_ if (markdownlint) { _%>
12
+ "source.fixAll.markdownlint": true
13
+ <%_ } _%>
14
+ },
15
+ <%_ if (prettier) { _%>
16
+ "editor.defaultFormatter": "esbenp.prettier-vscode",
17
+ "[javascript]": {
18
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
19
+ },
20
+ "[javascriptreact]": {
21
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
22
+ },
23
+ "[typescript]": {
24
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
25
+ },
26
+ "[typescriptreact]": {
27
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
28
+ },
29
+ "[vue]": {
30
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
31
+ },
32
+ "[css]": {
33
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
34
+ },
35
+ "[less]": {
36
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
37
+ },
38
+ "[scss]": {
39
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
40
+ },
41
+ "[html]": {
42
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
43
+ },
44
+ "[json]": {
45
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
46
+ },
47
+ "[jsonc]": {
48
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
49
+ },
50
+ <%_ } _%>
51
+ "editor.formatOnSave": <%= prettier ? 'true' : 'false' %>
52
+ }
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.MARKDOWN_LINT_IGNORE_PATTERN=exports.STYLELINT_IGNORE_PATTERN=exports.STYLELINT_FILE_EXT=exports.PROJECT_CATEGORYS=void 0,exports.PROJECT_CATEGORYS=[{name:"非 React、Vue、Node.js 的项目(JavaScript)",value:"javascript"},{name:"非 React、Vue、Node.js 的项目(TypeScript)",value:"typescript"},{name:"React 项目(JavaScript)",value:"react"},{name:"React 项目(TypeScript)",value:"typescript/react"},{name:"Vue 项目(JavaScript)",value:"vue"},{name:"Vue 项目(TypeScript)",value:"typescript/vue"},{name:"Node.js 项目(JavaScript)",value:"node"},{name:"Node.js 项目(TypeScript)",value:"typescript/node"},{name:"使用 ES5 及之前版本 JavaScript 的老项目",value:"es5"},{name:"uni-app 项目(JavaScript)",value:"uni-app"},{name:"uni-app 项目(TypeScript)",value:"typescript/uni-app"}],exports.STYLELINT_FILE_EXT=[".css",".scss",".less"],exports.STYLELINT_IGNORE_PATTERN=["build","statics","dist"],exports.MARKDOWN_LINT_IGNORE_PATTERN=["node_modules/","build","dist","statics"];
package/lib/index.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";var __awaiter=this&&this.__awaiter||function(t,a,u,s){return new(u=u||Promise)(function(e,i){function n(t){try{o(s.next(t))}catch(t){i(t)}}function r(t){try{o(s.throw(t))}catch(t){i(t)}}function o(t){var i;t.done?e(t.value):((i=t.value)instanceof u?i:new u(function(t){t(i)})).then(n,r)}o((s=s.apply(t,a||[])).next())})},__importDefault=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.init=void 0;const install_1=__importDefault(require("./scripts/install")),init=(t,i)=>__awaiter(void 0,void 0,void 0,function*(){return yield(0,install_1.default)(t,i)});exports.init=init;
@@ -0,0 +1 @@
1
+ "use strict";var __awaiter=this&&this.__awaiter||function(e,s,l,a){return new(l=l||Promise)(function(i,t){function n(e){try{o(a.next(e))}catch(e){t(e)}}function r(e){try{o(a.throw(e))}catch(e){t(e)}}function o(e){var t;e.done?i(e.value):((t=e.value)instanceof l?t:new l(function(e){e(t)})).then(n,r)}o((a=a.apply(e,s||[])).next())})},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});const path_1=__importDefault(require("path")),execa_1=__importDefault(require("execa")),inquirer_1=__importDefault(require("inquirer")),cgz_core_1=require("cgz-core"),extension_1=__importDefault(require("../utils/extension")),generate_template_1=__importDefault(require("../utils/generate-template")),constants_1=require("../constants");let step=0;const handleEslint=()=>__awaiter(void 0,void 0,void 0,function*(){var e=(yield inquirer_1.default.prompt({type:"list",name:"type",message:`第 ${++step} 步,请选择项目类型:`,choices:constants_1.PROJECT_CATEGORYS}))["type"];return e}),handleStylelint=t=>__awaiter(void 0,void 0,void 0,function*(){var e=(yield inquirer_1.default.prompt({type:"confirm",name:"enable",message:`第 ${++step} 步,是否启用 stylelint(若没有样式文件则不需要):`,default:t}))["enable"];return e}),handleMarkdownLint=()=>__awaiter(void 0,void 0,void 0,function*(){var e=(yield inquirer_1.default.prompt({type:"confirm",name:"enable",message:`第 ${++step} 步,是否启用 markdownlint:`,default:!0}))["enable"];return e}),handlePrettier=()=>__awaiter(void 0,void 0,void 0,function*(){var e=(yield inquirer_1.default.prompt({type:"confirm",name:"enable",message:`第 ${++step} 步,是否启用 Prettier 格式化代码(推荐始终开启):`,default:!0}))["enable"];return e});exports.default=(i,n)=>__awaiter(void 0,void 0,void 0,function*(){var e=i.cwd||process.cwd(),t={};process.chdir(e),i.eslint&&constants_1.PROJECT_CATEGORYS.some(e=>e.value===i.eslint)?t.eslint=i.eslint:t.eslint=yield handleEslint(),"boolean"==typeof i.stylelint?t.stylelint=i.stylelint:t.stylelint=yield handleStylelint(!/node/.test(t.eslint)),"boolean"==typeof i.markdownlint?t.markdownlint=i.markdownlint:t.markdownlint=yield handleMarkdownLint(),"boolean"==typeof i.prettier?t.prettier=i.prettier:t.prettier=yield handlePrettier(),cgz_core_1.log.info(`第 ${++step} 步,配置 git commit 卡点`);try{execa_1.default.sync("npx",["husky","install"],{cwd:e}),execa_1.default.sync("npx",["husky","set",".husky/commit-msg",'npx --no-install commitlint --edit "$1"'],{cwd:e}),execa_1.default.sync("npx",["husky","set",".husky/pre-commit","npx --no-install lint-staged"],{cwd:e}),(0,cgz_core_1.setScripts)("commit","git-cz",e),(0,cgz_core_1.setScripts)("postinstall","husky install",e),(0,cgz_core_1.setConfig)("config",{commitizen:{path:"@commitlint/cz-commitlint"}},e),(0,cgz_core_1.setConfig)("lint-staged",{"*.{js,jsx,tsx,ts,vue}":"eslint --cache --fix","*.{scss,less,css}":"stylelint --fix --allow-empty-input","*.md":"markdownlint --fix","*.{js,jsx,tsx,ts,vue,scss,less,css,json,html}":"prettier --write"},e),cgz_core_1.log.success("配置 git commit 卡点成功")}catch(e){cgz_core_1.log.error(e),cgz_core_1.log.error("配置 git commit 卡点失败")}cgz_core_1.log.info(`第 ${++step} 步,写入编码规范配置文件`),(0,generate_template_1.default)(e,t,n),cgz_core_1.log.success("写入编码规范配置文件成功"),cgz_core_1.log.info(`第 ${++step} 步,安装vscode 扩展`),(0,extension_1.default)(e),cgz_core_1.log.result("初始化完成",path_1.default.resolve(__dirname,"../../"),!0)});
@@ -0,0 +1 @@
1
+ "use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});const fs_1=__importDefault(require("fs")),child_process_1=require("child_process"),path_1=__importDefault(require("path")),cgz_core_1=require("cgz-core");exports.default=(e=path_1.default.resolve(__dirname,"../../../"))=>{try{(0,child_process_1.execSync)("code -v")}catch(e){return cgz_core_1.log.info("当前系统暂未安装 vscode,扩展安装已跳过,更多请参考:https://code.visualstudio.com/")}JSON.parse(fs_1.default.readFileSync(path_1.default.resolve(__dirname,"../config/_vscode/extensions.json.ejs"),"utf-8")).recommendations.forEach(e=>{cgz_core_1.log.info(`安装 ${e} ...`),(0,child_process_1.execSync)("code --install-extension "+e),cgz_core_1.log.info(e+" 安装成功")}),(0,cgz_core_1.setScripts)("extension","fabric i --ext",e),cgz_core_1.log.info("写入 vscode 扩展 scripts 配置成功"),cgz_core_1.log.success("安装推荐 vscode 扩展成功")};
@@ -0,0 +1 @@
1
+ "use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});const path_1=__importDefault(require("path")),fs_1=__importDefault(require("fs")),cgz_core_1=require("cgz-core"),lodash_1=__importDefault(require("lodash")),glob_1=__importDefault(require("glob")),ejs_1=__importDefault(require("ejs")),constants_1=require("../constants"),mergeVSCodeConfig=(e,t)=>{if(!(0,cgz_core_1.isAccessSync)(e))return t;try{var r=JSON.parse(fs_1.default.readFileSync(e,"utf8")),s=JSON.parse(t);return JSON.stringify(lodash_1.default.mergeWith(r,s,(e,t)=>{if(Array.isArray(e)&&Array.isArray(t))return lodash_1.default.union(t.concat(e))}),null,2)}catch(e){return""}};exports.default=(t,r,e,s=path_1.default.resolve(__dirname,"../config"))=>{e=glob_1.default.sync(`${e?"_vscode":"**"}/*.ejs`,{cwd:s});(0,cgz_core_1.isAccessSync)(path_1.default.resolve(t,".vscode"))||fs_1.default.mkdirSync(path_1.default.resolve(t,".vscode"));for(const a of e){var _=path_1.default.resolve(t,a.replace(/\.ejs$/,"").replace(/^_/,"."));let e=ejs_1.default.render(fs_1.default.readFileSync(path_1.default.resolve(s,a),"utf8"),Object.assign({stylelintExt:constants_1.STYLELINT_FILE_EXT,stylelintIgnores:constants_1.STYLELINT_IGNORE_PATTERN,markdownLintIgnores:constants_1.MARKDOWN_LINT_IGNORE_PATTERN},r));(e=/^_vscode/.test(a)?mergeVSCodeConfig(_,e):e).trim()&&fs_1.default.writeFileSync(_,e,"utf8")}};
package/package.json ADDED
@@ -0,0 +1,79 @@
1
+ {
2
+ "name": "@cgzair/cgz-fabric",
3
+ "version": "1.1.0",
4
+ "description": "A collection of configuration files containing prettier, eslint, stylelint, markdown",
5
+ "main": "lib/index.js",
6
+ "bin": {
7
+ "fabric": "./lib/cli.js"
8
+ },
9
+ "keywords": [
10
+ "cgz-fabric"
11
+ ],
12
+ "scripts": {
13
+ "build": "npm run copy && tsc",
14
+ "copy": "copyfiles -a -u 1 \"src/config/**\" lib",
15
+ "test": "jest",
16
+ "test-watch": "jest --watch",
17
+ "test:coverage": "nyc jest --coverage --forceExit"
18
+ },
19
+ "files": [
20
+ "lib",
21
+ "package.json",
22
+ "README.md",
23
+ "tsconfig.json"
24
+ ],
25
+ "author": "cgz",
26
+ "dependencies": {
27
+ "@babel/core": "^7.16.7",
28
+ "@babel/eslint-parser": "^7.16.5",
29
+ "@babel/plugin-proposal-class-properties": "^7.16.7",
30
+ "@babel/plugin-proposal-decorators": "^7.16.7",
31
+ "@babel/preset-env": "^7.16.10",
32
+ "@babel/preset-react": "^7.16.7",
33
+ "@babel/preset-typescript": "^7.16.7",
34
+ "@cgzair/cgz-core": "^0.3.7",
35
+ "@cgzair/commitlint-config-cgz": "^1.1.0",
36
+ "@cgzair/eslint-config-cgz": "^1.1.0",
37
+ "@cgzair/markdownlint-config-cgz": "^1.1.0",
38
+ "@cgzair/prettier-config-cgz": "^1.1.0",
39
+ "@cgzair/stylelint-config-cgz": "^1.1.0",
40
+ "@typescript-eslint/eslint-plugin": "^5.13.0",
41
+ "@typescript-eslint/parser": "^5.13.0",
42
+ "chalk": "4.1.2",
43
+ "commander": "^9.0.0",
44
+ "ejs": "^3.1.6",
45
+ "eslint-config-egg": "^11.0.1",
46
+ "eslint-config-prettier": "^8.5.0",
47
+ "eslint-plugin-import": "^2.25.4",
48
+ "eslint-plugin-jsx-a11y": "^6.5.1",
49
+ "eslint-plugin-react": "^7.28.0",
50
+ "eslint-plugin-react-hooks": "^4.3.0",
51
+ "eslint-plugin-vue": "^8.5.0",
52
+ "glob": "^7.2.0",
53
+ "inquirer": "^8.2.1",
54
+ "lint-staged": "^12.4.1",
55
+ "markdownlint-cli": "^0.31.1",
56
+ "vue-eslint-parser": "^8.3.0"
57
+ },
58
+ "devDependencies": {
59
+ "@types/ejs": "^3.1.0",
60
+ "@types/fs-extra": "^9.0.13",
61
+ "@types/glob": "^7.2.0",
62
+ "@types/inquirer": "^8.2.0",
63
+ "copyfiles": "^2.4.1",
64
+ "execa": "5.1.1",
65
+ "fs-extra": "^10.1.0",
66
+ "jest": "27.3.1",
67
+ "nyc": "^15.1.0",
68
+ "ts-node": "^10.8.1",
69
+ "typescript": "^4.4.4"
70
+ },
71
+ "publishConfig": {
72
+ "access": "public"
73
+ },
74
+ "engines": {
75
+ "node": ">=12.0.0"
76
+ },
77
+ "license": "MIT",
78
+ "gitHead": "ac4f859f68745c4250c8aab06047ce03b0de733e"
79
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es2016",
4
+ "module": "commonjs",
5
+ "rootDir": "./src",
6
+ "baseUrl": "./src",
7
+ "outDir": "./lib",
8
+ "types": ["node", "jest"],
9
+ "esModuleInterop": true,
10
+ "skipLibCheck": true,
11
+ "downlevelIteration": true,
12
+ "resolveJsonModule": true,
13
+ "declaration": false,
14
+ "strictNullChecks": true
15
+ },
16
+ "include": ["src"]
17
+ }