-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
161 lines (145 loc) · 5.53 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
/**
* Gruntfile for building SocialPress Plugin
*
* Tasks it handles
* 1. Minify javascript files
* a. Look into static directory
* b. Find all .js files
* c. Minify and save .min.js file under the same directory
* 2. Compile SASS and save
* a. Look into static/.../scss directory
* b. Compile and save into static/.../css directory with source mapping
* 3. Make pot file
* a. Use wp18n to generate pot file `wpq-sp.pot` under translations directory
* 4. Make Build
* a. Copy all files except scss, tests, node_module, .git, bin,
* .travis.yml, composer.*, package*, phpunit*, phpcs* to
* ../../build directory
*
*
* @param grunt grunt The grunt
*/
module.exports = function(grunt) {
// Load tasks.
require('load-grunt-tasks')(grunt);
require('time-grunt')(grunt);
// Project Configuration
grunt.initConfig( {
// Metadata
pkg: grunt.file.readJSON( 'package.json' ),
// Build environment
development: true,
// Project variables
paths: {
// Base assets directory
base: 'static',
// Useful directory structures
dir: {
// Build directory
build: 'build/package',
// Plugin directory
plugin: '<%= paths.dir.build %>/wpq-wp-update',
// Source directory - Not sure why using
source: '.',
// Bower source
bower_source: 'bower_components',
// Bower Build
bower_builds: 'bower_builds',
},
// Different assets
assets: {
admin: {
src: '<%= paths.base %>/admin', // static/admin
},
front: {
src: '<%= paths.base %>/front', // static/front
},
lib: {
src: '<%= paths.base %>/lib', // static/lib
}
},
// PHP assets
php: {
files_std: [ 'includes/**/*.php', 'tests/**/*.php', 'wpq-social-press.php' ], // Standard file match
files: '<%= paths.php.files_std %>' // Dynamic file match
},
// JavsScript Assets
js: {
// Our own packages
admin: {
src: '<%= paths.assets.admin.src %>/jsdev', // Source for this assets
files_std: '**/<%= paths.js.admin.src %>/**/*.js', // Standard file match
files: '<%= paths.js.admin.files_std %>', // Dynamic file match,
ignores: '<%= paths.js.admin.src %>/**/*.min.js', // Ignores
},
front: {
src: '<%= paths.assets.front.src %>/jsdev', // Source for this assets
files_std: '**/<%= paths.js.front.src %>/**/*.js', // Standard file match
files: '<%= paths.js.front.files_std %>', // Dynamic file match
ignores: '<%= paths.js.front.src %>/**/*.min.js', // Ignores
},
},
// Sass assets
sass: {
ext: '.css', // Compiled extension
// Admin
admin: {
src: '<%= paths.assets.admin.src %>/scss', // Source for this assets
dest: '<%= paths.assets.admin.src %>/css', // Destination
target_std: '<%= paths.sass.admin.src %>/**/*.scss', // All SCSS files in current and subdirectory
target: '<%= paths.sass.admin.target_std %>', // Dynamic binding
exclude: '<%= paths.sass.admin.src %>/**/_*.scss', // No need to even pass the partials
},
// Front
front: {
src: '<%= paths.assets.front.src %>/scss', // Source for this assets
dest: '<%= paths.assets.front.src %>/css', // Destination
target_std: '<%= paths.sass.front.src %>/**/*.scss', // All SCSS files in current and subdirectory
target: '<%= paths.sass.front.target_std %>', // Dynamic binding
exclude: '<%= paths.sass.front.src %>/**/_*.scss', // No need to even pass the partials
},
},
},
} );
// Now separately register our config to make them more readable
// This loads all files under `grunt/` directory
grunt.loadTasks( 'grunt' );
// Create a combined task for processing CSS
grunt.registerTask( 'css', [ 'sass:all', 'postcss:all' ] );
grunt.registerTask( 'css:admin', [ 'sass:admin', 'postcss:admin' ] );
grunt.registerTask( 'css:front', [ 'sass:front', 'postcss:front' ] );
// Default Tasks For testing
grunt.registerTask( 'test', [ 'clean:dist', 'phplint', 'exec:phpunit', 'jshint:all' ] );
grunt.registerTask( 'default', 'test' );
// Task for installing all dependencies
grunt.registerTask( 'install', [ 'clean:dist', 'exec:composer', 'exec:composerdev' ] );
// Build Task
// This is for development environment
// The files are created with source mapping for easier mapping
// Use this locally
grunt.registerTask( 'build', [ 'config:dev', 'clean:dist', 'uglify:all', 'css:all', 'makepot' ] );
// Production Task
grunt.registerTask( 'prod', [ 'config:prod', 'clean:dist', 'uglify:all', 'css:all', 'makepot' ] );
// Shortcut build task
// We will use this to speed up the testing time in CI
grunt.registerTask( 'prep', [ 'config:prod', 'clean:maps', 'uglify:all', 'sass:all' ] );
// Make distribution
// This is for production purpose
// Shall only be used by the release command on the CI
grunt.registerTask( 'dist', [ 'clean:all', 'prod', 'copy:dist' ] );
// Make zip
grunt.registerTask( 'make', [ 'dist', 'zip:dist' ] );
// Release Task
grunt.registerTask( 'release', [ 'make', 'clean:dist' ] );
// Make zip
grunt.registerTask( 'make', [ 'dist', 'zip:dist' ] );
// Release Task
grunt.registerTask( 'release', [ 'make', 'clean:dist' ] );
// Clean stuff after deploy
grunt.registerTask( 'cleanup', [ 'clean:all' ] );
// Common Watchers
grunt.registerTask( 'live', [ 'config:dev', 'clean:dist', 'concurrent:all' ] );
grunt.registerTask( 'live:css', [ 'config:dev', 'clean:dist', 'concurrent:css' ] );
grunt.registerTask( 'live:js', [ 'config:dev', 'clean:dist', 'concurrent:js' ] );
grunt.registerTask( 'live:jscss', [ 'config:dev', 'clean:dist', 'concurrent:jscss' ] );
};