forked from caomulaodao/yiye
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
211 lines (204 loc) · 6.2 KB
/
Gruntfile.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
204
205
206
207
208
209
210
211
'use strict';
var paths = {
js: ['*.js', 'test/**/*.js', '!test/coverage/**', '!bower_components/**', 'packages/server/*.js', '!packages/**/node_modules/**'],
html: ['packages/**/public/**/views/**', 'packages/**/server/views/**'],
css: ['!bower_components/**', 'packages/**/public/**/css/*.css']
};
var qiniu_url_1 = '"http://yiye-test.qiniudn.com';
var qiniu_url_2 = '\'http://yiye-test.qiniudn.com';
module.exports = function(grunt) {
if (process.env.NODE_ENV !== 'production') {
require('time-grunt')(grunt);
}
// Project Configuration
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
assets: grunt.file.readJSON('config/assets.json'),
clean: ['bower_components/build'],
copy: {
//remove all static files to 'static_files' folder
static: {
files: [
{expand: true, src: ['bower_components/**'], dest: 'static_files', nonull: true},
{expand: true, cwd: 'packages/bookmarks/public', src: ['**'], dest: 'static_files/bookmarks', nonull: true},
{expand: true, cwd: 'packages/channels/public', src: ['**'], dest: 'static_files/channels', nonull: true},
{expand: true, cwd: 'packages/home/public', src: ['**'], dest: 'static_files/home', nonull: true},
{expand: true, cwd: 'packages/person/public', src: ['**'], dest: 'static_files/person', nonull: true},
{expand: true, cwd: 'packages/system/public', src: ['**'], dest: 'static_files/system', nonull: true},
{expand: true, cwd: 'packages/users/public', src: ['**'], dest: 'static_files/users', nonull: true},
{expand: true, cwd: 'packages/overlook/public', src: ['**'], dest: 'static_files/overlook', nonull: true}
]
}
},
watch: {
js: {
files: paths.js,
tasks: ['jshint','concat'],
options: {
livereload: true
}
},
html: {
files: paths.html,
options: {
livereload: true,
interval: 500
}
},
css: {
files: paths.css,
tasks: ['csslint','concat'],
options: {
livereload: true
}
}
},
jshint: {
all: {
src: paths.js,
options: {
jshintrc: true
}
}
},
uglify: {
core: {
options: {
mangle: false
},
files: '<%= assets.core.js %>'
}
},
csslint: {
options: {
csslintrc: '.csslintrc'
},
src: paths.css
},
cssmin: {
core: {
files: '<%= assets.core.css %>'
}
},
nodemon: {
dev: {
script: 'server.js',
options: {
args: [],
ignore: ['node_modules/**'],
ext: 'js,html',
nodeArgs: ['--debug'],
delayTime: 1,
cwd: __dirname
}
}
},
concurrent: {
tasks: ['nodemon', 'watch'],
options: {
logConcurrentOutput: true
}
},
mochaTest: {
options: {
reporter: 'spec',
require: [
'server.js',
function() {
require('meanio/lib/util').preload(__dirname + '/packages/**/server', 'model');
}
]
},
src: ['packages/**/server/tests/**/*.js']
},
env: {
test: {
NODE_ENV: 'test'
}
},
karma: {
unit: {
configFile: 'karma.conf.js'
}
},
shell: {
qrsync_darwin: {
command: 'tasks/qrsync_darwin tasks/conf.json'
},
qrsync_linux: {
command: 'tasks/qrsync_linux tasks/conf.json'
}
},
replace:{
repHTML:{
src:['packages/*/server/views/**/*.html'],
overwrite: true,
replacements: [{
from: /["']\/[^"]+?\/assets\/img\/.+?\.(jpg|jpeg|gif|png|ico)["']/g,
to: function (matchedWord, index, fullText, regexMatches) {
console.log(matchedWord);
matchedWord = matchedWord.slice(1);
if (matchedWord.slice(-1) === '"')
return qiniu_url_1+matchedWord;
else
return qiniu_url_2+matchedWord;
}
},{
from: /["']\/bower_components\/.+?\/.+?\.(css|js)["']/g,
to: function (matchedWord, index, fullText, regexMatches) {
console.log(matchedWord);
matchedWord = matchedWord.slice(1);
if (matchedWord.slice(-1) === '"')
return qiniu_url_1+matchedWord;
else
return qiniu_url_2+matchedWord;
}
},{
from: /["']\/[^"]+?\/assets\/.+?\/.+?\.(css|js)["']/g,
to: function (matchedWord, index, fullText, regexMatches) {
console.log(matchedWord);
matchedWord = matchedWord.slice(1);
if (matchedWord.slice(-1) === '"')
return qiniu_url_1+matchedWord;
else
return qiniu_url_2+matchedWord;
}
}]
},
repCSS:{
src:['packages/*/public/assets/css/*.css'],
overwrite: true,
replacements: [{
from: /["']\/[^"]+?\/assets\/img\/.+?\.(jpg|jpeg|gif|png|ico)["']/g,
to: function (matchedWord, index, fullText, regexMatches) {
console.log(matchedWord);
matchedWord = matchedWord.slice(1);
if (matchedWord.slice(-1) === '"')
return qiniu_url_1+matchedWord;
else
return qiniu_url_2+matchedWord;
}
}]
}
},
});
//Load NPM tasks
require('load-grunt-tasks')(grunt);
grunt.loadNpmTasks('grunt-text-replace');
//Default task(s).
if (process.env.NODE_ENV === 'production') {
grunt.registerTask('default', ['clean', 'cssmin', 'uglify', 'concurrent']);
} else {
//grunt.registerTask('default', ['clean', 'jshint', 'concurrent']);
grunt.registerTask('default', ['clean', 'concurrent']); //close jshint
}
//Test task.
grunt.registerTask('test', ['env:test', 'mochaTest', 'karma:unit']);
//Upload static files task
if (process.platform === 'darwin') {
grunt.registerTask('upload_static', ['copy:static', 'shell:qrsync_darwin', 'replace']);
}
else if (process.platform === 'linux') {
grunt.registerTask('upload_static', ['copy:static', 'shell:qrsync_linux', 'replace']);
}
};