10 |
11 | {{ msg }}
12 |
13 |
14 | Recommended IDE setup:
15 | VSCode
16 | +
17 | Volar
18 |
19 |
20 | See README.md for more information.
21 |
22 |
23 |
24 | Vite Docs
25 |
26 | |
27 | Vue 3 Docs
28 |
29 |
30 |
31 |
32 | Edit
33 | components/HelloWorld.vue to test hot module replacement.
34 |
35 |
36 |
37 |
54 |
--------------------------------------------------------------------------------
/src/core/index.ts:
--------------------------------------------------------------------------------
1 | import { IExecOptions } from '../types'
2 | import viteRun from './viteRun'
3 | import gitInitRun from './gitInitRun'
4 | import { successLog } from '../utils'
5 | import eslintRun from './eslintRun'
6 | import prettierRun from './prettierRun'
7 | import gitHooksRun from './gitHooksRun'
8 | import startupProjectRun from './startupProjectRun'
9 | import replaceTplRun from './replaceTplRun'
10 |
11 | const execStacks = [viteRun, gitInitRun, eslintRun, prettierRun, gitHooksRun, replaceTplRun]
12 | /**
13 | * @author lihh
14 | * @description 开始执行命令
15 | * @param options 通过shell 以及入口 收集的参数
16 | */
17 | const run = async (options: IExecOptions) => {
18 | const len = execStacks.length
19 |
20 | // 表示成功的回调
21 | async function success() {
22 | successLog(`end: Project initialization succeeded`)
23 |
24 | // 启动后置钩子
25 | await startupProjectRun.apply(options)
26 | }
27 |
28 | async function next(index: number) {
29 | const instance = execStacks[index]
30 | await instance.apply({
31 | ...options, callback: async (flags?: string) => {
32 | const currentIndex = index + 1
33 | // 如果flags存在值 表示cli中途中断
34 | if (currentIndex === len || (flags && flags === 'end')) {
35 | await success()
36 | } else {
37 | await next(currentIndex)
38 | }
39 | }
40 | })
41 | }
42 |
43 | await next(0)
44 | }
45 |
46 | export default run
47 |
--------------------------------------------------------------------------------
/src/core/eslintRun.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * @author lihh
3 | * @description 需要执行的eslint命令处理
4 | */
5 | import { IExecOptions } from '../types'
6 | import getDependentPlugins from '../utils/plugins'
7 | import {
8 | copyFile,
9 | joinPath,
10 | resolvePath,
11 | runCommand,
12 | successLog,
13 | warningLog
14 | } from '../utils'
15 |
16 | class EslintRun {
17 | /**
18 | * @author lihh
19 | * @description 命令执行的入口
20 | * @param options 通过外界以及shell收集的参数
21 | */
22 | async apply(options: IExecOptions) {
23 | const { tpl, callback, tool, projectPath } = options
24 | const flags = `eslint-${tpl}`
25 |
26 | // 获取可以执行的模板
27 | const plugins = getDependentPlugins(flags)
28 | if (plugins.length === 0) {
29 | warningLog(
30 | `该脚手架暂时不支持<${flags}>, 后续逐渐支持,请持续关注. 但是vite创建的项目已经可以使用`
31 | )
32 | callback && callback('end')
33 | return
34 | }
35 |
36 | // 执行command命令
37 | await runCommand(
38 | tool,
39 | [tool === 'yarn' ? 'add' : 'install'].concat(plugins).concat(['-D']),
40 | { cwd: projectPath }
41 | )
42 | // 复制配置文件
43 | const basePath = resolvePath('./template')
44 |
45 | // 开始复制文件
46 | copyFile(
47 | joinPath(basePath, '.eslintignore'),
48 | joinPath(projectPath, '.eslintignore')
49 | )
50 | copyFile(joinPath(basePath, `language-template/${flags}`), projectPath)
51 |
52 | successLog('4. eslint configuration succeeded')
53 | callback && callback()
54 | }
55 | }
56 |
57 | export default new EslintRun()
58 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "vite-eslint-cli",
3 | "version": "1.0.1",
4 | "description": "基于vite + vue3/ vite + react等, 实现eslint prettier部署,内置vite vue3运行方式,执行代码构建以及eslint部署一体. 内置(pinia,vue-router等)",
5 | "bin": {
6 | "vite-eslint-cli": "entry/index.js"
7 | },
8 | "scripts": {
9 | "build": "rollup -c build/rollup.config.js"
10 | },
11 | "files": [
12 | "dist",
13 | "entry"
14 | ],
15 | "keywords": [
16 | "rollup",
17 | "vue3",
18 | "react",
19 | "eslint",
20 | "commitlint",
21 | "prettier"
22 | ],
23 | "repository": {
24 | "type": "git",
25 | "url": "https://github.com/a572251465/vite-eslint-cli.git"
26 | },
27 | "bugs": {
28 | "url": "https://github.com/a572251465/vite-eslint-cli/issues"
29 | },
30 | "homepage": "https://github.com/a572251465/vite-eslint-cli",
31 | "author": "lihaohao",
32 | "license": "MIT",
33 | "devDependencies": {
34 | "@rollup/plugin-commonjs": "^21.0.2",
35 | "@rollup/plugin-json": "^4.1.0",
36 | "@rollup/plugin-node-resolve": "^13.1.3",
37 | "@types/commander": "^2.12.2",
38 | "@types/node": "^17.0.21",
39 | "@types/prompts": "^2.0.14",
40 | "colors": "^1.4.0",
41 | "commander": "^9.0.0",
42 | "eslint": "^8.10.0",
43 | "fs-extra": "^10.0.1",
44 | "prettier": "^2.5.1",
45 | "prompts": "^2.4.2",
46 | "rollup": "^2.69.0",
47 | "rollup-plugin-copy": "^3.4.0",
48 | "rollup-plugin-delete": "^2.0.0",
49 | "rollup-plugin-typescript2": "^0.31.2",
50 | "tslib": "^2.3.1",
51 | "typescript": "^4.6.2"
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/.pnpm-debug.log:
--------------------------------------------------------------------------------
1 | {
2 | "0 debug pnpm:scope": {
3 | "selected": 1
4 | },
5 | "1 debug pnpm:package-manifest": {
6 | "initial": {
7 | "name": "vite-eslint-cli",
8 | "version": "1.0.0",
9 | "description": "",
10 | "main": "index.js",
11 | "scripts": {
12 | "test": "echo \"Error: no test specified\" && exit 1"
13 | },
14 | "keywords": [],
15 | "author": "",
16 | "license": "ISC"
17 | },
18 | "prefix": "F:\\my-project\\vite-eslint-cli"
19 | },
20 | "2 debug pnpm:context": {
21 | "currentLockfileExists": false,
22 | "storeDir": "F:\\.pnpm-store\\v3",
23 | "virtualStoreDir": "F:\\my-project\\vite-eslint-cli\\node_modules\\.pnpm"
24 | },
25 | "3 debug pnpm:stage": {
26 | "prefix": "F:\\my-project\\vite-eslint-cli",
27 | "stage": "resolution_started"
28 | },
29 | "4 error pnpm": {
30 | "code": "ERR_PNPM_FETCH_404",
31 | "hint": "perttier is not in the npm registry, or you have no permission to fetch it.\n\nNo authorization header was set for the request.",
32 | "request": {
33 | "url": "https://registry.npm.taobao.org/perttier"
34 | },
35 | "response": {
36 | "size": 0
37 | },
38 | "pkgName": "perttier",
39 | "pkgsStack": [],
40 | "err": {
41 | "name": "pnpm",
42 | "message": "GET https://registry.npm.taobao.org/perttier: Not Found - 404",
43 | "code": "ERR_PNPM_FETCH_404",
44 | "stack": "pnpm: GET https://registry.npm.taobao.org/perttier: Not Found - 404\n at RetryOperation._fn (C:\\Users\\Lenovo\\AppData\\Roaming\\npm\\node_modules\\pnpm\\dist\\pnpm.cjs:85680:19)\n at processTicksAndRejections (internal/process/task_queues.js:95:5)"
45 | }
46 | }
47 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |