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 |
|
30 | var pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
|
31 | var mainFile = pkg.mainFile;
|
32 | if (!mainFile) {
|
33 | var parts = pkg.name.split('/');
|
34 | mainFile = parts[parts.length - 1];
|
35 | }
|
36 |
|
37 | var main = '../build/' + mainFile;
|
38 | var bowerJson = {};
|
39 |
|
40 | if (pkg.plugin != null)
|
41 | {
|
42 | deploy = deploy || "build/";
|
43 | deploy += "plugins";
|
44 | }
|
45 | else
|
46 | {
|
47 | if (deploy != null)
|
48 | {
|
49 | deploy += "webapps";
|
50 | }
|
51 | var bPath = 'bower.json';
|
52 | bowerJson = utils.exists(bPath) ? JSON.parse(fs.readFileSync(bPath, 'utf8')) : {};
|
53 | }
|
54 |
|
55 | bowerJson.excludes = bowerJson.excludes || [];
|
56 | bowerJson.standalone = bowerJson.standalone || [];
|
57 | bowerJson.directories = bowerJson.directories || {};
|
58 | bowerJson.overrides = bowerJson.overrides || {};
|
59 | var gitHash = (utils.exists('.git/') ? utils.sh('git rev-parse --short HEAD') : 'current');
|
60 | var timestamp = utils.dateFormat(new Date(), '%Y-%m-%d %H:%M:%S')
|
61 | var replaceAll = lazypipe()
|
62 | .pipe(function ()
|
63 | {
|
64 | return replace('@@version', pkg.version + " " + gitHash)
|
65 | })
|
66 | .pipe(function ()
|
67 | {
|
68 | return replace('@@js_suffix', '.js?rel=' + gitHash)
|
69 | })
|
70 | .pipe(function ()
|
71 | {
|
72 | return replace('@@css_suffix', '.css?rel=' + gitHash)
|
73 | })
|
74 | .pipe(function ()
|
75 | {
|
76 | return replace('@@timestamp', timestamp)
|
77 | });
|
78 |
|
79 | var distDir = 'dist';
|
80 | var bundles = {
|
81 | main: mainFile + '.js',
|
82 | tests: 'tests-bundle.js',
|
83 | examples: 'examples-bundle.js'
|
84 | };
|
85 |
|
86 | var bundleKinds = ['main', 'tests'];
|
87 | if (pkg.examples) bundleKinds.push('examples');
|
88 |
|
89 | pkg = _.assign({build: {}}, pkg);
|
90 | pkg.build = _.assign({autoImportAll: true}, pkg.build);
|
91 |
|
92 | var config = {
|
93 | deploy: deploy,
|
94 | pkg: pkg,
|
95 | bundleKinds: bundleKinds,
|
96 | bundles: bundles,
|
97 | srcDirs: {
|
98 | main: 'src',
|
99 | tests: 'test',
|
100 | examples: 'examples'
|
101 | },
|
102 | bowerJson: bowerJson,
|
103 | watch: options.watch,
|
104 | host: argv.host || pkg.host || 'localhost',
|
105 | port: argv.port || pkg.port || '8101',
|
106 | prod: !process.env.DEV && options.env === 'production',
|
107 | main: main,
|
108 | replaceAll: replaceAll,
|
109 | build: {
|
110 | autoImportAll: {
|
111 | main: pkg.build.autoImportAll,
|
112 | tests: true,
|
113 | examples: true
|
114 | }
|
115 | },
|
116 | dist: {
|
117 | dir: distDir,
|
118 | main: distDir + '/main',
|
119 | tests: distDir + '/test',
|
120 | examples: distDir + '/examples'
|
121 | },
|
122 | module: {
|
123 | main: pkg.moduleName,
|
124 | tests: 'Tests',
|
125 | examples: 'Examples'
|
126 | },
|
127 | egisUiPkgName: '@egis/egis-ui',
|
128 | egisUiModuleName: 'EgisUI',
|
129 | };
|
130 |
|
131 | config.dependsOnEgisUi = function() {
|
132 | return pkg.devDependencies && pkg.devDependencies[config.egisUiPkgName] ||
|
133 | pkg.dependencies && pkg.dependencies[config.egisUiPkgName];
|
134 | };
|
135 |
|
136 | module.exports = config;
|