-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Gruntfile.js
325 lines (301 loc) · 10.4 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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
/*global require*/
/**
* When grunt command does not execute try these steps:
*
* - delete folder 'node_modules' and run command in console:
* $ npm install
*
* - Run test-command in console, to find syntax errors in script:
* $ grunt hello
*/
module.exports = function(grunt) {
// Show elapsed time at the end.
require('time-grunt')(grunt);
// Load all grunt tasks.
require('load-grunt-tasks')(grunt);
var buildtime = new Date().toISOString();
var buildyear = 1900 + new Date().getYear();
var conf = {
// Concatenate those JS files into a single file (target: [source, source, ...]).
js_files_concat: {},
// BUILD patterns to exclude code for specific builds.
replaces: {
patterns: [{
match: /AUTHOR_NAME/g,
replace: '<%= pkg.author[0].name %>'
}, {
match: /AUTHOR_URI/g,
replace: '<%= pkg.author[0].uri %>'
}, {
match: /BUILDTIME/g,
replace: buildtime
}, {
match: /IWORKS_RATE_TEXTDOMAIN/g,
replace: '<%= pkg.name %>'
}, {
match: /IWORKS_OPTIONS_TEXTDOMAIN/g,
replace: '<%= pkg.name %>'
}, {
match: /PLUGIN_DESCRIPTION/g,
replace: '<%= pkg.description %>'
}, {
match: /PLUGIN_NAME/g,
replace: '<%= pkg.name %>'
}, {
match: /PLUGIN_REQUIRES_PHP/g,
replace: '<%= pkg.requires.PHP %>'
}, {
match: /PLUGIN_REQUIRES_WORDPRESS/g,
replace: '<%= pkg.requires.WordPress %>'
}, {
match: /PLUGIN_TESTED_WORDPRESS/g,
replace: '<%= pkg.tested.WordPress %>'
}, {
match: /PLUGIN_TAGLINE/g,
replace: '<%= pkg.tagline %>'
}, {
match: /PLUGIN_TITLE/g,
replace: '<%= pkg.title %>'
}, {
match: /PLUGIN_TILL_YEAR/g,
replace: buildyear
}, {
match: /PLUGIN_URI/g,
replace: '<%= pkg.homepage %>'
}, {
match: /PLUGIN_VERSION/g,
replace: '<%= pkg.version %>'
}, {
match: /^Version: .+$/g,
replace: 'Version: <%= pkg.version %>'
}, ],
// Files to apply above patterns to (not only php files).
files: {
expand: true,
src: [
'**/*.php',
'**/*.css',
'**/*.js',
'**/*.html',
'**/*.txt',
'!node_modules/**',
'!lib/**',
'!docs/**',
'!release/**',
'!Gruntfile.js',
'!package-lock.json',
'!build/**',
'!tests/**',
'!.git/**',
'!stylelint.config.js',
],
dest: './release/<%= pkg.version %>/'
}
},
// Regex patterns to exclude from transation.
translation: {
ignore_files: [
'README.md',
'.git*',
'node_modules/.*',
'(^.php)', // Ignore non-php files.
'inc/external/.*', // External libraries.
'release/.*', // Temp release files.
'.sass-cache/.*',
'tests/.*', // Unit testing.
],
pot_dir: 'languages/', // With trailing slash.
textdomain: "<%= pkg.name %>",
},
dir: "<%= pkg.name %>/",
plugin_file: 'sierotki.php'
};
// Project configuration
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
// JS - Concat .js source files into a single .js file.
concat: {
options: {
stripBanners: true,
banner: '/*! <%= pkg.title %> - v<%= pkg.version %>\n' +
' * <%= pkg.homepage %>\n' +
' * Copyright (c) <%= grunt.template.today("yyyy") %>;' +
' * Licensed <%= pkg.license %>\n' +
' */\n'
},
scripts: {
files: conf.js_files_concat
}
},
// JS - Validate .js source code.
jshint: {
all: [
'Gruntfile.js',
'assets/js/src/**/*.js',
],
options: {
curly: true,
eqeqeq: true,
immed: true,
latedef: true,
newcap: true,
noarg: true,
sub: true,
undef: true,
boss: true,
eqnull: true,
globals: {
exports: true,
module: false
}
}
},
// JS - Uglyfies the source code of .js files (to make files smaller).
uglify: {
all: {
files: [{
expand: true,
src: ['*.js', '!*.min.js'],
cwd: 'assets/js/',
dest: 'assets/js/',
ext: '.js',
extDot: 'last'
}],
options: {
banner: '/*! <%= pkg.title %> - v<%= pkg.version %>\n' +
' * <%= pkg.homepage %>\n' +
' * Copyright (c) <%= grunt.template.today("yyyy") %>;' +
' * Licensed <%= pkg.license %>' +
' */\n',
mangle: {
except: ['jQuery']
}
}
}
},
// WATCH - Watch filesystem for changes during development.
watch: {
scripts: {
files: ['assets/js/src/**/*.js', 'assets/js/vendor/**/*.js'],
//tasks: ['jshint', 'concat', 'uglify' ],
tasks: ['concat', 'uglify'],
options: {
debounceDelay: 500
}
}
},
// BUILD - Create a zip-version of the plugin.
compress: {
target: {
options: {
mode: 'zip',
archive: './release/<%= pkg.name %>.zip'
},
expand: true,
cwd: './release/<%= pkg.version %>/',
src: ['**/*']
}
},
// BUILD - update the translation index .po file.
makepot: {
target: {
options: {
cwd: '',
domainPath: conf.translation.pot_dir,
exclude: conf.translation.ignore_files,
mainFile: conf.plugin_file,
potFilename: conf.translation.textdomain + '.pot',
potHeaders: {
poedit: true, // Includes common Poedit headers.
'x-poedit-keywordslist': true // Include a list of all possible gettext functions.
},
processPot: null, // A callback function for manipulating the POT file.
type: 'wp-plugin', // wp-plugin or wp-theme
updateTimestamp: true, // Whether the POT-Creation-Date should be updated without other changes.
updatePoFiles: true // Whether to update PO files in the same directory as the POT file.
}
}
},
// BUILD: Replace conditional tags in code.
replace: {
target: {
options: {
patterns: conf.replaces.patterns
},
files: [conf.replaces.files]
}
},
clean: {
options: {
force: true
},
release: {
options: {
force: true
},
src: ['./release', './release/*', './release/**']
}
},
copy: {
release: {
expand: true,
src: [
'*',
'**',
'!assets/js/src',
'!assets/js/src/*',
'!assets/js/src/**',
'!assets/sass',
'!assets/sass/*',
'!assets/sass/**',
'!bitbucket-pipelines.yml',
'!composer.json',
'!composer.lock',
'!.git',
'!.github',
'!.github/*',
'!.github/**',
'!Gruntfile.js',
'!.idea', // PHPStorm settings
'!languages/*~',
'!**/LICENSE',
'!LICENSE',
'!node_modules',
'!node_modules/*',
'!node_modules/**',
'!package.json',
'!package-lock.json',
'!phpcs.xml.dist',
'!**/README.md',
'!README.md',
'!stylelint.config.js',
'!tests/*',
'!tests/**',
'!.editorconfig',
],
dest: './release/<%= pkg.version %>/',
noEmpty: true
},
}
});
// Test task.
grunt.registerTask('hello', 'Test if grunt is working', function() {
grunt.log.subhead('Hi there :)');
grunt.log.writeln('Looks like grunt is installed!');
});
grunt.registerTask('release', 'Generating release copy', function() {
grunt.task.run('clean');
grunt.task.run('js');
grunt.task.run('makepot');
grunt.task.run('copy');
grunt.task.run('replace');
grunt.task.run('compress');
});
// Default task.
grunt.registerTask('build', ['release']);
grunt.registerTask('default', ['clean', 'jshint', 'concat', 'uglify', 'makepot']);
grunt.registerTask('js', ['concat', 'uglify']);
//grunt.registerTask( 'test', ['phpunit', 'jshint'] );
grunt.task.run('clear');
grunt.util.linefeed = '\n';
};