Skip to content

Commit

Permalink
Merge pull request #1 from 314857493/v2.2.0-alpha
Browse files Browse the repository at this point in the history
V2.2.0
  • Loading branch information
314857493 authored Jan 27, 2022
2 parents 3781bc9 + c83f963 commit 7706775
Show file tree
Hide file tree
Showing 105 changed files with 20,741 additions and 752 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
京东科技-平台研发部 前端模板生成工具
京东科技-技术与产品创新部-应用产品部 前端模板生成工具

### 安装

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jdt-cli",
"version": "2.1.18",
"version": "2.2.0",
"description": "",
"bin": {
"jdt": "bin/jdt"
Expand Down
7 changes: 5 additions & 2 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export function cli(args) {
"vue3-project",
"react-project",
"react-ts-project",
"craco-react-ts",
],
default: "vue-project",
},
Expand All @@ -37,7 +38,8 @@ export function cli(args) {
answers.template === "vue-project" ||
answers.template === "vue3-project" ||
answers.template === "react-project" ||
answers.template === "react-ts-project"
answers.template === "react-ts-project" ||
answers.template === "craco-react-ts"
);
},
},
Expand All @@ -51,7 +53,8 @@ export function cli(args) {
answers.template === "vue-project" ||
answers.template === "vue3-project" ||
answers.template === "react-project" ||
answers.template === "react-ts-project"
answers.template === "react-ts-project" ||
answers.template === "craco-react-ts"
);
},
},
Expand Down
81 changes: 47 additions & 34 deletions src/handle.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,35 @@ async function copyConfig(to, answers) {
await write(path.join(to, "package.json"), compile(pkg)(answers), {
overwrite: true,
});
if (
answers.template === "vue-project" ||
answers.template === "vue3-project"
) {
let env = fse.readFileSync(path.join(to, "vue.config.js"), "utf-8");
await write(path.join(to, "vue.config.js"), compile(env)(answers), {
overwrite: true,
});
} else if (answers.template === "react-project") {
let env = fse.readFileSync(path.join(to, "vite.config.js"), "utf-8");
await write(path.join(to, "vite.config.js"), compile(env)(answers), {
overwrite: true,
});
} else if (answers.template === "react-ts-project") {
let env = fse.readFileSync(path.join(to, "vite.config.ts"), "utf-8");
await write(path.join(to, "vite.config.ts"), compile(env)(answers), {
overwrite: true,
});
let env;
switch (answers.template) {
case "vue-project":
case "vue3-project":
env = fse.readFileSync(path.join(to, "vue.config.js"), "utf-8");
await write(path.join(to, "vue.config.js"), compile(env)(answers), {
overwrite: true,
});
break;
case "react-project":
env = fse.readFileSync(path.join(to, "vite.config.js"), "utf-8");
await write(path.join(to, "vite.config.js"), compile(env)(answers), {
overwrite: true,
});
break;
case "react-ts-project":
env = fse.readFileSync(path.join(to, "vite.config.ts"), "utf-8");
await write(path.join(to, "vite.config.ts"), compile(env)(answers), {
overwrite: true,
});
break;
case "craco-react-ts":
env = fse.readFileSync(path.join(to, "craco.config.js"), "utf-8");
await write(path.join(to, "craco.config.js"), compile(env)(answers), {
overwrite: true,
});
break;
default:
break;
}

if (answers.install) {
Expand All @@ -36,22 +47,24 @@ async function copyConfig(to, answers) {
const { frames } = cliSpinners.dots;
process.stdout.write(`\r${frames[(i = ++i % frames.length)]} install...`);
}, cliSpinners.dots.interval);
if (
answers.template === "react-project" ||
answers.template === "react-ts-project" ||
answers.template === "vue3-project"
) {
exec(`cd ${answers.name}&&yarn`, function (err) {
clearInterval(spin);
process.stdout.clearLine();
console.log("\n完成!\n");
});
} else {
exec(`cd ${answers.name}&&npm i`, function (err) {
clearInterval(spin);
process.stdout.clearLine();
console.log("\n完成!\n");
});
switch (answers.template) {
case "react-project":
case "react-ts-project":
case "vue3-project":
case "craco-react-ts":
exec(`cd ${answers.name}&&yarn`, function (err) {
clearInterval(spin);
process.stdout.clearLine();
console.log("\n完成!\n");
});
break;
default:
exec(`cd ${answers.name}&&npm i`, function (err) {
clearInterval(spin);
process.stdout.clearLine();
console.log("\n完成!\n");
});
break;
}
}
}
Expand Down
Empty file added template/craco-react-ts/.env
Empty file.
Empty file.
11 changes: 11 additions & 0 deletions template/craco-react-ts/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
extends: [require.resolve("@umijs/fabric/dist/eslint")],
globals: {},
plugins: ["react-hooks"],
rules: {
"no-restricted-syntax": 0,
"no-param-reassign": 0,
"no-unused-expressions": 0,
"react-hooks/exhaustive-deps": 0,
},
};
23 changes: 23 additions & 0 deletions template/craco-react-ts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
4 changes: 4 additions & 0 deletions template/craco-react-ts/.husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn lint
5 changes: 5 additions & 0 deletions template/craco-react-ts/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"quotes": true,
"semi": true,
"tabWidth": 2
}
21 changes: 21 additions & 0 deletions template/craco-react-ts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 使用 create-react-app 及 craco 搭建的 react 模板

