ttmg-compile 0.1.8 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,57 @@
1
+ ##
2
+
3
+ - 0.0.1-beta.11: 发布打包产物文件 .txt 类型,看是否可以正常上传
4
+
5
+ - 0.0.1-beta.19: 支持打包, 拆出分包逻辑,供 CLI 复用
6
+
7
+ - 0.0.1-beta.20: 移除项目中 pack 代码,代码 https://code.byted.org/tiktok/ttmg-pack
8
+
9
+ - 0.0.1-beta.21: 修复 ttmg-pack 提取 root/name 问题
10
+
11
+ - 0.0.1: 发布正式版本
12
+ - 0.0.2:
13
+ - 修复 windows 兼容问题
14
+ - 修复 分包判断问题
15
+ - 修复 主包大小限制问题
16
+
17
+ - 0.0.3
18
+ - 修复 独立分包大小限制问题
19
+
20
+ - 0.0.4
21
+ 支持 fyf_packages
22
+ - 0.0.5
23
+ -- 修复打包环节兼容问题
24
+ -- 支持 unity 项目打包大小限制
25
+
26
+ - 0.0.6
27
+ 升级 ttmg-pack 至 0.1.0 版本,和 CLI 保持一致
28
+
29
+ - 0.0.7
30
+ 升级 ttmg-pack 至 0.1.1 版本,不校验 project.config.json 中的字段
31
+ - 0.0.8
32
+ 升级 ttmg-pack 至 0.1.7 版本,修复 ttmg-pack esbuild 编译问题
33
+
34
+ - 0.0.9 升级 ttmg-pack 至 0.2.3 版本
35
+ - 增加对分包名称校验,不支持中文
36
+ - js 降级目标对齐 vmsdk,target es2020
37
+
38
+ - 0.1.0 升级 ttmg-pack 至 0.2.4 版本
39
+ - 修复 open data conetxt 文件丢失问题
40
+
41
+ - 0.1.1 升级 ttmg-pack 至 0.2.5 版本
42
+ - 修复打包到产物问题,包含 open data context 文件
43
+
44
+ - 0.1.2 升级 ttmg-pack 至 0.2.7 版本
45
+ - 修复丢失 openDataContext.txt 的问题
46
+
47
+ - 0.1.3 升级 ttmg-pack 至 0.2.8 版本
48
+ - 支持 unity 项目
49
+
50
+ - 0.1.4 升级 ttmg-pack 至 0.3.1 版本
51
+ - 支持 开放数据域名 Cocos 2.0 版本兼容
52
+
53
+ - 0.1.5~0.1.9 升级 ttmg-pack 至 0.4.4 版本
54
+ - 支持 requirePlugin
55
+
56
+ - 0.2.0
57
+ 升级 ttmg-pack 到 0.4.8,支持导出游戏引擎参数
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  "use strict";var e=require("path"),t=require("fs"),n=require("ttmg-pack"),r=require("crypto"),o=require("p-limit"),i=require("winston"),s=require("zlib"),u=require("buffer");const a=new class{constructor(){this.logger=null}init(t){this.logger=i.createLogger({level:"info",format:i.format.combine(i.format.timestamp(),i.format.json()),transports:[new i.transports.File({filename:e.join(t,"pack.log")}),new i.transports.Console]})}info(e){this.logger.info(e)}error(e){this.logger.error(e)}warn(e){this.logger.warn(e)}debug(e){this.logger.debug(e)}setOutput(e){this.output=e}};function f({rootDir:n,entryDir:r,pkgName:o,excludeFileExt:i=[]}){const s=[],u=t.readdirSync(r);for(const a of u){const u=e.join(r,a);if(t.statSync(u).isDirectory())s.push(...f({entryDir:u,excludeFileExt:i,rootDir:n,pkgName:o}));else{const r=e.extname(a);if(!i.includes(r)){const r=e.relative(e.join(n,o),u);s.push({name:r,buffer:t.readFileSync(u)})}}}return s}const c="packageConfig.json";function l(e,t){if("string"===t)return Buffer.from(e);if("uint16le"===t){const t=Buffer.alloc(2);return t.writeUInt16LE(e),t}const n=Buffer.alloc(4);return n.writeUInt32LE(e),n}function p(){}class m{constructor(){this.taskResolver=p,this.taskRejecter=p,this.task=new Promise((e,t)=>{this.taskResolver=e,this.taskRejecter=t})}resolve(e){this.taskResolver(e)}reject(e){this.taskRejecter(e)}then(...e){return this.task.then(...e)}catch(...e){return this.task.catch(...e)}}let g,h;async function d(e){return await(async()=>{if(!h){h=new m;try{g=require("@bokuweb/zstd-wasm"),await g.init(),h.resolve()}catch(e){h.reject(e)}}await h})(),Buffer.from(g.compress(Buffer.from(e),19))}function w(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var y,T,b,B={exports:{}};
2
- /*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */var k=w(function(){if(b)return T;b=1;var e=(y||(y=1,function(e,t){var n=u,r=n.Buffer;function o(e,t){for(var n in e)t[n]=e[n]}function i(e,t,n){return r(e,t,n)}r.from&&r.alloc&&r.allocUnsafe&&r.allocUnsafeSlow?e.exports=n:(o(n,t),t.Buffer=i),i.prototype=Object.create(r.prototype),o(r,i),i.from=function(e,t,n){if("number"==typeof e)throw new TypeError("Argument must not be a number");return r(e,t,n)},i.alloc=function(e,t,n){if("number"!=typeof e)throw new TypeError("Argument must be a number");var o=r(e);return void 0!==t?"string"==typeof n?o.fill(t,n):o.fill(t):o.fill(0),o},i.allocUnsafe=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return r(e)},i.allocUnsafeSlow=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return n.SlowBuffer(e)}}(B,B.exports)),B.exports).Buffer;return T=function(t,n){for(var r=Math.max(t.length,n.length),o=e.allocUnsafe(r),i=0;i<r;++i)o[i]=t[i]^n[i];return o}}());let S,P;async function $(e,t){const n=[];let r=1024;await(async()=>{if(!P){P=new m;try{S=require("ttmg-bdsword"),await S.InitBDSword(),P.resolve()}catch(e){P.reject(e)}}await P})();const o=e.slice(0,r),i=await S.RC4Encrypt(o,t),{encData:s}=i;for(n.push(Buffer.from(s));r<e.length;){const o=e.slice(r,r+32);if(o.length<32){const e=t.slice(0,o.length);n.push(k(o,e))}else n.push(k(o,t));r+=32}return Buffer.concat(n)}async function j({ttpkg:n,context:o}){let i=Date.now();a.info(`sttpkgs start,startTime:${i}`);const{seed:s,outputDir:u}=o,{name:f}=n,c={name:f,code:n.code};let p=o.needEncrypt;const m=Date.now().toString(16),g=r.createHash("sha256").update(s+m).digest();p=p&&n.code.byteLength>1024,p?(a.info(`TTPKG 加密文件 Buffer 开始, ${f}`),c.code=await $(n.code,g),a.info(`TTPKG 加密文件 Buffer 完成, ${f}`)):a.info(`TTPKG 压缩后内容小于1024B, 不进行加密, ${f}`),a.info(`STTPKG 生成 Header 开始, ${f}`);const h=function({salt:e,needEncrypt:t,useBrotli:n}){const r=[];if(r.push(l("SPKG","string")),r.push(l(1,"uint32le")),r.push(l(3,"uint16le")),t){const t="SA",{length:n}=e,o=2,{length:i}=t,s=o+i+n;r.push(l(s,"uint16le")),r.push(l(n,"uint16le")),r.push(l(t,"string")),r.push(l(e,"string"))}else r.push(l(0,"uint16le"));return Buffer.concat(r)}({salt:m,needEncrypt:p,useBrotli:!1});var d;return a.info(`STTPKG 生成 Header 完成, ${f}`),c.code=Buffer.concat([h,c.code]),c.md5=(d=c.code,r.createHash("md5").update(d).digest("hex")),t.writeFileSync(e.join(u,`${f}.txt`),c.code,"utf-8"),a.info(`基于游戏源代码生成 STTPKG 产物完成 ${c.name}`),t.rmSync(e.join(u,n.name),{recursive:!0}),a.info(`sttpkgs end,duration:${Date.now()-i}ms`),c}async function E({name:t,config:n={},root:r}){const{useBrotli:o=!1}=n,i=function(){const e=[];return e.push(l("TPKG","string")),e.push(l(2,"uint32le")),e.push(l(0,"uint32le")),e}(),u=i.reduce((e,t)=>e+t.length,0);a.info(`TTPKG 收集文件开始, ${t}`);const c=f({rootDir:r,entryDir:e.join(r,t),pkgName:t,excludeFileExt:[]});a.info(`TTPKG 收集文件完成, ${t}`),a.info(`TTPKG 生成文件 Buffer 开始, ${t}`);const p=function({offset:e,assets:t}){const n=[],r=function(e=[]){const t=[];let n;for(const r of e)r.name.endsWith("app-config.json")?n=r:t.push(r);return n&&t.unshift(n),t}(t);n.push(l(r.length,"uint32le")),e+=4;let o=0;r.forEach(e=>{const t=Buffer.byteLength(e.name);o+=t+12});let i=0;return r.forEach(t=>{const r=Buffer.byteLength(t.name);n.push(l(r,"uint32le"));const s=Buffer.byteLength(Buffer.from(t.buffer)),u=Buffer.alloc(r+4+4);u.write(t.name,0),u.writeInt32LE(e+o+i,r),u.writeInt32LE(s,r+4),n.push(u),i+=s}),r.forEach(e=>{let t=e.buffer;"string"==typeof t&&(t=Buffer.from(t)),n.push(t)}),n}({offset:u,assets:c});a.info(`TTPKG 生成文件 Buffer 完成, ${t}`);const m={name:t,code:Buffer.concat([...i,...p])};var g;return o?(a.info(`TTPKG 压缩文件 Buffer 开始, ${t}`),m.code=await(g=m.code,new Promise((e,t)=>{const n=Buffer.isBuffer(g)?g:Buffer.from(g);s.brotliCompress(n,(n,r)=>{n?t(n):e(r)})})),a.info(`TTPKG 压缩文件 Buffer 完成, ${t}`)):(a.info(`TTPKG 压缩文件 Buffer 开始, ${t}`),m.code=await d(m.code),a.info(`TTPKG 压缩文件 Buffer 完成, ${t}`)),m}exports.compile=async function({source_dir:r,output_dir:i,enable_odr:s=!0,type:u="game"}){let f=Date.now();a.init(i),a.info("TTMG_COMPILE_VERSION: 0.1.8"),a.info(`compile start, startTime:${f}`);let l={error_message:"success",config_path:`/${c}`};try{await n.buildPkgs({entry:r,output:i,build:{enableOdr:!0,pkgSizeLimit:31457280,mainPkgSizeLimit:4194304,independentSubPkgSizeLimit:4194304,type:u}});const f=await async function(n){let r=Date.now();a.info(`ttpkgs start,startTime:${r}`);const i=e.join(n,c),s=JSON.parse(t.readFileSync(i,"utf-8")).packages,u=o(10),f=[];for(const e in s){if("plugin"===s[e].type)continue;const t=await u(()=>E({name:e,config:{useBrotli:!1},root:n}));f.push(t)}return a.info(`压缩游戏包完成,duration:${Date.now()-r}ms`),f}(i);await async function({outputDir:n,ttpkgs:r,seed:i}){a.info("开始加密游戏包"),a.info(`游戏加密密钥:${i}`);const s=e.join(n,c),u=JSON.parse(t.readFileSync(s,"utf-8")),f=u.packages,l=o(10),p=await Promise.all(r.map(e=>l(async()=>{const t=await j({ttpkg:e,context:{seed:i,outputDir:n,needEncrypt:u.needEncrypt}});return f[e.name]=Object.assign(Object.assign({},f[e.name]),{md5:t.md5}),t})));return t.writeFileSync(s,JSON.stringify(u,null,2),"utf-8"),a.info("加密游戏包完成"),p}({outputDir:i,ttpkgs:f,seed:"TTMG_NATIVE"}),s&&await n.writeOdrConfig(i)}catch(e){a.error(`pack error:${e.message}`),l.error_message=e.message}t.writeFileSync(e.join(i,"output.json"),JSON.stringify(l),"utf-8"),a.info(`compile end:${Date.now()-f}ms`)};
2
+ /*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */var k=w(function(){if(b)return T;b=1;var e=(y||(y=1,function(e,t){var n=u,r=n.Buffer;function o(e,t){for(var n in e)t[n]=e[n]}function i(e,t,n){return r(e,t,n)}r.from&&r.alloc&&r.allocUnsafe&&r.allocUnsafeSlow?e.exports=n:(o(n,t),t.Buffer=i),i.prototype=Object.create(r.prototype),o(r,i),i.from=function(e,t,n){if("number"==typeof e)throw new TypeError("Argument must not be a number");return r(e,t,n)},i.alloc=function(e,t,n){if("number"!=typeof e)throw new TypeError("Argument must be a number");var o=r(e);return void 0!==t?"string"==typeof n?o.fill(t,n):o.fill(t):o.fill(0),o},i.allocUnsafe=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return r(e)},i.allocUnsafeSlow=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return n.SlowBuffer(e)}}(B,B.exports)),B.exports).Buffer;return T=function(t,n){for(var r=Math.max(t.length,n.length),o=e.allocUnsafe(r),i=0;i<r;++i)o[i]=t[i]^n[i];return o}}());let S,P;async function $(e,t){const n=[];let r=1024;await(async()=>{if(!P){P=new m;try{S=require("ttmg-bdsword"),await S.InitBDSword(),P.resolve()}catch(e){P.reject(e)}}await P})();const o=e.slice(0,r),i=await S.RC4Encrypt(o,t),{encData:s}=i;for(n.push(Buffer.from(s));r<e.length;){const o=e.slice(r,r+32);if(o.length<32){const e=t.slice(0,o.length);n.push(k(o,e))}else n.push(k(o,t));r+=32}return Buffer.concat(n)}async function j({ttpkg:n,context:o}){let i=Date.now();a.info(`sttpkgs start,startTime:${i}`);const{seed:s,outputDir:u}=o,{name:f}=n,c={name:f,code:n.code};let p=o.needEncrypt;const m=Date.now().toString(16),g=r.createHash("sha256").update(s+m).digest();p=p&&n.code.byteLength>1024,p?(a.info(`TTPKG 加密文件 Buffer 开始, ${f}`),c.code=await $(n.code,g),a.info(`TTPKG 加密文件 Buffer 完成, ${f}`)):a.info(`TTPKG 压缩后内容小于1024B, 不进行加密, ${f}`),a.info(`STTPKG 生成 Header 开始, ${f}`);const h=function({salt:e,needEncrypt:t,useBrotli:n}){const r=[];if(r.push(l("SPKG","string")),r.push(l(1,"uint32le")),r.push(l(3,"uint16le")),t){const t="SA",{length:n}=e,o=2,{length:i}=t,s=o+i+n;r.push(l(s,"uint16le")),r.push(l(n,"uint16le")),r.push(l(t,"string")),r.push(l(e,"string"))}else r.push(l(0,"uint16le"));return Buffer.concat(r)}({salt:m,needEncrypt:p,useBrotli:!1});var d;return a.info(`STTPKG 生成 Header 完成, ${f}`),c.code=Buffer.concat([h,c.code]),c.md5=(d=c.code,r.createHash("md5").update(d).digest("hex")),t.writeFileSync(e.join(u,`${f}.txt`),c.code,"utf-8"),a.info(`基于游戏源代码生成 STTPKG 产物完成 ${c.name}`),t.rmSync(e.join(u,n.name),{recursive:!0}),a.info(`sttpkgs end,duration:${Date.now()-i}ms`),c}async function E({name:t,config:n={},root:r}){const{useBrotli:o=!1}=n,i=function(){const e=[];return e.push(l("TPKG","string")),e.push(l(2,"uint32le")),e.push(l(0,"uint32le")),e}(),u=i.reduce((e,t)=>e+t.length,0);a.info(`TTPKG 收集文件开始, ${t}`);const c=f({rootDir:r,entryDir:e.join(r,t),pkgName:t,excludeFileExt:[]});a.info(`TTPKG 收集文件完成, ${t}`),a.info(`TTPKG 生成文件 Buffer 开始, ${t}`);const p=function({offset:e,assets:t}){const n=[],r=function(e=[]){const t=[];let n;for(const r of e)r.name.endsWith("app-config.json")?n=r:t.push(r);return n&&t.unshift(n),t}(t);n.push(l(r.length,"uint32le")),e+=4;let o=0;r.forEach(e=>{const t=Buffer.byteLength(e.name);o+=t+12});let i=0;return r.forEach(t=>{const r=Buffer.byteLength(t.name);n.push(l(r,"uint32le"));const s=Buffer.byteLength(Buffer.from(t.buffer)),u=Buffer.alloc(r+4+4);u.write(t.name,0),u.writeInt32LE(e+o+i,r),u.writeInt32LE(s,r+4),n.push(u),i+=s}),r.forEach(e=>{let t=e.buffer;"string"==typeof t&&(t=Buffer.from(t)),n.push(t)}),n}({offset:u,assets:c});a.info(`TTPKG 生成文件 Buffer 完成, ${t}`);const m={name:t,code:Buffer.concat([...i,...p])};var g;return o?(a.info(`TTPKG 压缩文件 Buffer 开始, ${t}`),m.code=await(g=m.code,new Promise((e,t)=>{const n=Buffer.isBuffer(g)?g:Buffer.from(g);s.brotliCompress(n,(n,r)=>{n?t(n):e(r)})})),a.info(`TTPKG 压缩文件 Buffer 完成, ${t}`)):(a.info(`TTPKG 压缩文件 Buffer 开始, ${t}`),m.code=await d(m.code),a.info(`TTPKG 压缩文件 Buffer 完成, ${t}`)),m}exports.compile=async function({source_dir:r,output_dir:i,enable_odr:s=!0,type:u="game"}){let f=Date.now();a.init(i),a.info("TTMG_COMPILE_VERSION: 0.2.0"),a.info(`compile start, startTime:${f}`);let l={error_message:"success",config_path:`/${c}`};try{await n.buildPkgs({entry:r,output:i,build:{enableOdr:!0,pkgSizeLimit:31457280,mainPkgSizeLimit:4194304,independentSubPkgSizeLimit:4194304,type:u}});const f=await async function(n){let r=Date.now();a.info(`ttpkgs start,startTime:${r}`);const i=e.join(n,c),s=JSON.parse(t.readFileSync(i,"utf-8")).packages,u=o(10),f=[];for(const e in s){if("plugin"===s[e].type)continue;const t=await u(()=>E({name:e,config:{useBrotli:!1},root:n}));f.push(t)}return a.info(`压缩游戏包完成,duration:${Date.now()-r}ms`),f}(i);await async function({outputDir:n,ttpkgs:r,seed:i}){a.info("开始加密游戏包"),a.info(`游戏加密密钥:${i}`);const s=e.join(n,c),u=JSON.parse(t.readFileSync(s,"utf-8")),f=u.packages,l=o(10),p=await Promise.all(r.map(e=>l(async()=>{const t=await j({ttpkg:e,context:{seed:i,outputDir:n,needEncrypt:u.needEncrypt}});return f[e.name]=Object.assign(Object.assign({},f[e.name]),{md5:t.md5}),t})));return t.writeFileSync(s,JSON.stringify(u,null,2),"utf-8"),a.info("加密游戏包完成"),p}({outputDir:i,ttpkgs:f,seed:"TTMG_NATIVE"}),s&&await n.writeOdrConfig(i)}catch(e){a.error(`pack error:${e.message}`),l.error_message=e.message}t.writeFileSync(e.join(i,"output.json"),JSON.stringify(l),"utf-8"),a.info(`compile end:${Date.now()-f}ms`)};
3
3
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "ttmg-compile",
3
3
  "author": "ttmg",
4
- "version": "0.1.8",
4
+ "version": "0.2.0",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "scripts": {
8
8
  "build": "rollup -c",
9
- "test": "node __TEST__/testPlugin.js",
9
+ "test": "node __TEST__/index.js",
10
10
  "prepublishOnly": "npm run build",
11
11
  "watch": "rollup -c --watch"
12
12
  },
@@ -24,7 +24,7 @@
24
24
  "magic-string": "0.30.17",
25
25
  "p-limit": "3.1.0",
26
26
  "ttmg-bdsword": "0.0.1",
27
- "ttmg-pack": "0.3.5",
27
+ "ttmg-pack": "0.4.8",
28
28
  "winston": "^3.17.0"
29
29
  },
30
30
  "devDependencies": {