-
Notifications
You must be signed in to change notification settings - Fork 5
/
default.js
148 lines (124 loc) · 3.87 KB
/
default.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
'use strict';
const path = require('path');
const cmdMap = require('./lib/utils').cmdMap;
const _ = require('lodash');
const defaults = {
/**
* wo 中有两种路径
* 1. 线上文件夹路径
* build/name/version/RELATIVE_DIR
* 2. 样式文件图片引用路径
* production/name/version/RELATIVE_DIR
*/
name: 'project_name',
version: '0.0.0',
production: 'http://your.domain.com/cdn-path/',
/* 压缩文件头注释, 感叹号(!)打头的注释不会被压缩 */
/* ----- example ----- */
/*!Name: base.js
* Date: 2015-51-20 17:21:6 */
banner: '/*!Name: {{ name }}\n * Date: {{ date }} */\n',
scripts: ['app/components/**/*.js'],
styles: ['app/components/**/*.scss'],
images: ['app/components/**/i/*.+(|png|gif)'],
templates: ['app/views/*.html', 'app/components/*/*.test.html'],
sprites: {
cssName: '__sprite.scss',
imgName: 'i/__sprite.png',
items: []
},
source: 'app',
view: 'views',
component: {
dir: 'components',
config: 'config.js',
test: '.test.html'
},
templateRefs: ['app/components/*/*.html', 'app/views/*/*.html'],
tests: ['app/tests/**'],
assets: ['app/components/**/*.+(|css|cur)'],
globalIgnore: ['!app/components/*/config.js'],
watchIgnore: /\/maco\/|\/layout\/|config\.js|node_modules/,
uglify: {
mangle: {
except: ['define', 'require', 'module', 'exports']
}
},
cleanCSS: {},
pngquant: {
quality: '80-90',
speed: 4
},
dest: 'build',
server: {
dir: '.www',
port: 80,
index: false
},
deploy: {
host: '127.0.0.1',
user: 'ftpuser',
password: 'ftppass',
parallel: 5,
src: 'build/**',
dest: './'
},
release: {
cmds: []
}
};
function addRuntimeVal(arg) {
let cwd = process.cwd();
let configFile = path.join(cwd, 'config.js');
if (arg.config) {
configFile = path.resolve(arg.config);
cwd = path.dirname(configFile);
process.chdir(cwd);
}
let config = {};
try {
config = require(configFile);
} catch (err) {
if (cmdMap[arg._[0]] != 'gen') {
let msg = 'Config file not found. Make sure your cwd has [config.js].';
console.info(msg);
return msg;
}
}
let options = _.defaultsDeep(config, defaults);
options._arg = arg;
options._cmd = arg._[0];
options._CWD = cwd;
options._VERSION = arg.ver || options.version;
options._SOURCE_ROOT = path.join(options._CWD, options.source);
options._COMPONENT_ROOT = path.join(options._SOURCE_ROOT, options.component.dir);
options._VIEW_ROOT = path.join(options._SOURCE_ROOT, options.view);
options._SERVER_ROOT = path.join(options._CWD, options.server.dir);
options._WO_ROOT = __dirname;
// project_name/version_number
options._PRD_PREFIX = path.join(options.name, options._VERSION);
// Debug mode
options._isDebug = options._arg.debug;
options._showLog = options._arg.log;
// Force mode
options._isForce = options._arg.force;
// Development
options._isDev = options._arg.development || cmdMap[options._cmd] === 'start';
// Production
options._isPrd = options._arg.production || /build|release|deploy/.test(cmdMap[options._cmd]);
// Release
//options._isRel = cmdMap[options._cmd] === 'release';
options._DEST_ROOT = path.resolve(options.dest);
if (options._isDev) {
options._DEST_ROOT = options._SERVER_ROOT;
}
if (options._isPrd) {
options._DEST_ROOT = path.join(options._CWD, options.dest, options._PRD_PREFIX);
}
// component data
options._components = {};
// sass includes reference
options._sass = {};
return _.defaultsDeep({}, options);
}
module.exports = addRuntimeVal;