-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
181 lines (139 loc) · 5.22 KB
/
index.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
var feather = module.exports = require('feather2');
var old = feather.cli.run;
feather.cli.run = function(argv, env){
var first = argv[2], action = argv._[0];
if(action == 'server' && !argv.root && !argv.r){
var www = feather.project.getTempPath('www'), script = www + '/preview/index.html';
!feather.util.exists(script) && feather.util.copy(__dirname + '/vendor/index.html', script);
argv.root = www + '/preview';
}
old(argv, env);
};
feather.config.merge({
project: {
name: '_default',
modulename: ''
},
modules: {
hook: require('feather2-lang-hook-components')
},
server: {
clean: false
},
postpackager: [require('feather2-lang-postpackager-runtime')]
});
feather.config.get('packager').unshift(require('feather2-lang-packager-map'));
feather.on('conf:loaded', function(){
var modulename = feather.config.get('project.modulename');
if(!modulename){
feather.config.set('project.modulename', modulename = 'common');
}
feather.config.set('namespace', modulename);
feather.match('map.json', {
release: 'view/_map_/${namespace}.json',
useHash: false
}, 1000000);
feather.match('/conf/(**)', {
release: feather.isPreviewMode ? '/conf/${namespace}/$1' : false
}, 1000000);
feather.match('/conf/engine.json', {
release: 'view/engine.json',
useHash: false
}, 1000000);
feather.match('/plugins/(**)', {
release: 'view/_plugins_/$1',
useCompile: false,
useHash: false,
isHtmlLike: false,
useMap: false,
url: false
}, 10000000);
if(modulename != 'common'){
feather.match('static/{pagelet,feather}.js', {
release: false
}, 1000000);
feather.match('/conf/engine.json', {
release: false
}, 1000001);
}
//feather2.0规定data目录 同feather1.x中的test目录,1.x中test目录创建的初衷也是为了测试数据
feather.match('/data/**', {
useHash: false,
useCompile: false,
release: feather.isPreviewMode ? 'data/${namespace}/$&' : false
});
var www = feather.project.getTempPath('www'), preview = www + '/preview';
feather.config.set('deploy.preview', [
{
from: '/',
to: www + '/project/' + feather.config.get('project.name'),
subOnly: true
},
{
from: '/static',
to: preview
}
]);
});
feather.on('conf:loaded', function(){
var modulename = feather.config.get('project.modulename'), name = feather.config.get('project.name');
//查找是否有common模块
if(modulename == 'common'){
feather.releaseInfo = {
config: {},
components: {},
map: {},
modules: {}
};
}else{
var root = feather.project.getCachePath() + '/info/' + name + '.json';
var info;
do{
if(feather.util.exists(root)){
info = feather.util.read(root);
try{
info = feather.releaseInfo = (new Function('return ' + info))();
break;
}catch(e){}
}
feather.log.error('Run common module first please!');
}while(0);
var config = feather.config.get(), commonConfig = info.config;
feather.config.set('template', commonConfig.template);
if(feather.util.isEmpty(config.project.domain)){
feather.config.set('project.domain', commonConfig.project.domain);
}
if(commonConfig.statics != config.statics){
feather.log.warn('common module\'s statics[' + commonConfig.statics + '] is different from current module\'s statics[' + config.statics + ']!');
}
feather.config.set('require.config.rules', (commonConfig.require.config.rules || []).concat(config.require.config.rules || []));
//判断如果找不到当前模块,说明已过期
if(!info.modules[modulename]){
feather._argv.clean = true;
delete feather._argv.c;
}
}
if(feather._argv.clean || feather._argv.c){
var www = feather.project.getTempPath('www'), preview = www + '/preview/', project = www + '/project/' + name + '/';
try{
feather.util.del(project + 'conf/' + modulename);
feather.util.del(project + 'data/' + modulename);
feather.util.del(project + 'view/_map_/' + modulename + '.json');
//feather.util.del(project + 'view/_plugins_');
feather.util.del(project + 'view/' + modulename);
}catch(e){};
}
});
var lookup = feather.project.lookup;
feather.project.lookup = function(path, file){
if(/:\/?[^\/]/.test(path)){
var quote = /['"]/.test(path) ? path[0] : '';
path = feather.util.stringQuote(path).rest;
var temp = path.split(':');
if(temp[0] == '' || temp[0] == feather.config.get('namespace')){
path = temp[1];
}
path = quote + path + quote;
}
return lookup(path, file);
};