## 使用 eslint 进行格式校验

使用@umijs/fabric 作为 eslint 插件

## 使用 husky 进行提交校验

使用 husky 对提交内容进行校验

## 使用 craco 对 webpack 配置进行修改

可以使用 craco 来配置 webpack 相关内容,不需要使用 eject 对配置内容进行弹出

## 使用技术栈

vite+react+redux+react-router(v5)+ts+antd+ahooks

## 模板后端服务

[https://github.com/314857493/test-nest](https://github.com/314857493/test-nest)
82 changes: 82 additions & 0 deletions template/craco-react-ts/craco.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
const CracoLessPlugin = require("craco-less");
const path = require("path");
const TerserPlugin = require("terser-webpack-plugin");
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
const merge = require("webpack-merge");
const BundleAnalyzerPlugin =
require("webpack-bundle-analyzer").BundleAnalyzerPlugin;

module.exports = {
devServer: {
host: "{{host}}",
port: 4000,
proxy: {
"/api": {
target: "http://{{proxy}}/",
changeOrigin: true,
},
},
},
plugins: [
{
plugin: CracoLessPlugin,
options: {
lessLoaderOptions: {
lessOptions: {
javascriptEnabled: true,
modifyVars: {
"primary-color": "#4762fe",
},
},
},
},
},
],
eslint: {
enable: true,
},
typescript: {
enableTypeChecking: true,
},
webpack: {
alias: {
"@": path.resolve(__dirname, "./src"),
},
configure: (webpackConfig, { env, paths }) => {
const analyzerMode = process.env.REACT_APP_INTERACTIVE_ANALYZE
? "server"
: "json";

const assignConfig = {
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
parallel: true,
terserOptions: {
compress: {
drop_console: true,
drop_debugger: true,
pure_funcs: ["console.log", "console.info", "console.warn"],
},
format: {
comments: false,
},
},
extractComments: false,
}),
new CssMinimizerPlugin(),
],
},
};
const mergeConfig = {
plugins: [new BundleAnalyzerPlugin({ analyzerMode })],
};
const config = merge(
Object.assign(webpackConfig, assignConfig),
mergeConfig
);
return process.env.NODE_ENV === "production" ? config : webpackConfig;
},
},
};
66 changes: 66 additions & 0 deletions template/craco-react-ts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"name": "{{name}}",
"version": "0.1.0",
"scripts": {
"analyze": "REACT_APP_INTERACTIVE_ANALYZE=1 yarn build",
"start": "craco start",
"build": "craco build",
"test": "craco test",
"eject": "react-scripts eject",
"lint": "eslint . --ext .js,.ts,.jsx,tsx --ignore-path .gitignore",
"prepare": "husky install"
},
"dependencies": {
"@craco/craco": "^6.4.3",
"@reduxjs/toolkit": "^1.7.1",
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^12.0.0",
"@testing-library/user-event": "^13.2.1",
"ahooks": "^3.1.5",
"antd": "^4.18.2",
"axios": "^0.24.0",
"craco-less": "^2.0.0",
"dayjs": "^1.10.7",
"less": "^4.1.2",
"less-loader": "^10.2.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-redux": "^7.2.6",
"react-router": "^5.2.0",
"react-router-dom": "^5.2.0",
"react-scripts": "5.0.0",
"web-vitals": "^2.1.0"
},
"devDependencies": {
"@types/craco__craco": "^6.4.0",
"@types/node": "^17.0.8",
"@types/react": "^17.0.38",
"@types/react-dom": "^17.0.10",
"@types/react-redux": "^7.1.21",
"@types/react-router": "^5.1.17",
"@types/react-router-dom": "^5.3.2",
"@umijs/fabric": "^2.10.0",
"@vitejs/plugin-react": "^1.1.4",
"husky": "^7.0.4",
"typescript": "^4.4.4",
"webpack-bundle-analyzer": "^4.5.0"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
Binary file added template/craco-react-ts/public/favicon.ico
Binary file not shown.
Loading

0 comments on commit 7706775

Please sign in to comment.