提交subgame插件
This commit is contained in:
1
dist/.__build_start_mark/13d50084e094b6a971c3ad55e15c9406.json
vendored
Normal file
1
dist/.__build_start_mark/13d50084e094b6a971c3ad55e15c9406.json
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":"58b3d21f775548914951a9f1d5b04e46db87ab1e","timestamp":1751867724144}
|
||||
1
dist/.__build_start_mark/a757e67b76372f67de1ccc25a1022dfb.json
vendored
Normal file
1
dist/.__build_start_mark/a757e67b76372f67de1ccc25a1022dfb.json
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":"0ed9406d004f0d8030c3f5ae143e950f181d10f5","timestamp":1716369142330}
|
||||
1
dist/.__build_start_mark/b9db1867371b4425d561520ad39a0941.json
vendored
Normal file
1
dist/.__build_start_mark/b9db1867371b4425d561520ad39a0941.json
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":"74bc0889a2e06ba6743eba998d36ec32c33e262a","timestamp":1751618394178}
|
||||
176
dist/Main.js
vendored
Normal file
176
dist/Main.js
vendored
Normal file
@@ -0,0 +1,176 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const FeishuHandler_1 = __importDefault(require("./build/handler/FeishuHandler"));
|
||||
const WechatHandler_1 = __importDefault(require("./build/handler/WechatHandler"));
|
||||
const PackagerAndroid_1 = __importDefault(require("./package/PackagerAndroid"));
|
||||
const PackagerWeb_1 = __importDefault(require("./package/PackagerWeb"));
|
||||
const FileUtils_1 = __importDefault(require("./utils/FileUtils"));
|
||||
const MD5Utils_1 = __importDefault(require("./utils/MD5Utils"));
|
||||
const ProcessUtils_1 = __importDefault(require("./utils/ProcessUtils"));
|
||||
(() => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const command = ProcessUtils_1.default.getArg('--run', value => ['package', 'begin', 'end', 'cache'].indexOf(value) >= 0);
|
||||
if (!command) {
|
||||
console.error(`command error: ${command}`);
|
||||
return;
|
||||
}
|
||||
if (command === 'cache') {
|
||||
const url = ProcessUtils_1.default.getArg('--url', value => !!value && value.startsWith('http'));
|
||||
if (!url) {
|
||||
console.error(`illegal parameter --url`);
|
||||
return;
|
||||
}
|
||||
const configCache = path_1.default.join(process.env.HOME || process.env.USERPROFILE, '.sgp', 'config', `${MD5Utils_1.default.md5(url)}.json`);
|
||||
console.log(`config cache: ${configCache}`);
|
||||
return;
|
||||
}
|
||||
const project = ProcessUtils_1.default.getArg('--project', fs_1.default.existsSync);
|
||||
if (!project) {
|
||||
console.error(`illegal parameter --project or file not exists`);
|
||||
return;
|
||||
}
|
||||
const platform = ProcessUtils_1.default.getArg('--platform', value => ['web-mobile', 'android'].indexOf(value) >= 0);
|
||||
if (!project) {
|
||||
console.error(`illegal parameter --platform`);
|
||||
return;
|
||||
}
|
||||
const isolate = ProcessUtils_1.default.haveArg('--isolate');
|
||||
const mode = ProcessUtils_1.default.getArg('--mode', value => ['dev', 'debug', 'release', 'testRelease'].indexOf(value) >= 0);
|
||||
const buildResultCacheFile = path_1.default.join(project, `build_result_${mode}.json`);
|
||||
switch (command) {
|
||||
case 'begin':
|
||||
case 'end':
|
||||
{
|
||||
const key = ProcessUtils_1.default.getArg('--key', value => !!value && !value.startsWith('--'));
|
||||
const robotKey = ProcessUtils_1.default.getArg('--robot-key', value => value && !value.startsWith('--'));
|
||||
if (!robotKey) {
|
||||
console.error(`illegal parameter --robot-key`);
|
||||
break;
|
||||
}
|
||||
const robotType = ProcessUtils_1.default.getArg('--robot-type', value => ['wechat', 'feishu'].indexOf(value.toLocaleLowerCase()) >= 0);
|
||||
if (!robotType) {
|
||||
console.error(`illegal parameter --robot-type`);
|
||||
break;
|
||||
}
|
||||
const data = [];
|
||||
data.push(`平台=${platform}`);
|
||||
mode && data.push(`环境=${mode}`);
|
||||
data.push(`引擎隔离=${isolate ? '开启' : '关闭'}`);
|
||||
if (fs_1.default.existsSync(buildResultCacheFile)) {
|
||||
if (command === 'end') {
|
||||
const cacheContent = fs_1.default.readFileSync(buildResultCacheFile).toString();
|
||||
console.log(`Cache Content: ${cacheContent}`);
|
||||
const buildResult = JSON.parse(cacheContent);
|
||||
if (buildResult.backupTimestamp)
|
||||
data.push(`构建备份=${buildResult.backupTimestamp}`);
|
||||
const results = buildResult.results;
|
||||
results.forEach(result => {
|
||||
results.length > 1 && data.push(`**SubGame - ${result.key}**`);
|
||||
data.push(`框架版本=${result.frameworkVersion}`);
|
||||
data.push(`游戏版本=${result.packageVersion}`);
|
||||
data.push(`新增文件=${result.added}`);
|
||||
data.push(`修改文件=${result.changed}`);
|
||||
data.push(`删除文件=${result.deleted}`);
|
||||
if (result.size >= 0) {
|
||||
data.push(`游戏包大小=${(result.size / 1024 / 1024).toFixed(2)}MB`);
|
||||
if (result.supportVersion && result.supportVersion.length) {
|
||||
if (result.supportVersion.length === 1)
|
||||
data.push(`增量支持版本=${result.supportVersion.shift()}`);
|
||||
else
|
||||
data.push(`增量支持版本=${result.supportVersion.shift()} - ${result.supportVersion.pop()}`);
|
||||
}
|
||||
}
|
||||
else {
|
||||
data.push(`没有需要构建的更新`);
|
||||
}
|
||||
});
|
||||
}
|
||||
FileUtils_1.default.rm(buildResultCacheFile);
|
||||
}
|
||||
const customData = ProcessUtils_1.default.getArg('--data', value => value && !value.startsWith('--'));
|
||||
customData && data.unshift(...customData.split(';'));
|
||||
const handler = new (robotType === 'wechat' ? WechatHandler_1.default : FeishuHandler_1.default)(robotKey, key ? `SubGame - ${key}` : `SubGame In Project`, project, data.join(';'));
|
||||
command === 'begin' ? yield handler.begin() : yield handler.end();
|
||||
}
|
||||
break;
|
||||
case 'package':
|
||||
{
|
||||
const outputDir = path_1.default.join(project, 'build', 'subgame', platform);
|
||||
FileUtils_1.default.rm(outputDir);
|
||||
const buildPath = path_1.default.join(project, 'build', platform === 'android' ? 'jsb-default' : platform, 'assets');
|
||||
const packageAll = ProcessUtils_1.default.haveArg('--all');
|
||||
const keys = [];
|
||||
if (packageAll) {
|
||||
const subGameDir = fs_1.default.readdirSync(buildPath);
|
||||
subGameDir.forEach(dir => {
|
||||
if (dir === 'main' || dir === 'internal' || dir === 'resources' || dir.startsWith('_'))
|
||||
return;
|
||||
const stat = fs_1.default.statSync(path_1.default.join(buildPath, dir));
|
||||
if (stat.isFile())
|
||||
return;
|
||||
keys.push(dir);
|
||||
});
|
||||
}
|
||||
else {
|
||||
const key = ProcessUtils_1.default.getArg('--key', value => fs_1.default.existsSync(path_1.default.join(buildPath, value)));
|
||||
if (!key) {
|
||||
console.error(`illegal parameter --key or file not exists`);
|
||||
break;
|
||||
}
|
||||
keys.push(key);
|
||||
}
|
||||
switch (platform) {
|
||||
case 'android':
|
||||
{
|
||||
if (!mode) {
|
||||
console.error(`illegal parameter --mode`);
|
||||
break;
|
||||
}
|
||||
const xxtea = ProcessUtils_1.default.getArg('--xxtea', value => !!value && !value.startsWith('--')) || '';
|
||||
const zipCompressJs = !!ProcessUtils_1.default.haveArg('--zipCompressJs');
|
||||
const url = ProcessUtils_1.default.getArg('--url', value => !!value && value.startsWith('http'));
|
||||
const codeVersion = ProcessUtils_1.default.getArg('--version', value => !!value);
|
||||
const results = [];
|
||||
for (const key of keys) {
|
||||
const result = yield (0, PackagerAndroid_1.default)(project, key, codeVersion, mode, url, xxtea, zipCompressJs, isolate);
|
||||
result && results.push(result);
|
||||
}
|
||||
const buildResult = { results };
|
||||
const backup = ProcessUtils_1.default.haveArg('--backup');
|
||||
if (backup) {
|
||||
const dateDir = (new Date()).toLocaleString().replace(/[\/\\:]/gm, '-');
|
||||
buildResult.backupTimestamp = dateDir;
|
||||
const backupDir = path_1.default.join(project, '.subgame_bak', dateDir);
|
||||
FileUtils_1.default.copy(outputDir, backupDir);
|
||||
fs_1.default.writeFileSync(path_1.default.join(backupDir, 'build_result.json'), JSON.stringify(results));
|
||||
}
|
||||
FileUtils_1.default.mkdir(path_1.default.dirname(buildResultCacheFile));
|
||||
fs_1.default.writeFileSync(buildResultCacheFile, JSON.stringify(buildResult));
|
||||
console.warn(`save build result ${buildResultCacheFile}`);
|
||||
}
|
||||
break;
|
||||
case 'web-mobile':
|
||||
{
|
||||
for (const key of keys) {
|
||||
(0, PackagerWeb_1.default)(project, key, isolate);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}))();
|
||||
173
dist/build/handler/FeishuHandler.js
vendored
Normal file
173
dist/build/handler/FeishuHandler.js
vendored
Normal file
@@ -0,0 +1,173 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const ProcessUtils_1 = __importDefault(require("../../utils/ProcessUtils"));
|
||||
const RobotFeishu_1 = __importDefault(require("../robot/RobotFeishu"));
|
||||
const Handler_1 = __importStar(require("./Handler"));
|
||||
const HEAD_TEMPLATE = ['blue', 'wathet', 'turquoise', 'green', 'yellow', 'orange', 'red', 'carmine', 'violet', 'purple', 'indigo', 'grey'];
|
||||
class FeishuHandler extends Handler_1.default {
|
||||
gitHistroyToMD(logs) {
|
||||
let logString = '';
|
||||
for (let index = 0, length = Math.min(logs.length, Handler_1.BUILD_HISTROY_LIMIT); index < length; index++) {
|
||||
const { name, title } = logs[index];
|
||||
if (index !== 0)
|
||||
logString += '\n';
|
||||
const fixTitle = title.replace(new RegExp('\\#', 'gm'), '\\#').replace(new RegExp('\\*', 'gm'), '\\*');
|
||||
;
|
||||
logString += `**${name}** - ${fixTitle}`;
|
||||
}
|
||||
if (logs.length > Handler_1.BUILD_HISTROY_LIMIT) {
|
||||
logString += '\n';
|
||||
logString += `......`;
|
||||
}
|
||||
return logString;
|
||||
}
|
||||
onExceBegin() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const customData = this.getCustomData();
|
||||
if (customData && customData.length) {
|
||||
const data = {
|
||||
config: { wide_screen_mode: true },
|
||||
header: {
|
||||
title: { tag: 'plain_text', content: `${this.taskName} 开始构建` },
|
||||
template: 'grey'
|
||||
},
|
||||
elements: []
|
||||
};
|
||||
const fields = [];
|
||||
customData.forEach(item => {
|
||||
if (typeof item === 'string')
|
||||
fields.push({ is_short: false, text: { tag: 'lark_md', content: item } });
|
||||
else
|
||||
fields.push({ is_short: true, text: { tag: 'lark_md', content: `${item.key}: **${item.value}**` } });
|
||||
});
|
||||
data.elements.push({ tag: 'div', fields });
|
||||
RobotFeishu_1.default.send(this.robotKey, 'interactive', data);
|
||||
}
|
||||
else {
|
||||
RobotFeishu_1.default.send(this.robotKey, 'text', { text: `${this.taskName} 开始构建` });
|
||||
}
|
||||
});
|
||||
}
|
||||
onExceEnd(buildInfo) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const data = {
|
||||
config: { wide_screen_mode: true },
|
||||
header: {
|
||||
title: { tag: 'plain_text', content: `${this.taskName} 构建完成` },
|
||||
template: 'grey'
|
||||
},
|
||||
elements: []
|
||||
};
|
||||
const customData = this.getCustomData();
|
||||
if (customData && customData.length) {
|
||||
data.elements.length && data.elements.push({ tag: 'hr' });
|
||||
const fields = [];
|
||||
customData.forEach(item => {
|
||||
if (typeof item === 'string')
|
||||
fields.push({ is_short: false, text: { tag: 'lark_md', content: item } });
|
||||
else
|
||||
fields.push({ is_short: true, text: { tag: 'lark_md', content: `${item.key}: **${item.value}**` } });
|
||||
});
|
||||
data.elements.push({ tag: 'div', fields });
|
||||
}
|
||||
if (buildInfo && buildInfo.logs && buildInfo.logs.length) {
|
||||
data.elements.length && data.elements.push({ tag: 'hr' });
|
||||
const gitHistroyString = this.gitHistroyToMD(buildInfo.logs);
|
||||
data.elements.push({ tag: 'markdown', content: gitHistroyString });
|
||||
}
|
||||
const url = ProcessUtils_1.default.getArg('--url', value => value && value.startsWith('http'));
|
||||
if (url) {
|
||||
data.elements.push({
|
||||
tag: 'div', text: { tag: 'lark_md', content: '' },
|
||||
extra: { tag: 'button', text: { tag: 'lark_md', content: '查看/下载' }, type: 'primary', url }
|
||||
});
|
||||
}
|
||||
if (buildInfo) {
|
||||
data.elements.push({ tag: 'note', elements: [{ tag: 'plain_text', content: `构建耗时: ${this.timeFormat(buildInfo.time)}` }] });
|
||||
}
|
||||
RobotFeishu_1.default.send(this.robotKey, 'interactive', data);
|
||||
});
|
||||
}
|
||||
beforeExceSleep(continueUrl) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const data = {
|
||||
config: { wide_screen_mode: true },
|
||||
header: {
|
||||
title: { tag: 'plain_text', content: `${this.taskName} 构建暂停` },
|
||||
template: 'grey'
|
||||
},
|
||||
elements: []
|
||||
};
|
||||
const customData = this.getCustomData();
|
||||
if (customData && customData.length) {
|
||||
data.elements.length && data.elements.push({ tag: 'hr' });
|
||||
const fields = [];
|
||||
customData.forEach(item => {
|
||||
if (typeof item === 'string')
|
||||
fields.push({ is_short: false, text: { tag: 'lark_md', content: item } });
|
||||
else
|
||||
fields.push({ is_short: true, text: { tag: 'lark_md', content: `${item.key}: **${item.value}**` } });
|
||||
});
|
||||
data.elements.push({ tag: 'div', fields });
|
||||
}
|
||||
data.elements.push({
|
||||
tag: 'div', text: { tag: 'lark_md', content: '' },
|
||||
extra: { tag: 'button', text: { tag: 'lark_md', content: '继续构建' }, type: 'primary', url: continueUrl }
|
||||
});
|
||||
RobotFeishu_1.default.send(this.robotKey, 'interactive', data);
|
||||
});
|
||||
}
|
||||
afterExceSleep() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
yield RobotFeishu_1.default.send(this.robotKey, 'text', { text: `${this.taskName} 构建恢复` });
|
||||
});
|
||||
}
|
||||
timeFormat(time) {
|
||||
let ms = time;
|
||||
let s = Math.floor(time / 1000);
|
||||
if (s <= 0)
|
||||
return `${ms}毫秒`;
|
||||
ms -= s * 1000;
|
||||
const min = Math.floor(s / 60);
|
||||
if (min <= 0)
|
||||
return `${s}秒 ${ms}毫秒`;
|
||||
s -= min * 60;
|
||||
return `${min}分 ${s}秒 ${ms}毫秒`;
|
||||
}
|
||||
}
|
||||
exports.default = FeishuHandler;
|
||||
98
dist/build/handler/Handler.js
vendored
Normal file
98
dist/build/handler/Handler.js
vendored
Normal file
@@ -0,0 +1,98 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.BUILD_HISTROY_LIMIT = void 0;
|
||||
const crypto_1 = __importDefault(require("crypto"));
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const BuildUtils_1 = __importDefault(require("../../utils/BuildUtils"));
|
||||
const FileUtils_1 = __importDefault(require("../../utils/FileUtils"));
|
||||
exports.BUILD_HISTROY_LIMIT = 20;
|
||||
class Handler {
|
||||
constructor(robotKey, taskName, projectDir, data) {
|
||||
this.robotKey = robotKey;
|
||||
this.taskName = taskName;
|
||||
this.projectDir = projectDir;
|
||||
this.data = data;
|
||||
const hash = crypto_1.default.createHash('md5');
|
||||
hash.update(projectDir, 'utf8');
|
||||
const hex = hash.digest('hex');
|
||||
console.log(`Project Hex: ${hex}`);
|
||||
this.configFilePath = path_1.default.join(__dirname, '..', '..', '.__build_start_mark', `${hex}.json`);
|
||||
FileUtils_1.default.mkdir(path_1.default.dirname(this.configFilePath));
|
||||
}
|
||||
markBuildStart() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let config;
|
||||
if (fs_1.default.existsSync(this.configFilePath)) {
|
||||
const configString = fs_1.default.readFileSync(this.configFilePath).toString();
|
||||
config = JSON.parse(configString);
|
||||
console.log(`Read Cache Git Version: ${config.version} From ${this.configFilePath}`);
|
||||
}
|
||||
else {
|
||||
config = {};
|
||||
config.version = yield BuildUtils_1.default.readGitVersion(this.projectDir);
|
||||
console.log(`Get Git Version: ${config.version}`);
|
||||
}
|
||||
config.timestamp = Date.now();
|
||||
fs_1.default.writeFileSync(this.configFilePath, JSON.stringify(config));
|
||||
});
|
||||
}
|
||||
getBuildInfo() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
if (!fs_1.default.existsSync(this.configFilePath)) {
|
||||
console.log(`Config File Not Exist`);
|
||||
return null;
|
||||
}
|
||||
const configString = fs_1.default.readFileSync(this.configFilePath).toString();
|
||||
const config = JSON.parse(configString);
|
||||
FileUtils_1.default.rm(this.configFilePath);
|
||||
const logs = config.version ? yield BuildUtils_1.default.readGitLog(this.projectDir, config.version) : [];
|
||||
const time = config.timestamp ? (Date.now() - config.timestamp) : 0;
|
||||
return { logs, time };
|
||||
});
|
||||
}
|
||||
getCustomData() {
|
||||
const customData = [];
|
||||
if (!this.data)
|
||||
return customData;
|
||||
const customDataArray = this.data.split(';');
|
||||
if (!customDataArray)
|
||||
return customData;
|
||||
customDataArray.forEach(item => {
|
||||
if (!item || !item.length)
|
||||
return;
|
||||
item = item.replace('==', '|||||');
|
||||
const data = item.split('=').map(value => value.replace('|||||', '='));
|
||||
if (data.length === 1)
|
||||
customData.push(data[0]);
|
||||
else if (data.length === 2)
|
||||
customData.push({ key: data[0], value: data[1] });
|
||||
});
|
||||
return customData;
|
||||
}
|
||||
begin() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
yield this.markBuildStart();
|
||||
yield this.onExceBegin();
|
||||
});
|
||||
}
|
||||
end() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const buildInfo = yield this.getBuildInfo();
|
||||
yield this.onExceEnd(buildInfo);
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.default = Handler;
|
||||
93
dist/build/handler/WechatHandler.js
vendored
Normal file
93
dist/build/handler/WechatHandler.js
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const RobotFeishu_1 = __importDefault(require("../robot/RobotFeishu"));
|
||||
const RobotWechat_1 = __importDefault(require("../robot/RobotWechat"));
|
||||
const Handler_1 = __importStar(require("./Handler"));
|
||||
class WechatHandler extends Handler_1.default {
|
||||
sendTextMessage(text) {
|
||||
const data = {
|
||||
config: { wide_screen_mode: true },
|
||||
header: {
|
||||
title: { tag: 'plain_text', content: this.taskName },
|
||||
template: 'grey'
|
||||
},
|
||||
elements: [{ tag: 'markdown', content: text }]
|
||||
};
|
||||
RobotFeishu_1.default.send(this.robotKey, 'interactive', data);
|
||||
}
|
||||
onExceBegin() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
this.sendTextMessage(`开始构建`);
|
||||
});
|
||||
}
|
||||
onExceEnd(buildInfo) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let message = `${this.taskName}构建完成`;
|
||||
const customData = this.getCustomData();
|
||||
if (customData && customData.length) {
|
||||
customData.forEach(item => {
|
||||
message += '\n';
|
||||
if (typeof item === 'string')
|
||||
message += item;
|
||||
else
|
||||
message += `${item.key}:: **${item.value}**`;
|
||||
});
|
||||
}
|
||||
if (buildInfo && buildInfo.logs && buildInfo.logs.length) {
|
||||
for (let index = 0, length = Math.min(buildInfo.logs.length, Handler_1.BUILD_HISTROY_LIMIT); index < length; index++) {
|
||||
const { name, title } = buildInfo.logs[index];
|
||||
if (index !== 0)
|
||||
message += '\n';
|
||||
const fixTitle = title.replace(new RegExp('\\#', 'gm'), '\\#').replace(new RegExp('\\*', 'gm'), '\\*');
|
||||
;
|
||||
message += `>**${name}** - ${fixTitle}`;
|
||||
}
|
||||
if (buildInfo.logs.length > Handler_1.BUILD_HISTROY_LIMIT)
|
||||
message += `\n>......`;
|
||||
}
|
||||
RobotWechat_1.default.send(this.robotKey, 'markdown', message);
|
||||
});
|
||||
}
|
||||
beforeExceSleep(continueUrl) {
|
||||
return __awaiter(this, void 0, void 0, function* () { });
|
||||
}
|
||||
afterExceSleep() {
|
||||
return __awaiter(this, void 0, void 0, function* () { });
|
||||
}
|
||||
}
|
||||
exports.default = WechatHandler;
|
||||
28
dist/build/robot/RobotFeishu.js
vendored
Normal file
28
dist/build/robot/RobotFeishu.js
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const request_1 = __importDefault(require("request"));
|
||||
var RobotFeishu;
|
||||
(function (RobotFeishu) {
|
||||
const WEBHOOK_URL = 'https://open.larksuite.com/open-apis/bot/v2/hook/';
|
||||
function send(key, messageType, content) {
|
||||
const promise = new Promise(resolve => {
|
||||
const messageData = { msg_type: messageType };
|
||||
if (messageType === 'interactive')
|
||||
messageData.card = content;
|
||||
else
|
||||
messageData.content = content;
|
||||
const body = JSON.stringify(messageData);
|
||||
request_1.default.post({
|
||||
url: WEBHOOK_URL + key, method: "POST",
|
||||
headers: { "content-type": "application/json", },
|
||||
body
|
||||
}, (error, response, body) => resolve({ error, response, body }));
|
||||
});
|
||||
return promise;
|
||||
}
|
||||
RobotFeishu.send = send;
|
||||
})(RobotFeishu || (RobotFeishu = {}));
|
||||
exports.default = RobotFeishu;
|
||||
24
dist/build/robot/RobotWechat.js
vendored
Normal file
24
dist/build/robot/RobotWechat.js
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const request_1 = __importDefault(require("request"));
|
||||
var RobotWechat;
|
||||
(function (RobotWechat) {
|
||||
const WEBHOOK_URL = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=';
|
||||
RobotWechat.send = (key, messageType, message) => {
|
||||
let messageData = { msgtype: messageType };
|
||||
messageData[messageType] = { content: message };
|
||||
let messageString = JSON.stringify(messageData);
|
||||
(0, request_1.default)({
|
||||
url: WEBHOOK_URL + key,
|
||||
method: "POST",
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
},
|
||||
body: messageString
|
||||
});
|
||||
};
|
||||
})(RobotWechat || (RobotWechat = {}));
|
||||
exports.default = RobotWechat;
|
||||
76
dist/package/PackageScript.js
vendored
Normal file
76
dist/package/PackageScript.js
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.PackageScript = void 0;
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const xxtea_node_1 = __importDefault(require("xxtea-node"));
|
||||
const pako_1 = __importDefault(require("pako"));
|
||||
const FileUtils_1 = __importDefault(require("../utils/FileUtils"));
|
||||
const SCRIPT_PACKAGE = fs_1.default.readFileSync(path_1.default.join(__dirname, '..', '..', 'template', 'SCRIPT_PACKAGE.js')).toString();
|
||||
const SETTING_GOURPLIST_REGEXP = /groupList:\s*(\[['",a-zA-Z0-9\s]+])/mg;
|
||||
const SETTING_COLLISIONMATRIX_REGEXP = /collisionMatrix:\s*(\[[\[\],truefalse\s]+\])/mg;
|
||||
function PackageScript(key, buildPath, isolate = false, xxtea, ungzip = false) {
|
||||
const bundleDir = path_1.default.join(buildPath, 'assets', key);
|
||||
if (fs_1.default.existsSync(path_1.default.join(bundleDir, 'config.subgame.json'))) {
|
||||
console.warn(`Package [${key}] script packaged`);
|
||||
return;
|
||||
}
|
||||
console.log(`Package [${key}] find config`);
|
||||
const configPath = FileUtils_1.default.find(bundleDir, /config\.([a-zA-Z0-9\.]+\.)?json/);
|
||||
fs_1.default.renameSync(configPath, path_1.default.join(bundleDir, 'config.subgame.json'));
|
||||
console.log(`Package [${key}] config finded, renames`);
|
||||
console.log(`Package [${key}] find index script`);
|
||||
const scriptPath = FileUtils_1.default.find(bundleDir, /index\.([a-zA-Z0-9\.]+\.)?js/);
|
||||
const scriptEncrypt = path_1.default.extname(scriptPath) === '.jsc';
|
||||
let scriptBuffer = fs_1.default.readFileSync(scriptPath);
|
||||
let script;
|
||||
if (scriptEncrypt) {
|
||||
script = decryptJSC(scriptBuffer, xxtea, ungzip);
|
||||
console.log(`Package [${key}] index script decrypt result: ${script.substring(0, 100)}...`);
|
||||
}
|
||||
else {
|
||||
script = scriptBuffer.toString();
|
||||
}
|
||||
if (isolate) {
|
||||
console.log(`Package [${key}] find settings`);
|
||||
const settingPath = FileUtils_1.default.find(path_1.default.join(buildPath, 'src'), /settings\.([a-zA-Z0-9\.]+\.)?js/);
|
||||
const settingsBuffer = fs_1.default.readFileSync(settingPath);
|
||||
let settings;
|
||||
if (path_1.default.extname(settingPath) === '.jsc') {
|
||||
settings = decryptJSC(settingsBuffer, xxtea, ungzip);
|
||||
console.log(`Package [${key}] settings script decrypt result: ${settings.substring(0, 100)}...`);
|
||||
}
|
||||
else
|
||||
settings = settingsBuffer.toString();
|
||||
const groupList = SETTING_GOURPLIST_REGEXP.exec(settings)[1];
|
||||
const collisionMatrix = SETTING_COLLISIONMATRIX_REGEXP.exec(settings)[1];
|
||||
console.log(`Package [${key}] settings finded, saved`);
|
||||
script = SCRIPT_PACKAGE
|
||||
.replace('"%{subgame_key}"', key)
|
||||
.replace('"%{subgame_content}"', script)
|
||||
.replace('"%{subgame_group_list}"', groupList)
|
||||
.replace('"%{subgame_collision_matrix}"', collisionMatrix);
|
||||
console.log(`Package [${key}] class isolate`);
|
||||
}
|
||||
if (scriptEncrypt)
|
||||
fs_1.default.writeFileSync(scriptPath, encryptJS(script, xxtea, ungzip));
|
||||
else
|
||||
fs_1.default.writeFileSync(scriptPath, script);
|
||||
fs_1.default.renameSync(scriptPath, path_1.default.join(bundleDir, 'index.subgame' + path_1.default.extname(scriptPath)));
|
||||
console.log(`Package [${key}] index script packaged`);
|
||||
}
|
||||
exports.PackageScript = PackageScript;
|
||||
const decryptJSC = (data, key, ungzip = true) => {
|
||||
let res = xxtea_node_1.default.decrypt(data, xxtea_node_1.default.toBytes(key));
|
||||
res = pako_1.default.ungzip(res);
|
||||
return xxtea_node_1.default.toString(res);
|
||||
};
|
||||
const encryptJS = (data, key, ungzip = true) => {
|
||||
const res = pako_1.default.gzip(xxtea_node_1.default.toBytes(data), { level: 6 });
|
||||
const result = xxtea_node_1.default.encrypt(res, xxtea_node_1.default.toBytes(key));
|
||||
console.dir(result);
|
||||
return result;
|
||||
};
|
||||
185
dist/package/PackagerAndroid.js
vendored
Normal file
185
dist/package/PackagerAndroid.js
vendored
Normal file
@@ -0,0 +1,185 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const FileUtils_1 = __importDefault(require("../utils/FileUtils"));
|
||||
const MD5Utils_1 = __importDefault(require("../utils/MD5Utils"));
|
||||
const PackageScript_1 = require("./PackageScript");
|
||||
const START_VERSION = 1000;
|
||||
const VERSION_SUPPORT = 50;
|
||||
function readExistPackageRecords(versionCacheDir) {
|
||||
const versions = [];
|
||||
const versionFiles = fs_1.default.readdirSync(versionCacheDir);
|
||||
versionFiles.forEach(versionFile => {
|
||||
const versionFilePath = path_1.default.join(versionCacheDir, versionFile);
|
||||
const stat = fs_1.default.statSync(versionFilePath);
|
||||
if (stat.isDirectory())
|
||||
return;
|
||||
const versionString = path_1.default.basename(versionFile, path_1.default.extname(versionFile));
|
||||
const version = parseInt(versionString);
|
||||
versions.push(version);
|
||||
});
|
||||
return versions.sort((a, b) => a - b).slice(-VERSION_SUPPORT);
|
||||
}
|
||||
function readPackageRecord(version, versionCacheDir) {
|
||||
const infoFilePath = path_1.default.join(versionCacheDir, `${version}.json`);
|
||||
if (!fs_1.default.existsSync(infoFilePath))
|
||||
return null;
|
||||
const subpackageInfoContent = fs_1.default.readFileSync(infoFilePath);
|
||||
const info = JSON.parse(subpackageInfoContent.toString());
|
||||
return info;
|
||||
}
|
||||
function writePackageRecord(version, record, versionCacheDir) {
|
||||
const content = JSON.stringify(record);
|
||||
const infoFilePath = path_1.default.join(versionCacheDir, `${version}.json`);
|
||||
FileUtils_1.default.mkdir(path_1.default.dirname(infoFilePath));
|
||||
fs_1.default.writeFileSync(infoFilePath, content);
|
||||
}
|
||||
function loadMainConfig(url) {
|
||||
const configCache = path_1.default.join(process.env.HOME || process.env.USERPROFILE, '.sgp', 'config', `${MD5Utils_1.default.md5(url)}`, `subgame_config.json`);
|
||||
if (fs_1.default.existsSync(configCache)) {
|
||||
const mainConfig = JSON.parse(fs_1.default.readFileSync(configCache).toString());
|
||||
return mainConfig;
|
||||
}
|
||||
return [];
|
||||
}
|
||||
function loadPackageConfig(url, key) {
|
||||
const configCache = path_1.default.join(process.env.HOME || process.env.USERPROFILE, '.sgp', 'config', `${MD5Utils_1.default.md5(url)}`, `subgame_config_${key}.json`);
|
||||
if (fs_1.default.existsSync(configCache)) {
|
||||
const packageConfig = JSON.parse(fs_1.default.readFileSync(configCache).toString());
|
||||
return packageConfig;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
function writeMainConfig(url, mainConfigs) {
|
||||
const configCacheDir = path_1.default.join(process.env.HOME || process.env.USERPROFILE, '.sgp', 'config', `${MD5Utils_1.default.md5(url)}`);
|
||||
FileUtils_1.default.mkdir(configCacheDir);
|
||||
fs_1.default.writeFileSync(path_1.default.join(configCacheDir, `subgame_config.json`), JSON.stringify(mainConfigs));
|
||||
}
|
||||
function writePackageConfig(url, key, packageConfig) {
|
||||
const configCacheDir = path_1.default.join(process.env.HOME || process.env.USERPROFILE, '.sgp', 'config', `${MD5Utils_1.default.md5(url)}`);
|
||||
FileUtils_1.default.mkdir(configCacheDir);
|
||||
fs_1.default.writeFileSync(path_1.default.join(configCacheDir, `subgame_config_${key}.json`), JSON.stringify(packageConfig));
|
||||
}
|
||||
function PackageAndroid(projectDir, key, frameworkVersion, mode, url, xxtea, zipCompressJs, isolate = false) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
console.log(`-----------------------------------------------------Handle package [${key}] start-----------------------------------------------------`);
|
||||
const outputDir = path_1.default.join(projectDir, 'build', 'subgame', 'android');
|
||||
console.log(`Make package [${key}] zip dir: ${outputDir}`);
|
||||
FileUtils_1.default.mkdir(outputDir);
|
||||
const versionCacheDir = path_1.default.join(projectDir, 'version', key, mode);
|
||||
console.log(`Make package [${key}] info dir: ${versionCacheDir}`);
|
||||
FileUtils_1.default.mkdir(versionCacheDir);
|
||||
const buildDir = path_1.default.join(projectDir, 'build', 'jsb-default');
|
||||
const bundleDir = path_1.default.join(buildDir, 'assets', key);
|
||||
(0, PackageScript_1.PackageScript)(key, buildDir, isolate, xxtea, zipCompressJs);
|
||||
const mainConfigs = loadMainConfig(url);
|
||||
if (!mainConfigs)
|
||||
throw new Error(`load main config fail`);
|
||||
const existVersions = readExistPackageRecords(versionCacheDir);
|
||||
const haveExistVersion = existVersions && existVersions.length;
|
||||
const config = loadPackageConfig(url, key) || { version: START_VERSION, packages: [] };
|
||||
const previousVersion = config.version;
|
||||
const previousRecord = haveExistVersion ? readPackageRecord(previousVersion, versionCacheDir) : { md5: [] };
|
||||
console.log(`Package [${key}] previous version: ${previousVersion}`);
|
||||
const md5 = MD5Utils_1.default.md5Dir(bundleDir, null);
|
||||
const md5Compare = MD5Utils_1.default.md5Compare(md5, previousRecord.md5);
|
||||
console.log(`Package [${key}] compare with last: added=${md5Compare.added.length}, deleted:${md5Compare.deleted.length}, same:${md5Compare.same.length}, changed:${md5Compare.changed.length}`);
|
||||
const packageResult = {
|
||||
project: projectDir,
|
||||
key, frameworkVersion, mode, url, xxtea, zipCompressJs, isolate,
|
||||
packageVersion: previousVersion,
|
||||
supportVersion: existVersions,
|
||||
added: md5Compare.added.length,
|
||||
changed: md5Compare.changed.length,
|
||||
deleted: md5Compare.deleted.length,
|
||||
size: -1
|
||||
};
|
||||
if (md5Compare.changed.length || md5Compare.added.length) {
|
||||
console.log(`Package [${key}] changed`);
|
||||
const zipCacheOutputDir = path_1.default.join(outputDir, 'cache');
|
||||
console.log(`Make package [${key}] zip cache dir: ${zipCacheOutputDir}`);
|
||||
FileUtils_1.default.rm(zipCacheOutputDir);
|
||||
FileUtils_1.default.mkdir(zipCacheOutputDir);
|
||||
const packages = [];
|
||||
const newVersion = previousVersion + 1;
|
||||
for (const versionItem of existVersions) {
|
||||
console.log(`Pick package [${key}] assets for version ${versionItem} to ${newVersion}`);
|
||||
const versionInfo = readPackageRecord(versionItem, versionCacheDir);
|
||||
if (!versionInfo) {
|
||||
console.warn(`ackage [${key}] skip exits version ${versionItem}, no version info.`);
|
||||
continue;
|
||||
}
|
||||
const versionCompareResult = MD5Utils_1.default.md5Compare(md5, versionInfo.md5);
|
||||
console.log(`Package [${key}] compare with version ${versionItem}: added=${versionCompareResult.added.length}, deleted:${versionCompareResult.deleted.length} , same:${versionCompareResult.same.length}, changed:${versionCompareResult.changed.length}`);
|
||||
const files = versionCompareResult.changed.concat(versionCompareResult.added);
|
||||
const zipCacheDir = path_1.default.join(zipCacheOutputDir, `${versionItem}_${newVersion}`);
|
||||
FileUtils_1.default.mkdir(zipCacheDir);
|
||||
files.forEach(value => {
|
||||
const outPath = path_1.default.join(zipCacheDir, value.path);
|
||||
FileUtils_1.default.mkdir(path_1.default.dirname(outPath));
|
||||
fs_1.default.copyFileSync(path_1.default.join(bundleDir, value.path), outPath);
|
||||
});
|
||||
const zipOutFile = path_1.default.join(outputDir, `${key}_${versionItem}_${newVersion}.zip`);
|
||||
const fileCount = FileUtils_1.default.fileCount(zipCacheDir, true);
|
||||
yield FileUtils_1.default.zipdir(zipCacheDir, zipOutFile);
|
||||
FileUtils_1.default.rm(zipCacheDir);
|
||||
const zipStat = fs_1.default.statSync(zipOutFile);
|
||||
const zipMD5 = MD5Utils_1.default.md5Dir(zipOutFile)[0].md5;
|
||||
packages.push({ version: versionItem, size: zipStat.size, files: fileCount, md5: zipMD5 });
|
||||
}
|
||||
FileUtils_1.default.rm(zipCacheOutputDir);
|
||||
const zipOutFile = path_1.default.join(outputDir, `${key}_${newVersion}.zip`);
|
||||
const fileCount = FileUtils_1.default.fileCount(bundleDir, true);
|
||||
yield FileUtils_1.default.zipdir(bundleDir, zipOutFile);
|
||||
const zipStat = fs_1.default.statSync(zipOutFile);
|
||||
const zipMD5 = MD5Utils_1.default.md5Dir(zipOutFile)[0].md5;
|
||||
packages.push({ version: 0, size: zipStat.size, files: fileCount, md5: zipMD5 });
|
||||
writePackageRecord(newVersion, { md5 }, versionCacheDir);
|
||||
const mainConfig = mainConfigs.find(value => value.key === key);
|
||||
if (mainConfig) {
|
||||
mainConfig.version = newVersion;
|
||||
mainConfig.supports = existVersions;
|
||||
}
|
||||
else {
|
||||
mainConfigs.push({ key, version: newVersion, supports: existVersions });
|
||||
}
|
||||
writeMainConfig(url, mainConfigs);
|
||||
config.version = newVersion;
|
||||
config.packages = packages;
|
||||
writePackageConfig(url, key, config);
|
||||
packageResult.packageVersion = newVersion;
|
||||
packageResult.size = zipStat.size;
|
||||
console.log(`Package [${key}] build finished`);
|
||||
}
|
||||
else if (md5Compare.deleted.length) {
|
||||
console.log(`Package [${key}] no changes (but delete)`);
|
||||
}
|
||||
else {
|
||||
console.log(`Package [${key}] no changes`);
|
||||
}
|
||||
console.log(`save package [${key}] config`);
|
||||
const configFileName = `subgame_config_${key}_${frameworkVersion}.json`;
|
||||
const configFilePath = path_1.default.join(outputDir, configFileName);
|
||||
fs_1.default.writeFileSync(configFilePath, JSON.stringify(config));
|
||||
console.log(`save main config`);
|
||||
fs_1.default.writeFileSync(path_1.default.join(outputDir, `subgame_config_${frameworkVersion}.json`), JSON.stringify(mainConfigs));
|
||||
FileUtils_1.default.rm(bundleDir);
|
||||
console.log(`Package [${key}] build result: \n ${JSON.stringify(packageResult)}`);
|
||||
console.log(`-----------------------------------------------------Handle package [${key}] end-------------------------------------------------------\n\n`);
|
||||
return packageResult;
|
||||
});
|
||||
}
|
||||
exports.default = PackageAndroid;
|
||||
22
dist/package/PackagerWeb.js
vendored
Normal file
22
dist/package/PackagerWeb.js
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const FileUtils_1 = __importDefault(require("../utils/FileUtils"));
|
||||
const PackageScript_1 = require("./PackageScript");
|
||||
function PackageWeb(projectDir, key, isolate = false) {
|
||||
console.log(`-----------------------------------------------------Handle package [${key}] start-----------------------------------------------------`);
|
||||
const outputDir = path_1.default.join(projectDir, 'build', 'subgame', 'web-mobile', key);
|
||||
FileUtils_1.default.rm(outputDir);
|
||||
FileUtils_1.default.mkdir(path_1.default.dirname(outputDir));
|
||||
console.log(`Make package [${key}] output dir: ${outputDir}`);
|
||||
const buildDir = path_1.default.join(projectDir, 'build', 'web-mobile');
|
||||
const bundleDir = path_1.default.join(buildDir, 'assets', key);
|
||||
(0, PackageScript_1.PackageScript)(key, buildDir, isolate);
|
||||
fs_1.default.renameSync(bundleDir, outputDir);
|
||||
console.log(`-----------------------------------------------------Handle package [${key}] end-------------------------------------------------------\n\n`);
|
||||
}
|
||||
exports.default = PackageWeb;
|
||||
59
dist/utils/BuildUtils.js
vendored
Normal file
59
dist/utils/BuildUtils.js
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const child_process_1 = __importDefault(require("child_process"));
|
||||
var BuildUtils;
|
||||
(function (BuildUtils) {
|
||||
const LOG_SPLIT_SEPARATOR = '||||||';
|
||||
const exec = (cmd) => {
|
||||
const promise = new Promise((resolve) => {
|
||||
let result = '';
|
||||
const stream = child_process_1.default.exec(cmd);
|
||||
stream.stdout.on('data', data => {
|
||||
console.log('stdout: ' + data);
|
||||
result += data;
|
||||
});
|
||||
stream.stderr.on('data', data => console.error(`stderr: ${data}`));
|
||||
stream.on('close', (code) => {
|
||||
if (code !== 0)
|
||||
console.warn(`process exited with code ${code}`);
|
||||
resolve(result || "");
|
||||
});
|
||||
});
|
||||
return promise;
|
||||
};
|
||||
BuildUtils.readGitVersion = (dir) => __awaiter(this, void 0, void 0, function* () {
|
||||
const commit = yield exec(`cd ${dir} && git show -s --format=%H`);
|
||||
return commit.trim();
|
||||
});
|
||||
BuildUtils.readGitLog = (dir, startVersion) => __awaiter(this, void 0, void 0, function* () {
|
||||
let command = `cd ${dir} && `;
|
||||
command += startVersion ? `git log ${startVersion}.. ` : 'git log ';
|
||||
command += `--pretty=format:"%an${LOG_SPLIT_SEPARATOR}%s${LOG_SPLIT_SEPARATOR}%H" --no-merges`;
|
||||
const log = yield exec(command);
|
||||
const logArray = log.split('\n');
|
||||
const messageArray = [];
|
||||
logArray.forEach((element) => {
|
||||
if (!element || !element.length)
|
||||
return;
|
||||
const data = element.split(LOG_SPLIT_SEPARATOR);
|
||||
if (!data || data.length !== 3)
|
||||
return;
|
||||
const [name, title, id] = data;
|
||||
messageArray.push({ name, title });
|
||||
});
|
||||
return messageArray;
|
||||
});
|
||||
})(BuildUtils || (BuildUtils = {}));
|
||||
exports.default = BuildUtils;
|
||||
120
dist/utils/FileUtils.js
vendored
Normal file
120
dist/utils/FileUtils.js
vendored
Normal file
@@ -0,0 +1,120 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const archiver_1 = __importDefault(require("archiver"));
|
||||
var FileUtils;
|
||||
(function (FileUtils) {
|
||||
function copy(srcFileOrDir, destFileOrDir) {
|
||||
if (!fs_1.default.existsSync(srcFileOrDir))
|
||||
return;
|
||||
const stat = fs_1.default.statSync(srcFileOrDir);
|
||||
if (stat.isDirectory()) {
|
||||
mkdir(destFileOrDir);
|
||||
const files = fs_1.default.readdirSync(srcFileOrDir);
|
||||
files.forEach(item => copy(path_1.default.join(srcFileOrDir, item), path_1.default.join(destFileOrDir, item)));
|
||||
}
|
||||
else {
|
||||
mkdir(path_1.default.dirname(destFileOrDir));
|
||||
fs_1.default.copyFileSync(srcFileOrDir, destFileOrDir);
|
||||
}
|
||||
}
|
||||
FileUtils.copy = copy;
|
||||
function mkdir(dir) {
|
||||
if (fs_1.default.existsSync(dir))
|
||||
return;
|
||||
let parentDir = path_1.default.dirname(dir);
|
||||
mkdir(parentDir);
|
||||
fs_1.default.mkdirSync(dir);
|
||||
}
|
||||
FileUtils.mkdir = mkdir;
|
||||
function rm(fileOrDir) {
|
||||
if (!fs_1.default.existsSync(fileOrDir))
|
||||
return;
|
||||
const stat = fs_1.default.statSync(fileOrDir);
|
||||
if (stat.isDirectory()) {
|
||||
const files = fs_1.default.readdirSync(fileOrDir);
|
||||
files.forEach(item => rm(path_1.default.join(fileOrDir, item)));
|
||||
fs_1.default.rmdirSync(fileOrDir);
|
||||
}
|
||||
else {
|
||||
fs_1.default.unlinkSync(fileOrDir);
|
||||
}
|
||||
}
|
||||
FileUtils.rm = rm;
|
||||
function find(dir, nameOrRegExp, deepFind = false) {
|
||||
if (!fs_1.default.existsSync(dir))
|
||||
return null;
|
||||
const files = fs_1.default.readdirSync(dir);
|
||||
const check = typeof nameOrRegExp === 'string' ? (value) => value === nameOrRegExp : (value) => nameOrRegExp.test(value);
|
||||
for (const file of files) {
|
||||
const fullPath = path_1.default.join(dir, file);
|
||||
const stat = fs_1.default.statSync(fullPath);
|
||||
if (!stat.isDirectory()) {
|
||||
if (check(file))
|
||||
return fullPath;
|
||||
}
|
||||
else if (deepFind) {
|
||||
const result = find(fullPath, nameOrRegExp);
|
||||
if (result)
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
FileUtils.find = find;
|
||||
function fileCount(dir, includeFolder = false) {
|
||||
if (!fs_1.default.existsSync(dir))
|
||||
return 0;
|
||||
const stat = fs_1.default.statSync(dir);
|
||||
if (!stat.isDirectory()) {
|
||||
return 1;
|
||||
}
|
||||
let count = includeFolder ? 1 : 0;
|
||||
const files = fs_1.default.readdirSync(dir);
|
||||
files.forEach(item => count += fileCount(path_1.default.join(dir, item)));
|
||||
return count;
|
||||
}
|
||||
FileUtils.fileCount = fileCount;
|
||||
function checkFileNameIndex(fileFullPath, indexGen = index => `(${index})`) {
|
||||
if (!fs_1.default.existsSync(fileFullPath))
|
||||
return fileFullPath;
|
||||
const extname = path_1.default.extname(fileFullPath);
|
||||
const basename = path_1.default.basename(fileFullPath, extname);
|
||||
const dirname = path_1.default.dirname(fileFullPath);
|
||||
let i = 1;
|
||||
let limit = 1000;
|
||||
while (limit-- > 0) {
|
||||
const newPath = path_1.default.join(dirname, `${basename}${indexGen(i)}${extname}`);
|
||||
if (!fs_1.default.existsSync(newPath))
|
||||
return newPath;
|
||||
i++;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
FileUtils.checkFileNameIndex = checkFileNameIndex;
|
||||
function zipdir(srcDir, outputFile) {
|
||||
mkdir(path_1.default.dirname(outputFile));
|
||||
var promise = new Promise((resolve, reject) => {
|
||||
const writeStream = fs_1.default.createWriteStream(outputFile);
|
||||
const archive = (0, archiver_1.default)('zip', {
|
||||
zlib: { level: 9 }
|
||||
});
|
||||
writeStream.on('close', () => {
|
||||
resolve();
|
||||
});
|
||||
archive.on('error', function (error) {
|
||||
reject(error);
|
||||
});
|
||||
archive.pipe(writeStream);
|
||||
archive.directory(srcDir, false);
|
||||
archive.finalize();
|
||||
});
|
||||
return promise;
|
||||
}
|
||||
FileUtils.zipdir = zipdir;
|
||||
})(FileUtils || (FileUtils = {}));
|
||||
exports.default = FileUtils;
|
||||
66
dist/utils/MD5Utils.js
vendored
Normal file
66
dist/utils/MD5Utils.js
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const crypto_1 = __importDefault(require("crypto"));
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
const path_1 = __importDefault(require("path"));
|
||||
var MD5Utils;
|
||||
(function (MD5Utils) {
|
||||
function md5(text) {
|
||||
const hash = crypto_1.default.createHash('md5');
|
||||
hash.update(text);
|
||||
const hex = hash.digest('hex');
|
||||
return hex;
|
||||
}
|
||||
MD5Utils.md5 = md5;
|
||||
function md5Dir(fileOrDir, output) {
|
||||
output = output || [];
|
||||
if (!fs_1.default.existsSync(fileOrDir))
|
||||
return output;
|
||||
const relativePath = fileOrDir;
|
||||
const md5 = (file) => {
|
||||
const stat = fs_1.default.statSync(file);
|
||||
if (!stat.isDirectory()) {
|
||||
const buffer = fs_1.default.readFileSync(file);
|
||||
const hash = crypto_1.default.createHash('md5');
|
||||
hash.update(buffer);
|
||||
const hex = hash.digest('hex');
|
||||
output.push({ path: path_1.default.relative(relativePath, file), md5: hex });
|
||||
}
|
||||
else {
|
||||
const files = fs_1.default.readdirSync(file);
|
||||
files.forEach(item => md5(path_1.default.join(file, item)));
|
||||
}
|
||||
};
|
||||
md5(fileOrDir);
|
||||
return output;
|
||||
}
|
||||
MD5Utils.md5Dir = md5Dir;
|
||||
function md5Compare(source, target) {
|
||||
const result = { added: [], deleted: [], changed: [], same: [] };
|
||||
target = target.concat([]);
|
||||
source = source.concat([]);
|
||||
let sourceItem;
|
||||
while (sourceItem = source.shift()) {
|
||||
let matchItem = undefined;
|
||||
for (let j = 0, length = target.length; j < length; j++) {
|
||||
const targetItem = target[j];
|
||||
if (targetItem.path !== sourceItem.path)
|
||||
continue;
|
||||
matchItem = targetItem;
|
||||
target.splice(j, 1);
|
||||
break;
|
||||
}
|
||||
if (!matchItem)
|
||||
result.added.push(sourceItem);
|
||||
else
|
||||
matchItem.md5 === sourceItem.md5 ? result.same.push(sourceItem) : result.changed.push(sourceItem);
|
||||
}
|
||||
result.deleted.push(...target);
|
||||
return result;
|
||||
}
|
||||
MD5Utils.md5Compare = md5Compare;
|
||||
})(MD5Utils || (MD5Utils = {}));
|
||||
exports.default = MD5Utils;
|
||||
19
dist/utils/ProcessUtils.js
vendored
Normal file
19
dist/utils/ProcessUtils.js
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var ProcessUtils;
|
||||
(function (ProcessUtils) {
|
||||
function getArg(key, check) {
|
||||
const index = process.argv.indexOf(key);
|
||||
if (index < 0)
|
||||
return null;
|
||||
const value = process.argv[index + 1];
|
||||
return check ? (check(value) ? value : null) : value;
|
||||
}
|
||||
ProcessUtils.getArg = getArg;
|
||||
function haveArg(key) {
|
||||
const index = process.argv.indexOf(key);
|
||||
return index >= 0;
|
||||
}
|
||||
ProcessUtils.haveArg = haveArg;
|
||||
})(ProcessUtils || (ProcessUtils = {}));
|
||||
exports.default = ProcessUtils;
|
||||
Reference in New Issue
Block a user