/
Gruntfile.js
147 lines (130 loc) · 4.19 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
/*!
* Ratchet's Gruntfile
* http://goratchet.com
* Copyright 2015 Connor Sears
* Licensed under MIT (https://github.com/twbs/ratchet/blob/master/LICENSE)
*/
/* jshint node: true */
module.exports = function (grunt) {
'use strict';
// Force use of Unix newlines
grunt.util.linefeed = '\n';
RegExp.quote = function (string) {
return string.replace(/[-\\^$*+?.()|[\]{}]/g, '\\$&');
};
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
// Metadata.
meta: {
distPath: 'dist/',
jsPath: 'src/scripts/',
cssPath: 'src/css/',
imagesPath: 'src/images'
},
banner: '/*!\n' +
' * =============================================================\n' +
' * Chitu Web App v<%= pkg.version %> (<%= pkg.homepage %>)\n' +
' * Copyright <%= grunt.template.today("yyyy") %> <%= pkg.author %>\n' +
' * Licensed under <%= pkg.license %> (https://github.com/mazong1123/chitu/blob/master/LICENSE)\n' +
' *\n' +
' * v<%= pkg.version %> designed by @mazong1123.\n' +
' * =============================================================\n' +
' */\n',
clean: {
dist: ['<%= meta.distPath %>']
},
/*concat: {
chitu: {
options: {
banner: '<%= banner %>'
},
src: [],
dest: '<%= meta.distPath %>js/<%= pkg.name %>.js'
}
},*/
usebanner: {
dist: {
options: {
position: 'top',
banner: '<%= banner %>'
},
files: {
src: [
'<%= meta.distPath %>css/*.css'
]
}
}
},
copy: {
all: {
expand: true,
cwd: 'src/',
src: '**',
dest: '<%= meta.distPath %>'
}
},
cssmin: {
options: {
keepSpecialComments: '*' // keep all important comments
},
chitu: {
files: [{
expand: true,
cwd: '<%= meta.distPath %>css',
src: '**/*.css',
dest: '<%= meta.distPath %>css'
}]
}
},
uglify: {
options: {
banner: '<%= banner %>',
compress: {
warnings: false
},
mangle: true,
preserveComments: false
},
chitu: {
files: [{
expand: true,
cwd: '<%= meta.distPath %>scripts',
src: '**/*.js',
dest: '<%= meta.distPath %>scripts'
}]
}
},
sed: {
versionNumber: {
pattern: (function () {
var old = grunt.option('oldver');
return old ? RegExp.quote(old) : old;
})(),
replacement: grunt.option('newver'),
exclude: [
'dist/fonts',
'docs/assets',
'fonts',
'node_modules'
],
recursive: true
}
},
qunit: {
all: ['tests/*.html']
}
});
// Load the plugins
require('load-grunt-tasks')(grunt, { scope: 'devDependencies' });
require('time-grunt')(grunt);
// Default task(s).
grunt.registerTask('dist-css', ['usebanner', 'cssmin']);
grunt.registerTask('dist-js', ['uglify']);
grunt.registerTask('dist', ['clean', 'copy', 'dist-css', 'dist-js']);
grunt.registerTask('default', ['dist']);
// Version numbering task.
// grunt change-version-number --oldver=A.B.C --newver=X.Y.Z
// This can be overzealous, so its changes should always be manually reviewed!
grunt.registerTask('change-version-number', 'sed');
};