-
Notifications
You must be signed in to change notification settings - Fork 89
/
Gruntfile.js
271 lines (257 loc) · 6.32 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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
/* jshint node:true */
module.exports = function( grunt ) {
// Load all Grunt tasks
require( 'load-grunt-tasks' )( grunt );
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON( 'package.json' ),
sass: {
theme: {
options: {
outputStyle: 'nested'
},
files: {
'src/style.css': 'assets/sass/style.scss'
}
}
},
csscomb: {
style: {
options: {
config: 'csscomb.json'
},
files: {
'src/style.css': ['src/style.css']
}
}
},
jshint: {
options: grunt.file.readJSON( '.jshintrc' ),
grunt: {
src: [
'Gruntfile.js'
]
},
theme: {
src: [
'src/js/**/*.js',
'!src/js/**/*.min.js',
'!src/js/libs/**/*.js',
'src/inc/customizer/js/customizer.js',
'src/inc/builder/core/js/**/*.js',
'src/inc/builder/sections/js/**/*.js'
]
}
},
concat: {
options: {
banner: '/*! <%= pkg.version %> */\n',
separator: ';'
},
cycle2: {
src: [
'src/js/libs/cycle2/jquery.cycle2.js',
'src/js/libs/cycle2/jquery.cycle2.center.js',
'src/js/libs/cycle2/jquery.cycle2.swipe.js'
],
dest: 'src/js/libs/cycle2/jquery.cycle2.min.js'
}
},
uglify: {
options: {
preserveComments: 'some'
},
libs: {
files: {
// Cycle2 source filename already has '.min' because of concat
'src/js/libs/cycle2/jquery.cycle2.min.js': ['src/js/libs/cycle2/jquery.cycle2.min.js'],
'src/js/libs/fitvids/jquery.fitvids.min.js': ['src/js/libs/fitvids/jquery.fitvids.js']
}
},
theme: {
files: {
'src/js/global.min.js': ['src/js/global.js']
}
},
customizer: {
files:{
'src/inc/customizer/js/customizer-preview.min.js': ['src/inc/customizer/js/customizer-preview.js'],
'src/inc/customizer/js/customizer-sections.min.js': ['src/inc/customizer/js/customizer-sections.js']
}
},
admin: {
files:{
'src/js/admin/edit-page.min.js': ['src/js/admin/edit-page.js'],
'src/inc/gallery-slider/gallery-slider.min.js': ['src/inc/gallery-slider/gallery-slider.js']
}
}
},
shell: {
commit: {
command: 'git add . --all && git commit -m "Version <%= pkg.version %>"'
},
tag: {
command: 'git tag -a <%= pkg.version %> -m "Version <%= pkg.version %>"'
}
},
watch: {
css: {
files: 'assets/sass/**/*.scss',
tasks: [ 'sass', 'csscomb:style' ]
}
},
makepot: {
theme: {
options: {
cwd: 'src',
potFilename: 'make.pot',
domainPath: '/languages',
type: 'wp-theme',
exclude: [],
processPot: function( pot, options ) {
pot.headers['report-msgid-bugs-to'] = 'https://thethemefoundry.com/support';
pot.headers['last-translator'] = 'The Theme Foundry';
pot.headers['language-team'] = 'The Theme Foundry';
return pot;
}
}
}
},
copy: {
build: {
files: [
{
expand: true,
cwd: 'src/',
src: [
'**/*',
'!**/.{svn,git}/**',
'!**/.DS_Store/**'
],
dest: 'dist/temp'
}
]
}
},
compress: {
build: {
options: {
archive: 'dist/<%= pkg.name %>-<%= pkg.version %>.zip',
mode: 'zip'
},
files: [
{
expand: true,
src: ['**/*'],
dest: '<%= pkg.name %>',
cwd: 'dist/temp'
}
]
}
},
clean:{
build: {
src: [ 'dist/temp' ]
}
},
replace: {
styleVersion: {
src: [
'assets/sass/header.scss',
'src/style.css'
],
overwrite: true,
replacements: [ {
from: /^.*Version:.*$/m,
to: ' * Version: <%= pkg.version %>'
} ]
},
functionsVersion: {
src: [
'src/functions.php'
],
overwrite: true,
replacements: [ {
from: /^define\( 'TTFMAKE_VERSION'.*$/m,
to: 'define( \'TTFMAKE_VERSION\', \'<%= pkg.version %>\' );'
} ]
},
readmeVersion: {
src: [
'readme.md'
],
overwrite: true,
replacements: [ {
from: /^\* \*\*Stable version:\*\* .*$/m,
to: '* **Stable version:** <%= pkg.version %>'
} ]
}
},
bump: {
options: {
files: [ 'package.json' ],
updateConfigs: [ 'pkg' ],
commit: false
}
},
other: {
changelog: 'src/changelog.md'
}
});
// Top level function to build a new release
grunt.registerTask( 'release', function( releaseType ) {
if ( 'minor' !== releaseType && 'major' !== releaseType && 'patch' !== releaseType ) {
grunt.fail.fatal( 'Please specify the release type (e.g., "grunt release:patch")' );
} else {
// Check to make sure the log exists
grunt.task.run( 'log:' + releaseType );
// Bump the version numbers
grunt.task.run( 'bumpto:' + releaseType );
// Create the .pot file
grunt.task.run( 'makepot' );
// Build the SASS and scripts
grunt.task.run( 'default' );
// Zip it up
grunt.task.run( 'package' );
// Commit and tag version update
//grunt.task.run( 'shell:commit' );
//grunt.task.run( 'shell:tag' );
}
} );
// Default task(s).
grunt.registerTask( 'default', [ 'sass', 'csscomb:style', 'concat', 'uglify' ] );
// Bump the version to the specified value; e.g., "grunt bumpto:patch"
grunt.registerTask( 'bumpto', function( releaseType ) {
if ( 'minor' !== releaseType && 'major' !== releaseType && 'patch' !== releaseType ) {
grunt.fail.fatal( 'Please specify the bump type (e.g., "grunt bumpto:patch")' );
} else {
grunt.task.run( 'bump-only:' + releaseType );
// Update the version numbers
grunt.task.run( 'replace' );
}
} );
// Prompt for the changelog
grunt.registerTask( 'log', function( releaseType ) {
var semver = require( 'semver' ),
changelog,
newVersion = semver.inc( grunt.config.get( 'pkg' ).version, releaseType),
regex = new RegExp( '^## ' + newVersion, 'gm' ); // Match the version number (e.g., "# 1.2.3")
if ( 'minor' !== releaseType && 'major' !== releaseType && 'patch' !== releaseType ) {
grunt.log.writeln().fail( 'Please choose a valid version type (minor, major, or patch)' );
} else {
// Get the new version
changelog = grunt.file.read( grunt.config.get( 'other' ).changelog );
if ( changelog.match( regex ) ) {
grunt.log.ok( 'v' + newVersion + ' changlelog entry found' );
} else {
grunt.fail.fatal( 'Please enter a changelog entry for v' + newVersion );
}
}
} );
// Package a new release
grunt.registerTask( 'package', [
'copy:build',
'compress:build',
'clean:build'
] );
};