create-project-template-cli 1.0.0 → 1.0.1
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 +5 -5
- package/index.js +133 -133
- package/package.json +2 -2
- package/template/react-shadcn/.gitignore +24 -0
- package/template/react-shadcn/.husky/commit-msg +4 -4
- package/template/react-shadcn/.stylelintignore +19 -19
- package/template/react-shadcn/.stylelintrc.cjs +258 -258
- package/template/react-shadcn/.vscode/extensions.json +7 -7
- package/template/react-shadcn/README.md +75 -75
- package/template/react-shadcn/commitlint.config.cjs +90 -90
- package/template/react-shadcn/components.json +22 -22
- package/template/react-shadcn/eslint.config.js +58 -58
- package/template/react-shadcn/index.html +13 -13
- package/template/react-shadcn/lint-staged.config.cjs +4 -4
- package/template/react-shadcn/package.json +62 -62
- package/template/react-shadcn/pnpm-lock.yaml +4514 -4514
- package/template/react-shadcn/src/App.css +23 -23
- package/template/react-shadcn/src/App.tsx +20 -20
- package/template/react-shadcn/src/assets/css/tailwindcss.css +120 -120
- package/template/react-shadcn/src/components/ui/button.tsx +58 -58
- package/template/react-shadcn/src/components/ui/card.tsx +92 -92
- package/template/react-shadcn/src/components/ui/input.tsx +21 -21
- package/template/react-shadcn/src/components/ui/label.tsx +22 -22
- package/template/react-shadcn/src/components/ui/navigation-menu.tsx +168 -168
- package/template/react-shadcn/src/lib/utils.ts +6 -6
- package/template/react-shadcn/src/main.tsx +11 -11
- package/template/react-shadcn/src/router/index.tsx +71 -71
- package/template/react-shadcn/src/views/404/index.scss +133 -133
- package/template/react-shadcn/src/views/404/index.tsx +26 -26
- package/template/react-shadcn/src/views/Index/index.tsx +7 -7
- package/template/react-shadcn/src/views/index.tsx +58 -58
- package/template/react-shadcn/tsconfig.app.json +33 -33
- package/template/react-shadcn/tsconfig.json +13 -13
- package/template/react-shadcn/tsconfig.node.json +32 -32
- package/template/react-shadcn/vite.config.ts +36 -36
- package/template/vue-tailwindcss/.gitignore +30 -0
- package/utils.js +73 -73
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
# 项目模板工具
|
|
2
|
-
## template
|
|
3
|
-
该文件夹下面为自定义的项目模板,每个模板为一个文件夹,文件夹名称为模板名称
|
|
4
|
-
## 自定义模板
|
|
5
|
-
用户可以选择自定义模板,输入gitee或者github的仓库地址,clone该项目
|
|
1
|
+
# 项目模板工具
|
|
2
|
+
## template
|
|
3
|
+
该文件夹下面为自定义的项目模板,每个模板为一个文件夹,文件夹名称为模板名称
|
|
4
|
+
## 自定义模板
|
|
5
|
+
用户可以选择自定义模板,输入gitee或者github的仓库地址,clone该项目
|
package/index.js
CHANGED
|
@@ -1,133 +1,133 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
// commander
|
|
4
|
-
import { program } from "commander";
|
|
5
|
-
// inquirer (v9+ 支持ESM)
|
|
6
|
-
import inquirer from "inquirer";
|
|
7
|
-
// fs (Node.js内置模块,ESM使用命名导入)
|
|
8
|
-
import fs from "fs";
|
|
9
|
-
import { fileURLToPath } from "url";
|
|
10
|
-
import { dirname } from "path";
|
|
11
|
-
// path (Node.js内置模块)
|
|
12
|
-
import path from "path";
|
|
13
|
-
// chalk (v5+ 是ESM)
|
|
14
|
-
import chalk from "chalk";
|
|
15
|
-
import ora from "ora";
|
|
16
|
-
|
|
17
|
-
// fs-extra
|
|
18
|
-
import fsExtra from "fs-extra";
|
|
19
|
-
|
|
20
|
-
import packageJson from "./package.json" with { type: "json" };
|
|
21
|
-
import { getTemplateList ,downloadCustomTemplate} from "./utils.js";
|
|
22
|
-
// 设置版本号
|
|
23
|
-
program.version(packageJson.version);
|
|
24
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
25
|
-
const __dirname = dirname(__filename);
|
|
26
|
-
const TEMPLATES_DIR = path.resolve(__dirname, "./template");
|
|
27
|
-
|
|
28
|
-
// 类型
|
|
29
|
-
const TEMPLATE_TYPE = {
|
|
30
|
-
CUSTOM: "custom",
|
|
31
|
-
}
|
|
32
|
-
// 定义命令行参数
|
|
33
|
-
program
|
|
34
|
-
.description("自定义项目模板工具")
|
|
35
|
-
.argument("[project-name]", "项目名称")
|
|
36
|
-
.action(async (projectName) => {
|
|
37
|
-
try {
|
|
38
|
-
if (!projectName) {
|
|
39
|
-
const answers = await inquirer.prompt([
|
|
40
|
-
{
|
|
41
|
-
type: "input",
|
|
42
|
-
name: "projectName",
|
|
43
|
-
message: "请输入项目名称",
|
|
44
|
-
default: "project-template",
|
|
45
|
-
},
|
|
46
|
-
]);
|
|
47
|
-
projectName = answers.projectName;
|
|
48
|
-
// 检查项目名称是否已存在
|
|
49
|
-
if (fs.existsSync(projectName)) {
|
|
50
|
-
console.log(chalk.red("项目名称已存在"));
|
|
51
|
-
// 退出
|
|
52
|
-
process.exit(1);
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
// 选择模板
|
|
56
|
-
const templatesName = await inquirer.prompt([
|
|
57
|
-
{
|
|
58
|
-
type: "list",
|
|
59
|
-
name: "template",
|
|
60
|
-
message: "请选择项目模板",
|
|
61
|
-
choices: await getTemplateList(),
|
|
62
|
-
},
|
|
63
|
-
]);
|
|
64
|
-
|
|
65
|
-
const {template} = templatesName;
|
|
66
|
-
// 创建的项目地址
|
|
67
|
-
const projectPath = path.resolve(process.cwd(), projectName);
|
|
68
|
-
// 如果不是自定义
|
|
69
|
-
if (template !== TEMPLATE_TYPE.CUSTOM) {
|
|
70
|
-
// 创建项目目录
|
|
71
|
-
const spinner = ora('正在创建项目...').start();
|
|
72
|
-
// 创建文件夹
|
|
73
|
-
fsExtra.mkdirSync(projectPath, { recursive: true });
|
|
74
|
-
// 模板地址
|
|
75
|
-
const templatePath = path.join(TEMPLATES_DIR, template);
|
|
76
|
-
await createFile(templatePath, projectPath);
|
|
77
|
-
spinner.succeed('项目创建成功');
|
|
78
|
-
return
|
|
79
|
-
}else {
|
|
80
|
-
await custom(projectName);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
} catch (error) {
|
|
84
|
-
console.log(chalk.red("创建项目失败"));
|
|
85
|
-
// console.log(chalk.red(error.message));
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
// 处理自定义模板
|
|
91
|
-
async function custom(projectPath, ) {
|
|
92
|
-
|
|
93
|
-
// 输入github或者gitee地址
|
|
94
|
-
const answers = await inquirer.prompt([
|
|
95
|
-
{
|
|
96
|
-
type: "input",
|
|
97
|
-
name: "customTemplate",
|
|
98
|
-
message: "请输入项目模板gitee或者github地址",
|
|
99
|
-
},
|
|
100
|
-
]);
|
|
101
|
-
|
|
102
|
-
const {customTemplate} = answers;
|
|
103
|
-
console.log(customTemplate)
|
|
104
|
-
// 下载项目模板
|
|
105
|
-
await downloadCustomTemplate(customTemplate, projectPath);
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
// 创建文件 非自定义的
|
|
110
|
-
async function createFile(templatePath, projectPath) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
const entries = await fsExtra.readdir(templatePath, { withFileTypes: true });
|
|
114
|
-
for (const entry of entries) {
|
|
115
|
-
const srcPath = path.join(templatePath, entry.name);
|
|
116
|
-
const destPath = path.join(projectPath, entry.name);
|
|
117
|
-
// 处理目录
|
|
118
|
-
if (entry.isDirectory()) {
|
|
119
|
-
await fsExtra.mkdir(destPath, { recursive: true });
|
|
120
|
-
await createFile(srcPath, destPath);
|
|
121
|
-
}
|
|
122
|
-
// 复制其他文件
|
|
123
|
-
else {
|
|
124
|
-
await fsExtra.copyFile(srcPath, destPath);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
program.parse(process.argv);
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// commander
|
|
4
|
+
import { program } from "commander";
|
|
5
|
+
// inquirer (v9+ 支持ESM)
|
|
6
|
+
import inquirer from "inquirer";
|
|
7
|
+
// fs (Node.js内置模块,ESM使用命名导入)
|
|
8
|
+
import fs from "fs";
|
|
9
|
+
import { fileURLToPath } from "url";
|
|
10
|
+
import { dirname } from "path";
|
|
11
|
+
// path (Node.js内置模块)
|
|
12
|
+
import path from "path";
|
|
13
|
+
// chalk (v5+ 是ESM)
|
|
14
|
+
import chalk from "chalk";
|
|
15
|
+
import ora from "ora";
|
|
16
|
+
|
|
17
|
+
// fs-extra
|
|
18
|
+
import fsExtra from "fs-extra";
|
|
19
|
+
|
|
20
|
+
import packageJson from "./package.json" with { type: "json" };
|
|
21
|
+
import { getTemplateList ,downloadCustomTemplate} from "./utils.js";
|
|
22
|
+
// 设置版本号
|
|
23
|
+
program.version(packageJson.version);
|
|
24
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
25
|
+
const __dirname = dirname(__filename);
|
|
26
|
+
const TEMPLATES_DIR = path.resolve(__dirname, "./template");
|
|
27
|
+
|
|
28
|
+
// 类型
|
|
29
|
+
const TEMPLATE_TYPE = {
|
|
30
|
+
CUSTOM: "custom",
|
|
31
|
+
}
|
|
32
|
+
// 定义命令行参数
|
|
33
|
+
program
|
|
34
|
+
.description("自定义项目模板工具")
|
|
35
|
+
.argument("[project-name]", "项目名称")
|
|
36
|
+
.action(async (projectName) => {
|
|
37
|
+
try {
|
|
38
|
+
if (!projectName) {
|
|
39
|
+
const answers = await inquirer.prompt([
|
|
40
|
+
{
|
|
41
|
+
type: "input",
|
|
42
|
+
name: "projectName",
|
|
43
|
+
message: "请输入项目名称",
|
|
44
|
+
default: "project-template",
|
|
45
|
+
},
|
|
46
|
+
]);
|
|
47
|
+
projectName = answers.projectName;
|
|
48
|
+
// 检查项目名称是否已存在
|
|
49
|
+
if (fs.existsSync(projectName)) {
|
|
50
|
+
console.log(chalk.red("项目名称已存在"));
|
|
51
|
+
// 退出
|
|
52
|
+
process.exit(1);
|
|
53
|
+
|
|
54
|
+
}
|
|
55
|
+
// 选择模板
|
|
56
|
+
const templatesName = await inquirer.prompt([
|
|
57
|
+
{
|
|
58
|
+
type: "list",
|
|
59
|
+
name: "template",
|
|
60
|
+
message: "请选择项目模板",
|
|
61
|
+
choices: await getTemplateList(),
|
|
62
|
+
},
|
|
63
|
+
]);
|
|
64
|
+
|
|
65
|
+
const {template} = templatesName;
|
|
66
|
+
// 创建的项目地址
|
|
67
|
+
const projectPath = path.resolve(process.cwd(), projectName);
|
|
68
|
+
// 如果不是自定义
|
|
69
|
+
if (template !== TEMPLATE_TYPE.CUSTOM) {
|
|
70
|
+
// 创建项目目录
|
|
71
|
+
const spinner = ora('正在创建项目...').start();
|
|
72
|
+
// 创建文件夹
|
|
73
|
+
fsExtra.mkdirSync(projectPath, { recursive: true });
|
|
74
|
+
// 模板地址
|
|
75
|
+
const templatePath = path.join(TEMPLATES_DIR, template);
|
|
76
|
+
await createFile(templatePath, projectPath);
|
|
77
|
+
spinner.succeed('项目创建成功');
|
|
78
|
+
return
|
|
79
|
+
}else {
|
|
80
|
+
await custom(projectName);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
} catch (error) {
|
|
84
|
+
console.log(chalk.red("创建项目失败"));
|
|
85
|
+
// console.log(chalk.red(error.message));
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// 处理自定义模板
|
|
91
|
+
async function custom(projectPath, ) {
|
|
92
|
+
|
|
93
|
+
// 输入github或者gitee地址
|
|
94
|
+
const answers = await inquirer.prompt([
|
|
95
|
+
{
|
|
96
|
+
type: "input",
|
|
97
|
+
name: "customTemplate",
|
|
98
|
+
message: "请输入项目模板gitee或者github地址",
|
|
99
|
+
},
|
|
100
|
+
]);
|
|
101
|
+
|
|
102
|
+
const {customTemplate} = answers;
|
|
103
|
+
console.log(customTemplate)
|
|
104
|
+
// 下载项目模板
|
|
105
|
+
await downloadCustomTemplate(customTemplate, projectPath);
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
}
|
|
109
|
+
// 创建文件 非自定义的
|
|
110
|
+
async function createFile(templatePath, projectPath) {
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
const entries = await fsExtra.readdir(templatePath, { withFileTypes: true });
|
|
114
|
+
for (const entry of entries) {
|
|
115
|
+
const srcPath = path.join(templatePath, entry.name);
|
|
116
|
+
const destPath = path.join(projectPath, entry.name);
|
|
117
|
+
// 处理目录
|
|
118
|
+
if (entry.isDirectory()) {
|
|
119
|
+
await fsExtra.mkdir(destPath, { recursive: true });
|
|
120
|
+
await createFile(srcPath, destPath);
|
|
121
|
+
}
|
|
122
|
+
// 复制其他文件
|
|
123
|
+
else {
|
|
124
|
+
await fsExtra.copyFile(srcPath, destPath);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
program.parse(process.argv);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-project-template-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "模板快速创建",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
},
|
|
10
10
|
"files": [
|
|
11
11
|
"index.js",
|
|
12
|
-
"template
|
|
12
|
+
"template/**",
|
|
13
13
|
"utils.js"
|
|
14
14
|
],
|
|
15
15
|
"keywords": [
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Logs
|
|
2
|
+
logs
|
|
3
|
+
*.log
|
|
4
|
+
npm-debug.log*
|
|
5
|
+
yarn-debug.log*
|
|
6
|
+
yarn-error.log*
|
|
7
|
+
pnpm-debug.log*
|
|
8
|
+
lerna-debug.log*
|
|
9
|
+
|
|
10
|
+
node_modules
|
|
11
|
+
dist
|
|
12
|
+
dist-ssr
|
|
13
|
+
*.local
|
|
14
|
+
|
|
15
|
+
# Editor directories and files
|
|
16
|
+
.vscode/*
|
|
17
|
+
!.vscode/extensions.json
|
|
18
|
+
.idea
|
|
19
|
+
.DS_Store
|
|
20
|
+
*.suo
|
|
21
|
+
*.ntvs*
|
|
22
|
+
*.njsproj
|
|
23
|
+
*.sln
|
|
24
|
+
*.sw?
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#!/usr/bin/env sh
|
|
2
|
-
. "$(dirname -- "$0")/_/husky.sh"
|
|
3
|
-
|
|
4
|
-
npx --no -- commitlint --edit $1
|
|
1
|
+
#!/usr/bin/env sh
|
|
2
|
+
. "$(dirname -- "$0")/_/husky.sh"
|
|
3
|
+
|
|
4
|
+
npx --no -- commitlint --edit $1
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
# .stylelintignore
|
|
2
|
-
# 旧的不需打包的样式库
|
|
3
|
-
*.min.css
|
|
4
|
-
|
|
5
|
-
# 其他类型文件
|
|
6
|
-
*.js
|
|
7
|
-
*.jpg
|
|
8
|
-
*.png
|
|
9
|
-
*.eot
|
|
10
|
-
*.ttf
|
|
11
|
-
*.woff
|
|
12
|
-
*.json
|
|
13
|
-
tailwindcss.css
|
|
14
|
-
|
|
15
|
-
# 测试和打包目录
|
|
16
|
-
/test/
|
|
17
|
-
/dist/
|
|
18
|
-
/node_modules/
|
|
19
|
-
/lib/
|
|
1
|
+
# .stylelintignore
|
|
2
|
+
# 旧的不需打包的样式库
|
|
3
|
+
*.min.css
|
|
4
|
+
|
|
5
|
+
# 其他类型文件
|
|
6
|
+
*.js
|
|
7
|
+
*.jpg
|
|
8
|
+
*.png
|
|
9
|
+
*.eot
|
|
10
|
+
*.ttf
|
|
11
|
+
*.woff
|
|
12
|
+
*.json
|
|
13
|
+
tailwindcss.css
|
|
14
|
+
|
|
15
|
+
# 测试和打包目录
|
|
16
|
+
/test/
|
|
17
|
+
/dist/
|
|
18
|
+
/node_modules/
|
|
19
|
+
/lib/
|
|
20
20
|
/assets/
|