-
Notifications
You must be signed in to change notification settings - Fork 207
/
gulpfile.js
203 lines (167 loc) · 6.76 KB
/
gulpfile.js
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/*!
* Project: cv
* File: ./gulpfile.js
* Copyright(c) 2016-present Baltrushaitis Tomas <[email protected]>
* License: MIT
*/
'use strict';
// Reads configuration from .env file
require('dotenv').config();
// ------------------------------------------------------------------------ //
// ----------------------------- DEPENDENCIES --------------------------- //
// ------------------------------------------------------------------------ //
const fs = require('fs');
const path = require('path');
const utin = require('util').inspect;
const _ = require('lodash');
const argv = require('yargs').argv;
const dateFormat = require('dateformat');
const readConfig = require('read-config');
const vPaths = require('vinyl-paths');
const {series, parallel} = require('gulp');
const pkg = require('./package.json');
// ------------------------------------------------------------------------ //
// ---------------------------- CONFIGURATION --------------------------- //
// ------------------------------------------------------------------------ //
let now = new Date();
let ME = {};
globalThis.ME = ME ;
ME.WD = path.join(__dirname);
ME.CFGD = path.join(ME.WD, 'config');
ME.pkg = Object.assign({}, pkg || {});
ME.version = ME.pkg.version;
ME.pkg.built = `${dateFormat(now, 'yyyy-mm-dd')}T${dateFormat(now, 'HH:MM:ss')} ${dateFormat(now, 'Z')}`;
ME.pkg.year = `${dateFormat(now, 'yyyy')}`;
ME.pkg.options.readconf = Object.assign({}, ME.pkg.options.readconf, {
basedir: `${ME.CFGD}`
});
utin.defaultOptions = { ...ME.pkg.options.iopts };
ME.NODE_ENV = process.env.NODE_ENV
? process.env.NODE_ENV
: argv.env
? argv.env
: fs.existsSync('./NODE_ENV')
? fs.readFileSync('./NODE_ENV', ME.pkg.options.file).split('\n')[0].trim()
: fs.existsSync(`${ME.CFGD}/.NODE_ENV`)
? fs.readFileSync(`${ME.CFGD}/.NODE_ENV`, ME.pkg.options.file).split('\n')[0].trim()
: ME.NODE_ENV || 'test';
process.env.NODE_ENV = `${ME.NODE_ENV}`;
ME.ENV = ME.NODE_ENV;
ME.VERSION = fs.existsSync('./VERSION') ? fs.readFileSync('./VERSION', ME.pkg.options.file).trim() : ME.version;
ME.COMMIT = fs.existsSync('./COMMIT') ? fs.readFileSync('./COMMIT', ME.pkg.options.file).trim() : 'COMMIT_UNKNOWN';
let BUILD_FILE = path.join(ME.WD, `BUILD-${ME.VERSION}`);
ME.CNTR = fs.existsSync(`${BUILD_FILE}`)
? fs.readFileSync(`${BUILD_FILE}`, ME.pkg.options.file).trim()
: 'tmp';
const modsPath = path.join(ME.WD, 'modules');
const confBase = path.join(ME.CFGD, ME.NODE_ENV + '.json');
let config = readConfig(confBase, Object.assign({}, ME.pkg.options.readconf));
ME.Config = config;
let C = ME.Config.colors;
ME.L = `\n${C.W}${'-'.repeat(80)}${C.N}\n`;
ME.d = (() => {
return `[${C.Gray}${dateFormat(Date.now(), 'HH:MM:ss')}${C.N}][${C.G}${ME.pkg.name}${C.N}:${C.Gr}${ME.VERSION}${C.N}]`;
})();
ME.DIR = {};
ME.CURDIR = path.join(process.cwd());
ME.DOC = path.join('docs');
ME.TMP = path.join('tmp');
ME.SRC = path.join('src');
ME.BUILD = path.join(`build-${ME.VERSION}-${ME.CNTR}-${ME.ENV}`);
ME.DIST = path.join(`dist-${ME.VERSION}-${ME.CNTR}-${ME.ENV}`);
ME.WEB = path.join(`web-${ME.VERSION}-${ME.CNTR}-${ME.ENV}`);
ME.BOWER = JSON.parse(fs.existsSync('.bowerrc')
? fs.readFileSync('.bowerrc')
: '{"directory": "bower_modules"}'
).directory;
let headTplName = path.join(ME.CFGD, 'header.tpl');
let footTplName = path.join(ME.CFGD, 'footer.tpl');
let headTplCtx = fs.existsSync( headTplName )
? fs.readFileSync( headTplName )
: `
/*!
* =========================================================================== *
* <%= pkg.name %>@<%= pkg.version %>
* =========================================================================== *
**/
`;
let footTplCtx = fs.existsSync( footTplName )
? fs.readFileSync( footTplName )
: `
/*!
* <%= pkg.name %>@<%= pkg.version %> - <%= pkg.title %> [${dateFormat(now, 'yyyy-mm-dd')}T${dateFormat(now, 'HH:MM:ss')}Z ${dateFormat(now, 'Z')}]
* =========================================================================== *
**/
`;
let headTpl = _.template(`${headTplCtx}`);
let footTpl = _.template(`${footTplCtx}`);
const Banner = {
header: headTpl({pkg: ME.pkg, ME: ME})
, footer: footTpl({pkg: ME.pkg, ME: ME})
};
ME.Banner = Banner;
console.log(`${ME.L}`);
console.log(`${ME.d} ${C.Y}ARGUMENTS${C.N} = [${utin(argv)}]`);
console.log(`${ME.d} ${C.BY}NPM_LIFECYCLE_EVENT${C.N} = [${C.Orange}${process.env.npm_lifecycle_event}${C.N}]`);
console.log(`${ME.d} ${C.Y}ME.ENV${C.N} = [${C.BR}${ME.ENV}${C.N}]`);
console.log(`${ME.d} ${C.Y}ME.NODE_ENV${C.N} = [${C.BR}${ME.NODE_ENV}${C.N}]`);
console.log(`${ME.d} ${C.Y}ME.WD${C.N} = [${C.Purple}${ME.WD}${C.N}]`);
console.log(`${ME.d} ${C.Y}ME.BUILD${C.N} = [${C.Blue}${ME.BUILD}${C.N}]`);
console.log(`${ME.d} ${C.Y}ME.DIST${C.N} = [${C.Blue}${ME.DIST}${C.N}]`);
console.log(`${ME.d} ${C.Y}ME.WEB${C.N} = [${C.Blue}${ME.WEB}${C.N}]`);
console.log(`${ME.L}`);
// ------------------------------------------------------------------------ //
// ------------------------------- TASKS -------------------------------- //
// ------------------------------------------------------------------------ //
const Tasks = require(`./gulp-tasks`);
// ------------------------------------------------------------------------ //
// ---------------------- DEFAULT Scenario Route ------------------------ //
// ------------------------------------------------------------------------ //
function defaultTask (cb) {
console.log(`[defaultTask] CallBack(${typeof cb})`);
console.log(`Tasks.default(${typeof Tasks.default}) =`, Tasks.default);
console.log(`Tasks.data(${typeof Tasks.data}) =`, Tasks.data);
// ROUTE by ENV
// (function () {
//
// let TaskMap = {
// _: 'usage'
// , default: 'usage'
// , test: 'test'
// , dev: 'dev'
// , development: 'dev'
// , prod: 'prod'
// , production: 'prod'
// , local: 'local'
// }
// let TaskRun = TaskMap._
//
// if ('string' === typeof ME.NODE_ENV) {
// TaskRun = TaskMap[ `${ME.NODE_ENV}` ]
// }
//node -v
// console.log(`${ME.d} ${C.Y}Starting ${C.BW}${C.OnBlue}${TaskRun.toUpperCase()}${C.N}`)
// return gulp.start(`${TaskRun}`);
//
// })();
Tasks.data.help();
// console.log(`${ME.d}[${C.Y}DEFAULT${C.N}] task ${C.BW}${C.OnBlue}FINISHED${C.N}`);
if ('function' === typeof cb) {
cb();
}
}
/**
* @_EXPOSE
*/
exports.bower = Tasks.bower;
exports.build = Tasks.build;
exports.help = Tasks.help;
exports.lint = Tasks.lint;
exports.test = Tasks.test;
exports.populate = Tasks.populate;
exports.usage = Tasks.usage;
/**
* @_EXPORTS
*/
exports.default = defaultTask;
/* EOF: ROOT/gulpfile.js */