-
Notifications
You must be signed in to change notification settings - Fork 5
/
conf-loaded.js
152 lines (114 loc) · 4 KB
/
conf-loaded.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
'use strict';
var _ = feather.util;
function serialize(exts){
if(!exts) return [];
if(typeof exts == 'string'){
exts = exts.split(/\s*,\s*/);
}
return exts.map(function(ext){
return ext.replace(/^\./, '');
});
}
feather.on('conf:loaded', function(){
//强制components作为component目录
feather.config.set('component.dir', 'components');
var jsExts = serialize(feather.config.get('project.fileType.js'));
var cssExts = serialize(feather.config.get('project.fileType.css'));
var txtExts = serialize(feather.config.get('project.fileType.text'));
var cExts = feather.config.get('component.ext'), exts = [];
var cJsExts = [], cCssExts = [];
jsExts.forEach(function(ext){
cJsExts.push('.' + ext);
});
cExts = cJsExts.concat(cExts);
cssExts.forEach(function(ext){
cCssExts.push('.' + ext);
});
cExts = cExts.concat(cCssExts);
feather.config.set('project.fileType.text', txtExts.concat(jsExts, cssExts));
jsExts.unshift('js');
cssExts.unshift('css');
feather.config.set('project.fileType.js', jsExts);
feather.config.set('project.fileType.css', cssExts);
feather.config.set('component.ext', cExts);
});
feather.on('conf:loaded', function(){
require('./config.js');
if(feather.config.get('server.clean')){
try{
feather.util.del(feather.project.getTempPath('www'));
}catch(e){}
}
});
//load all pack.json
feather.on('conf:loaded', function(){
var path = require('path'), root = feather.project.getProjectPath();
var previousPack = feather.config.get('pack') || {}, pack = {};
var files = (feather.util.find(root, null, 'node_modules') || []).filter(function(file){
return feather.util.filter(file, '**/pack.json');
});
files.reverse().forEach(function(realpath){
var file = feather.file(realpath);
var id = file.subpath.replace('/', '');
var dir = path.dirname(id) + '/';
var json;
try{
json = JSON.parse(file.getContent());
}catch(e){
feather.log.warn('unable to load file [`%s`].', id);
}
if(json){
for(var i in json){
var list = json[i];
if(i[0] == '.'){
i = path.normalize(dir + i).replace(/[\\\/]+/g, '/');
}
if(list.constructor != Array){
list = [list];
}
list = list.map(function(item){
if(typeof item == 'string' && item[0] == '.'){
return path.normalize(dir + item).replace(/[\\\/]+/g, '/');
}
return item;
});
pack[i] = list;
}
}
});
for(var i in pack){
previousPack[i] = pack[i];
}
feather.config.set('pack', _.merge({
'conf/pkg_.js': 'conf/**.js' //备份conf下的js文件,防止用户打包时,不小心收集了里面的内容
}, previousPack));
});
//analyse deploy files
feather.on('conf:loaded', function(){
var root = feather.project.getProjectPath();
if(!feather.util.exists(root + '/conf/deploy')){
return ;
}
var files = feather.util.find(root + '/conf/deploy', '*.js') || [];
var deploys = feather.config.get('deploy') || {};
files.forEach(function(file){
var info = feather.util.ext(file);
if(deploys[info.filename]) return;
var exports = require(file);
var config = [];
if(!Array.isArray(exports)){
exports = [exports];
}
exports.forEach(function(item){
if(!item.to) return;
if(item.to[0] == '.'){
item.to = require('path').normalize(root + '/' + item.to).replace(/[\\\/]+/g, '/');
}
config.push(item);
});
if(config.length){
deploys[info.filename] = config;
}
});
feather.config.set('deploy', deploys);
});