@itera-web/cli 1.1.54
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 +56 -0
- package/bin/index.js +18 -0
- package/dist/commands/app/app-obs.d.ts +14 -0
- package/dist/commands/app/app-obs.js +243 -0
- package/dist/commands/app/up.d.ts +11 -0
- package/dist/commands/app/up.js +103 -0
- package/dist/commands/web/buildapp.d.ts +10 -0
- package/dist/commands/web/buildapp.js +106 -0
- package/dist/commands/web/git.d.ts +3 -0
- package/dist/commands/web/git.js +57 -0
- package/dist/commands/web/init.d.ts +4 -0
- package/dist/commands/web/init.js +129 -0
- package/dist/commands/web/packageapp.d.ts +5 -0
- package/dist/commands/web/packageapp.js +98 -0
- package/dist/commands/web/publish.d.ts +10 -0
- package/dist/commands/web/publish.js +104 -0
- package/dist/commands/web/pullprojects.d.ts +5 -0
- package/dist/commands/web/pullprojects.js +108 -0
- package/dist/commands/web/startapp.d.ts +5 -0
- package/dist/commands/web/startapp.js +98 -0
- package/dist/commands/web/updateprojects.d.ts +17 -0
- package/dist/commands/web/updateprojects.js +220 -0
- package/dist/config/util.d.ts +14 -0
- package/dist/config/util.js +88 -0
- package/dist/config/webpack.buildpackage.d.ts +1 -0
- package/dist/config/webpack.buildpackage.js +63 -0
- package/dist/config/webpack.common.d.ts +1 -0
- package/dist/config/webpack.common.js +178 -0
- package/dist/config/webpack.dev.d.ts +1 -0
- package/dist/config/webpack.dev.js +27 -0
- package/dist/config/webpack.pro.d.ts +1 -0
- package/dist/config/webpack.pro.js +43 -0
- package/dist/plugins/app.exe +0 -0
- package/dist/plugins/sortSrciptTag.d.ts +1 -0
- package/dist/plugins/sortSrciptTag.js +75 -0
- package/dist/plugins/webSocketServer.d.ts +4 -0
- package/dist/plugins/webSocketServer.js +53 -0
- package/dist/public/git.d.ts +1 -0
- package/dist/public/git.js +375 -0
- package/dist/public/hook.d.ts +18 -0
- package/dist/public/hook.js +93 -0
- package/dist/public/log.d.ts +8 -0
- package/dist/public/log.js +58 -0
- package/dist/public/public.d.ts +19 -0
- package/dist/public/public.js +425 -0
- package/dist/public/sign.d.ts +2 -0
- package/dist/public/sign.js +148 -0
- package/dist/public/smartMerge.d.ts +3 -0
- package/dist/public/smartMerge.js +31 -0
- package/dist/public/update-version.d.ts +2 -0
- package/dist/public/update-version.js +130 -0
- package/dist/public/upload-obs.d.ts +1 -0
- package/dist/public/upload-obs.js +242 -0
- package/dist/public/upload-web.d.ts +1 -0
- package/dist/public/upload-web.js +154 -0
- package/dist/store/index.d.ts +2 -0
- package/dist/store/index.js +65 -0
- package/dist/store/types.d.ts +53 -0
- package/dist/store/types.js +2 -0
- package/package.json +110 -0
- package/tsconfig.json +30 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var cheerio_1 = __importDefault(require("cheerio"));
|
|
7
|
+
var fs_1 = __importDefault(require("fs"));
|
|
8
|
+
var path_1 = __importDefault(require("path"));
|
|
9
|
+
var Console = require('../public/log').Console;
|
|
10
|
+
var SortScriptTagPlugin = (function () {
|
|
11
|
+
function SortScriptTagPlugin() {
|
|
12
|
+
}
|
|
13
|
+
SortScriptTagPlugin.prototype.apply = function (compiler) {
|
|
14
|
+
compiler.hooks.compile.tap('SortScriptTagPlugin', function () {
|
|
15
|
+
Console.cyan('编译开始...');
|
|
16
|
+
});
|
|
17
|
+
compiler.hooks.emit.tapAsync('SortScriptTagPlugin', function (compilation, callback) {
|
|
18
|
+
Console.cyan('emit 阶段开始...');
|
|
19
|
+
callback();
|
|
20
|
+
});
|
|
21
|
+
compiler.hooks.afterEmit.tapAsync('SortScriptTagPlugin', function (compilation, callback) {
|
|
22
|
+
Console.cyan('afterEmit 阶段开始...');
|
|
23
|
+
callback();
|
|
24
|
+
});
|
|
25
|
+
compiler.hooks.done.tap('SortScriptTagPlugin', function (stats) {
|
|
26
|
+
Console.success('构建完毕');
|
|
27
|
+
var outputPath = compiler.options.output.path;
|
|
28
|
+
var baseHtmlPath = path_1.default.join(outputPath, 'base.html');
|
|
29
|
+
if (fs_1.default.existsSync(baseHtmlPath)) {
|
|
30
|
+
Console.cyan('开始引入排序');
|
|
31
|
+
var baseHtmlContent = fs_1.default.readFileSync(baseHtmlPath, 'utf8');
|
|
32
|
+
var $_1 = cheerio_1.default.load(baseHtmlContent, { decodeEntities: false });
|
|
33
|
+
var srcTag = $_1('script');
|
|
34
|
+
var scripts = srcTag.toArray().reverse();
|
|
35
|
+
var priorityList_1 = ['react', 'main'];
|
|
36
|
+
var priorityScripts_1 = {};
|
|
37
|
+
priorityList_1.forEach(function (key) {
|
|
38
|
+
priorityScripts_1[key] = null;
|
|
39
|
+
});
|
|
40
|
+
var otherScripts_1 = [];
|
|
41
|
+
scripts.forEach(function (script) {
|
|
42
|
+
var src = $_1(script).attr('src') || '';
|
|
43
|
+
var matched = false;
|
|
44
|
+
for (var _i = 0, priorityList_2 = priorityList_1; _i < priorityList_2.length; _i++) {
|
|
45
|
+
var key = priorityList_2[_i];
|
|
46
|
+
if (src.includes("js/".concat(key, ".")) && !priorityScripts_1[key]) {
|
|
47
|
+
priorityScripts_1[key] = script;
|
|
48
|
+
matched = true;
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (!matched)
|
|
53
|
+
otherScripts_1.push(script);
|
|
54
|
+
});
|
|
55
|
+
srcTag.remove();
|
|
56
|
+
priorityList_1.forEach(function (key) {
|
|
57
|
+
if (priorityScripts_1[key]) {
|
|
58
|
+
$_1('body').append(priorityScripts_1[key]);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
otherScripts_1.forEach(function (script) {
|
|
62
|
+
$_1('body').append(script);
|
|
63
|
+
});
|
|
64
|
+
var modifiedHtml = $_1.html();
|
|
65
|
+
fs_1.default.writeFileSync(baseHtmlPath, modifiedHtml, 'utf8');
|
|
66
|
+
Console.success('引入排序完毕');
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
compiler.hooks.failed.tap('SortScriptTagPlugin', function (err) {
|
|
70
|
+
Console.error('构建失败:', err);
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
return SortScriptTagPlugin;
|
|
74
|
+
}());
|
|
75
|
+
module.exports = SortScriptTagPlugin;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WebsocketServerInit = init;
|
|
4
|
+
exports.reloadWS = reloadWS;
|
|
5
|
+
exports.sendWSMessage = sendWSMessage;
|
|
6
|
+
var ws_1 = require("ws");
|
|
7
|
+
var store_1 = require("../store");
|
|
8
|
+
var log_1 = require("../public/log");
|
|
9
|
+
function reloadWS() {
|
|
10
|
+
var _a, _b;
|
|
11
|
+
(_b = (_a = store_1.mainData.ws.server) === null || _a === void 0 ? void 0 : _a.close) === null || _b === void 0 ? void 0 : _b.call(_a, function () {
|
|
12
|
+
store_1.mainData.ws.server = new ws_1.WebSocketServer({ port: store_1.mainData.ws.port });
|
|
13
|
+
store_1.mainData.ws.server.on('connection', onConnection);
|
|
14
|
+
log_1.Console.info('重启 WebSocketServer');
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
function onConnection(ws, req) {
|
|
18
|
+
log_1.Console.success('客户端已连接: ', req.connection.remoteAddress, req.connection.remotePort);
|
|
19
|
+
store_1.mainData.ws.obj = ws;
|
|
20
|
+
ws.on('message', function message(data) {
|
|
21
|
+
onMessage(ws, req, data);
|
|
22
|
+
});
|
|
23
|
+
ws.on('close', function close() {
|
|
24
|
+
log_1.Console.success('客户端已关闭');
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
function onMessage(ws, req, data) {
|
|
28
|
+
try {
|
|
29
|
+
var json = JSON.parse(data);
|
|
30
|
+
controller(ws, req, json);
|
|
31
|
+
}
|
|
32
|
+
catch (err) {
|
|
33
|
+
log_1.Console.error('来自客户端的消息解析失败: ', err);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function controller(ws, req, param) {
|
|
37
|
+
switch (param.cmd.toLowerCase()) {
|
|
38
|
+
case 'start':
|
|
39
|
+
break;
|
|
40
|
+
default:
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function sendWSMessage(msg) {
|
|
45
|
+
var _a;
|
|
46
|
+
if (store_1.mainData.ws.obj) {
|
|
47
|
+
(_a = store_1.mainData.ws.obj) === null || _a === void 0 ? void 0 : _a.send(JSON.stringify(msg));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function init() {
|
|
51
|
+
store_1.mainData.ws.server = new ws_1.WebSocketServer({ port: store_1.mainData.ws.port });
|
|
52
|
+
store_1.mainData.ws.server.on('connection', onConnection);
|
|
53
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function performGitOperations(): Promise<void>;
|
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
39
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
40
|
+
if (ar || !(i in from)) {
|
|
41
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
42
|
+
ar[i] = from[i];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
46
|
+
};
|
|
47
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
48
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
49
|
+
};
|
|
50
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
|
+
exports.performGitOperations = performGitOperations;
|
|
52
|
+
var child_process_1 = require("child_process");
|
|
53
|
+
var fs_1 = __importDefault(require("fs"));
|
|
54
|
+
var inquirer_1 = __importDefault(require("inquirer"));
|
|
55
|
+
var os_1 = __importDefault(require("os"));
|
|
56
|
+
var path_1 = __importDefault(require("path"));
|
|
57
|
+
var log_1 = require("./log");
|
|
58
|
+
var configPath = path_1.default.join(os_1.default.homedir(), '.publish-config.json');
|
|
59
|
+
function commitInfo() {
|
|
60
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
61
|
+
var commitType, commitMsg;
|
|
62
|
+
return __generator(this, function (_a) {
|
|
63
|
+
switch (_a.label) {
|
|
64
|
+
case 0: return [4, inquirer_1.default.prompt([
|
|
65
|
+
{
|
|
66
|
+
type: 'list',
|
|
67
|
+
name: 'commitType',
|
|
68
|
+
message: '请选择 commit 类型:',
|
|
69
|
+
choices: [
|
|
70
|
+
{ name: 'feat - 增加新的功能', value: 'feat' },
|
|
71
|
+
{ name: 'fix - 修复 BUG', value: 'fix' },
|
|
72
|
+
{ name: 'perf - 优化功能', value: 'perf' },
|
|
73
|
+
{ name: 'style - 代码风格调整', value: 'style' },
|
|
74
|
+
{ name: 'refactor - 重构代码', value: 'refactor' },
|
|
75
|
+
{ name: 'revert - 撤销修改', value: 'revert' },
|
|
76
|
+
{ name: 'test - 测试相关', value: 'test' },
|
|
77
|
+
{ name: 'docs - 文档和注释相关', value: 'docs' },
|
|
78
|
+
{ name: 'chore - 依赖更新/脚手架配置修改', value: 'chore' },
|
|
79
|
+
{ name: 'workflow - 工作流改进', value: 'workflow' },
|
|
80
|
+
{ name: 'ci - 持续集成', value: 'ci' },
|
|
81
|
+
{ name: 'types - 类型定义文件更改', value: 'types' },
|
|
82
|
+
{ name: 'wip - 开发中', value: 'wip' },
|
|
83
|
+
],
|
|
84
|
+
default: 'feat',
|
|
85
|
+
},
|
|
86
|
+
])];
|
|
87
|
+
case 1:
|
|
88
|
+
commitType = (_a.sent()).commitType;
|
|
89
|
+
return [4, inquirer_1.default.prompt([
|
|
90
|
+
{
|
|
91
|
+
type: 'input',
|
|
92
|
+
name: 'commitMsg',
|
|
93
|
+
message: '请输入 commit 信息:',
|
|
94
|
+
default: 'init',
|
|
95
|
+
},
|
|
96
|
+
])];
|
|
97
|
+
case 2:
|
|
98
|
+
commitMsg = (_a.sent()).commitMsg;
|
|
99
|
+
return [2, "".concat(commitType, ": ").concat(commitMsg)];
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
function runGitCommand(cmd, cwd, inherit) {
|
|
105
|
+
if (cwd === void 0) { cwd = process.cwd(); }
|
|
106
|
+
if (inherit === void 0) { inherit = false; }
|
|
107
|
+
try {
|
|
108
|
+
var result = (0, child_process_1.execSync)(cmd, { cwd: cwd, stdio: inherit ? 'inherit' : 'pipe' });
|
|
109
|
+
return inherit ? '' : result.toString().trim();
|
|
110
|
+
}
|
|
111
|
+
catch (err) {
|
|
112
|
+
log_1.Console.error(err.message);
|
|
113
|
+
return 'false';
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
function getGitRemoteUrl(cwd) {
|
|
117
|
+
return runGitCommand('git remote get-url origin', cwd);
|
|
118
|
+
}
|
|
119
|
+
function getSavedRepo(projectPath) {
|
|
120
|
+
if (!fs_1.default.existsSync(configPath))
|
|
121
|
+
return null;
|
|
122
|
+
try {
|
|
123
|
+
var cfg = JSON.parse(fs_1.default.readFileSync(configPath, 'utf8'));
|
|
124
|
+
return cfg[projectPath] || null;
|
|
125
|
+
}
|
|
126
|
+
catch (_a) {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function saveRepo(projectPath, repoUrl) {
|
|
131
|
+
var cfg = {};
|
|
132
|
+
if (fs_1.default.existsSync(configPath)) {
|
|
133
|
+
try {
|
|
134
|
+
cfg = JSON.parse(fs_1.default.readFileSync(configPath, 'utf8'));
|
|
135
|
+
}
|
|
136
|
+
catch (_a) {
|
|
137
|
+
cfg = {};
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
cfg[projectPath] = repoUrl;
|
|
141
|
+
fs_1.default.writeFileSync(configPath, JSON.stringify(cfg, null, 2), 'utf8');
|
|
142
|
+
}
|
|
143
|
+
function checkGitConfig() {
|
|
144
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
145
|
+
var name, email;
|
|
146
|
+
return __generator(this, function (_a) {
|
|
147
|
+
name = runGitCommand('git config user.name');
|
|
148
|
+
email = runGitCommand('git config user.email');
|
|
149
|
+
if (!name || !email) {
|
|
150
|
+
log_1.Console.error('Git 配置未完善,请先设置 user.name 和 user.email');
|
|
151
|
+
process.exit(1);
|
|
152
|
+
}
|
|
153
|
+
log_1.Console.success("Git \u914D\u7F6E\u68C0\u67E5\u901A\u8FC7: ".concat(name, " <").concat(email, ">"));
|
|
154
|
+
return [2];
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
function initGitRepo() {
|
|
159
|
+
if (!fs_1.default.existsSync('.git')) {
|
|
160
|
+
log_1.Console.cyan('执行 git 初始化...');
|
|
161
|
+
runGitCommand('git init');
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
function writeGitignore() {
|
|
165
|
+
var gitignorePath = path_1.default.join(process.cwd(), '.gitignore');
|
|
166
|
+
if (!fs_1.default.existsSync(gitignorePath)) {
|
|
167
|
+
fs_1.default.writeFileSync(gitignorePath, 'node_modules\n.DS_Store\n/dist\n', 'utf8');
|
|
168
|
+
log_1.Console.success('自动写入 .gitignore 文件成功');
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
function addRemote(repoUrl) {
|
|
172
|
+
var _a;
|
|
173
|
+
var remotes = ((_a = runGitCommand('git remote')) === null || _a === void 0 ? void 0 : _a.split('\n')) || [];
|
|
174
|
+
if (!remotes.includes('origin')) {
|
|
175
|
+
runGitCommand("git remote add origin ".concat(repoUrl));
|
|
176
|
+
log_1.Console.cyan("\u6DFB\u52A0\u8FDC\u7A0B\u4ED3\u5E93: ".concat(repoUrl));
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
function checkConflicts() {
|
|
180
|
+
var status = runGitCommand('git status --porcelain');
|
|
181
|
+
if (status) {
|
|
182
|
+
var conflicts = status.split('\n').filter(function (line) { return line.startsWith('UU'); });
|
|
183
|
+
if (conflicts.length > 0) {
|
|
184
|
+
log_1.Console.error('检测到冲突文件,请先解决冲突:');
|
|
185
|
+
conflicts.forEach(function (f) { return console.log(' ' + f); });
|
|
186
|
+
process.exit(1);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
log_1.Console.success('未检测到冲突');
|
|
190
|
+
}
|
|
191
|
+
function commitAndPush(branch, message, changes) {
|
|
192
|
+
log_1.Console.success("\u6B63\u5728\u63A8\u9001\u4EE3\u7801 ".concat(message));
|
|
193
|
+
if (changes) {
|
|
194
|
+
runGitCommand('git add .');
|
|
195
|
+
runGitCommand("git commit -m \"".concat(message, "\""));
|
|
196
|
+
}
|
|
197
|
+
runGitCommand("git branch -M ".concat(branch));
|
|
198
|
+
runGitCommand("git push -u origin ".concat(branch));
|
|
199
|
+
log_1.Console.success("\u4EE3\u7801\u5DF2\u63A8\u9001\u5230\u8FDC\u7A0B\u4ED3\u5E93\u5206\u652F ".concat(branch));
|
|
200
|
+
}
|
|
201
|
+
function createTag() {
|
|
202
|
+
var pkgPath = path_1.default.join(process.cwd(), 'package.json');
|
|
203
|
+
if (!fs_1.default.existsSync(pkgPath)) {
|
|
204
|
+
log_1.Console.cyan('未找到 package.json,跳过 tag 创建');
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
var pkg = JSON.parse(fs_1.default.readFileSync(pkgPath, 'utf8'));
|
|
208
|
+
var version = pkg.version || '0.0.1';
|
|
209
|
+
var tagName = "release-".concat(version);
|
|
210
|
+
runGitCommand("git tag -a ".concat(tagName, " -m \"Release ").concat(version, "\""));
|
|
211
|
+
runGitCommand("git push origin ".concat(tagName));
|
|
212
|
+
log_1.Console.success("\u5DF2\u521B\u5EFA\u5E76\u63A8\u9001 tag: ".concat(tagName));
|
|
213
|
+
}
|
|
214
|
+
function selectBranch() {
|
|
215
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
216
|
+
var localBranches, sortedBranches, answers, selectedBranch;
|
|
217
|
+
var _a;
|
|
218
|
+
return __generator(this, function (_b) {
|
|
219
|
+
switch (_b.label) {
|
|
220
|
+
case 0:
|
|
221
|
+
localBranches = ((_a = runGitCommand('git branch --format="%(refname:short)%(if)%(HEAD)%(then) *%(end)"')) === null || _a === void 0 ? void 0 : _a.split('\n').map(function (b) { return b.trim(); }).filter(Boolean)) || [];
|
|
222
|
+
sortedBranches = localBranches.sort(function (a, b) {
|
|
223
|
+
var isA = a.includes('*');
|
|
224
|
+
var isB = b.includes('*');
|
|
225
|
+
if (isA && !isB)
|
|
226
|
+
return -1;
|
|
227
|
+
if (!isA && isB)
|
|
228
|
+
return 1;
|
|
229
|
+
return 0;
|
|
230
|
+
});
|
|
231
|
+
return [4, inquirer_1.default.prompt([
|
|
232
|
+
{
|
|
233
|
+
type: 'list',
|
|
234
|
+
name: 'branch',
|
|
235
|
+
message: '请选择要操作的分支或输入新分支名:',
|
|
236
|
+
choices: __spreadArray(__spreadArray([], sortedBranches, true), ['新建分支'], false),
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
type: 'input',
|
|
240
|
+
name: 'newBranch',
|
|
241
|
+
message: '请输入新分支名称:',
|
|
242
|
+
when: function (ans) { return ans.branch === '新建分支'; },
|
|
243
|
+
validate: function (input) { return (input ? true : '分支名不能为空'); },
|
|
244
|
+
},
|
|
245
|
+
])];
|
|
246
|
+
case 1:
|
|
247
|
+
answers = _b.sent();
|
|
248
|
+
selectedBranch = answers.branch === '新建分支' ? answers.newBranch : answers.branch.replace(/\s*\*$/, '');
|
|
249
|
+
runGitCommand("git checkout -B ".concat(selectedBranch));
|
|
250
|
+
log_1.Console.success("\u5F53\u524D\u64CD\u4F5C\u5206\u652F: ".concat(selectedBranch));
|
|
251
|
+
return [2, selectedBranch];
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
function performGitOperations() {
|
|
257
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
258
|
+
var projectPath, currentBranch, aheadBehind, changes, _a, aheadCount, behindCount, answers_1, finalCommitMsg_1, answers, res, branch, repoUrl, answers, finalCommitMsg;
|
|
259
|
+
var _b, _c, _d;
|
|
260
|
+
return __generator(this, function (_e) {
|
|
261
|
+
switch (_e.label) {
|
|
262
|
+
case 0:
|
|
263
|
+
projectPath = process.cwd();
|
|
264
|
+
log_1.Console.cyan('\n\n=== 发布项目到 Git 仓库 ===\n');
|
|
265
|
+
return [4, checkGitConfig()];
|
|
266
|
+
case 1:
|
|
267
|
+
_e.sent();
|
|
268
|
+
initGitRepo();
|
|
269
|
+
writeGitignore();
|
|
270
|
+
runGitCommand('git fetch', projectPath);
|
|
271
|
+
currentBranch = ((_b = runGitCommand('git rev-parse --abbrev-ref HEAD', projectPath)) === null || _b === void 0 ? void 0 : _b.trim()) || '';
|
|
272
|
+
aheadBehind = (_c = runGitCommand("git rev-list --left-right --count ".concat(currentBranch, "...origin/").concat(currentBranch), projectPath)) === null || _c === void 0 ? void 0 : _c.trim();
|
|
273
|
+
if (!aheadBehind) {
|
|
274
|
+
log_1.Console.success('当前分支已与远程同步,无需提交或拉取,程序退出。');
|
|
275
|
+
process.exit(0);
|
|
276
|
+
}
|
|
277
|
+
changes = (_d = runGitCommand('git status --porcelain', projectPath)) === null || _d === void 0 ? void 0 : _d.trim();
|
|
278
|
+
_a = aheadBehind.split('\t').map(Number), aheadCount = _a[0], behindCount = _a[1];
|
|
279
|
+
if (!(behindCount > 0)) return [3, 8];
|
|
280
|
+
if (!changes) return [3, 6];
|
|
281
|
+
return [4, inquirer_1.default.prompt([
|
|
282
|
+
{
|
|
283
|
+
type: 'list',
|
|
284
|
+
name: 'localAction',
|
|
285
|
+
message: '远程仓库有更新,拉取前,检测到本地有改动,如何处理?',
|
|
286
|
+
choices: [
|
|
287
|
+
{ name: '暂存改动 (git add .)', value: 'add' },
|
|
288
|
+
{ name: '暂存并提交改动 (git add/commit)', value: 'commit' },
|
|
289
|
+
{ name: '退出', value: 'exit' },
|
|
290
|
+
],
|
|
291
|
+
},
|
|
292
|
+
])];
|
|
293
|
+
case 2:
|
|
294
|
+
answers_1 = _e.sent();
|
|
295
|
+
if (!(answers_1.localAction === 'add')) return [3, 3];
|
|
296
|
+
runGitCommand('git add .', projectPath);
|
|
297
|
+
log_1.Console.success('已暂存改动。');
|
|
298
|
+
return [3, 6];
|
|
299
|
+
case 3:
|
|
300
|
+
if (!(answers_1.localAction === 'commit')) return [3, 5];
|
|
301
|
+
return [4, commitInfo()];
|
|
302
|
+
case 4:
|
|
303
|
+
finalCommitMsg_1 = _e.sent();
|
|
304
|
+
runGitCommand('git add .', projectPath);
|
|
305
|
+
runGitCommand("git commit -m \"".concat(finalCommitMsg_1, "\""), projectPath);
|
|
306
|
+
log_1.Console.success('已提交改动。');
|
|
307
|
+
return [3, 6];
|
|
308
|
+
case 5:
|
|
309
|
+
log_1.Console.info('用户选择退出。');
|
|
310
|
+
process.exit(0);
|
|
311
|
+
_e.label = 6;
|
|
312
|
+
case 6: return [4, inquirer_1.default.prompt([
|
|
313
|
+
{
|
|
314
|
+
type: 'confirm',
|
|
315
|
+
name: 'pull',
|
|
316
|
+
message: "\u8FDC\u7A0B\u5206\u652F\u6709 ".concat(behindCount, " \u4E2A\u63D0\u4EA4\u672A\u62C9\u53D6\uFF0C\u662F\u5426\u7ACB\u5373\u62C9\u53D6\uFF1F"),
|
|
317
|
+
default: true,
|
|
318
|
+
},
|
|
319
|
+
])];
|
|
320
|
+
case 7:
|
|
321
|
+
answers = _e.sent();
|
|
322
|
+
if (answers.pull) {
|
|
323
|
+
res = runGitCommand("git pull origin ".concat(currentBranch), projectPath, true);
|
|
324
|
+
if (res === 'false') {
|
|
325
|
+
log_1.Console.info('拉取失败,请检查冲突。');
|
|
326
|
+
process.exit(0);
|
|
327
|
+
}
|
|
328
|
+
log_1.Console.success('已拉取远程最新代码。');
|
|
329
|
+
}
|
|
330
|
+
else {
|
|
331
|
+
log_1.Console.info('未拉取远程代码,程序退出。');
|
|
332
|
+
process.exit(0);
|
|
333
|
+
}
|
|
334
|
+
return [3, 9];
|
|
335
|
+
case 8:
|
|
336
|
+
log_1.Console.success('本地分支已与远程同步。');
|
|
337
|
+
_e.label = 9;
|
|
338
|
+
case 9: return [4, selectBranch()];
|
|
339
|
+
case 10:
|
|
340
|
+
branch = _e.sent();
|
|
341
|
+
checkConflicts();
|
|
342
|
+
repoUrl = getGitRemoteUrl(projectPath) || getSavedRepo(projectPath);
|
|
343
|
+
if (!!repoUrl) return [3, 12];
|
|
344
|
+
return [4, inquirer_1.default.prompt([
|
|
345
|
+
{
|
|
346
|
+
type: 'input',
|
|
347
|
+
name: 'repoUrl',
|
|
348
|
+
message: '请输入远程仓库地址(如 https://gitee.com/username/repo.git):',
|
|
349
|
+
validate: function (input) { return (input ? true : '远程仓库地址不能为空'); },
|
|
350
|
+
},
|
|
351
|
+
])];
|
|
352
|
+
case 11:
|
|
353
|
+
answers = _e.sent();
|
|
354
|
+
repoUrl = answers.repoUrl;
|
|
355
|
+
saveRepo(projectPath, typeof repoUrl === 'string' ? repoUrl : '');
|
|
356
|
+
return [3, 13];
|
|
357
|
+
case 12:
|
|
358
|
+
log_1.Console.success("\u4F7F\u7528\u5DF2\u4FDD\u5B58\u7684\u8FDC\u7A0B\u4ED3\u5E93\u5730\u5740: ".concat(repoUrl));
|
|
359
|
+
_e.label = 13;
|
|
360
|
+
case 13:
|
|
361
|
+
finalCommitMsg = '';
|
|
362
|
+
if (!changes) return [3, 15];
|
|
363
|
+
return [4, commitInfo()];
|
|
364
|
+
case 14:
|
|
365
|
+
finalCommitMsg = _e.sent();
|
|
366
|
+
_e.label = 15;
|
|
367
|
+
case 15:
|
|
368
|
+
addRemote(typeof repoUrl === 'string' ? repoUrl : '');
|
|
369
|
+
commitAndPush(branch, finalCommitMsg, changes);
|
|
370
|
+
createTag();
|
|
371
|
+
return [2];
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
});
|
|
375
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
interface HookMap {
|
|
2
|
+
beforeStart: [{
|
|
3
|
+
cwd: string;
|
|
4
|
+
}];
|
|
5
|
+
afterEnd: [{
|
|
6
|
+
cwd: string;
|
|
7
|
+
}];
|
|
8
|
+
onTask: [taskName: string, retryCount: number];
|
|
9
|
+
}
|
|
10
|
+
type HookName = keyof HookMap;
|
|
11
|
+
type HookFn<K extends HookName> = (...args: HookMap[K]) => any;
|
|
12
|
+
export declare class Hook {
|
|
13
|
+
private hooks;
|
|
14
|
+
register<K extends HookName>(name: K, fn: HookFn<K>): void;
|
|
15
|
+
call<K extends HookName>(name: K, ...args: HookMap[K]): Promise<Record<string, boolean>>;
|
|
16
|
+
}
|
|
17
|
+
export declare const hook: Hook;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.hook = exports.Hook = void 0;
|
|
40
|
+
var log_1 = require("../public/log");
|
|
41
|
+
var Hook = (function () {
|
|
42
|
+
function Hook() {
|
|
43
|
+
this.hooks = {};
|
|
44
|
+
}
|
|
45
|
+
Hook.prototype.register = function (name, fn) {
|
|
46
|
+
if (!this.hooks[name])
|
|
47
|
+
this.hooks[name] = [];
|
|
48
|
+
this.hooks[name].push(fn);
|
|
49
|
+
};
|
|
50
|
+
Hook.prototype.call = function (name) {
|
|
51
|
+
var args = [];
|
|
52
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
53
|
+
args[_i - 1] = arguments[_i];
|
|
54
|
+
}
|
|
55
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
56
|
+
var fns, resultObj, _a, fns_1, fn, res, err_1;
|
|
57
|
+
return __generator(this, function (_b) {
|
|
58
|
+
switch (_b.label) {
|
|
59
|
+
case 0:
|
|
60
|
+
fns = this.hooks[name];
|
|
61
|
+
resultObj = {};
|
|
62
|
+
if (!fns || fns.length === 0)
|
|
63
|
+
return [2, resultObj];
|
|
64
|
+
_a = 0, fns_1 = fns;
|
|
65
|
+
_b.label = 1;
|
|
66
|
+
case 1:
|
|
67
|
+
if (!(_a < fns_1.length)) return [3, 6];
|
|
68
|
+
fn = fns_1[_a];
|
|
69
|
+
_b.label = 2;
|
|
70
|
+
case 2:
|
|
71
|
+
_b.trys.push([2, 4, , 5]);
|
|
72
|
+
return [4, fn.apply(void 0, args)];
|
|
73
|
+
case 3:
|
|
74
|
+
res = _b.sent();
|
|
75
|
+
resultObj[name] = typeof res === 'boolean' ? res : true;
|
|
76
|
+
return [3, 5];
|
|
77
|
+
case 4:
|
|
78
|
+
err_1 = _b.sent();
|
|
79
|
+
log_1.Console.error("\u94A9\u5B50 ".concat(name, " \u6267\u884C\u5931\u8D25:"), err_1);
|
|
80
|
+
resultObj[name] = false;
|
|
81
|
+
return [3, 5];
|
|
82
|
+
case 5:
|
|
83
|
+
_a++;
|
|
84
|
+
return [3, 1];
|
|
85
|
+
case 6: return [2, resultObj];
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
return Hook;
|
|
91
|
+
}());
|
|
92
|
+
exports.Hook = Hook;
|
|
93
|
+
exports.hook = new Hook();
|