publish.js 761 B

12345678910111213141516171819202122232425262728
  1. const fs = require('fs-extra');
  2. const ch = require('child_process');
  3. const SCENE = process.env.SCENE;
  4. fs.ensureDirSync('.temp');
  5. fs.emptyDirSync('.temp');
  6. const distDir = `build${!!SCENE ? '/' + SCENE : ''}`;
  7. ch.execSync(`npm run build${!!SCENE ? ':' + SCENE : ''}:test`, {
  8. stdio: ['ignore', 'inherit', 'inherit'],
  9. });
  10. const distFiles = fs.readdirSync(distDir);
  11. // 静态资源默认不上传
  12. const IGNORE_FILES = ['images', 'js', 'fonts'];
  13. if (!distFiles.length) throw new Error(`请先执行 yarn ${distDir}`);
  14. distFiles.forEach((fileName) => {
  15. if (!process.env.INCLUDE_STATIC && IGNORE_FILES.includes(fileName)) return;
  16. fs.copySync(
  17. `${distDir}/${fileName}`,
  18. `.temp/${fileName === 'resources' ? fileName : 'data/' + fileName}`
  19. );
  20. });