-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathGruntfile.js
144 lines (123 loc) · 2.62 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
/* eslint-env es6, node */
/* eslint camelcase: warn, comma-dangle: off */
const ignoreParse = require( 'parse-gitignore' );
const exec = require( 'child_process' ).exec;
const fs = require( 'fs' );
const deployConfig = {
plugin_slug: 'contact-form-7-extras',
svn_user: 'kasparsd',
build_dir: '<%= dist_dir %>',
plugin_main_file: 'plugin.php',
assets_dir: 'assets/dotorg',
};
const readmeReplaceRules = [
{
from: /^#\s(.+)$/gm,
to: '=== $1 ==='
},
{
from: /^##\s(.+)$/gm,
to: '== $1 =='
},
{
from: /^#{3,}\s(.+)$/gm,
to: '= $1 ='
},
];
module.exports = function( grunt ) {
// Load all Grunt plugins.
require( 'load-grunt-tasks' )( grunt );
const pluginVersion = grunt.file.read( 'plugin.php' ).match( /Version:\s*(.+)$/mi )[1];
// Get a list of all the files and directories to exclude from the distribution.
const releaseFiles = ignoreParse( '.distignore', {
invert: true,
} );
grunt.initConfig( {
pkg: grunt.file.readJSON( 'package.json' ),
dist_dir: 'dist',
clean: {
build: [ '<%= dist_dir %>' ],
},
replace: {
readme: {
src: 'readme.txt.md',
dest: '<%= dist_dir %>/readme.txt',
replacements: readmeReplaceRules
},
version: {
src: [
'<%= dist_dir %>/readme.txt'
],
overwrite: true,
replacements: [
{
from: /"version":\s*"(.+)"/,
to: `"version": "${pluginVersion}"`
},
{
from: 'STABLETAG',
to: pluginVersion
},
]
}
},
copy: {
dist: {
src: [ '**' ].concat( releaseFiles ),
dest: '<%= dist_dir %>',
expand: true,
}
},
wp_deploy: {
default: {
options: deployConfig,
},
trunk: {
options: Object.assign( {}, deployConfig, {
deploy_tag: false,
} )
}
},
} );
grunt.registerTask(
'check-diff',
function() {
const done = this.async(); // This won't work with the ES6 fat arrow syntax.
exec( 'git diff HEAD --quiet', ( err ) => {
if ( err ) {
grunt.log.error( 'Found uncommited changes in your current working directory.' );
done( false );
}
done();
} );
}
);
grunt.registerTask(
'blueprint-url',
function() {
const blueprintJson = JSON.parse( fs.readFileSync( 'assets/dotorg/blueprints/blueprint.json', 'utf8' ) );
grunt.log.write( `Blueprint URL: https://playground.wordpress.net/#${ encodeURI( JSON.stringify( blueprintJson ) ) }` );
}
);
grunt.registerTask(
'build', [
'clean',
'copy',
'replace',
]
);
grunt.registerTask(
'deploy', [
'build',
'check-diff',
'wp_deploy:default',
]
);
grunt.registerTask(
'deploy:trunk', [
'build',
'check-diff',
'wp_deploy:trunk',
]
);
};