ljr-cli 1.0.0 → 1.0.2
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/lib/demo1.js +39 -0
- package/lib/demo2.js +87 -0
- package/lib/index.js +220 -14
- package/lib/templates/flutter//346/210/221/346/230/257flutter.txt +0 -0
- package/lib/templates/java//346/210/221/346/230/257java.txt +0 -0
- package/lib/templates/monorepo//346/210/221/346/230/257monorepo.txt +0 -0
- package/lib/templates/mysql//346/210/221/346/230/257mysql.txt +0 -0
- package/lib/templates/node//346/210/221/346/230/257node.txt +0 -0
- package/lib/templates/qiankun//346/210/221/346/230/257qiankun.txt +0 -0
- package/lib/templates/react//346/210/221/346/230/257react.txt +0 -0
- package/lib/templates/uni-app//346/210/221/346/230/257uni-app.txt +0 -0
- package/lib/templates/vue2.7.16/.browserslistrc +3 -0
- package/lib/templates/vue2.7.16/.env +4 -0
- package/lib/templates/vue2.7.16/.env.development +7 -0
- package/lib/templates/vue2.7.16/.env.production +7 -0
- package/lib/templates/vue2.7.16/.eslintignore +3 -0
- package/lib/templates/vue2.7.16/.eslintrc.js +21 -0
- package/lib/templates/vue2.7.16/.prettierrc.js +11 -0
- package/lib/templates/vue2.7.16/.vscode/settings.json +10 -0
- package/lib/templates/vue2.7.16/README.md +71 -0
- package/lib/templates/vue2.7.16/babel.config.js +3 -0
- package/lib/templates/vue2.7.16/jsconfig.json +19 -0
- package/lib/templates/vue2.7.16/package.json +41 -0
- package/lib/templates/vue2.7.16/pnpm-lock.yaml +8171 -0
- package/lib/templates/vue2.7.16/public/favicon.svg +14 -0
- package/lib/templates/vue2.7.16/public/index.html +20 -0
- package/lib/templates/vue2.7.16/src/App.vue +14 -0
- package/lib/templates/vue2.7.16/src/api/interface/index.js +6 -0
- package/lib/templates/vue2.7.16/src/api/request.js +121 -0
- package/lib/templates/vue2.7.16/src/api/server/index.js +6 -0
- package/lib/templates/vue2.7.16/src/assets/logo.png +0 -0
- package/lib/templates/vue2.7.16/src/components/README.md +5 -0
- package/lib/templates/vue2.7.16/src/components/baseInfo/index.vue +29 -0
- package/lib/templates/vue2.7.16/src/components/baseInfo/item.vue +64 -0
- package/lib/templates/vue2.7.16/src/components/index.js +14 -0
- package/lib/templates/vue2.7.16/src/components/layout/left-menu-and-top-info.vue +121 -0
- package/lib/templates/vue2.7.16/src/components/pagination/index.vue +52 -0
- package/lib/templates/vue2.7.16/src/css/coverage-style.css +6 -0
- package/lib/templates/vue2.7.16/src/directive/index.js +16 -0
- package/lib/templates/vue2.7.16/src/directive/input-number.js +18 -0
- package/lib/templates/vue2.7.16/src/directive/permission.js +52 -0
- package/lib/templates/vue2.7.16/src/directive/re-click.js +12 -0
- package/lib/templates/vue2.7.16/src/global-config.js +12 -0
- package/lib/templates/vue2.7.16/src/main.js +79 -0
- package/lib/templates/vue2.7.16/src/prototype/README.md +1 -0
- package/lib/templates/vue2.7.16/src/prototype/el-dialog.js +127 -0
- package/lib/templates/vue2.7.16/src/prototype/index.js +53 -0
- package/lib/templates/vue2.7.16/src/router/index.js +257 -0
- package/lib/templates/vue2.7.16/src/store/index.js +50 -0
- package/lib/templates/vue2.7.16/src/store/modules/dd.js +128 -0
- package/lib/templates/vue2.7.16/src/store/modules/permissions.js +24 -0
- package/lib/templates/vue2.7.16/src/views/404.vue +7 -0
- package/lib/templates/vue2.7.16/src/views/Pitfalls//345/206/205/345/255/230/346/272/242/345/207/272/index.vue +56 -0
- package/lib/templates/vue2.7.16/src/views/Pitfalls//345/206/205/345/255/230/346/272/242/345/207/272//351/200/240/346/210/220vue2/345/206/205/345/255/230/346/272/242/345/207/272/347/232/204/345/257/271/350/261/241.js +33518 -0
- package/lib/templates/vue2.7.16/src/views/about.vue +5 -0
- package/lib/templates/vue2.7.16/src/views/demo//345/205/250/345/261/200store/346/225/260/346/215/256/345/255/227/345/205/270/index.vue +85 -0
- package/lib/templates/vue2.7.16/src/views/demo//345/205/250/345/261/200/345/274/271/347/252/227/ce.vue +42 -0
- package/lib/templates/vue2.7.16/src/views/demo//345/205/250/345/261/200/345/274/271/347/252/227/index.vue +24 -0
- package/lib/templates/vue2.7.16/src/views/demo//345/205/250/345/261/200/346/214/207/344/273/244/index.vue +78 -0
- package/lib/templates/vue2.7.16/src/views/demo//350/257/267/346/261/202/347/244/272/344/276/213/index.vue +51 -0
- package/lib/templates/vue2.7.16/src/views/home.vue +3 -0
- package/lib/templates/vue2.7.16/src/views/login.vue +67 -0
- package/lib/templates/vue2.7.16/src/views/template/base-info.vue +29 -0
- package/lib/templates/vue2.7.16/src/views/template/base-info2.vue +56 -0
- package/lib/templates/vue2.7.16/src/views/template/list/ce.vue +58 -0
- package/lib/templates/vue2.7.16/src/views/template/list/index.vue +111 -0
- package/lib/templates/vue2.7.16/src/views/template/list/search.vue +60 -0
- package/lib/templates/vue2.7.16/vue.config.js +26 -0
- package/lib/templates/vue3.5.25-2025.12.4/.editorconfig +8 -0
- package/lib/templates/vue3.5.25-2025.12.4/.gitattributes +1 -0
- package/lib/templates/vue3.5.25-2025.12.4/.prettierrc.json +11 -0
- package/lib/templates/vue3.5.25-2025.12.4/.vscode/extensions.json +8 -0
- package/lib/templates/vue3.5.25-2025.12.4/.vscode/settings.json +13 -0
- package/lib/templates/vue3.5.25-2025.12.4/README.md +93 -0
- package/lib/templates/vue3.5.25-2025.12.4/auto-imports.d.ts +78 -0
- package/lib/templates/vue3.5.25-2025.12.4/components.d.ts +28 -0
- package/lib/templates/vue3.5.25-2025.12.4/env.d.ts +1 -0
- package/lib/templates/vue3.5.25-2025.12.4/eslint.config.ts +32 -0
- package/lib/templates/vue3.5.25-2025.12.4/index.html +13 -0
- package/lib/templates/vue3.5.25-2025.12.4/package.json +47 -0
- package/lib/templates/vue3.5.25-2025.12.4/pnpm-lock.yaml +3515 -0
- package/lib/templates/vue3.5.25-2025.12.4/public/favicon.svg +14 -0
- package/lib/templates/vue3.5.25-2025.12.4/src/App.vue +12 -0
- package/lib/templates/vue3.5.25-2025.12.4/src/assets/vue.svg +1 -0
- package/lib/templates/vue3.5.25-2025.12.4/src/boot/index.ts +14 -0
- package/lib/templates/vue3.5.25-2025.12.4/src/boot/pinia.ts +10 -0
- package/lib/templates/vue3.5.25-2025.12.4/src/boot/router.ts +10 -0
- package/lib/templates/vue3.5.25-2025.12.4/src/boot/style.ts +9 -0
- package/lib/templates/vue3.5.25-2025.12.4/src/css/coverage-style.css +6 -0
- package/lib/templates/vue3.5.25-2025.12.4/src/directive/index.js +8 -0
- package/lib/templates/vue3.5.25-2025.12.4/src/directive/rememberScrollPosition.ts +17 -0
- package/lib/templates/vue3.5.25-2025.12.4/src/main.ts +7 -0
- package/lib/templates/vue3.5.25-2025.12.4/src/router/index.ts +20 -0
- package/lib/templates/vue3.5.25-2025.12.4/src/stores/counter.ts +12 -0
- package/lib/templates/vue3.5.25-2025.12.4/src/views/AboutView.vue +3 -0
- package/lib/templates/vue3.5.25-2025.12.4/src/views/HomeView.vue +14 -0
- package/lib/templates/vue3.5.25-2025.12.4/tsconfig.app.json +12 -0
- package/lib/templates/vue3.5.25-2025.12.4/tsconfig.json +11 -0
- package/lib/templates/vue3.5.25-2025.12.4/tsconfig.node.json +19 -0
- package/lib/templates/vue3.5.25-2025.12.4/vite.config.ts +31 -0
- package/lib/templates/wx-miniapp//346/210/221/346/230/257wx-miniapp.txt +0 -0
- package/package.json +16 -3
package/lib/demo1.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { program } from "commander"
|
|
4
|
+
import gradient from "gradient-string"
|
|
5
|
+
import { readFileSync } from "fs"
|
|
6
|
+
import { fileURLToPath } from "url"
|
|
7
|
+
import path from "path"
|
|
8
|
+
|
|
9
|
+
/** 渐变字符串 */
|
|
10
|
+
const gradientString = (str, gradientColor = ["#42d392", "#647eff"]) => {
|
|
11
|
+
return gradient(gradientColor)(str)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
console.log(
|
|
15
|
+
gradientString(`------------------------------- ljr-cli --------------------------------`, ["red", "yellow"]),
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
// 读取 package.json 里的 version(在 ESM 下安全做法)
|
|
19
|
+
// 当前运行文件的路径
|
|
20
|
+
const __filename = fileURLToPath(import.meta.url)
|
|
21
|
+
// 当前运行文件的文件夹
|
|
22
|
+
const __dirname = path.dirname(__filename)
|
|
23
|
+
const pkg = JSON.parse(readFileSync(path.join(__dirname, "../package.json"), "utf-8"))
|
|
24
|
+
const version = pkg.version
|
|
25
|
+
|
|
26
|
+
program.version(version, "-v, --version", "查看版本号信息")
|
|
27
|
+
|
|
28
|
+
program
|
|
29
|
+
.command("init <name>")
|
|
30
|
+
.description("demo1演示")
|
|
31
|
+
.option("-l, --local", "从本地模板创建目录")
|
|
32
|
+
.option("-g, --git", "从git地址创建目录")
|
|
33
|
+
.action((name, options) => {
|
|
34
|
+
console.log("参数name=====>", name)
|
|
35
|
+
console.log("选项options=====>", options)
|
|
36
|
+
// 这里就是你真正要做的事情了
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
program.parse(process.argv)
|
package/lib/demo2.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { program } from "commander"
|
|
4
|
+
import gradient from "gradient-string"
|
|
5
|
+
import * as prompts from "@clack/prompts"
|
|
6
|
+
import { readFileSync } from "fs"
|
|
7
|
+
import { fileURLToPath } from "url"
|
|
8
|
+
import path from "path"
|
|
9
|
+
|
|
10
|
+
/** 渐变字符串 */
|
|
11
|
+
const gradientString = (str, gradientColor = ["#42d392", "#647eff"]) => {
|
|
12
|
+
return gradient(gradientColor)(str)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
console.log(
|
|
16
|
+
gradientString(`------------------------------- ljr-cli --------------------------------`, ["red", "yellow"]),
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
// 读取 package.json 里的 version(在 ESM 下安全做法)
|
|
20
|
+
// 当前运行文件的路径
|
|
21
|
+
const __filename = fileURLToPath(import.meta.url)
|
|
22
|
+
// 当前运行文件的文件夹
|
|
23
|
+
const __dirname = path.dirname(__filename)
|
|
24
|
+
const pkg = JSON.parse(readFileSync(path.join(__dirname, "../package.json"), "utf-8"))
|
|
25
|
+
const version = pkg.version
|
|
26
|
+
|
|
27
|
+
program.version(version, "-v, --version", "查看版本号信息")
|
|
28
|
+
|
|
29
|
+
// 案例2
|
|
30
|
+
program
|
|
31
|
+
.command("init")
|
|
32
|
+
.description("demo2演示")
|
|
33
|
+
.action(async () => {
|
|
34
|
+
prompts.intro(gradientString("创建项目"))
|
|
35
|
+
|
|
36
|
+
const group = await prompts.group(
|
|
37
|
+
{
|
|
38
|
+
name: () =>
|
|
39
|
+
prompts.text({
|
|
40
|
+
message: "请输入项目名称:",
|
|
41
|
+
placeholder: "项目名称",
|
|
42
|
+
validate: (value) => {
|
|
43
|
+
if (!value.trim().length) {
|
|
44
|
+
return "请输入项目名称"
|
|
45
|
+
}
|
|
46
|
+
if (/[^a-z-_]+/i.test(value)) {
|
|
47
|
+
return "英文开头或下划线开头,且只能包含英文、数字、下划线或中划线"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
}),
|
|
51
|
+
template: () =>
|
|
52
|
+
prompts.select({
|
|
53
|
+
message: "请选择模板:",
|
|
54
|
+
options: [
|
|
55
|
+
{ label: "vue3.x", value: "vue3.x", hint: "vue3项目" },
|
|
56
|
+
{ label: "vue2.7.16", value: "vue2.7.16", hint: "vue2的最后一个版本" },
|
|
57
|
+
],
|
|
58
|
+
}),
|
|
59
|
+
age: () => prompts.text({ message: "What is your age?" }),
|
|
60
|
+
shouldContinue: () =>
|
|
61
|
+
prompts.confirm({
|
|
62
|
+
message: "是否继续?",
|
|
63
|
+
}),
|
|
64
|
+
color: ({ results }) =>
|
|
65
|
+
prompts.multiselect({
|
|
66
|
+
message: `What is your favorite color ${results.name}?`,
|
|
67
|
+
options: [
|
|
68
|
+
{ value: "red", label: "Red" },
|
|
69
|
+
{ value: "green", label: "Green" },
|
|
70
|
+
{ value: "blue", label: "Blue" },
|
|
71
|
+
],
|
|
72
|
+
}),
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
onCancel: ({ results }) => {
|
|
76
|
+
prompts.cancel("取消操作!")
|
|
77
|
+
process.exit(0)
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
console.log("group=====>", group)
|
|
83
|
+
|
|
84
|
+
prompts.outro(gradientString("项目创建完成"))
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
program.parse(process.argv)
|
package/lib/index.js
CHANGED
|
@@ -1,23 +1,229 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// 第一行固定写法,指定脚本的解释器路径(注意:第一行不要添加注释啥的,不然运行不起来)
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
import { program } from "commander"
|
|
4
|
+
import gradient from "gradient-string"
|
|
5
|
+
import * as prompts from "@clack/prompts"
|
|
6
|
+
import { readFileSync, existsSync } from "fs"
|
|
7
|
+
import { copySync, emptyDirSync } from "fs-extra/esm"
|
|
8
|
+
import { fileURLToPath } from "url"
|
|
9
|
+
import path from "path"
|
|
10
|
+
import { dateFormat } from "l-global/utils/date.js"
|
|
11
|
+
import download from "download-git-repo"
|
|
12
|
+
import { replaceInFile } from "replace-in-file"
|
|
5
13
|
|
|
6
|
-
|
|
7
|
-
const
|
|
14
|
+
/** 渐变字符串 */
|
|
15
|
+
const gradientString = (str, gradientColor = ["#42d392", "#647eff"]) => {
|
|
16
|
+
return gradient(gradientColor)(str)
|
|
17
|
+
}
|
|
8
18
|
|
|
9
|
-
|
|
19
|
+
console.log(
|
|
20
|
+
gradientString(`------------------------------- ljr-cli --------------------------------`, ["red", "yellow"]),
|
|
21
|
+
)
|
|
22
|
+
program.hook("preAction", () => {
|
|
23
|
+
console.log(gradientString(`-------------------- 开始时间 - ${dateFormat()} --------------------`, ["red", "yellow"]))
|
|
24
|
+
})
|
|
25
|
+
program.hook("postAction", () => {
|
|
26
|
+
console.log(gradientString(`-------------------- 结束时间 - ${dateFormat()} --------------------`, ["red", "yellow"]))
|
|
27
|
+
})
|
|
10
28
|
|
|
29
|
+
// 读取 package.json 里的 version(在 ESM 下安全做法)
|
|
30
|
+
// 当前运行文件的路径
|
|
31
|
+
const __filename = fileURLToPath(import.meta.url)
|
|
32
|
+
// 当前运行文件的文件夹
|
|
33
|
+
const __dirname = path.dirname(__filename)
|
|
34
|
+
const pkg = JSON.parse(readFileSync(path.join(__dirname, "../package.json"), "utf-8"))
|
|
35
|
+
const version = pkg.version
|
|
36
|
+
|
|
37
|
+
// 当前命令行的路径
|
|
38
|
+
const cwdPath = process.cwd()
|
|
39
|
+
|
|
40
|
+
program.version(version, "-v, --version", "查看版本号信息")
|
|
41
|
+
|
|
42
|
+
function downloadTemplate(gitUrl, projectName) {
|
|
43
|
+
return new Promise((resolve, reject) => {
|
|
44
|
+
download(gitUrl, path.resolve(cwdPath, projectName), { clone: true }, function (err) {
|
|
45
|
+
if (err) {
|
|
46
|
+
return reject(err)
|
|
47
|
+
}
|
|
48
|
+
resolve()
|
|
49
|
+
})
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// 初始化项目
|
|
11
54
|
program
|
|
12
|
-
.command("init
|
|
13
|
-
.description("创建项目")
|
|
14
|
-
.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
55
|
+
.command("init")
|
|
56
|
+
.description("创建项目")
|
|
57
|
+
.action(async () => {
|
|
58
|
+
prompts.intro(gradientString("开始创建项目"))
|
|
59
|
+
|
|
60
|
+
const group = await prompts.group(
|
|
61
|
+
{
|
|
62
|
+
name: () =>
|
|
63
|
+
prompts.text({
|
|
64
|
+
message: "请输入项目名称:",
|
|
65
|
+
placeholder: "项目名称",
|
|
66
|
+
validate: (value) => {
|
|
67
|
+
if (!value.trim().length) {
|
|
68
|
+
return "请输入项目名称"
|
|
69
|
+
}
|
|
70
|
+
if (/[^a-z-_]+/i.test(value)) {
|
|
71
|
+
return "英文开头或下划线开头,且只能包含英文、数字、下划线或中划线"
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
}),
|
|
75
|
+
templateName: () =>
|
|
76
|
+
prompts.select({
|
|
77
|
+
message: "请选择模板:",
|
|
78
|
+
options: [
|
|
79
|
+
{ label: "vue3.5.25-2025.12.4", value: "vue3.5.25-2025.12.4", hint: "2025.12.4创建的" },
|
|
80
|
+
{ label: "vue2.7.16", value: "vue2.7.16", hint: "vue2项目,这是vue2的最后一个版本" },
|
|
81
|
+
{ label: "react", value: "react", hint: "react项目" },
|
|
82
|
+
{ label: "qiankun", value: "qiankun", hint: "微前端-乾坤版本" },
|
|
83
|
+
{ label: "monorepo", value: "monorepo", hint: "monorepo架构-单仓库多项目" },
|
|
84
|
+
{ label: "node", value: "node", hint: "node服务" },
|
|
85
|
+
{ label: "java", value: "java", hint: "java服务" },
|
|
86
|
+
{ label: "mysql", value: "mysql", hint: "mysql数据库" },
|
|
87
|
+
{ label: "wx-miniapp", value: "wx-miniapp", hint: "微信原生小程序" },
|
|
88
|
+
{ label: "uni-app", value: "uni-app", hint: "uni-app项目" },
|
|
89
|
+
{ label: "flutter", value: "flutter", hint: "flutter项目" },
|
|
90
|
+
],
|
|
91
|
+
}),
|
|
92
|
+
source: () =>
|
|
93
|
+
prompts.select({
|
|
94
|
+
message: "请选择来源:",
|
|
95
|
+
options: [
|
|
96
|
+
{ label: "本地", value: "local", hint: "从本地模板创建" },
|
|
97
|
+
{
|
|
98
|
+
label: "git仓库",
|
|
99
|
+
value: "git",
|
|
100
|
+
hint: "从git地址创建,这里为了演示,只是随便用了个git仓库,并不是真正的模版仓库",
|
|
101
|
+
},
|
|
102
|
+
],
|
|
103
|
+
}),
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
onCancel: ({ results }) => {
|
|
107
|
+
prompts.cancel("取消操作!")
|
|
108
|
+
process.exit(0)
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
const s = prompts.spinner({ indicator: "timer" })
|
|
114
|
+
|
|
115
|
+
// 判断文件夹是否存在,存在询问是否清空
|
|
116
|
+
if (existsSync(group.name)) {
|
|
117
|
+
const confirm = await prompts.confirm({
|
|
118
|
+
message: gradientString("文件夹已存在,是否清空?", ["red", "red"]),
|
|
119
|
+
})
|
|
120
|
+
if (confirm) {
|
|
121
|
+
emptyDirSync(group.name)
|
|
122
|
+
} else {
|
|
123
|
+
prompts.cancel("取消操作!")
|
|
124
|
+
process.exit(0)
|
|
125
|
+
}
|
|
126
|
+
} else {
|
|
127
|
+
emptyDirSync(group.name)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
s.start("创建文件夹...")
|
|
131
|
+
s.stop("文件夹操作完成!")
|
|
132
|
+
|
|
133
|
+
s.start("写入模版中...")
|
|
134
|
+
try {
|
|
135
|
+
if (group.source === "local") {
|
|
136
|
+
// 源路径
|
|
137
|
+
const srcPath = path.join(__dirname, "/templates/", group.templateName)
|
|
138
|
+
// 目标路径
|
|
139
|
+
const destPath = `./${group.name}`
|
|
140
|
+
|
|
141
|
+
copySync(srcPath, destPath, {
|
|
142
|
+
recursive: true,
|
|
143
|
+
filter: (src) => {
|
|
144
|
+
// 相对于模板根的相对路径
|
|
145
|
+
const rel = path.relative(srcPath, src)
|
|
146
|
+
// 根目录本身允许
|
|
147
|
+
if (!rel) return true
|
|
148
|
+
const parts = rel.split(path.sep)
|
|
149
|
+
// 如果路径中包含 node_modules 或 dist 则过滤掉
|
|
150
|
+
if (parts.includes("node_modules") || parts.includes("dist") || parts.includes(".eslintcache")) {
|
|
151
|
+
return false
|
|
152
|
+
}
|
|
153
|
+
return true
|
|
154
|
+
},
|
|
155
|
+
})
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (group.source === "git") {
|
|
159
|
+
await downloadTemplate("direct:https://gitee.com/ljr-395181403/git-test.git#master", group.name)
|
|
160
|
+
}
|
|
161
|
+
} catch (error) {
|
|
162
|
+
console.log("error=====>", error)
|
|
163
|
+
prompts.cancel("模版写入失败!")
|
|
164
|
+
process.exit(0)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
await new Promise((resolve) => setTimeout(resolve, 2000)) // 为了更好的演示效果,强制等待
|
|
168
|
+
s.stop("模版写入完成!")
|
|
169
|
+
|
|
170
|
+
// 判断package.json是否存在
|
|
171
|
+
if (existsSync(path.join(cwdPath, group.name, "package.json"))) {
|
|
172
|
+
s.start("项目名操作...")
|
|
173
|
+
try {
|
|
174
|
+
const pkgFile = path.join(cwdPath, group.name, "package.json")
|
|
175
|
+
await replaceInFile({
|
|
176
|
+
files: pkgFile,
|
|
177
|
+
from: /("name"\s*:\s*)".*?"/,
|
|
178
|
+
to: `$1"${group.name}"`,
|
|
179
|
+
})
|
|
180
|
+
} catch (err) {
|
|
181
|
+
console.error("替换 package.json name 失败:", err)
|
|
182
|
+
prompts.cancel("项目名修改失败")
|
|
183
|
+
process.exit(1)
|
|
184
|
+
}
|
|
185
|
+
await new Promise((resolve) => setTimeout(resolve, 1000)) // 为了更好的演示效果,强制等待
|
|
186
|
+
s.stop("项目名操作完成!")
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
prompts.outro(gradientString("项目创建完成! 🎉"))
|
|
20
190
|
})
|
|
21
191
|
|
|
22
|
-
//
|
|
192
|
+
// 同步文件
|
|
193
|
+
program
|
|
194
|
+
.command("sync")
|
|
195
|
+
.description("同步文件")
|
|
196
|
+
.action(async () => {
|
|
197
|
+
prompts.intro(gradientString("开始同步"))
|
|
198
|
+
|
|
199
|
+
try {
|
|
200
|
+
// 本程序所在包里 node_modules/l-global 的路径
|
|
201
|
+
const moduleBase = path.join(__dirname, "../node_modules/l-global")
|
|
202
|
+
const cssSrc = path.join(moduleBase, "css")
|
|
203
|
+
const utilsSrc = path.join(moduleBase, "utils")
|
|
204
|
+
// 当前命令行运行路径下的目标 src 文件夹
|
|
205
|
+
const destBase = path.join(cwdPath, "src")
|
|
206
|
+
|
|
207
|
+
// 逐项拷贝(fs-extra.copySync 会自动创建目标父目录)
|
|
208
|
+
if (existsSync(cssSrc)) {
|
|
209
|
+
copySync(cssSrc, path.join(destBase, "css"), { recursive: true, overwrite: true })
|
|
210
|
+
console.log("已复制:l-global/css -> src/css")
|
|
211
|
+
} else {
|
|
212
|
+
console.warn("未找到 l-global/css:", cssSrc)
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (existsSync(utilsSrc)) {
|
|
216
|
+
copySync(utilsSrc, path.join(destBase, "utils"), { recursive: true, overwrite: true })
|
|
217
|
+
console.log("已复制:l-global/utils -> src/utils")
|
|
218
|
+
} else {
|
|
219
|
+
console.warn("未找到 l-global/utils:", utilsSrc)
|
|
220
|
+
}
|
|
221
|
+
} catch (err) {
|
|
222
|
+
console.error("同步出错:", err)
|
|
223
|
+
prompts.cancel("同步失败")
|
|
224
|
+
process.exit(1)
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
prompts.outro(gradientString("同步完成! 🎉"))
|
|
228
|
+
})
|
|
23
229
|
program.parse(process.argv)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
root: true,
|
|
3
|
+
env: {
|
|
4
|
+
node: true,
|
|
5
|
+
},
|
|
6
|
+
extends: ["plugin:vue/essential", "eslint:recommended", "plugin:prettier/recommended"],
|
|
7
|
+
parserOptions: {
|
|
8
|
+
parser: "@babel/eslint-parser",
|
|
9
|
+
},
|
|
10
|
+
rules: {
|
|
11
|
+
semi: ["error", "never"], // 不允许将分号作为语句的结尾
|
|
12
|
+
indent: ["error", 2, { SwitchCase: 1 }], // 强制执行一致的缩进风格
|
|
13
|
+
quotes: ["error", "double", { avoidEscape: true, allowTemplateLiterals: true }], // 使用双引号
|
|
14
|
+
"no-unused-vars": ["off", { vars: "all", args: "none" }], // 有没有未使用的变量
|
|
15
|
+
"no-console": process.env.NODE_ENV === "production" ? "warn" : "off", // console是否要警告
|
|
16
|
+
"no-debugger": process.env.NODE_ENV === "production" ? "warn" : "off", // debugger是否要警告
|
|
17
|
+
"spaced-comment": ["error", "always", { markers: ["/"] }], // 注释 // 或 /* 开始后的间距的一致性
|
|
18
|
+
"vue/multi-word-component-names": "off", // 组件名是否多单词
|
|
19
|
+
"vue/attributes-order": "error", // vue属性排序
|
|
20
|
+
},
|
|
21
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
$schema: "https://json.schemastore.org/prettierrc",
|
|
3
|
+
printWidth: 120, // 一行的字符数,如果超过会进行换行,默认为80
|
|
4
|
+
semi: false, // 句尾是否添加分号
|
|
5
|
+
tabWidth: 2, // 一个tab代表几个空格数,默认为2
|
|
6
|
+
useTabs: false, // 是否使用tab进行缩进,默认为false,表示用空格进行缩减
|
|
7
|
+
singleQuote: false, // 字符串是否使用单引号,默认为false,使用双引号
|
|
8
|
+
trailingComma: "all", // 是否使用尾逗号,有三个可选值"<none|es5|all>"
|
|
9
|
+
bracketSpacing: true, // 对象大括号直接是否有空格,默认为true,效果:{ foo: bar }
|
|
10
|
+
endOfLine: "auto", // 避免报错delete (cr)的错
|
|
11
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"eslint.validate": ["javascript", "html", "vue"], // eslint指定要执行验证的文件
|
|
3
|
+
"editor.codeActionsOnSave": {
|
|
4
|
+
"source.fixAll.eslint": "explicit" // 显示保存时执行eslint程序
|
|
5
|
+
},
|
|
6
|
+
"editor.formatOnPaste": false, // 粘贴时自动格式化
|
|
7
|
+
"editor.formatOnSave": true, // 保存时自动格式化
|
|
8
|
+
"editor.formatOnType": false, // 控制编辑器在键入一行后,是否自动格式化该行
|
|
9
|
+
"editor.defaultFormatter": "esbenp.prettier-vscode" // 默认格式化程序
|
|
10
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# vue2.7.16 模版
|
|
2
|
+
|
|
3
|
+
此项目使用 vue-cli 搭建的 vue2.7.16 的最新版本,此版本应该是 vue2 最后一个版本了
|
|
4
|
+
引入 l-global 包,包括 variable.css、base.css、global.css 和 utils 工具类
|
|
5
|
+
引入 element-ui
|
|
6
|
+
做了登录页,404 页
|
|
7
|
+
做了通过路由配置生成左侧菜单
|
|
8
|
+
使用 vuex-persist 插件做 vuex 持久化
|
|
9
|
+
封装了全局登录判断的路由卫士
|
|
10
|
+
eslint + prettier
|
|
11
|
+
axios 封装
|
|
12
|
+
封装自定义指令
|
|
13
|
+
封装自动注册全局组件
|
|
14
|
+
封装函数式弹窗
|
|
15
|
+
封装 store 的数据字典
|
|
16
|
+
原型扩展
|
|
17
|
+
收集一些模版
|
|
18
|
+
收集一些遇到的问题
|
|
19
|
+
收集一些动画
|
|
20
|
+
列表的模版,顶部搜索,中间表格,底下分页,新建编辑弹窗,删除二次确认模版
|
|
21
|
+
|
|
22
|
+
## 初始化(必须在当前根目录执行)
|
|
23
|
+
|
|
24
|
+
##### 此项目使用 pnpm 作为包管理工具
|
|
25
|
+
|
|
26
|
+
首次使用 corepack 需要先启用
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
corepack enable
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
使用最新版本 pnpm (需要更新最新版 pnpm 再使用)
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
corepack use pnpm@latest
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
初始化依赖
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
pnpm install
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### 项目运行
|
|
45
|
+
|
|
46
|
+
```sh
|
|
47
|
+
pnpm run dev || pnpm run serve
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### 项目打包
|
|
51
|
+
|
|
52
|
+
```sh
|
|
53
|
+
pnpm run build
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### 检查和修复文件
|
|
57
|
+
|
|
58
|
+
```sh
|
|
59
|
+
pnpm run lint
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### 命名规范
|
|
63
|
+
|
|
64
|
+
| 类别 | 推荐命名方式 | 示例 | 关键点/例外情况 |
|
|
65
|
+
| ------------------ | ----------------------------------------------- | ----------------- | ---------------------- |
|
|
66
|
+
| 通用 | kebab-case | package-lock.json | 没有特别说明尽量用这个 |
|
|
67
|
+
| 变量 | camelCase | userProfile | |
|
|
68
|
+
| 路由名称 | camelCase 或者 PascalCase | userProfile | |
|
|
69
|
+
| App.vue | PascalCase | | |
|
|
70
|
+
| Vue 组件里的组件名 | PascalCase | | |
|
|
71
|
+
| Vue 组件里的 Props | 在声明时使用 camelCase,在模板中使用 kebab-case | | |
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es5",
|
|
4
|
+
"module": "esnext",
|
|
5
|
+
"baseUrl": "./",
|
|
6
|
+
"moduleResolution": "node",
|
|
7
|
+
"paths": {
|
|
8
|
+
"@/*": [
|
|
9
|
+
"src/*"
|
|
10
|
+
]
|
|
11
|
+
},
|
|
12
|
+
"lib": [
|
|
13
|
+
"esnext",
|
|
14
|
+
"dom",
|
|
15
|
+
"dom.iterable",
|
|
16
|
+
"scripthost"
|
|
17
|
+
]
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "vue2.7.16",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"packageManager": "pnpm@10.27.0",
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": ">=22.18.0"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"dev": "vue-cli-service serve --port 9999",
|
|
11
|
+
"serve": "vue-cli-service serve --port 9999",
|
|
12
|
+
"build": "vue-cli-service build",
|
|
13
|
+
"lint": "vue-cli-service lint"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"axios": "^1.13.2",
|
|
17
|
+
"core-js": "^3.8.3",
|
|
18
|
+
"element-ui": "^2.15.14",
|
|
19
|
+
"l-global": "^1.0.2",
|
|
20
|
+
"lodash": "^4.17.21",
|
|
21
|
+
"vue": "^2.6.14",
|
|
22
|
+
"vue-router": "^3.5.1",
|
|
23
|
+
"vuex": "^3.6.2",
|
|
24
|
+
"vuex-persist": "^3.1.3"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@babel/core": "^7.12.16",
|
|
28
|
+
"@babel/eslint-parser": "^7.12.16",
|
|
29
|
+
"@vue/cli-plugin-babel": "~5.0.0",
|
|
30
|
+
"@vue/cli-plugin-eslint": "~5.0.0",
|
|
31
|
+
"@vue/cli-plugin-router": "~5.0.0",
|
|
32
|
+
"@vue/cli-plugin-vuex": "~5.0.0",
|
|
33
|
+
"@vue/cli-service": "~5.0.0",
|
|
34
|
+
"eslint": "^7.32.0",
|
|
35
|
+
"eslint-config-prettier": "^8.3.0",
|
|
36
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
37
|
+
"eslint-plugin-vue": "^8.0.3",
|
|
38
|
+
"prettier": "^2.4.1",
|
|
39
|
+
"vue-template-compiler": "^2.6.14"
|
|
40
|
+
}
|
|
41
|
+
}
|