Blame view

node_modules/zrender/build/build.js 2.27 KB
aaac7fed   liuqimichale   add
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
  #!/usr/bin/env node
  
  const fsExtra = require('fs-extra');
  const {resolve} = require('path');
  const config = require('./config.js');
  const commander = require('commander');
  const {build, watch} = require('./helper');
  const prePublish = require('./pre-publish');
  
  function run() {
  
      /**
       * Tips for `commander`:
       * (1) If arg xxx not specified, `commander.xxx` is undefined.
       *     Otherwise:
       *      If '-x, --xxx', `commander.xxx` can only be true/false, even if '--xxx yyy' input.
       *      If '-x, --xxx <some>', the 'some' string is required, or otherwise error will be thrown.
       *      If '-x, --xxx [some]', the 'some' string is optional, that is, `commander.xxx` can be boolean or string.
       * (2) `node ./build/build.js --help` will print helper info and exit.
       */
  
      commander
          .usage('[options]')
          .description('Build zrender and generate result files in directory `zrender/dist` ')
          .option(
              '--release',
              'Build all for release'
          )
          .option(
              '--prepublish',
              'Build all for release'
          )
          .option(
              '-w, --watch',
              'Watch modifications of files and auto-compile to dist file (e.g., `zrender/dist/zrender.js`).'
          )
          .option(
              '--min',
              'Whether to compress the output file.'
          )
          .parse(process.argv);
  
      let isWatch = !!commander.watch;
      let isRelease = !!commander.release;
      let isPrePublish = !!commander.prepublish;
      let min = !!commander.min;
  
      // Clear `echarts/dist`
      if (isRelease) {
          fsExtra.removeSync(getPath('./dist'));
      }
  
      if (isWatch) {
          watch(config.create());
      }
      else if (isPrePublish) {
          prePublish();
      }
      else if (isRelease) {
          build([
              config.create(false),
              config.create(true)
          ]).then(function () {
              prePublish();
          }).catch(handleBuildError);
      }
      else {
          build([config.create(min)]).catch(handleBuildError);
      }
  }
  
  function handleBuildError(err) {
      console.log(err);
  }
  
  /**
   * @param {string} relativePath Based on zrender directory.
   * @return {string} Absolute path.
   */
  function getPath(relativePath) {
      return resolve(__dirname, '../', relativePath);
  }
  
  run();