1+ module . exports = function ( grunt ) {
2+ 'use strict' ;
3+
4+ grunt . initConfig ( {
5+ pkg : grunt . file . readJSON ( 'package.json' ) ,
6+
7+ // setting folder templates
8+ dirs : {
9+ css : 'assets/css' ,
10+ images : 'assets/images' ,
11+ js : 'assets/js' ,
12+ less : 'assets/less' ,
13+ } ,
14+
15+ // Compile all .less files.
16+ less : {
17+
18+ // one to one
19+ front : {
20+ files : {
21+ '<%= dirs.css %>/style.css' : '<%= dirs.less %>/style.less'
22+ } ,
23+ options : {
24+ banner : '/*\n<%= pkg.name %> - v<%= pkg.version %>\n' +
25+ 'Generated: <%= grunt.template.today("yyyy-mm-dd") %> (<%= new Date().getTime() %>)\n' +
26+ 'PLEASE DO NOT MODIFY*/ \n\n'
27+ }
28+ } ,
29+ } ,
30+
31+ // Generate POT files.
32+ makepot : {
33+ target : {
34+ options : {
35+ exclude : [ 'build/.*' , 'node_modules/*' , 'assets/*' ] ,
36+ domainPath : '/languages/' , // Where to save the POT file.
37+ potFilename : 'woocommerce-conversion-tracking.pot' , // Name of the POT file.
38+ type : 'wp-plugin' , // Type of project (wp-plugin or wp-theme).
39+ potHeaders : {
40+ 'report-msgid-bugs-to' : 'https://example.com' ,
41+ 'language-team' : 'LANGUAGE <EMAIL@ADDRESS>'
42+ }
43+ }
44+ }
45+ } ,
46+
47+ uglify : {
48+ minify : {
49+ files : {
50+ '<%= dirs.js %>/admin.min.js' : [ '<%= dirs.js %>/admin.js' ] ,
51+ }
52+ }
53+ } ,
54+
55+ watch : {
56+ less : {
57+ files : [ '<%= dirs.less %>/*.less' ] ,
58+ tasks : [ 'less:front' ]
59+ } ,
60+
61+ js : {
62+ files : [
63+ '<%= dirs.js %>/*.js' ,
64+ ] ,
65+ tasks : [
66+ 'jshint:all'
67+ ]
68+ }
69+ } ,
70+
71+ // Clean up build directory
72+ clean : {
73+ main : [ 'build/' ]
74+ } ,
75+
76+ // Copy the plugin into the build directory
77+ copy : {
78+ main : {
79+ src : [
80+ '**' ,
81+ '!node_modules/**' ,
82+ '!build/**' ,
83+ '!bin/**' ,
84+ '!.git/**' ,
85+ '!Gruntfile.js' ,
86+ '!secret.json' ,
87+ '!package.json' ,
88+ '!debug.log' ,
89+ '!phpunit.xml' ,
90+ '!phpcs.xml.dist' ,
91+ '!composer.json' ,
92+ '!.gitignore' ,
93+ '!.gitmodules' ,
94+ '!npm-debug.log' ,
95+ '!plugin-deploy.sh' ,
96+ '!export.sh' ,
97+ '!config.codekit' ,
98+ '!package-lock.json' ,
99+ '!README.md' ,
100+ '!**/nbproject/**' ,
101+ '!assets/less/**' ,
102+ '!tests/**' ,
103+ '!**/Gruntfile.js' ,
104+ '!**/package.json' ,
105+ '!**/readme.md' ,
106+ '!**/*~'
107+ ] ,
108+ dest : 'build/'
109+ }
110+ } ,
111+
112+ //Compress build directory into <name>.zip and <name>-<version>.zip
113+ compress : {
114+ main : {
115+ options : {
116+ mode : 'zip' ,
117+ archive : './build/woocommerce-conversion-tracking-v<%= pkg.version %>.zip'
118+ } ,
119+ expand : true ,
120+ cwd : 'build/' ,
121+ src : [ '**/*' ] ,
122+ dest : 'woocommerce-conversion-tracking'
123+ }
124+ } ,
125+
126+ // jshint
127+ jshint : {
128+ options : {
129+ jshintrc : '.jshintrc' ,
130+ reporter : require ( 'jshint-stylish' )
131+ } ,
132+
133+ all : [
134+ 'Gruntfile.js' ,
135+ '<%= dirs.js %>/*.js' ,
136+ ]
137+ } ,
138+
139+ // concat/join files
140+ concat : {
141+ example : {
142+ files : {
143+ '<%= dirs.js %>/all-scripts.js' : [
144+ 'script1.js' , 'script2.js'
145+ ] ,
146+ } ,
147+ } ,
148+ } ,
149+ } ) ;
150+
151+ // Load NPM tasks to be used here
152+ grunt . loadNpmTasks ( 'grunt-contrib-less' ) ;
153+ grunt . loadNpmTasks ( 'grunt-contrib-concat' ) ;
154+ grunt . loadNpmTasks ( 'grunt-contrib-jshint' ) ;
155+ grunt . loadNpmTasks ( 'grunt-wp-i18n' ) ;
156+ grunt . loadNpmTasks ( 'grunt-contrib-uglify' ) ;
157+ grunt . loadNpmTasks ( 'grunt-contrib-watch' ) ;
158+ grunt . loadNpmTasks ( 'grunt-contrib-clean' ) ;
159+ grunt . loadNpmTasks ( 'grunt-contrib-copy' ) ;
160+ grunt . loadNpmTasks ( 'grunt-contrib-compress' ) ;
161+ grunt . loadNpmTasks ( 'grunt-notify' ) ;
162+
163+ grunt . registerTask ( 'default' , [
164+ 'watch'
165+ ] ) ;
166+
167+ grunt . registerTask ( 'release' , [
168+ 'makepot' , 'uglify'
169+ ] ) ;
170+
171+ grunt . registerTask ( 'zip' , [
172+ 'clean' , 'copy' , 'compress'
173+ ] ) ;
174+ } ;
0 commit comments