-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·191 lines (176 loc) · 5.38 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
182
183
184
185
186
187
188
189
190
191
/**
* fis3和yii整合解决方案
*/
var path = require('path');
module.exports = function(fis, isMount) {
var sets = {
'namespace': '',
'static': 'static',
'template': 'template',
'views': 'views',
'smarty': {
'left_delimiter': '{%',
'right_delimiter': '%}'
}
};
fis.set('server.type', 'smarty');
fis.set('project.ignore', ['*.bak', 'fis-conf.js', '*.md', 'component.json', '/components/**', '/plugin/**']);
var matchRules = {
// all release to $static dir
'*': {
release: '/${static}/${namespace}/$0'
},
'*.{js,css,scss}': {
useHash: true
},
'*.js': {
optimizer: fis.plugin('uglify-js')
},
'*.scss': {
parser: fis.plugin('sass'),
rExt: '.css'
},
'*.{css,scss}': {
optimizer: fis.plugin('clean-css'),
useSprite: true
},
'::image': {
useHash: true
},
'*.png': {
optimizer: fis.plugin('png-compressor')
},
'/static/module/**.{js,es}': {
isMod: true
},
'/(**.tpl)': {
preprocessor: fis.plugin('extlang'),
optimizer: [
fis.plugin('smarty-xss'),
fis.plugin('html-compress')
],
useMap: true,
release: '/${template}/${namespace}/$1'
},
'*.{tpl,js}': {
useSameNameRequire: true
},
// page dir
'/page/**.tpl': {
// 标记是否是个页面,向下兼容
extras: {
isPage: true
}
},
// widget
'/(widget/**.tpl)': {
url: '${namespace}/$1',
useMap: true,
},
'/widget/{*.{js,css},**/*.{js,css}}': {
isMod: true
},
'/{plugin/**.*,smarty.conf,domain.conf,**.php}': {
release: '$0'
},
'server.conf': {
release: '/server-conf/${namespace}.conf'
},
'/static/(**)': {
release: '/${static}/${namespace}/$1'
},
// test & config
'/(test)/(**)': {
useMap: false,
release: '/$1/${namespace}/$2'
},
'/(config)/(**)': {
useMap: false,
release: '/$1/${namespace}/$2'
},
'${namespace}-map.json': {
release: '/config/$0'
},
'*.sh': {
release: '$0'
},
'::package': {
prepackager: [
fis.plugin('widget-inline'),
fis.plugin('js-i18n')
]
}
};
function mount() {
// smarty
fis.set('system.localNPMFolder', path.join(__dirname, 'node_modules'));
// since [email protected]
// 帮当前目录的查找提前在 global 查找的前面,同时又保证 local 的查找是优先的。
if (fis.require.paths && fis.require.paths.length) {
fis.require.paths.splice(1, 0, path.join(__dirname, 'node_modules'));
}
fis.util.map(sets, function(key, value) {
fis.set(key, value);
});
fis.util.map(matchRules, function(selector, rules) {
fis.match(selector, rules);
});
// 模块化支持
fis.hook('commonjs');
// map.json
fis.match('::package', {
postpackager: function createMap(ret) {
var path = require('path')
var root = fis.project.getProjectPath();
var map = fis.file.wrap(path.join(root, fis.get('namespace') ? fis.get('namespace') + '-map.json' : 'map.json'));;
map.setContent(JSON.stringify(ret.map, null, map.optimizer ? null : 4));
ret.pkg[map.subpath] = map;
}
});
}
if (isMount !== false) {
mount();
}
//后续做优化,先临时解决
//远程部署设置
fis.media('remote').match('/components/**', {
release: '/fe/${static}/$&'
}).match('/{static,widget}/(**)', {
release: '/fe/${static}/${namespace}/$0'
}).match(/\/page\/(.+?)\/(.+?)\/(.+)/i, {
release: '/protected/modules/$1/views/$2/$3'
}).match('/page/{doc,wii_ui}/**', {
release: false
}).match('/{layout,widget}/**.tpl', {
release: '/protected/views/${namespace}/$0'
}).match('{*-map.json,map.json,wiiui.json}', {
release: '/protected/config/wii_ui/$0'
}).match('{*.conf,deploy.json}', {
release: false
}).match('/test/**', {
release: false
});
//doc 部署
fis.media('wiidoc').match('/components/**', {
release: '/fe/${static}/$&'
}).match('/{static,widget}/(**)', {
release: '/fe/${static}/${namespace}/$0'
}).match('/page/doc/**', {
release: false
}).match(/\/page\/(.+?)\/(.+?)\/(.+)/i, {
release: '/protected/modules/$1/views/$2/$3'
}).match('/{layout,widget}/**.tpl', {
release: '/protected/views/${namespace}/$0'
}).match('{*-map.json,map.json,wiiui.json}', {
release: '/protected/config/wii_ui/$0'
}).match('{*.conf,deploy.json}', {
release: false
}).match('/test/**', {
release: false
});
return {
loadPath: path.join(__dirname, 'node_modules'),
sets: sets,
matchRules: matchRules
}
};