forked from ywzhaiqi/userscript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
63 lines (49 loc) · 1.64 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
module.exports = function(grunt) {
var concatOptions = {
banner: '(function() {\n',
footer: '\n})();',
separator: '\n\n//----------------------------------\n',
process: true
};
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
concat: {
dist: {
options: concatOptions,
src: ['src/meta.js', 'src/rule.js', 'src/setting.js', 'src/main.js'],
dest: '<%= pkg.name %>.user.js'
},
},
watch: {
files: ['src/**/*.js'],
tasks: ['default']
}
})
grunt.registerTask('split', 'split file', function () {
grunt.file.expand('src/*').forEach(function(path){
grunt.file.delete(path);
});
var source = grunt.file.read('super_preloaderplus_one.user.js');
// 去除首行和尾行
source = source.replace(/^\(function\(\).*/, '')
.replace(/\}\)\(\);$/, '');
var arr = source.split(/\n\/\/\-+/);
arr.forEach(function (text, index) {
if (index === 0) {
grunt.file.write('src/meta.js', text);
} else {
var match = text.match(/\n\/\/\s*(.*)/);
var name = match ? match[1] : ('split' + index + '.js' );
grunt.file.write('src/' + name, text);
}
});
// grunt.log.writeln();
});
grunt.registerTask('default', [
//'jshint',
'concat',
])
grunt.registerTask('watch', ['watch'])
grunt.loadNpmTasks('grunt-contrib-concat')
grunt.loadNpmTasks('grunt-contrib-watch')
}