-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathgruntfile.js
119 lines (102 loc) · 2.59 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
const ignoreParse = require( 'parse-gitignore' );
const loadGruntTasks = require( 'load-grunt-tasks' );
module.exports = function ( grunt ) {
// Load all Grunt plugins.
loadGruntTasks( grunt );
// TODO: Move to own Grunt plugin.
grunt.registerTask( 'readmeMdToTxt', 'Log some stuff.', function () {
const formatReadme = function ( content ) {
const replaceRules = {
'#': '=== $1 ===',
'##': '== $1 ==',
'#{3,}': '= $1 =',
};
// Replace Markdown headings with WP.org style headings
Object.keys( replaceRules ).forEach( function ( pattern ) {
const patternRegExp = [ '^', pattern, '\\s(.+)$' ].join( '' );
content = content.replace(
new RegExp( patternRegExp, 'gm' ),
replaceRules[ pattern ]
);
} );
return content;
};
const options = this.options( {
src: 'readme.md',
dest: 'readme.txt',
} );
const srcFile = grunt.file.read( options.src );
// Write the readme.txt.
grunt.file.write( options.dest, formatReadme( srcFile ) );
} );
// Get a list of all the files and directories to exclude from the distribution.
const distignore = ignoreParse( '.distignore', {
invert: true,
} );
grunt.initConfig( {
pkg: grunt.file.readJSON( 'package.json' ),
dist_dir: 'dist',
clean: {
build: [ '<%= dist_dir %>' ],
},
readmeMdToTxt: {
options: {
src: 'readme.md',
dest: 'readme.txt',
},
},
copy: {
dist: {
src: [ '**' ].concat( distignore ),
dest: '<%= dist_dir %>',
expand: true,
},
},
compress: {
main: {
options: {
archive: 'code-prettify.zip',
},
files: [
{
cwd: 'dist',
src: [ '**/*' ],
dest: 'code-prettify',
},
],
},
},
wp_deploy: {
options: {
plugin_slug: 'code-prettify',
build_dir: '<%= dist_dir %>',
assets_dir: 'assets/wporg',
},
all: {
options: {
deploy_tag: true,
deploy_trunk: true,
},
},
ci: {
options: {
force_interactive: false,
assets_dir:
'true' === process.env.DEPLOY_TAG &&
'true' === process.env.DEPLOY_TRUNK
? 'assets/wporg'
: null,
skip_confirmation:
'true' === process.env.DEPLOY_SKIP_CONFIRMATION,
svn_user: process.env.DEPLOY_SVN_USERNAME,
deploy_tag: 'true' === process.env.DEPLOY_TAG,
deploy_trunk: 'true' === process.env.DEPLOY_TRUNK,
},
},
},
} );
grunt.registerTask( 'build', [ 'clean', 'readmeMdToTxt', 'copy' ] );
grunt.registerTask( 'deploy', [ 'build', 'wp_deploy:all' ] );
grunt.registerTask( 'deploy-ci', [ 'build', 'wp_deploy:ci' ] );
grunt.registerTask( 'package', [ 'build', 'compress' ] );
};