硬核工程目錄結(jié)構(gòu)
Hardcore -laya工程 硬核首頁
|
|--- bin 魅族打包的內(nèi)容
| ...
|--- release 硬核
|--- huawei 華為工程
|--- quickgame oppo工程
|--- vivogame vivo工程
|--- src 硬核首頁代碼
npm 安裝依賴
npm install gulp typescript gulp-concat gulp-typescript gulp-typescript-filesort gulp-filelist gulp gulp-shell glob silly-datetime minimist tsify
創(chuàng)建gulpfile.js
const gulp = require("gulp");
const ts = require("gulp-typescript");
const sorter = require("gulp-typescript-sort");
const concat = require('gulp-concat');
const tsProject = ts.createProject("tsconfig.json");
const zip = require('gulp-zip');
var exec = require('child_process').exec;
// 輸出到的目錄
let outDir = "bin/js/"; // 魅族
// 編譯硬核工程 該工程只是首頁工程 用于加載游戲js
function compileTSFile() {
return gulp.src([
"libs/*.ts",
"src/**/*.ts"
])
.pipe(sorter(false))
.pipe(tsProject())
.pipe(concat('hardcore.js'))
.pipe(gulp.dest(outDir));
}
/**
* 執(zhí)行CDM命令
* @param { } cmd
* @param {*} callBack
*/
function executeCMD(cmd, callBack) {
exec(cmd, function (error, stdout, stderr) {
if (error) {
console.error(cmd, ' error');
} else {
console.log(cmd, " \n 執(zhí)行 成功");
callBack && callBack();
}
});
}
// 魅族壓縮zip文件命令
gulp.task('zip', function (args, args2) {
return gulp.src('bin/**/*.*')
.pipe(zip('bin.zip'))
.pipe(gulp.dest('.'));
});
///////////////////////// 魅族 ////////////////////
/** 魅族編譯壓縮成zip */
gulp.task('meizu', function (args, args2) {
outDir = "bin/js/"; // 魅族輸出目錄
return compileTSFile().on('end', () => {
return gulp.src('bin/**/*.*')
.pipe(zip('bin.zip'))
.pipe(gulp.dest('.')).on('end', () => {
console.log('meizu zip end');
});
});
});
////////////////////////////// OPPO //////////////////////////////////
/**
* 推送rpk到 OPPO手機
* @param { } callBack
*/
function pushOppoSDCARD(callBack) {
let cmd = 'adb push D:/SVN/frontend/sdk/project/HardCore/release/quickgame/dist/com.hzby.tjyr.nearme.gamecenter.rpk'
+ ' /sdcard/games/com.hzby.tjyr.nearme.gamecenter.rpk';
executeCMD(cmd, callBack);
}
/**
* 打包oppo
* @param { } callBack
*/
function packOppo(callBack) {
let cmd = " cd /D D:/SVN/frontend/sdk/project/HardCore/release/quickgame "
+ ' & quickgame pack ';
executeCMD(cmd, pushOppoSDCARD);
}
function packOppoRelease(callBack) {
let cmd = " cd /D D:/SVN/frontend/sdk/project/HardCore/release/quickgame "
+ ' & quickgame pack release';
executeCMD(cmd, pushOppoReleaseSDCARD);
}
function pushOppoReleaseSDCARD(callBack) {
let cmd = 'adb push D:/SVN/frontend/sdk/project/HardCore/release/quickgame/dist/com.hzby.tjyr.nearme.gamecenter.signed.rpk'
+ ' /sdcard/games/com.hzby.tjyr.nearme.gamecenter.signed.rpk';
executeCMD(cmd, callBack);
}
gulp.task('oppo', function () {
outDir = 'release/quickgame/js/';
return compileTSFile().on('end', () => {
packOppoRelease();
});
})
/////////////////////////// 華為 //////////////////////////////
let packHuawei = function (callBack) {
let cmd = 'start D:/SVN/frontend/sdk/project/HardCore/release/huawei/run.bat';
executeCMD(cmd, callBack);
}
gulp.task('huawei', function () {
outDir = 'release/huawei/game/js/';
return compileTSFile().on('end', () => {
packHuawei(() => { console.log("華為完成") });
});
})
///////////////////// vivo /////////////////////////////
function pushVIVO(callBack) {
let cmd = 'cd D:/SVN/frontend/sdk/project/HardCore/release/vivogame '
+ '& start D:/SVN/frontend/sdk/project/HardCore/release/vivogame/run.bat'
executeCMD(cmd, callBack);
}
function vivoRelease(callBack) {
let cmd = 'cd D:/SVN/frontend/sdk/project/HardCore/release/vivogame '
+ '& start D:/SVN/frontend/sdk/project/HardCore/release/vivogame/release.bat'
executeCMD(cmd, callBack);
}
gulp.task('vivo', function () {
outDir = 'release/vivogame/js/';
return compileTSFile().on('end', () => {
// pushVIVO();
vivoRelease();
});
})
// 串行打包所有的硬核(順序)執(zhí)行
gulp.task('all', gulp.series('oppo','vivo','huawei','meizu'))