build_step_4.js 1.87 KB
Newer Older
1 2 3 4 5
const { removeDir, copyDir, fix2 } = require('./utils');
const compressing = require('compressing');
let fs = require('fs');

async function main() {
6
  await removeDir('../dist/web_desktop');
7
  const projectName = await getBundleName('../play/build_web_desktop/web-desktop/assets');
8
  await copyDir(`../play/build_web_desktop/web-desktop/assets/${projectName}`, '../dist/web_desktop');
9 10 11
  await removeDir('../play/build_web_desktop');

  const bundleData = {
12 13
    ios: await getBundleData('../dist/ios'),
    android: await getBundleData('../dist/android'),
14 15
  }

16
  fs.writeFileSync('../dist/config.json', JSON.stringify(bundleData));
17 18

  const tarStream = new compressing.zip.Stream();
19 20 21 22 23 24 25
  tarStream.addEntry('../dist/play');
  tarStream.addEntry('../dist/ios');
  tarStream.addEntry('../dist/android');
  tarStream.addEntry('../dist/web_desktop');
  tarStream.addEntry('../dist/config.json');

  const destStream = fs.createWriteStream(`../publish/${getReleaseFileName()}.zip`);
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62

  tarStream.pipe(destStream);

  console.log('打包完成!');
}

async function getBundleName(path) {
  const paths = fs.readdirSync(path);
  return paths.find(path => path != 'internal' && path !='main');
}

async function getBundleData(path) {
  const bundleData = {
    sceneName: '',
    version: '',
  }
  const paths = fs.readdirSync(path);
  bundleData.sceneName = paths[0];
  const files = fs.readdirSync(path + '/' + bundleData.sceneName);
  files.forEach(fileName => {
    fileName.split('.').forEach((str, idx, arr) => {
      if (str == 'config') {
        bundleData.version = arr[idx + 1];
      }
    })
  });
  return bundleData;
}

function getReleaseFileName() {
  let date = new Date();
  let fileName = `Release_${date.getFullYear()}${fix2(date.getMonth() + 1)}${fix2(date.getDate())} `;
  fileName += `${fix2(date.getHours())}-${fix2(date.getMinutes())}-${fix2(date.getSeconds())}`;
  return fileName;
}

main();