build-pro.js 682 B

1234567891011121314151617181920212223
  1. console.log('build > 文件开始执行!')
  2. const fs = require('fs')
  3. const path = require('path')
  4. function getRootPath(...dir) {
  5. return path.resolve(process.cwd(), ...dir)
  6. }
  7. const runBuild = async () => {
  8. try {
  9. const OUTPUT_DIR = 'dist'
  10. const VERSION = 'version.json'
  11. const versionJson = {
  12. version: 'V_' + Math.floor(Math.random() * 10000) + Date.now()
  13. }
  14. fs.writeFileSync(getRootPath(`${OUTPUT_DIR}/${VERSION}`), JSON.stringify(versionJson))
  15. console.log(`version file is build successfully!`)
  16. } catch (error) {
  17. console.error('version build error:\n' + error)
  18. process.exit(1)
  19. }
  20. }
  21. runBuild()
  22. console.log('build > 文件执行结束!')