This repository has been archived by the owner on Mar 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0c719c2
commit b070432
Showing
6 changed files
with
170 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
node_modules | ||
out | ||
dist | ||
app-builds | ||
app-builds | ||
package-release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
|
||
import * as program from 'commander'; | ||
import { execSync, exec } from 'child_process'; | ||
import * as fs from 'fs-extra'; | ||
import * as path from 'path'; | ||
import * as AdmZip from 'adm-zip'; | ||
import * as semver from 'semver'; | ||
|
||
enum Platform { | ||
All = "all", | ||
Browser = "browser", | ||
Desktop = "desktop", | ||
} | ||
|
||
const PackageFile = path.resolve(__dirname, "../package.json"); | ||
|
||
export function sleep(ms: number) { | ||
return new Promise<void>(res => setTimeout(res, ms)); | ||
} | ||
|
||
function readPackageInfo() { | ||
return JSON.parse(fs.readFileSync(PackageFile).toString("utf8")); | ||
} | ||
|
||
program | ||
.option('-p, --platform [platform]', '要编译的平台') | ||
.option('-v, --version [buildVersion]', "发布的版本,在不同的版本标记上递增").description(`可选: major, premajor, minor, preminor, patch, prepatch, prerelease`) | ||
.option('-o, --output-directory [output]', '输出目录') | ||
|
||
program.parse(process.argv); | ||
|
||
console.log("[!] 构建平台: ", program.platform) | ||
|
||
|
||
// 设置默认参数 | ||
if (!program.platform) { | ||
program.platform = Platform.All; | ||
} | ||
|
||
if (!program.output) { | ||
program.output = path.join(__dirname, "../package-release"); | ||
} | ||
|
||
if (!program.buildVersion) { | ||
program.buildVersion = "patch"; | ||
} | ||
|
||
// 创建输出目录 | ||
fs.mkdirpSync(program.output); | ||
|
||
const buildingPlatforms = []; | ||
|
||
if (program.platform === Platform.Browser) { | ||
buildingPlatforms.push(Platform.Browser) | ||
} | ||
|
||
if (program.platform === Platform.Desktop) { | ||
buildingPlatforms.push(Platform.Desktop) | ||
} | ||
|
||
if (program.platform === Platform.All) { | ||
buildingPlatforms.push(Platform.Browser) | ||
buildingPlatforms.push(Platform.Desktop) | ||
} | ||
|
||
|
||
buildingPlatforms.forEach((platform) => { | ||
|
||
console.log(`[!] 开始构建 ${platform} ...`) | ||
|
||
const cmd = exec(`yarn build:${platform}`); | ||
// const cmd = exec(`echo a`); | ||
cmd.stdout.on('data', (data) => { | ||
console.log(data); | ||
}); | ||
|
||
cmd.stderr.on('data', (data) => { | ||
console.error(data); | ||
}); | ||
|
||
cmd.on("exit", async (code: number) => { | ||
if (code !== 0) { | ||
console.log(`[X] ${platform} 构建失败`); | ||
return; | ||
} | ||
|
||
let packageInfo = readPackageInfo(); | ||
const originalVersion = `v${packageInfo.version}`; | ||
|
||
console.log("[!] 更新版本信息 ... ") | ||
const newVersion = semver.inc(packageInfo.version, program.buildVersion); | ||
packageInfo.version = newVersion; | ||
fs.writeJSONSync(PackageFile, packageInfo, { spaces: 2 }); | ||
|
||
const newVersionWithTag = `v${newVersion}`; | ||
|
||
console.log(`[!] 打包版本号:${newVersionWithTag} (${originalVersion} -> ${newVersionWithTag})`) | ||
|
||
console.log("[!] 更新引擎配置文件 ... ") | ||
const buildOutputDir = path.resolve(__dirname, `../dist/${platform}`); | ||
const engineConfig = path.resolve(buildOutputDir, `engine.json`); | ||
const engineInfo = require(engineConfig); | ||
engineInfo.game_assets_root = "http://localhost:2336" | ||
engineInfo.version = packageInfo.version; | ||
|
||
fs.writeFileSync(engineConfig, JSON.stringify(engineInfo, null, 2), { encoding: "utf8" }) | ||
|
||
console.log("[!] 开始打包...") | ||
const outputFile = path.resolve(__dirname, `../package-release/AVGPlus-${platform}-v${packageInfo.version}_alpha.zip`); | ||
|
||
const zip = new AdmZip(); | ||
zip.addLocalFolder(buildOutputDir); | ||
zip.writeZip(outputFile); | ||
console.log(`[!] 发布文件路径:${outputFile}`) | ||
|
||
console.log(`\n[√] ✨ 版本 ${newVersionWithTag} 发布完成!`) | ||
}) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1577,6 +1577,13 @@ | |
dependencies: | ||
defer-to-connect "^1.0.1" | ||
|
||
"@types/adm-zip@^0.4.32": | ||
version "0.4.32" | ||
resolved "https://registry.npm.taobao.org/@types/adm-zip/download/@types/adm-zip-0.4.32.tgz#6de01309af60677065d2e52b417a023303220931" | ||
integrity sha1-beATCa9gZ3Bl0uUrQXoCMwMiCTE= | ||
dependencies: | ||
"@types/node" "*" | ||
|
||
"@types/[email protected]": | ||
version "3.5.8" | ||
resolved "https://registry.npm.taobao.org/@types/bluebird/download/@types/bluebird-3.5.8.tgz#242a83379f06c90f96acf6d1aeab3af6faebdb98" | ||
|
@@ -1624,6 +1631,13 @@ | |
resolved "https://registry.npm.taobao.org/@types/events/download/@types/events-3.0.0.tgz#2862f3f58a9a7f7c3e78d79f130dd4d71c25c2a7" | ||
integrity sha1-KGLz9Yqaf3w+eNefEw3U1xwlwqc= | ||
|
||
"@types/fs-extra@^8.0.1": | ||
version "8.0.1" | ||
resolved "https://registry.npm.taobao.org/@types/fs-extra/download/@types/fs-extra-8.0.1.tgz#a2378d6e7e8afea1564e44aafa2e207dadf77686" | ||
integrity sha1-ojeNbn6K/qFWTkSq+i4gfa33doY= | ||
dependencies: | ||
"@types/node" "*" | ||
|
||
"@types/glob@*", "@types/glob@^7.1.1": | ||
version "7.1.1" | ||
resolved "https://registry.npm.taobao.org/@types/glob/download/@types/glob-7.1.1.tgz#aa59a1c6e3fbc421e07ccd31a944c30eba521575" | ||
|
@@ -1715,6 +1729,11 @@ | |
resolved "https://registry.npm.taobao.org/@types/selenium-webdriver/download/@types/selenium-webdriver-2.53.43.tgz#2de3d718819bc20165754c4a59afb7e9833f6707" | ||
integrity sha1-LePXGIGbwgFldUxKWa+36YM/Zwc= | ||
|
||
"@types/semver@^6.2.0": | ||
version "6.2.0" | ||
resolved "https://registry.npm.taobao.org/@types/semver/download/@types/semver-6.2.0.tgz#d688d574400d96c5b0114968705366f431831e1a" | ||
integrity sha1-1ojVdEANlsWwEUlocFNm9DGDHho= | ||
|
||
"@types/sizzle@*": | ||
version "2.3.2" | ||
resolved "https://registry.npm.taobao.org/@types/sizzle/download/@types/sizzle-2.3.2.tgz#a811b8c18e2babab7d542b3365887ae2e4d9de47" | ||
|
@@ -2164,7 +2183,7 @@ [email protected]: | |
resolved "https://registry.npm.taobao.org/adm-zip/download/adm-zip-0.4.4.tgz#a61ed5ae6905c3aea58b3a657d25033091052736" | ||
integrity sha1-ph7VrmkFw66lizplfSUDMJEFJzY= | ||
|
||
adm-zip@^0.4.7, adm-zip@^0.4.9: | ||
adm-zip@^0.4.13, adm-zip@^0.4.7, adm-zip@^0.4.9: | ||
version "0.4.13" | ||
resolved "https://registry.npm.taobao.org/adm-zip/download/adm-zip-0.4.13.tgz#597e2f8cc3672151e1307d3e95cddbc75672314a" | ||
integrity sha1-WX4vjMNnIVHhMH0+lc3bx1ZyMUo= | ||
|
@@ -4768,6 +4787,11 @@ commander@^2.11.0, commander@^2.18.0, commander@^2.19.0, commander@^2.20.0, comm | |
resolved "https://registry.npm.taobao.org/commander/download/commander-2.20.3.tgz?cache=0&sync_timestamp=1573464028535&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fcommander%2Fdownload%2Fcommander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33" | ||
integrity sha1-/UhehMA+tIgcIHIrpIA16FMa6zM= | ||
|
||
commander@^4.1.0: | ||
version "4.1.0" | ||
resolved "https://registry.npm.taobao.org/commander/download/commander-4.1.0.tgz#545983a0603fe425bc672d66c9e3c89c42121a83" | ||
integrity sha1-VFmDoGA/5CW8Zy1myePInEISGoM= | ||
|
||
commander@~2.1.0: | ||
version "2.1.0" | ||
resolved "https://registry.npm.taobao.org/commander/download/commander-2.1.0.tgz?cache=0&sync_timestamp=1573464028535&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fcommander%2Fdownload%2Fcommander-2.1.0.tgz#d121bbae860d9992a3d517ba96f56588e47c6781" | ||
|
@@ -14501,6 +14525,11 @@ semver@^4.1.0, semver@~4.3.3: | |
resolved "https://registry.npm.taobao.org/semver/download/semver-4.3.6.tgz?cache=0&sync_timestamp=1565627380363&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fsemver%2Fdownload%2Fsemver-4.3.6.tgz#300bc6e0e86374f7ba61068b5b1ecd57fc6532da" | ||
integrity sha1-MAvG4OhjdPe6YQaLWx7NV/xlMto= | ||
|
||
semver@^7.1.1: | ||
version "7.1.1" | ||
resolved "https://registry.npm.taobao.org/semver/download/semver-7.1.1.tgz#29104598a197d6cbe4733eeecbe968f7b43a9667" | ||
integrity sha1-KRBFmKGX1svkcz7uy+lo97Q6lmc= | ||
|
||
semver@~2.2.1: | ||
version "2.2.1" | ||
resolved "https://registry.npm.taobao.org/semver/download/semver-2.2.1.tgz?cache=0&sync_timestamp=1565627380363&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fsemver%2Fdownload%2Fsemver-2.2.1.tgz#7941182b3ffcc580bff1c17942acdf7951c0d213" | ||
|