-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
executable file
·109 lines (103 loc) · 2.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
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
/**
* Plugin base arguments
*
* @type {Object}
*/
var plugin_args = {
path : './', // plugin directory path
domainPath : '/languages', // language files location ( relative to "path" )
potFilename: 'template.pot', // generated pot file name
exclude : [ // excluded files and directory from parsing
'vendor/' // composer libs vendor dir
],
mainFile : 'init.php', // plugin main file ( with plugin description comment doc )
watchFiles : {
assets : [ 'assets/src/css/**/*.css', 'assets/src/js/**/*.js' ],
potfile: [ './**/*.php' ]
}
};
// requires
var fs = require( 'fs' );
/**
* Grunt tasks
*/
module.exports = function ( grunt ) {
// Project configuration.
grunt.initConfig( {
pkg : grunt.file.readJSON( 'package.json' ),
uglify : {
my_target: {
options: {
preserveComments: 'some'
},
files : [ {
expand: true,
cwd : 'assets/src/js',
src : '**/*.js',
dest : 'assets/dist/js'
} ]
}
},
cssmin : {
minify: {
expand: true,
cwd : 'assets/src/css',
src : '**/*.css',
dest : 'assets/dist/css'
}
},
makepot: {
target: {
options: {
cwd : plugin_args.path,
domainPath : plugin_args.domainPath,
exclude : plugin_args.exclude,
mainFile : plugin_args.mainFile,
potFilename : plugin_args.potFilename,
potHeaders : {
poedit : true,
'x-poedit-keywordslist': true,
'Last-Translator' : '',
'Language-Team' : 'Nabeel Molham <[email protected]>'
},
type : 'wp-plugin',
updateTimestamp: true,
updatePoFiles : true
}
}
},
watch : {
// for localization .pot file
potfile: {
files: plugin_args.watchFiles.potfile,
tasks: [ 'makepot' ]
},
// for JS & CSS assets
assets : {
files: plugin_args.watchFiles.assets,
tasks: [ 'uglify', 'cssmin' ]
},
// for JS & CSS assets
all : {
files: plugin_args.watchFiles.potfile.concat( plugin_args.watchFiles.assets ),
tasks: [ 'makepot', 'uglify', 'cssmin' ]
}
}
} );
// Load plugins
grunt.loadNpmTasks( 'grunt-wp-i18n' );
grunt.loadNpmTasks( 'grunt-contrib-uglify' );
grunt.loadNpmTasks( 'grunt-contrib-cssmin' );
grunt.loadNpmTasks( 'grunt-contrib-watch' );
// when the watch task triggers
grunt.event.on( 'watch', function () {
fs.writeFile( "assets/last_update", (new Date()).toISOString().replace( /[^0-9]/g, '' ), function ( err ) {
if ( err ) {
return console.log( err );
}
console.log( "The watch file was saved!" );
} );
} );
// Default task(s).
grunt.registerTask( 'default', [ 'watch:all' ] );
};