javascript prebuild.js

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript prebuild.js相关的知识,希望对你有一定的参考价值。

// automatic script build number management

const fs = require('fs');
const moment = require('moment-es6').default;
let childProcess = require('child_process')

let file = './build-info.ts'
if (process.argv.some(arg => arg === '--postbuild')) {
  console.log('reset build number..')
  let buf = fs.readFileSync(file, { encoding: 'utf-8' })
  let newBuf = buf.replace(/const appVersion = "[^"]*"/, `const appVersion = 'APP_VERSION'`)
  fs.writeFileSync(file, newBuf)
} else if (process.argv.some(arg => arg === '--prebuild')) {
  console.log('attaching build number..')
  let git_hash
  try {
    git_hash = childProcess.execSync('git rev-parse HEAD', { encoding: 'ascii' })
  } catch (e) {
    // no HEAD on remote build system
    git_hash = 'staging_build'
  }

  let buf = fs.readFileSync(file, { encoding: 'utf-8' })
  let newBuf = buf.replace(/const appVersion = 'APP_VERSION'/, `const appVersion = "${moment().format('YY.MM.DD')}.${git_hash.slice(0, 7)}"`)
  fs.writeFileSync(file, newBuf)
} else if (process.argv.some(arg => arg === '--build')) {
  new Promise((resolve, reject) => {
    childProcess.exec('ng build --aot -prod --app 0 > /dev/null', null, (err, stdout, stderr) => {
      console.log('exec done0')
      resolve()
    })
  }).then(_ => {
    Promise.all([
      new Promise((resolve, reject) => {
        childProcess.exec('ng build --aot -prod --app 1 > /dev/null', null, (err, stdout, stderr) => {
          console.log('exec done1')
          resolve()
        })
      }),
      new Promise((resolve, reject) => {
        childProcess.exec('ng build --aot -prod --app 2 > /dev/null', null, (err, stdout, stderr) => {
          console.log('exec done2')
          resolve()
        })
      }),
    ]).then(_ => console.log('apps all built'))
  })
} else {
  console.log(`
  [Usage] node build.js [--prebuild|--build|--postbuild]
  `)
}

以上是关于javascript prebuild.js的主要内容,如果未能解决你的问题,请参考以下文章

javascript的题。

javascript JavaScript isset()等效: - JavaScript

JavaScript 使用JavaScript更改CSS(JavaScript)

JavaScript之基础-1 JavaScript(概述基础语法)

前端基础-JavaScript的基本概述和语法

JavaScript