UNPKG

3.04 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 main = '../build/' + pkg.mainFile;
36var bowerJson = {};
37
38if (pkg.plugin != null)
39{
40 deploy += "plugins";
41}
42else
43{
44 deploy += "webapps";
45 var bPath = 'bower.json';
46 bowerJson = utils.exists(bPath) ? JSON.parse(fs.readFileSync(bPath, 'utf8')) : {};
47}
48
49bowerJson.excludes = bowerJson.excludes || [];
50bowerJson.standalone = bowerJson.standalone || [];
51bowerJson.directories = bowerJson.directories || {};
52bowerJson.overrides = bowerJson.overrides || {};
53var gitHash = (utils.exists('.git/') ? utils.sh('git rev-parse --short HEAD') : 'current');
54var timestamp = utils.dateFormat(new Date(), '%Y-%m-%d %H:%M:%S')
55var 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
73var distDir = 'dist';
74var bundles = {
75 main: pkg.mainFile + '.js',
76 tests: 'tests-bundle.js',
77 examples: 'examples-bundle.js'
78};
79
80var bundleKinds = ['main', 'tests'];
81if (pkg.examples) bundleKinds.push('examples');
82var egisUiPkgName = 'EgisUI';
83
84pkg = _.assign({build: {}}, pkg);
85pkg.build = _.assign({autoImportAll: true}, pkg.build); //so pkg.build.autoImportAll will be true by default
86
87module.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};