UNPKG

layaair2-cmd

Version:

layaair version 2 toolkit

1 lines 1.8 kB
"use strict";var _fs=require("fs"),_path=require("path"),_archiver=require("archiver"),_bundle=require("./bundle");function signRpkFile(){mkdirsSync(output);var s=[],a=_path.join(output,"bundle."+(new Date).getTime()+".zip"),e=_fs.createWriteStream(a),r=_archiver("zip");e.on("finish",function(){var e=_path.join(output,packageName+".rpk"),i=_fs.readFileSync(privateKeyFilePath),r=_fs.readFileSync(certificateFilePath);_fs.existsSync(e)&&_fs.unlinkSync(e),_bundle.signZip({zip:a,files:s},i,r,e),_fs.existsSync(a)&&_fs.unlinkSync(a)}),r.on("error",function(e){console.error("ERROR:打包异常,请重试。"),_fs.existsSync(a)&&_fs.unlinkSync(a),process.exit(1)}),r.pipe(e),parse(src,".",function(e,i){s.push({name:Buffer.from(e),file:i,hash:_bundle.hashFile(i)}),r.append(_fs.createReadStream(i),{name:e})}),r.finalize()}function parse(n,t,c){t=t||".";var p=void 0,o=_path.join(n,t);_fs.readdirSync(o).forEach(function(e){var i=_path.join(o,e),r=_fs.statSync(i);if(r.isFile()){var s=t.split(_path.sep).join(_path.posix.sep);p=_path.posix.join(s,_path.basename(e)),c(p,i)}else if(r.isDirectory()){var a=_path.join(t,e);parse(n,a,c)}})}function mkdirsSync(e){if(!_fs.existsSync(e))return!_fs.existsSync(_path.dirname(e))&&mkdirsSync(_path.dirname(e))?void print("mkdirSync err : "+e):_fs.mkdirSync(e)}function checkFile(){return _fs.existsSync(privateKeyFilePath)?_fs.existsSync(certificateFilePath)?!!_fs.existsSync(src)||(console.error("无法找到打包目录:"+src),!1):(console.error("无法找到证书文件:"+certificateFilePath),!1):(console.error("无法找到秘钥文件:"+privateKeyFilePath),!1)}var src=process.argv[2],output=process.argv[3],packageName=process.argv[4],privateKeyFilePath=process.argv[5],certificateFilePath=process.argv[6];checkFile()?signRpkFile():process.exit(1);