Skip to content

Commit 0861b76

Browse files
committed
1.5.2
1 parent 56f87ba commit 0861b76

File tree

4 files changed

+1037
-0
lines changed

4 files changed

+1037
-0
lines changed

Gruntfile.js

Lines changed: 384 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,384 @@
1+
module.exports = function (grunt) {
2+
'use strict';
3+
4+
require('load-grunt-tasks')(grunt);
5+
6+
var formBuilderAssets = require('./assets/js/utils/form-builder-assets.js');
7+
var vendorAssets = require('./assets/js/utils/vendor-assets.js');
8+
var babelConfig = {sourceMap: false, presets: ['env'] };
9+
10+
function template_from_path(src, filepath) {
11+
var id = filepath.replace('/template.php', '').split('/').pop();
12+
13+
return '<script type="text/x-template" id="tmpl-wpuf-' + id + '">\n' + src + '</script>\n';
14+
}
15+
16+
function filename_on_concat(src, filepath) {
17+
return '/* ' + filepath + ' */\n' + src;
18+
}
19+
20+
grunt.initConfig({
21+
pkg: grunt.file.readJSON('package.json'),
22+
// directory paths
23+
dirs: {
24+
css: 'assets/css',
25+
images: 'assets/images',
26+
js: 'assets/js',
27+
less: 'assets/less',
28+
spa: 'assets/spa',
29+
template: 'assets/js-templates',
30+
wpuf: 'assets/wpuf',
31+
},
32+
33+
// jshint
34+
jshint: {
35+
options: {
36+
jshintrc: '.jshintrc',
37+
reporter: require('jshint-stylish')
38+
},
39+
40+
main: [
41+
// 'assets/js/**/*.js',
42+
'assets/spa/components/**/*.js',
43+
]
44+
},
45+
46+
// Compile all .less files.
47+
less: {
48+
49+
// one to one
50+
front: {
51+
files: {
52+
// '<%= dirs.css %>/frontend.css': '<%= dirs.css %>/frontend.less'
53+
}
54+
},
55+
56+
admin: {
57+
files: {
58+
'<%= dirs.css %>/admin.css': ['<%= dirs.less %>/admin.less']
59+
}
60+
},
61+
},
62+
63+
wp_readme_to_markdown: {
64+
your_target: {
65+
files: {
66+
'README.md': 'readme.txt'
67+
}
68+
},
69+
},
70+
71+
watch: {
72+
73+
less: {
74+
files: ['<%= dirs.less %>/*.less'],
75+
tasks: ['less:admin']
76+
},
77+
78+
components: {
79+
files: [
80+
'assets/components/**/*',
81+
],
82+
tasks: [
83+
'concat:formBuilder', 'concat:formComponentTemplates', 'jshint:main','babel:components','uglify:components'
84+
]
85+
},
86+
87+
spa: {
88+
files: [
89+
'assets/spa/**/*',
90+
],
91+
tasks: [
92+
'concat:spa', 'concat:spaMixins', 'concat:spaComponentTemplates', 'jshint:main','babel:spa','uglify:spa'
93+
]
94+
}
95+
},
96+
97+
addtextdomain: {
98+
options: {
99+
textdomain: 'weforms',
100+
},
101+
update_all_domains: {
102+
options: {
103+
updateDomains: true
104+
},
105+
src: [ '*.php', '**/*.php', '!node_modules/**', '!php-tests/**', '!bin/**', '!build/**', '!assets/**' ]
106+
}
107+
},
108+
109+
// Generate POT files.
110+
makepot: {
111+
target: {
112+
options: {
113+
exclude: ['build/.*', 'node_modules/*', 'assets/*'],
114+
mainFile: 'weforms.php',
115+
domainPath: '/languages/',
116+
potFilename: 'weforms.pot',
117+
type: 'wp-plugin',
118+
updateTimestamp: true,
119+
potHeaders: {
120+
'report-msgid-bugs-to': 'https://wedevs.com/contact/',
121+
'language-team': 'LANGUAGE <EMAIL@ADDRESS>',
122+
poedit: true,
123+
'x-poedit-keywordslist': true
124+
}
125+
}
126+
}
127+
},
128+
129+
// concat/join files
130+
concat: {
131+
formBuilder: {
132+
options: {
133+
process: filename_on_concat
134+
},
135+
136+
files: {
137+
'<%= dirs.js %>/form-builder-components.js': formBuilderAssets.components,
138+
}
139+
},
140+
141+
formComponentTemplates: {
142+
options: {
143+
process: template_from_path
144+
},
145+
files: {
146+
'<%= dirs.template %>/form-components.php': formBuilderAssets.componentTemplates
147+
}
148+
},
149+
150+
spaComponentTemplates: {
151+
options: {
152+
process: template_from_path
153+
},
154+
files: {
155+
'<%= dirs.template %>/spa-components.php': formBuilderAssets.spa.templates
156+
}
157+
},
158+
159+
spaMixins: {
160+
options: {
161+
process: filename_on_concat
162+
},
163+
files: {
164+
'<%= dirs.js %>/spa-mixins.js': formBuilderAssets.spa.mixins
165+
}
166+
},
167+
168+
spa: {
169+
options: {
170+
banner: '/*!\n<%= pkg.name %> - v<%= pkg.version %>\n' +
171+
'Generated: <%= grunt.template.today("yyyy-mm-dd") %> (<%= new Date().getTime() %>)\n*/\n\n' +
172+
';(function($) {\n',
173+
footer: '\n})(jQuery);',
174+
process: filename_on_concat
175+
},
176+
files: {
177+
'<%= dirs.js %>/spa-app.js': formBuilderAssets.spa.app
178+
}
179+
},
180+
vendor: {
181+
options: {
182+
process: filename_on_concat
183+
},
184+
files: {
185+
'<%= dirs.js %>/vendor.js': vendorAssets,
186+
}
187+
},
188+
frontendScripts: {
189+
options: {
190+
process: filename_on_concat
191+
},
192+
files: {
193+
'<%= dirs.js %>/weforms.js': ['<%= dirs.wpuf %>/js/frontend-form.js', '<%= dirs.wpuf %>/vendor/sweetalert2/dist/sweetalert2.js', '<%= dirs.wpuf %>/js/jquery-ui-timepicker-addon.js', '<%= dirs.wpuf %>/js/upload.js'],
194+
}
195+
},
196+
},
197+
198+
// Clean up build directory
199+
clean: {
200+
build: ['build/'],
201+
wpuf: ['assets/wpuf']
202+
},
203+
204+
// Copy the plugin into the build directory
205+
copy: {
206+
main: {
207+
src: [
208+
'**',
209+
'!node_modules/**',
210+
'!assets/less/**',
211+
'!assets/components/**',
212+
'!assets/spa/**',
213+
'!.codekit-cache/**',
214+
'!.idea/**',
215+
'!build/**',
216+
'!bin/**',
217+
'!.git/**',
218+
'!Gruntfile.js',
219+
'!package.json',
220+
'!composer.json',
221+
'!composer.lock',
222+
'!debug.log',
223+
'!phpunit.xml',
224+
'!.gitignore',
225+
'!.gitmodules',
226+
'!npm-debug.log',
227+
'!package-lock.json',
228+
'!plugin-deploy.sh',
229+
'!export.sh',
230+
'!config.codekit',
231+
'!gulpfile.js',
232+
'!nbproject/*',
233+
'!tests/**',
234+
'!README.md',
235+
'!CONTRIBUTING.md',
236+
'!**/*~',
237+
'!.csscomb.json',
238+
'!.editorconfig',
239+
'!.jshintrc',
240+
'!.tmp',
241+
'!assets/src/**',
242+
],
243+
dest: 'build/'
244+
},
245+
246+
wpuf: {
247+
files: [
248+
{
249+
expand: true,
250+
flatten: false,
251+
src: [
252+
'js/wpuf-form-builder-components.js',
253+
'js/wpuf-form-builder-mixins.js',
254+
'js/jquery-ui-timepicker-addon.js',
255+
'js/frontend-form.js',
256+
'js/frontend-form.min.js',
257+
'js/upload.js',
258+
'js/upload.min.js',
259+
'css/wpuf-form-builder.css',
260+
'css/frontend-forms.css',
261+
'css/jquery-ui-1.9.1.custom.css',
262+
'css/images/**',
263+
'images/wpspin_light.gif',
264+
'js-templates/form-components.php',
265+
'vendor/**',
266+
],
267+
cwd: '../wp-user-frontend/assets',
268+
dest: 'assets/wpuf/'
269+
}
270+
]
271+
}
272+
},
273+
274+
// Compress build directory into <name>.zip and <name>-<version>.zip
275+
compress: {
276+
main: {
277+
options: {
278+
mode: 'zip',
279+
archive: './build/weforms-v<%= pkg.version %>.zip'
280+
},
281+
expand: true,
282+
cwd: 'build/',
283+
src: ['**/*'],
284+
dest: 'weforms'
285+
}
286+
},
287+
288+
uglify: {
289+
components: {
290+
files: {
291+
'<%= dirs.js %>/form-builder-components.min.js': ['<%= dirs.js %>/form-builder-components.js'],
292+
}
293+
},
294+
spa: {
295+
files: {
296+
'<%= dirs.js %>/spa-app.min.js': '<%= dirs.js %>/spa-app.js',
297+
'<%= dirs.js %>/spa-mixins.min.js': '<%= dirs.js %>/spa-mixins.js',
298+
}
299+
},
300+
main: {
301+
files: {
302+
'<%= dirs.js %>/form-builder-components.min.js': ['<%= dirs.js %>/form-builder-components.js'],
303+
'<%= dirs.js %>/spa-app.min.js': '<%= dirs.js %>/spa-app.js',
304+
'<%= dirs.js %>/spa-mixins.min.js': '<%= dirs.js %>/spa-mixins.js',
305+
'<%= dirs.js %>/wpuf-form-builder-contact-forms.min.js': '<%= dirs.js %>/wpuf-form-builder-contact-forms.js',
306+
'<%= dirs.wpuf %>/js/frontend-form.min.js': '<%= dirs.wpuf %>/js/frontend-form.js',
307+
'<%= dirs.wpuf %>/js/wpuf-form-builder-components.min.js': '<%= dirs.wpuf %>/js/wpuf-form-builder-components.js',
308+
'<%= dirs.wpuf %>/js/upload.min.js': '<%= dirs.wpuf %>/js/upload.js',
309+
'<%= dirs.wpuf %>/js/jquery-ui-timepicker-addon.min.js': '<%= dirs.wpuf %>/js/jquery-ui-timepicker-addon.js',
310+
}
311+
},
312+
313+
vendor: {
314+
files: {
315+
'<%= dirs.js %>/vendor.min.js': '<%= dirs.js %>/vendor.js',
316+
}
317+
},
318+
319+
frontendScripts: {
320+
files: {
321+
'<%= dirs.js %>/weforms.min.js': '<%= dirs.js %>/weforms.js',
322+
}
323+
},
324+
325+
},
326+
327+
babel: {
328+
options: babelConfig,
329+
components: {
330+
files: {
331+
'<%= dirs.js %>/form-builder-components.js': '<%= dirs.js %>/form-builder-components.js',
332+
}
333+
},
334+
spa: {
335+
files: {
336+
'<%= dirs.js %>/spa-app.js': '<%= dirs.js %>/spa-app.js',
337+
'<%= dirs.js %>/spa-mixins.js': '<%= dirs.js %>/spa-mixins.js',
338+
}
339+
},
340+
main: {
341+
files: {
342+
'<%= dirs.js %>/form-builder-components.js': '<%= dirs.js %>/form-builder-components.js',
343+
'<%= dirs.js %>/spa-app.js': '<%= dirs.js %>/spa-app.js',
344+
'<%= dirs.js %>/spa-mixins.js': '<%= dirs.js %>/spa-mixins.js',
345+
'<%= dirs.js %>/wpuf-form-builder-contact-forms.js': '<%= dirs.js %>/wpuf-form-builder-contact-forms.js',
346+
'<%= dirs.wpuf %>/js/wpuf-form-builder-components.js': '<%= dirs.wpuf %>/js/wpuf-form-builder-components.js',
347+
}
348+
},
349+
vendor: {
350+
files: {
351+
'<%= dirs.js %>/vendor.js': '<%= dirs.js %>/vendor.js',
352+
}
353+
},
354+
}
355+
});
356+
357+
// load npm tasks to be used here
358+
grunt.loadNpmTasks('grunt-contrib-jshint');
359+
grunt.loadNpmTasks('grunt-contrib-watch');
360+
grunt.loadNpmTasks('grunt-contrib-clean');
361+
grunt.loadNpmTasks('grunt-contrib-copy');
362+
grunt.loadNpmTasks('grunt-contrib-compress');
363+
grunt.loadNpmTasks('grunt-notify');
364+
grunt.loadNpmTasks('grunt-wp-i18n');
365+
grunt.loadNpmTasks('grunt-contrib-less' );
366+
grunt.loadNpmTasks('grunt-contrib-concat');
367+
grunt.loadNpmTasks('grunt-wp-readme-to-markdown');
368+
369+
// grunt tasks
370+
grunt.registerTask('default', ['watch']);
371+
grunt.registerTask('wpuf', ['clean:wpuf', 'copy:wpuf']);
372+
373+
// file auto generation
374+
grunt.registerTask('i18n', ['addtextdomain', 'makepot']);
375+
grunt.registerTask('readme', ['wp_readme_to_markdown']);
376+
grunt.registerTask('vendor', ['concat:vendor','uglify:vendor']);
377+
grunt.registerTask('frontendassets', ['concat:frontendScripts','uglify:frontendScripts']);
378+
379+
// build stuff
380+
grunt.registerTask('release', ['i18n', 'readme', 'babel:main', 'uglify:main','vendor', 'frontendassets']); // 'wpuf' removed
381+
grunt.registerTask('zip', ['clean:build', 'copy', 'compress']); // 'wpuf' removed
382+
383+
grunt.util.linefeed = '\n';
384+
};

0 commit comments

Comments
 (0)