ono-cli 0.0.1 → 0.0.3
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 +1 -1
- package/bin/commands/config.js +49 -3
- package/bin/commands/create.js +193 -172
- package/bin/constants.js +1 -5
- package/bin/index.js +3 -10
- package/bin/utils/project.js +52 -48
- package/package.json +37 -30
- package/bin/commands/index.js +0 -1
package/README.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
# 自定义脚手架
|
|
1
|
+
# 自定义脚手架
|
package/bin/commands/config.js
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
1
10
|
import { existsSync, readFileSync, writeFileSync } from "fs";
|
|
2
11
|
import { decode, encode } from "ini";
|
|
12
|
+
import inquirer from "inquirer";
|
|
3
13
|
import { configPath } from "../constants.js";
|
|
4
|
-
export default (value, option) => {
|
|
14
|
+
export default (value, option) => __awaiter(void 0, void 0, void 0, function* () {
|
|
5
15
|
const { exists, config } = getAllConfig();
|
|
6
16
|
const action = Object.keys(option)[0];
|
|
7
17
|
const key = option[action];
|
|
@@ -17,9 +27,45 @@ export default (value, option) => {
|
|
|
17
27
|
if (exists)
|
|
18
28
|
writeFileSync(configPath, encode(config));
|
|
19
29
|
}
|
|
20
|
-
|
|
30
|
+
else if (action === 'repo') {
|
|
31
|
+
const { repo } = yield inquirer.prompt([
|
|
32
|
+
{
|
|
33
|
+
name: 'repo',
|
|
34
|
+
type: 'list', // list, input, confirm, checkbox, rawlist, expand
|
|
35
|
+
message: '选择仓库',
|
|
36
|
+
choices: [{
|
|
37
|
+
name: 'github',
|
|
38
|
+
value: 'github'
|
|
39
|
+
}, {
|
|
40
|
+
name: 'gitee',
|
|
41
|
+
value: 'gitee'
|
|
42
|
+
}]
|
|
43
|
+
}
|
|
44
|
+
]);
|
|
45
|
+
config.repo = repo;
|
|
46
|
+
writeFileSync(configPath, encode(config));
|
|
47
|
+
}
|
|
48
|
+
else if (action === 'mode') {
|
|
49
|
+
const { mode } = yield inquirer.prompt([
|
|
50
|
+
{
|
|
51
|
+
name: 'mode',
|
|
52
|
+
type: 'list', // list, input, confirm, checkbox, rawlist, expand
|
|
53
|
+
message: '选择模式',
|
|
54
|
+
choices: [{
|
|
55
|
+
name: '模板选择模式',
|
|
56
|
+
value: 'template'
|
|
57
|
+
}, {
|
|
58
|
+
name: '依赖性选择模式',
|
|
59
|
+
value: 'dependencies'
|
|
60
|
+
}]
|
|
61
|
+
}
|
|
62
|
+
]);
|
|
63
|
+
config.mode = mode;
|
|
64
|
+
writeFileSync(configPath, encode(config));
|
|
65
|
+
}
|
|
66
|
+
});
|
|
21
67
|
export const getAllConfig = () => {
|
|
22
|
-
const config = { organization: '', access_token: '' };
|
|
68
|
+
const config = { organization: '', access_token: '', repo: 'github', mode: 'template' };
|
|
23
69
|
const exists = existsSync(configPath);
|
|
24
70
|
if (exists) {
|
|
25
71
|
const userConfig = decode(readFileSync(configPath, 'utf-8'));
|
package/bin/commands/create.js
CHANGED
|
@@ -11,193 +11,214 @@ import chalk from "chalk";
|
|
|
11
11
|
import { existsSync } from "fs";
|
|
12
12
|
import inquirer from 'inquirer';
|
|
13
13
|
import path from "path";
|
|
14
|
-
import {
|
|
14
|
+
import { cloneCodeDeps, cloneCodeTemplate, getOrganizationProjects } from "../utils/project.js";
|
|
15
|
+
import { getAllConfig } from "./config.js";
|
|
16
|
+
const { mode } = getAllConfig().config;
|
|
15
17
|
export default (name, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
name: 'projectName',
|
|
25
|
-
type: 'input', // list, input, confirm, checkbox, rawlist, expand
|
|
26
|
-
default: 'my-project',
|
|
27
|
-
message: '项目名称',
|
|
28
|
-
}
|
|
29
|
-
]);
|
|
30
|
-
projectConfig.name = projectName ? projectName.trim() : 'my-project';
|
|
31
|
-
}
|
|
32
|
-
const cwd = process.cwd();
|
|
33
|
-
const targetDir = path.join(cwd, projectConfig.name);
|
|
34
|
-
if (existsSync(targetDir)) {
|
|
35
|
-
if (options.force) {
|
|
36
|
-
projectConfig.isOverwrite = true;
|
|
37
|
-
projectConfig.path = targetDir;
|
|
38
|
-
}
|
|
18
|
+
try {
|
|
19
|
+
const projectConfig = {
|
|
20
|
+
name: '', // 项目名称
|
|
21
|
+
path: '', // 项目路径
|
|
22
|
+
isOverwrite: false, // 是否覆盖
|
|
23
|
+
};
|
|
24
|
+
if (name)
|
|
25
|
+
projectConfig.name = name.trim();
|
|
39
26
|
else {
|
|
40
|
-
const {
|
|
27
|
+
const { projectName } = yield inquirer.prompt([
|
|
41
28
|
{
|
|
42
|
-
name: '
|
|
43
|
-
type: '
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
name: '覆盖',
|
|
47
|
-
value: 'overwrite'
|
|
48
|
-
}, {
|
|
49
|
-
name: '取消',
|
|
50
|
-
value: 'cancel'
|
|
51
|
-
}]
|
|
29
|
+
name: 'projectName',
|
|
30
|
+
type: 'input', // list, input, confirm, checkbox, rawlist, expand
|
|
31
|
+
default: 'my-project',
|
|
32
|
+
message: '项目名称',
|
|
52
33
|
}
|
|
53
34
|
]);
|
|
54
|
-
|
|
55
|
-
case 'overwrite':
|
|
56
|
-
projectConfig.isOverwrite = true;
|
|
57
|
-
projectConfig.path = targetDir;
|
|
58
|
-
break;
|
|
59
|
-
case 'cancel':
|
|
60
|
-
return console.log(`取消创建目录${projectConfig.name}`);
|
|
61
|
-
default:
|
|
62
|
-
break;
|
|
63
|
-
}
|
|
35
|
+
projectConfig.name = projectName ? projectName.trim() : 'my-project';
|
|
64
36
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
name: chalk.hex('#087ea4')('React'),
|
|
97
|
-
value: 'react'
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
name: chalk.hex('#fecf05')('Vanilla'),
|
|
101
|
-
value: 'vanilla'
|
|
37
|
+
const cwd = process.cwd();
|
|
38
|
+
const targetDir = path.join(cwd, projectConfig.name);
|
|
39
|
+
if (existsSync(targetDir)) {
|
|
40
|
+
if (options.force) {
|
|
41
|
+
projectConfig.isOverwrite = true;
|
|
42
|
+
projectConfig.path = targetDir;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
const { action } = yield inquirer.prompt([
|
|
46
|
+
{
|
|
47
|
+
name: 'action',
|
|
48
|
+
type: 'list', // list, input, confirm, checkbox, rawlist, expand
|
|
49
|
+
message: `目录${projectConfig.name}已存在,是否覆盖?`,
|
|
50
|
+
choices: [{
|
|
51
|
+
name: '覆盖',
|
|
52
|
+
value: 'overwrite'
|
|
53
|
+
}, {
|
|
54
|
+
name: '取消',
|
|
55
|
+
value: 'cancel'
|
|
56
|
+
}]
|
|
57
|
+
}
|
|
58
|
+
]);
|
|
59
|
+
switch (action) {
|
|
60
|
+
case 'overwrite':
|
|
61
|
+
projectConfig.isOverwrite = true;
|
|
62
|
+
projectConfig.path = targetDir;
|
|
63
|
+
break;
|
|
64
|
+
case 'cancel':
|
|
65
|
+
return console.log(`取消创建目录${projectConfig.name}`);
|
|
66
|
+
default:
|
|
67
|
+
break;
|
|
102
68
|
}
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
]);
|
|
106
|
-
const { language } = yield inquirer.prompt([
|
|
107
|
-
{
|
|
108
|
-
name: 'language',
|
|
109
|
-
type: 'confirm',
|
|
110
|
-
message: '是否使用TypeScript?',
|
|
69
|
+
}
|
|
111
70
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
name: 'router',
|
|
116
|
-
type: 'list',
|
|
117
|
-
message: '选择路由',
|
|
118
|
-
choices: [
|
|
119
|
-
{
|
|
120
|
-
name: chalk.hex('#3451b2')('React Router'),
|
|
121
|
-
value: 'react-router'
|
|
122
|
-
},
|
|
71
|
+
if (mode === 'chootemplate') {
|
|
72
|
+
const projects = yield getOrganizationProjects();
|
|
73
|
+
const { projectName } = yield inquirer.prompt([
|
|
123
74
|
{
|
|
124
|
-
name:
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
name: 'Vanilla',
|
|
129
|
-
value: ''
|
|
75
|
+
name: 'projectName',
|
|
76
|
+
type: 'list', // list, input, confirm, checkbox, rawlist, expand
|
|
77
|
+
message: '选择模板',
|
|
78
|
+
choices: projects
|
|
130
79
|
}
|
|
131
|
-
]
|
|
80
|
+
]);
|
|
81
|
+
// const tags = await getProjectVersion(projectName)
|
|
82
|
+
// const { tag } = await inquirer.prompt([
|
|
83
|
+
// {
|
|
84
|
+
// name: 'tag',
|
|
85
|
+
// type: 'list', // list, input, confirm, checkbox, rawlist, expand
|
|
86
|
+
// message: '请选择版本',
|
|
87
|
+
// choices: tags
|
|
88
|
+
// }
|
|
89
|
+
// ])
|
|
90
|
+
// console.log(tag);
|
|
91
|
+
cloneCodeTemplate('master', projectName, projectConfig);
|
|
132
92
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
93
|
+
else if (mode === 'dependencies') {
|
|
94
|
+
const framework = yield inquirer.prompt([
|
|
95
|
+
{
|
|
96
|
+
name: 'framework',
|
|
97
|
+
type: 'list',
|
|
98
|
+
message: '选择框架',
|
|
99
|
+
choices: [
|
|
100
|
+
{
|
|
101
|
+
name: chalk.hex('#42b883')('Vue'),
|
|
102
|
+
value: 'vue'
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
name: chalk.hex('#087ea4')('React'),
|
|
106
|
+
value: 'react'
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
name: chalk.hex('#fecf05')('Vanilla'),
|
|
110
|
+
value: 'vanilla'
|
|
111
|
+
}
|
|
112
|
+
]
|
|
151
113
|
}
|
|
152
|
-
]
|
|
153
|
-
|
|
154
|
-
]);
|
|
155
|
-
const atomStyle = yield inquirer.prompt([
|
|
156
|
-
{
|
|
157
|
-
name: 'atomStyle',
|
|
158
|
-
type: 'list',
|
|
159
|
-
message: '选择原子化样式库',
|
|
160
|
-
choices: [
|
|
161
|
-
{
|
|
162
|
-
name: chalk.hex('#38bdf8')('Tailwind CSS'),
|
|
163
|
-
value: 'tailwindcss'
|
|
164
|
-
},
|
|
165
|
-
{
|
|
166
|
-
name: chalk.hex('#4d9375')('Uno CSS'),
|
|
167
|
-
value: 'unocss'
|
|
168
|
-
},
|
|
114
|
+
]);
|
|
115
|
+
const { language } = yield inquirer.prompt([
|
|
169
116
|
{
|
|
170
|
-
name: '
|
|
171
|
-
|
|
117
|
+
name: 'language',
|
|
118
|
+
type: 'confirm',
|
|
119
|
+
message: '是否使用TypeScript?',
|
|
172
120
|
}
|
|
173
|
-
]
|
|
174
|
-
|
|
175
|
-
]);
|
|
176
|
-
const stylePrecompiler = yield inquirer.prompt([
|
|
177
|
-
{
|
|
178
|
-
name: 'stylePrecompiler',
|
|
179
|
-
type: 'list',
|
|
180
|
-
message: '选择预编译器',
|
|
181
|
-
choices: [
|
|
182
|
-
{
|
|
183
|
-
name: chalk.hex('#cc6699')('Sass'),
|
|
184
|
-
value: 'sass'
|
|
185
|
-
},
|
|
186
|
-
{
|
|
187
|
-
name: chalk.hex('#1d365d')('Less'),
|
|
188
|
-
value: 'less'
|
|
189
|
-
},
|
|
190
|
-
{
|
|
191
|
-
name: chalk.hex('#89ba1b')('Stylus'),
|
|
192
|
-
value: 'stylus'
|
|
193
|
-
},
|
|
121
|
+
]);
|
|
122
|
+
const { eslint } = yield inquirer.prompt([
|
|
194
123
|
{
|
|
195
|
-
name: '
|
|
196
|
-
|
|
124
|
+
name: 'eslint',
|
|
125
|
+
type: 'confirm',
|
|
126
|
+
message: '是否使用Eslint?',
|
|
127
|
+
}
|
|
128
|
+
]);
|
|
129
|
+
const router = yield inquirer.prompt([
|
|
130
|
+
{
|
|
131
|
+
name: 'router',
|
|
132
|
+
type: 'list',
|
|
133
|
+
message: '选择路由',
|
|
134
|
+
choices: [
|
|
135
|
+
{
|
|
136
|
+
name: chalk.hex('#3451b2')('React Router'),
|
|
137
|
+
value: 'react-router'
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
name: chalk.hex('#39c05b')('TanStack Router'),
|
|
141
|
+
value: 'tanStack-router'
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
name: 'Vanilla',
|
|
145
|
+
value: ''
|
|
146
|
+
}
|
|
147
|
+
]
|
|
197
148
|
}
|
|
198
|
-
]
|
|
149
|
+
]);
|
|
150
|
+
const store = yield inquirer.prompt([
|
|
151
|
+
{
|
|
152
|
+
name: 'store',
|
|
153
|
+
type: 'list',
|
|
154
|
+
message: '选择状态管理仓库',
|
|
155
|
+
choices: [
|
|
156
|
+
{
|
|
157
|
+
name: chalk.hex('#764abc')('Redux'),
|
|
158
|
+
value: 'redux'
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
name: chalk.hex('#1c16df')('Zustand'),
|
|
162
|
+
value: 'zustand'
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
name: 'Vanilla',
|
|
166
|
+
value: ''
|
|
167
|
+
}
|
|
168
|
+
]
|
|
169
|
+
}
|
|
170
|
+
]);
|
|
171
|
+
const atomStyle = yield inquirer.prompt([
|
|
172
|
+
{
|
|
173
|
+
name: 'atomStyle',
|
|
174
|
+
type: 'list',
|
|
175
|
+
message: '选择原子化样式库',
|
|
176
|
+
choices: [
|
|
177
|
+
{
|
|
178
|
+
name: chalk.hex('#38bdf8')('Tailwind CSS'),
|
|
179
|
+
value: 'tailwindcss'
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
name: chalk.hex('#4d9375')('Uno CSS'),
|
|
183
|
+
value: 'unocss'
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
name: 'Vanilla',
|
|
187
|
+
value: ''
|
|
188
|
+
}
|
|
189
|
+
]
|
|
190
|
+
}
|
|
191
|
+
]);
|
|
192
|
+
const stylePrecompiler = yield inquirer.prompt([
|
|
193
|
+
{
|
|
194
|
+
name: 'stylePrecompiler',
|
|
195
|
+
type: 'list',
|
|
196
|
+
message: '选择预编译器',
|
|
197
|
+
choices: [
|
|
198
|
+
{
|
|
199
|
+
name: chalk.hex('#cc6699')('Sass'),
|
|
200
|
+
value: 'sass'
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
name: chalk.hex('#1d365d')('Less'),
|
|
204
|
+
value: 'less'
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
name: chalk.hex('#89ba1b')('Stylus'),
|
|
208
|
+
value: 'stylus'
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
name: 'Vanilla',
|
|
212
|
+
value: ''
|
|
213
|
+
}
|
|
214
|
+
]
|
|
215
|
+
}
|
|
216
|
+
]);
|
|
217
|
+
Object.assign(projectConfig, framework, { lanuage: language ? 'ts' : 'js' }, router, store, atomStyle, stylePrecompiler, { eslint: eslint ? 'eslint' : '' });
|
|
218
|
+
cloneCodeDeps('master', projectConfig);
|
|
199
219
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
220
|
+
}
|
|
221
|
+
catch (error) {
|
|
222
|
+
return console.log(chalk.red('退出创建项目'));
|
|
223
|
+
}
|
|
203
224
|
});
|
package/bin/constants.js
CHANGED
|
@@ -1,5 +1 @@
|
|
|
1
|
-
export const
|
|
2
|
-
organization: 'fireflies_foam',
|
|
3
|
-
access_token: '0161dea0e646b4989aa911c4bc0c57d0',
|
|
4
|
-
};
|
|
5
|
-
export const configPath = `${process.env.HOME || process.env.USERPROFILE}/.onocrc`;
|
|
1
|
+
export const configPath = `${process.env.HOME || process.env.USERPROFILE}/.onoclirc`;
|
package/bin/index.js
CHANGED
|
@@ -12,22 +12,15 @@ import chalk from 'chalk';
|
|
|
12
12
|
import { program } from 'commander';
|
|
13
13
|
import pkg from './pkg.js';
|
|
14
14
|
const baseAction = (url, arg) => __awaiter(void 0, void 0, void 0, function* () { return (yield import(url)).default(...arg); });
|
|
15
|
-
const projectUrlList = {
|
|
16
|
-
'vue': 'git@gitee.com:onoxm/test.git',
|
|
17
|
-
'react': '456',
|
|
18
|
-
'vue&ts': '789',
|
|
19
|
-
'react&ts': '0'
|
|
20
|
-
};
|
|
21
15
|
// 首行提示
|
|
22
16
|
program.name('ono-cli').usage('<command> [option]');
|
|
23
17
|
// 版本号
|
|
24
|
-
|
|
18
|
+
// program.option('-V, --version', '输出版本号');
|
|
25
19
|
program.version(`ono-cli@${pkg.version}`);
|
|
26
20
|
program
|
|
27
21
|
.command('create [project-name]')
|
|
28
22
|
.description('创建新项目')
|
|
29
23
|
.option('-f, --force', '强制创建')
|
|
30
|
-
// .option('-t, --template <template>', '指定模板')
|
|
31
24
|
.action((projectName, options) => baseAction('./commands/create.js', [projectName, options]));
|
|
32
25
|
program
|
|
33
26
|
.command('config [value]')
|
|
@@ -35,8 +28,8 @@ program
|
|
|
35
28
|
.option('-g, --get <path>', 'get value')
|
|
36
29
|
.option('-s, --set <path> <value>', 'set value')
|
|
37
30
|
.option('-d, --delete <path>', 'delete value')
|
|
31
|
+
.option('-r, --repo', 'choose repo')
|
|
32
|
+
.option('-m, --mode', 'choose mode')
|
|
38
33
|
.action((value, options) => baseAction('./commands/config.js', [value, options]));
|
|
39
34
|
program.addHelpText('after', `Run ${chalk.blueBright('ono-cli <command> --help')} for detailed usage of given command.`);
|
|
40
35
|
program.parse(process.argv);
|
|
41
|
-
/* const options = program.opts();
|
|
42
|
-
console.log(options); */
|
package/bin/utils/project.js
CHANGED
|
@@ -9,63 +9,67 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import axios from "axios";
|
|
11
11
|
import chalk from "chalk";
|
|
12
|
-
import { exec } from "child_process";
|
|
13
12
|
import { rmSync } from "fs";
|
|
14
13
|
import { rm } from "fs/promises";
|
|
15
|
-
import util from "util";
|
|
16
|
-
import { wrapLoading } from "./loading.js";
|
|
17
14
|
import { getAllConfig } from "../commands/config.js";
|
|
18
|
-
|
|
15
|
+
import { wrapLoading } from "./loading.js";
|
|
16
|
+
import { exec } from "child_process";
|
|
17
|
+
import util from "util";
|
|
18
|
+
export const execPromisified = util.promisify(exec);
|
|
19
19
|
const { organization, access_token } = getAllConfig().config;
|
|
20
|
-
export function
|
|
21
|
-
|
|
20
|
+
export const getOrganizationProjects = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
+
try {
|
|
22
22
|
const res = yield axios.get(`https://gitee.com/api/v5/orgs/${organization}/repos`, {
|
|
23
23
|
headers: {
|
|
24
24
|
Authorization: `Bearer ${access_token}`
|
|
25
25
|
}
|
|
26
26
|
});
|
|
27
27
|
return res.data.map(item => item.name);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return res.data.map(item => item.name);
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
export function cloneAndCheckoutTag(tag, projectConfig) {
|
|
41
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
-
const oProjectConfig = Object.assign({}, projectConfig);
|
|
43
|
-
delete projectConfig.name;
|
|
44
|
-
delete projectConfig.path;
|
|
45
|
-
delete projectConfig.isOverwrite;
|
|
46
|
-
const projectConfigValues = Object.values(projectConfig).filter(item => item !== '');
|
|
47
|
-
const projects = yield getOrganizationProject();
|
|
48
|
-
const templateObj = projects.reduce((acc, item) => {
|
|
49
|
-
acc[item] = 0;
|
|
50
|
-
return acc;
|
|
51
|
-
}, {});
|
|
52
|
-
for (let i = 0; i < projects.length; i++) {
|
|
53
|
-
for (let j = 0; j < projectConfigValues.length; j++) {
|
|
54
|
-
if (projects[i].includes(projectConfigValues[j]))
|
|
55
|
-
templateObj[projects[i]]++;
|
|
56
|
-
}
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
return console.log(chalk.red(`🚀 没有找到组织项目!${chalk.white(`请使用 ${chalk.hex('#89ba1b')("ono-cli config -s")} 设置正确的 ${chalk.hex('#1c16df')('organization')} 和 ${chalk.hex('#1c16df')('access_token')} !`)}`));
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
export const getProjectVersion = (repo) => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
+
const res = yield axios.get(`https://gitee.com/api/v5/repos/${organization}/${repo}/tags`, {
|
|
35
|
+
headers: {
|
|
36
|
+
Authorization: `Bearer ${access_token}`
|
|
57
37
|
}
|
|
58
|
-
const templateObjKeys = Object.keys(templateObj);
|
|
59
|
-
const matchedProject = templateObjKeys.find(template => templateObj[template] === projectConfigValues.length);
|
|
60
|
-
if (!matchedProject)
|
|
61
|
-
return console.log(chalk.red('🚀 没有找到匹配的项目模板!'));
|
|
62
|
-
if (oProjectConfig.isOverwrite)
|
|
63
|
-
wrapLoading('remove', () => __awaiter(this, void 0, void 0, function* () { return rmSync(oProjectConfig.path, { recursive: true }); }));
|
|
64
|
-
const cmd = `git clone --branch ${tag} --depth 1 https://gitee.com/${organization}/${matchedProject}.git ${oProjectConfig.name}`;
|
|
65
|
-
return wrapLoading(chalk.green(`🚀 创建项目 ${oProjectConfig.name}...`), () => __awaiter(this, void 0, void 0, function* () {
|
|
66
|
-
yield execPromisified(cmd);
|
|
67
|
-
console.log(chalk.green(`\n🚀 创建项目 ${oProjectConfig.name} 成功!`));
|
|
68
|
-
return rm(`${oProjectConfig.name}/.git`, { recursive: true });
|
|
69
|
-
}));
|
|
70
38
|
});
|
|
71
|
-
|
|
39
|
+
return res.data.map(item => item.name);
|
|
40
|
+
});
|
|
41
|
+
export const cloneCodeTemplate = (tag, projectName, projectConfig) => __awaiter(void 0, void 0, void 0, function* () {
|
|
42
|
+
const cmd = `git clone --branch ${tag} --depth 1 https://gitee.com/${organization}/${projectName}.git ${projectConfig.name}`;
|
|
43
|
+
if (projectConfig.isOverwrite)
|
|
44
|
+
wrapLoading('remove', () => __awaiter(void 0, void 0, void 0, function* () { return rmSync(projectConfig.path, { recursive: true }); }));
|
|
45
|
+
return wrapLoading(chalk.green(`🚀 创建项目 ${projectConfig.name}...`), () => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
|
+
yield execPromisified(cmd);
|
|
47
|
+
console.log(`\n\n🚀 创建项目成功!\n\n\n 进入项目目录:${chalk.hex('#89ba1b')(`cd .\\${projectConfig.name}`)}\n\n 打开项目:${chalk.hex('#89ba1b')("code .")}\n\n`);
|
|
48
|
+
return rm(`${projectConfig.name}/.git`, { recursive: true });
|
|
49
|
+
}));
|
|
50
|
+
});
|
|
51
|
+
export const cloneCodeDeps = (tag, projectConfig) => __awaiter(void 0, void 0, void 0, function* () {
|
|
52
|
+
const oProjectConfig = Object.assign({}, projectConfig);
|
|
53
|
+
delete projectConfig.name;
|
|
54
|
+
delete projectConfig.path;
|
|
55
|
+
delete projectConfig.isOverwrite;
|
|
56
|
+
const projectConfigValues = Object.values(projectConfig).filter(item => item !== '');
|
|
57
|
+
const projects = yield getOrganizationProjects();
|
|
58
|
+
if (!projects)
|
|
59
|
+
return;
|
|
60
|
+
const templateObj = projects.reduce((acc, item) => {
|
|
61
|
+
acc[item] = 0;
|
|
62
|
+
return acc;
|
|
63
|
+
}, {});
|
|
64
|
+
for (let i = 0; i < projects.length; i++) {
|
|
65
|
+
for (let j = 0; j < projectConfigValues.length; j++) {
|
|
66
|
+
if (projects[i].includes(projectConfigValues[j]))
|
|
67
|
+
templateObj[projects[i]]++;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const templateObjKeys = Object.keys(templateObj);
|
|
71
|
+
const matchedProject = templateObjKeys.find(template => templateObj[template] === projectConfigValues.length);
|
|
72
|
+
if (!matchedProject)
|
|
73
|
+
return console.log(chalk.red('🚀 没有找到匹配的项目模板!'));
|
|
74
|
+
cloneCodeTemplate(tag, matchedProject, oProjectConfig);
|
|
75
|
+
});
|
package/package.json
CHANGED
|
@@ -1,30 +1,37 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "ono-cli",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "A CLI tool for ono template",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"bin": "./bin/index.js",
|
|
7
|
-
"type": "module",
|
|
8
|
-
"scripts": {},
|
|
9
|
-
"files": [
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "ono-cli",
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"description": "A CLI tool for ono template",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"bin": "./bin/index.js",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"scripts": {},
|
|
9
|
+
"files": [
|
|
10
|
+
"bin",
|
|
11
|
+
"lib"
|
|
12
|
+
],
|
|
13
|
+
"keywords": [
|
|
14
|
+
"ono",
|
|
15
|
+
"cli",
|
|
16
|
+
"template"
|
|
17
|
+
],
|
|
18
|
+
"author": "ono",
|
|
19
|
+
"license": "ISC",
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"axios": "^1.7.7",
|
|
22
|
+
"chalk": "^5.3.0",
|
|
23
|
+
"commander": "^12.0.0",
|
|
24
|
+
"figlet": "^1.7.0",
|
|
25
|
+
"fs-extra": "^11.2.0",
|
|
26
|
+
"git-clone": "^0.2.0",
|
|
27
|
+
"ini": "^5.0.0",
|
|
28
|
+
"inquirer": "^11.0.2",
|
|
29
|
+
"ora": "^8.0.1"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/ini": "^4.1.1",
|
|
33
|
+
"@types/node": "^22.7.2",
|
|
34
|
+
"nodemon": "^3.1.7",
|
|
35
|
+
"typescript": "^5.0.2"
|
|
36
|
+
}
|
|
37
|
+
}
|
package/bin/commands/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './create.js';
|