build.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. const { execSync } = require('child_process')
  2. const path = require('path')
  3. const fs = require('fs')
  4. const process = require('process')
  5. const buildDir = path.join(process.cwd(), 'build')
  6. const distDir = path.join(process.cwd(), 'dist')
  7. const buildIndexJs = path.join(buildDir, 'index.js')
  8. const distIndexJs = path.join(distDir, 'index.js')
  9. const distCleanupJs = path.join(distDir, 'cleanup.js')
  10. var ncc = `./node_modules/.bin/ncc`;
  11. if (process.platform === "win32") {
  12. ncc = `.\\node_modules\\.bin\\ncc.cmd`;
  13. }
  14. if (!fs.existsSync(buildDir)) {
  15. fs.mkdirSync(buildDir)
  16. }
  17. // Build the main index.js file
  18. console.log('Building index.js...')
  19. execSync(`${ncc} build index.js -q -o ${buildDir}`)
  20. if (fs.existsSync(distIndexJs)) {
  21. fs.unlinkSync(distIndexJs)
  22. }
  23. fs.renameSync(buildIndexJs, distIndexJs)
  24. // Build the cleanup.js file
  25. console.log('Building cleanup.js...')
  26. execSync(`${ncc} build cleanup.js -q -o ${buildDir}`)
  27. if (fs.existsSync(distCleanupJs)) {
  28. fs.unlinkSync(distCleanupJs)
  29. }
  30. fs.renameSync(buildIndexJs, distCleanupJs)
  31. console.log('Cleaning up...')
  32. fs.rmdirSync(buildDir)
  33. console.log('Done')