Commit d46ba3bf authored by wildfirecode's avatar wildfirecode

1

parent 8ade3b6c
// const publish = require('./publish');
const ora = require('ora');
const rm = require('rimraf');
const path = require('path');
const chalk = require('chalk');
const webpack = require('webpack');
const prodConfig = require('./webpack.prod.conf');
const shelljs = require('shelljs');
let build = opts => {
if (!opts.BUILD_SKIN) {
console.error('请输入需要构建的项目名称\n');
return false;
}
const dist = path.join(process.cwd(), opts.BUILD_SKIN, 'bin-release')
rm(dist, err => {
if (err) throw err;
let webpackConfig = prodConfig(opts);
var spinner = ora('building for production...\n');
spinner.start();
// 构建
webpack(webpackConfig, function (err, stats) {
spinner.stop();
if (err) throw err;
process.stdout.write(
stats.toString({
colors: true,
modules: false,
children: false,
chunks: false,
chunkModules: false
}) + '\n\n'
);
console.log(chalk.cyan('Build complete.\n'));
spinner.text = '正在生成TextureMerger proj\n';
spinner.start();
shelljs.cd(opts.BUILD_SKIN);
shelljs.exec('node autoMerger.js');
spinner.stop();
spinner.text = '正在编译exmls\n';
spinner.start();
shelljs.exec('egret publish');
console.log('编译exmls结束');
spinner.stop();
shelljs.exec('dbtinypng -i bin-release/resource/TextureMerger -o bin-release/resource/TextureMerger && node publish.js');
shelljs.cd('..');
});
});
};
module.exports = build;
const co = require.resolve('co');
const fs = require('fs');
const path = require('path');
const OSS = require('ali-oss');
const chalk = require('chalk');
const ProgressBar = require('progress');
class TuiaAutoUpload {
constructor(props, type) {
this.type = type;
const defaultOptions = {
dir: undefined,
originDir: undefined
}
this.options = Object.assign({}, defaultOptions, props);
if (!this.options.dir || !this.options.originDir) {
console.log(chalk.red('缺少参数,初始化失败'))
return;
}
this.init();
}
init() {
var _this = this;
this.client = new OSS({
region: 'oss-cn-hangzhou',
accessKeyId: 'LTAIdGi1IOap7fkF',
accessKeySecret: 'SKrOOp6EVtDGEV47yn0t2h97gyNioQ',
bucket: _this.type === 'prod' ? 'duiba' : 'daily-duiba'
});
this.bar = new ProgressBar(chalk.yellow(` 文件上传中 [:bar] :current/${this.files().length} :percent :elapseds`), {
complete: '●',
incomplete: '○',
width: 20,
total: this.files().length,
callback: () => {
console.log(chalk.green('\n All complete.'));
console.log(chalk.blue(`\n 本次队列文件共${this.files().length}个,已存在文件${this.existFiles}个,上传文件${this.uploadFiles}个,上传失败文件${this.errorFiles}个\n`));
}
})
return this;
}
files() {
var _this = this;
if (this._files) return this._files;
this._files = [];
/**
* 文件遍历方法
* @param filePath 需要遍历的文件路径
*/
function fileDisplay(filePath) {
//根据文件路径读取文件,返回文件列表
var files = fs.readdirSync(filePath);
files.forEach(function (filename) {
//获取当前文件的绝对路径
var filedir = path.join(filePath, filename);
//根据文件路径获取文件信息,返回一个fs.Stats对象
var stats = fs.statSync(filedir);
var isFile = stats.isFile();//是文件
var isDir = stats.isDirectory();//是文件夹
if (isFile) {
var sep = '/';
if ('win32' == process.platform)
sep = '\\';
var newDirArr = filedir.split(sep);
newDirArr.shift();
_this._files.push(newDirArr.join('/'));
}
if (isDir) {
fileDisplay(filedir);//递归,如果是文件夹,就继续遍历该文件夹下面的文件
}
});
}
//调用文件遍历方法
fileDisplay(this.options.dir);
return this._files;
}
start() {
this.files().map((file, index) => {
let _this = this;
const path1 = path.join(__dirname, 'bin-release', file);
let originFile;
this.existFiles = 0;
this.uploadFiles = 0;
this.errorFiles = 0;
co(function* () {
const originPath = `${_this.options.originDir}${file}`;
try {
originFile = yield _this.client.head(originPath);
} catch (error) {
originFile = error;
}
if (_this.type === 'prod') {
if (originFile.status === 404) {
yield _this.client.put(originPath, path1);
_this.uploadFiles += 1;
} else {
_this.existFiles += 1;
}
} else if (_this.type === 'dev') {
if (originFile.status === 404 || originFile.status === 200) {
_this.existFiles += 1;
}
yield _this.client.put(originPath, path1, {
headers: {
'Cache-Control': 'no-cache'
}
})
_this.uploadFiles += 1;
}
_this.bar.tick();
}).catch(function (err) {
_this.errorFiles += 1;
console.log(err);
});
});
}
}
module.exports = TuiaAutoUpload;
\ No newline at end of file
module.exports = opts => {
const TuiaAutoUpload = require('./publish');
const now = new Date();
const version = Math.round(now.getTime() / 1000);
console.log(`版本号:${version}`)
const autoupload = new TuiaAutoUpload({
dir: './bin-release/',
originDir: `/db_games/activity/${config.name}/${version}/`
}, "prod")
autoupload.start()
}
\ No newline at end of file
...@@ -20,7 +20,7 @@ module.exports = opts => { ...@@ -20,7 +20,7 @@ module.exports = opts => {
}, },
output: { output: {
filename: `./${opts.BUILD_SKIN}/output.js`, filename: `./${opts.BUILD_SKIN}/output.js`,
path: __dirname path: process.cwd()
} }
}; };
return result return result
......
...@@ -5,7 +5,6 @@ const path = require('path'); ...@@ -5,7 +5,6 @@ const path = require('path');
const MockWebpackPlugin = require('mock-webpack-plugin'); const MockWebpackPlugin = require('mock-webpack-plugin');
const configPath = path.join(process.cwd(), './mock/config.js'); const configPath = path.join(process.cwd(), './mock/config.js');
console.log(configPath)
const mockConfig = require(configPath); const mockConfig = require(configPath);
let config = opts => { let config = opts => {
......
const merge = require('webpack-merge'); const merge = require('webpack-merge');
const common = require('./webpack.common.js'); const baseConfig = require('./webpack.base.conf');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin'); const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const webpack = require('webpack'); const webpack = require('webpack');
const path=require('path'); const path = require('path');
module.exports = merge(common, {
let config = opts => {
let baseWebpackConfig = baseConfig(opts);
return merge(baseWebpackConfig, {
devtool: 'source-map', devtool: 'source-map',
plugins: [ plugins: [
new UglifyJSPlugin( new UglifyJSPlugin(
...@@ -14,7 +17,10 @@ module.exports = merge(common, { ...@@ -14,7 +17,10 @@ module.exports = merge(common, {
}) })
], ],
output: { output: {
filename: 'output.js', filename: `./${opts.BUILD_SKIN}/bin-release/output.js`,
path: path.join(__dirname,'bin-release') path: process.cwd()
} }
}); });
\ No newline at end of file }
module.exports = config;
\ No newline at end of file
const devServer = require('./build/dev-server'); const devServer = require('./build/dev-server');
// const build = require('./build/build'); const build = require('./build/build');
// const backup = require('./util/backup'); // const backup = require('./util/backup');
// const copy = require('./util/copy'); // const copy = require('./util/copy');
...@@ -53,7 +53,6 @@ class DuibaGameBuild { ...@@ -53,7 +53,6 @@ class DuibaGameBuild {
* @param {*} skin 皮肤名称 * @param {*} skin 皮肤名称
*/ */
buildProd(skin) { buildProd(skin) {
this.opts.daily = false;
this.buildBase(skin); this.buildBase(skin);
} }
...@@ -62,7 +61,6 @@ class DuibaGameBuild { ...@@ -62,7 +61,6 @@ class DuibaGameBuild {
* @param {*} skin 皮肤名称 * @param {*} skin 皮肤名称
*/ */
buildBase(skin) { buildBase(skin) {
process.env.NODE_ENV = '"production"';
this.slicePath(skin); this.slicePath(skin);
build(this.opts); build(this.opts);
} }
......
This diff is collapsed.
...@@ -2,13 +2,20 @@ ...@@ -2,13 +2,20 @@
"name": "duiba-game-build", "name": "duiba-game-build",
"main": "index.js", "main": "index.js",
"dependencies": { "dependencies": {
"mock-webpack-plugin": "^2.0.0",
"ora": "^3.0.0",
"rimraf": "^2.6.2",
"shelljs": "^0.8.2",
"ts-loader": "^4.0.0", "ts-loader": "^4.0.0",
"typescript": "^3.0.3", "typescript": "^3.0.3",
"webpack": "^4.1.0", "webpack": "^4.1.0",
"webpack-cli": "^2.0.9", "webpack-cli": "^2.0.9",
"webpack-dev-server": "^3.1.0", "webpack-dev-server": "^3.1.0",
"webpack-merge": "^4.1.2", "webpack-merge": "^4.1.2",
"mock-webpack-plugin": "^2.0.0" "ali-oss": "^4.11.4",
"chalk": "^2.3.0",
"co": "^4.6.0",
"progress": "^2.0.0"
}, },
"version": "0.0.2" "version": "0.0.2"
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment