1 |
|
2 |
|
3 |
|
4 |
|
5 | var fs = require('fs');
|
6 | var minimist = require('minimist');
|
7 | var lazypipe = require('lazypipe');
|
8 | var replace = require('gulp-replace');
|
9 | var utils = require('../utils');
|
10 | var deploy = process.env.WORK_DIR;
|
11 | var _ = require('lodash');
|
12 | var argv = require('optimist').argv;
|
13 |
|
14 | var knownOptions = {
|
15 | string: 'env',
|
16 | default: {
|
17 | env: process.env.NODE_ENV || 'development',
|
18 | watch: process.env.watch || false
|
19 |
|
20 | }
|
21 | };
|
22 |
|
23 | var options = minimist(process.argv.slice(2), knownOptions);
|
24 |
|
25 | if (deploy != null)
|
26 | {
|
27 | deploy += '/work/';
|
28 | }
|
29 | else
|
30 | {
|
31 | deploy = 'build/';
|
32 | }
|
33 |
|
34 | var pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
|
35 | var main = '../build/' + pkg.mainFile;
|
36 | var bowerJson = {};
|
37 |
|
38 | if (pkg.plugin != null)
|
39 | {
|
40 | deploy += "plugins";
|
41 | }
|
42 | else
|
43 | {
|
44 | deploy += "webapps";
|
45 | var bPath = 'bower.json';
|
46 | bowerJson = utils.exists(bPath) ? JSON.parse(fs.readFileSync(bPath, 'utf8')) : {};
|
47 | }
|
48 |
|
49 | bowerJson.excludes = bowerJson.excludes || [];
|
50 | bowerJson.standalone = bowerJson.standalone || [];
|
51 | bowerJson.directories = bowerJson.directories || {};
|
52 | bowerJson.overrides = bowerJson.overrides || {};
|
53 | var gitHash = (utils.exists('.git/') ? utils.sh('git rev-parse --short HEAD') : 'current');
|
54 | var timestamp = utils.dateFormat(new Date(), '%Y-%m-%d %H:%M:%S')
|
55 | var replaceAll = lazypipe()
|
56 | .pipe(function ()
|
57 | {
|
58 | return replace('@@version', pkg.version + " " + gitHash)
|
59 | })
|
60 | .pipe(function ()
|
61 | {
|
62 | return replace('@@js_suffix', '.js?rel=' + gitHash)
|
63 | })
|
64 | .pipe(function ()
|
65 | {
|
66 | return replace('@@css_suffix', '.css?rel=' + gitHash)
|
67 | })
|
68 | .pipe(function ()
|
69 | {
|
70 | return replace('@@timestamp', timestamp)
|
71 | });
|
72 |
|
73 | var distDir = 'dist';
|
74 | var bundles = {
|
75 | main: pkg.mainFile + '.js',
|
76 | tests: 'tests-bundle.js',
|
77 | examples: 'examples-bundle.js'
|
78 | };
|
79 |
|
80 | var bundleKinds = ['main', 'tests'];
|
81 | if (pkg.examples) bundleKinds.push('examples');
|
82 | var egisUiPkgName = 'EgisUI';
|
83 |
|
84 | pkg = _.assign({build: {}}, pkg);
|
85 | pkg.build = _.assign({autoImportAll: true}, pkg.build);
|
86 |
|
87 | module.exports = {
|
88 | deploy: deploy,
|
89 | pkg: pkg,
|
90 | bundleKinds: bundleKinds,
|
91 | bundles: bundles,
|
92 | srcDirs: {
|
93 | main: 'src',
|
94 | tests: 'test',
|
95 | examples: 'examples'
|
96 | },
|
97 | bowerJson: bowerJson,
|
98 | watch: options.watch,
|
99 | host: argv.host || pkg.host || 'localhost',
|
100 | port: argv.port || pkg.port || '8101',
|
101 | prod: options.env === 'production',
|
102 | main: main,
|
103 | replaceAll: replaceAll,
|
104 | build: {
|
105 | autoImportAll: {
|
106 | main: pkg.build.autoImportAll,
|
107 | tests: true,
|
108 | examples: true
|
109 | }
|
110 | },
|
111 | dist: {
|
112 | dir: distDir,
|
113 | main: distDir + '/main',
|
114 | tests: distDir + '/test',
|
115 | examples: distDir + '/examples'
|
116 | },
|
117 | module: {
|
118 | main: pkg.moduleName,
|
119 | tests: 'Tests',
|
120 | examples: 'Examples'
|
121 | },
|
122 | egisUiPkgName: egisUiPkgName,
|
123 | egisUiModuleName: egisUiPkgName
|
124 | };
|