Skip to content
This repository has been archived by the owner on Mar 31, 2024. It is now read-only.

Commit

Permalink
feat: Add building script
Browse files Browse the repository at this point in the history
  • Loading branch information
AngryPowman committed Jan 13, 2020
1 parent 0c719c2 commit b070432
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
out
dist
app-builds
app-builds
package-release
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Example config for browser:
Example config for PC (You can also use a relative path):
```json
{
"game_assets_root": "D:\GameProjects\hello-avg",
"game_assets_root": "D:\\GameProjects\\hello-avg",
"engine_bundle_root": "data"
}
```
Expand Down Expand Up @@ -136,3 +136,17 @@ If your game assets folder is addressable, you can see a game window launched an
- [ ] Save & Load
- [ ] UI Designer
- [ ] Packaging Tools


## Buiding Problems

- `electron` & `node-sass` install failed or takes a long time
Due to `electron-prebuilt` and `node-sass` deploy on Github, it causing a problem of downloading. Especially in China, it will take a long time when you run `yarn`. To resolve the problem, you could use the following solution:

```
ELECTRON_MIRROR="https://npm.taobao.org/mirrors/electron/" yarn add electron -D
SASS_BINARY_SITE=https://npm.taobao.org/mirrors/node-sass/ yarn add node-sass -D
```

This changes the downloading mirror to `Taobao` in China.
But it should be noted this solution is **different** from changing the registry of `yarn`.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "avg-plus",
"version": "0.1.13",
"version": "0.1.22",
"description": "Powerful AVG Engine",
"homepage": "http://avg-engine.com",
"author": {
Expand Down Expand Up @@ -80,6 +80,7 @@
"@types/jquery": "^3.3.2",
"@types/node": "7.0.7",
"@types/pixi.js": "^4.8.8",
"@types/semver": "^6.2.0",
"@typescript-eslint/eslint-plugin": "^1.9.0",
"@typescript-eslint/parser": "^1.9.0",
"adm-zip": "^0.4.13",
Expand Down Expand Up @@ -142,6 +143,7 @@
"raw-loader": "0.5.1",
"sass-loader": "6.0.6",
"script-loader": "0.7.0",
"semver": "^7.1.1",
"shelljs": "^0.7.8",
"source-map-loader": "0.2.1",
"style-loader": "0.18.2",
Expand Down
119 changes: 119 additions & 0 deletions tools/version-release.ts
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} 发布完成!`)
})

})
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"declaration": false,
"skipLibCheck": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowJs": true,
Expand Down
31 changes: 30 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit b070432

Please sign in to comment.