- 安裝 node.js
- 會使用指令介面 (cmd,bash,...)
- 把這個 gist 下載成一個 zip 檔後解壓縮
- 在裡面執行
npm i - 把目標 apk 放到同個資料夾
- 執行
node index.js xxx.apk(假設目標是xxx.apk) - 會得到一個
xxx.fas檔案,這就是成品了
| const zipper = require('zip-local') | |
| const fs = require('fs') | |
| const path = require('path') | |
| const rimraf = require('rimraf') | |
| const file = process.argv[2] || '' | |
| const TARGET = path.parse(file).name | |
| const TARGETAPK = `${TARGET}.apk` | |
| const TARGETPATH = path.join(process.cwd(), TARGET) | |
| const ASSETS = path.join(TARGETPATH, 'assets') | |
| const RESULT = path.join(process.cwd(), `${TARGET}.fas`) | |
| if (!fs.existsSync(TARGETAPK)) { | |
| console.error('沒有檔案') | |
| process.exit(1) | |
| } | |
| if (fs.existsSync(TARGETPATH)) { | |
| rimraf.sync(TARGETPATH) | |
| } | |
| fs.mkdirSync(TARGETPATH) | |
| console.log('開始解開 apk') | |
| zipper.sync.unzip(TARGETAPK).save(TARGETPATH) | |
| console.log('解開 apk 完成') | |
| function deleteNotFushion(curpath) { | |
| for (const p of fs.readdirSync(curpath)) { | |
| //console.log(p) | |
| const pa = path.join(curpath, p) | |
| const stat = fs.statSync(pa) | |
| if (stat.isDirectory()) { | |
| deleteNotFushion(pa) | |
| } else if (!/(init\.lua|table|png|jpeg|jpg|mht)$/.test(p)) { | |
| fs.unlinkSync(pa) | |
| } | |
| } | |
| if (fs.readdirSync(curpath).length === 0) { | |
| fs.rmdirSync(curpath) | |
| } | |
| } | |
| console.log('開始刪除非 FushionApp 的檔案') | |
| deleteNotFushion(ASSETS) | |
| console.log('刪除非 FushionApp 的檔案完成') | |
| console.log('開始壓縮 fas 檔') | |
| zipper.sync.zip(ASSETS).save(RESULT) | |
| console.log('壓縮 fas 檔完成') | |
| console.log('開始清除暫存資料夾') | |
| rimraf.sync(TARGETPATH) | |
| console.log('清除暫存資料夾完成') |
| { | |
| "name": "fa-extract", | |
| "version": "1.0.0", | |
| "main": "index.js", | |
| "keywords": [], | |
| "author": "maple3142", | |
| "license": "MIT", | |
| "dependencies": { | |
| "rimraf": "^2.6.2", | |
| "zip-local": "^0.3.4" | |
| } | |
| } |