123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- 'use strict'
- require('./check-versions')()
- const fs = require('fs');
- process.env.NODE_ENV = 'production'
- const ora = require('ora')
- const rm = require('rimraf')
- const path = require('path')
- const chalk = require('chalk')
- const webpack = require('webpack')
- const config = require('../config')
- const webpackConfig = require('./webpack.prod.conf')
- const spinner = ora('building for production...')
- spinner.start()
- rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
- if (err) throw err
- webpack(webpackConfig, function (err, stats) {
- spinner.stop()
- if (err) throw err
- process.stdout.write(stats.toString({
- colors: true,
- modules: false,
- children: false,
- chunks: false,
- chunkModules: false
- }) + '\n\n')
- if (stats.hasErrors()) {
- console.log(chalk.red(' Build failed with errors.\n'))
- process.exit(1)
- }
- console.log(chalk.cyan(' Build complete.\n'))
- console.log(chalk.yellow(
- ' Tip: built files are meant to be served over an HTTP server.\n' +
- ' Opening index.html over file:// won\'t work.\n'
- ))
- const fs = require('fs');
- const git_hash = () => {
- try {
- const rev = fs.readFileSync('.git/HEAD').toString().trim().split(/.*[: ]/).slice(-1)[0];
- if (rev.indexOf('/') === -1) {
- return rev;
- } else {
- return fs.readFileSync('.git/' + rev).toString().trim();
- }
- } catch (e) {
- // eslint-disable-next-line no-console
- console.log(e);
- return 'git_hash_error';
- }
- }
- const git_branch = () => {
- try {
- const revBase = fs.readFileSync('.git/HEAD').toString().trim()
- return revBase.split('refs/heads/')[1]
- }catch (e) {
- // eslint-disable-next-line no-console
- console.log(e);
- return 'git_branch_error';
- }
- }
- const getVersion = () => {
- const raw = fs.readFileSync('./package.json').toString();
- const packageJson = JSON.parse(/{[\s\S]*}/mg.exec(raw)[0]);
- // eslint-disable-next-line no-console
- // console.log(packageJson.version);
- return packageJson.version;
- }
- const PROJECT_NAME = '追迹者-第三方支付数据分析'
- const GIT_COMMIT = git_hash()
- const TICK = getVersion();
- const BUILD_TIME_BASE = new Date(new Date().getTime() + 28800000)
- const BUILD_TIME = BUILD_TIME_BASE.toUTCString()
- // console.log(BUILD_TIME_BASE.toLocaleString(),BUILD_TIME_BASE.getFullYear(),BUILD_TIME_BASE.getMonth()+1,BUILD_TIME_BASE.getDate())
- console.log(chalk.red(`PROJECT_NAME: ${PROJECT_NAME}`));
- console.log(chalk.red('BUILD_TIME:', BUILD_TIME))
- console.log(chalk.red('GIT_COMMIT:', GIT_COMMIT))
- console.log(chalk.red('GIT_BRANCH:', git_branch()))
- console.log(chalk.red('FILE_NAME:', PROJECT_NAME+'版'+TICK+'-('+git_branch()+')-'+GIT_COMMIT.slice(0, 8)+'('+BUILD_TIME+')'))
- console.log(chalk.red('TICK:', TICK))
- let html = fs.readFileSync('dist/index.html').toString();
- html += '\r\n<!-- ';
- html = html + '\r\n PROJECT_NAME: ' + PROJECT_NAME + ';';
- html = html + '\r\n BUILD_TIME:' + BUILD_TIME + '; ';
- html = html + '\r\n GIT_BRANCH:' + git_branch() + '; ';
- html = html + '\r\n GIT_COMMIT:' + GIT_COMMIT + '; ';
- html = html + '\r\n TICK:' + TICK + '; ';
- html += '\r\n -->';
- html = html.replace('VUE_APP_SHORT_VERSION_NAME', TICK);
- fs.writeFileSync('dist/index.html', html);
- // eslint-disable-next-line no-console
- console.log(chalk.green(`insert timestamp and env into index.html.`));
- })
- })
|