Commit 795a4873 authored by huoshizhe's avatar huoshizhe

feat: 自动化打包完成

parent 8cd992fe
/publish/form /publish/form
/publish/play /publish/play
/publish/node_modules /publish/node_modules
/publish/publish/play
/publish/publish/form
/publish/publish/*.zip
...@@ -69,7 +69,8 @@ const runSpawn = async function (){ ...@@ -69,7 +69,8 @@ const runSpawn = async function (){
let zippath = path.resolve(__dirname,"../dist", pkg.name); let zippath = path.resolve(__dirname,"../dist", pkg.name);
//压缩包的存放目录 //压缩包的存放目录
let date = new Date(); let date = new Date();
let zipname = pkg.name+"_"+date.Format("yyyyMMdd hh-mm-ss"); // let zipname = pkg.name+"_"+date.Format("yyyyMMdd hh-mm-ss");
let zipname = 'form';
let zipdir = path.resolve(__dirname,"../publish/"+zipname+".zip"); let zipdir = path.resolve(__dirname,"../publish/"+zipname+".zip");
clean(zipdir); //删除原有的包 clean(zipdir); //删除原有的包
......
/****
* 批量编译打包模板工具
* 运行 npm run publish T_01 命令来打包T_01模板
* 运行 npm run publish T_01,T_02,T_03,T_04 命令来分别打包 T_01,T_02,T_03,T_04 这四个模板,注意逗号要用英文的
* 运行 npm run publish all 命令来打包所有模板
*/
const spawn = require('child_process').spawn;
const path = require("path");
const fs = require("fs");
const os = require('os');
const compressing = require("compressing");
//Linux系统上'Linux'
//macOS 系统上'Darwin'
//Windows系统上'Windows_NT'
let sysType = os.type();
Date.prototype.Format = function(fmt) {
var o = {
"M+" : this.getMonth() + 1,
"d+" : this.getDate(),
"h+" : this.getHours(),
"m+" : this.getMinutes(),
"s+" : this.getSeconds(),
"q+" : Math.floor((this.getMonth() + 3) / 3),
"S" : this.getMilliseconds()
};
if (/(y+)/.test(fmt))
fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o)
if (new RegExp("(" + k + ")").test(fmt))
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
return fmt;
}
function clean(zipPath){
if(fs.existsSync(zipPath)){
fs.unlinkSync(zipPath);
}
}
const runSpawn = async function (){
await new Promise(function(resolve,reject){
let pkg = require("../package.json");
let ls;
if(sysType==="Windows_NT"){
//ng build --prod --build--optimizer --base-href /ng-one/
ls = spawn("cmd.exe", ['/c', 'ng', 'build', '--prod', '--build--optimizer', '--base-href', '/template-base-href/'] );
}else{
ls = spawn("ng", ['build', '--prod', '--build--optimizer', '--base-href', '/template-base-href/'] );
}
ls.stdout.on('data', (data) => {
console.log(` ${data}`);
});
ls.stderr.on('data', (data) => {
console.log(`stderr: ${data}`);
reject();
});
ls.on('close', (code) => {
console.log(`child process exited with code ${code}`);
//要压缩的目录
let zippath = path.resolve(__dirname,"../dist", pkg.name);
//压缩包的存放目录
let date = new Date();
// let zipname = pkg.name+"_"+date.Format("yyyyMMdd hh-mm-ss");
let zipname = 'form';
let zipdir = path.resolve(__dirname,"../publish/"+zipname+".zip");
clean(zipdir); //删除原有的包
const tarStream = new compressing.zip.Stream();
fs.readdir(zippath,function(err,files){
if(err){
console.log("======文件打开异常======");
console.log(err);
reject();
}
for(let i=0;i<files.length;i++){
tarStream.addEntry(zippath+"/"+files[i]);
}
let writeStream = fs.createWriteStream(zipdir);
tarStream.pipe(writeStream);
writeStream.on('close', () => {
console.log(`模板 ${pkg.name} 打包已完成!`);
resolve();
})
});
});
});
}
// let projects = "";
// if(process.argv.length<3){
// console.log("缺少参数");
// return;
// }
// projects = process.argv[2];
let exec = async function(){
//压缩模板
await runSpawn();
}
exec();
This diff is collapsed.
...@@ -103,8 +103,8 @@ cc.Class({ ...@@ -103,8 +103,8 @@ cc.Class({
}, },
initListeners() { initListeners() {
const nodeWheel = cc.find('Canvas/NodeBg/NodeWheel'); const btnWheel = cc.find('Canvas/NodeBg/BtnWheel');
nodeWheel.on('click', () => { btnWheel.on('click', () => {
this.onClickWheel(); this.onClickWheel();
}); });
}, },
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
] ]
], ],
"excluded-modules": [ "excluded-modules": [
"3D Physics/cannon.js",
"3D Physics/Builtin" "3D Physics/Builtin"
], ],
"preview-port": 7456, "preview-port": 7456,
......
cd ../play
CocosCreator.exe --path "./" --build "configPath=../publish/buildConfig.json" --force
cd ../form
npm run publish_2
cd ../publish
node build.js
pause
cd ../form & npm run publish & cd ../play & CocosCreator.exe --path "./" --build "configPath=../publish/buildConfig.json" --force & cd ../publish & node build.js
pause
...@@ -16,54 +16,50 @@ async function initFiles() { ...@@ -16,54 +16,50 @@ async function initFiles() {
} }
} }
async function copyDir(src, dst) {
// fs.fileex
const exists = await fs.existsSync(dst);
if (!exists) {
await fs.mkdirSync(dst);
}
//读取目录
const paths = await fs.readdirSync(src);
paths.forEach(async function (path) {
const newSrc = `${src}/${path}`;
const newDst = `${dst}/${path}`;
const st = await fs.statSync(newSrc);
if (st.isFile()) {
console.log('copy ' + newDst);
const data = await fs.readFileSync(newSrc);
await fs.writeFileSync(newDst, data);
} else if (st.isDirectory()) {
copyDir(newSrc, newDst);
}
});
}
async function main() { async function main() {
let date = new Date(); let date = new Date();
let fileName = `Release_${date.getFullYear()}${fix2(date.getMonth() + 1)}${fix2(date.getDate())} `; let fileName = `Release_${date.getFullYear()}${fix2(date.getMonth() + 1)}${fix2(date.getDate())} `;
fileName += `${fix2(date.getHours())}-${fix2(date.getMinutes())}-${fix2(date.getSeconds())}`; fileName += `${fix2(date.getHours())}-${fix2(date.getMinutes())}-${fix2(date.getSeconds())}`;
// await initFiles(); await copyDir('../play/build/web-desktop', './publish/play');
const data = await fs.readFileSync('./index.html');
await fs.writeFileSync('./publish/play/index.html', data);
compressing.zip.uncompress('../form/publish/form.zip', './publish/form') compressing.zip.uncompress('../form/publish/form.zip', './publish/form')
.then(() => { .then(() => {
const tarStream = new compressing.zip.Stream(); const tarStream = new compressing.zip.Stream();
tarStream.addEntry('../play/build/web-desktop'); tarStream.addEntry('./publish/play');
tarStream.addEntry('./publish/form'); tarStream.addEntry('./publish/form');
const destStream = fs.createWriteStream(`publish/${fileName}.zip`); const destStream = fs.createWriteStream(`publish/${fileName}.zip`);
tarStream.pipe(destStream); tarStream.pipe(destStream);
console.log('打包完成!');
}); });
} }
main(); main();
\ No newline at end of file
// var copy = async function (src, dst) {
// //读取目录
// const paths = await fs.readdirSync(src);
// paths.forEach(async function (path) {
// const newSrc = `${src}/${path}`;
// const newDst = `${dst}/${path}`;
// const st = await fs.statSync(newSrc);
// if (st.isFile()) {
// const data = await fs.readFileSync(newSrc);
// await fs.writeFileSync(newDst, data);
// } else if (st.isDirectory()) {
// exists(newSrc, newDst, copy);
// }
// });
// }
// var exists = function (src, dst, callback) {
// //测试某个路径下文件是否存在
// fs.exists(dst, function (exists) {
// if (exists) {//不存在
// callback(src, dst);
// } else {//存在
// fs.mkdir(dst, function () {//创建目录
// callback(src, dst)
// })
// }
// })
// }
// exists('../from', '../to', copy)
\ No newline at end of file
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