UNPKG

3.36 kBJavaScriptView Raw
1/**
2 * Created by Nikolay Glushchenko <nick@nickalie.com> on 08.09.2015.
3 */
4
5var fs = require('fs');
6var minimist = require('minimist');
7var lazypipe = require('lazypipe');
8var replace = require('gulp-replace');
9var utils = require('../utils');
10var deploy = process.env.WORK_DIR;
11var _ = require('lodash');
12var argv = require('optimist').argv;
13
14var knownOptions = {
15 string: 'env',
16 default: {
17 env: process.env.NODE_ENV || 'development',
18 watch: process.env.watch || false
19
20 }
21};
22
23var options = minimist(process.argv.slice(2), knownOptions);
24
25if (deploy != null)
26{
27 deploy += '/work/';
28}
29else
30{
31 deploy = 'build/';
32}
33
34var pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
35var mainFile = pkg.mainFile;
36if (!mainFile) {
37 var parts = pkg.name.split('/');
38 mainFile = parts[parts.length - 1];
39}
40
41var main = '../build/' + mainFile;
42var bowerJson = {};
43
44if (pkg.plugin != null)
45{
46 deploy += "plugins";
47}
48else
49{
50 deploy += "webapps";
51 var bPath = 'bower.json';
52 bowerJson = utils.exists(bPath) ? JSON.parse(fs.readFileSync(bPath, 'utf8')) : {};
53}
54
55bowerJson.excludes = bowerJson.excludes || [];
56bowerJson.standalone = bowerJson.standalone || [];
57bowerJson.directories = bowerJson.directories || {};
58bowerJson.overrides = bowerJson.overrides || {};
59var gitHash = (utils.exists('.git/') ? utils.sh('git rev-parse --short HEAD') : 'current');
60var timestamp = utils.dateFormat(new Date(), '%Y-%m-%d %H:%M:%S')
61var 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
79var distDir = 'dist';
80var bundles = {
81 main: mainFile + '.js',
82 tests: 'tests-bundle.js',
83 examples: 'examples-bundle.js'
84};
85
86var bundleKinds = ['main', 'tests'];
87if (pkg.examples) bundleKinds.push('examples');
88
89pkg = _.assign({build: {}}, pkg);
90pkg.build = _.assign({autoImportAll: true}, pkg.build); //so pkg.build.autoImportAll will be true by default
91
92var 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
131config.dependsOnEgisUi = function() {
132 return pkg.devDependencies && pkg.devDependencies[config.egisUiPkgName] ||
133 pkg.dependencies && pkg.dependencies[config.egisUiPkgName];
134};
135
136module.exports = config;