This repository has been archived by the owner on Mar 30, 2020. It is now read-only.
/
Gruntfile.js
165 lines (154 loc) · 5.29 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
162
163
164
165
/* jshint node:true */
module.exports = function (grunt) {
// determine what else does Grunt need to do
// other than build a deployable plugin
var path = require('path'),
fs = require( 'fs' ),
BUILD_DIR = 'build/';
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
pot: {
options: {
dest: 'languages/',
text_domain : '<%=pkg.name%>',
keywords: [
'__',
'_e',
'__ngettext:1,2',
'_n:1,2',
'__ngettext_noop:1,2',
'_n_noop:1,2',
'_c,_nc:4c,1,2',
'_x:1,2c',
'_ex:1,2c',
'_nx:4c,1,2',
'_nx_noop:4c,1,2',
'esc_attr__',
'esc_attr_e',
'esc_attr_x:1,2c',
'esc_html__',
'esc_html_e',
'esc_html_x:1,2c'
]
},
files: {
src: [
'mangapress-*.php',
'includes/*.php'
],
expand: true
}
},
copy: {
files: {
files: [
{
src: [
'**',
'!**/.{svn,git}/**', // Ignore version control directories.
'!build/**',
'!bin/**',
'!docs/**',
'!examples/**',
'!node_modules/**',
'!tests/**',
'!Gruntfile.js',
'!package.json',
'!phpunit.xml.dist',
'!phpdoc.xml',
'!phpunit.phar'
],
dest: BUILD_DIR + '/<%= pkg.version %>/mangapress-next/'
}
]
}
},
phpunit: {
'default': {
cmd: 'phpunit',
args: ['-c', 'phpunit.xml.dist']
},
ajax: {
cmd: 'phpunit',
args: ['-c', 'phpunit.xml.dist', '--group', 'ajax']
},
'external-http': {
cmd: 'phpunit',
args: ['-c', 'phpunit.xml.dist', '--group', 'external-http']
}
},
watch: {
scripts: {
files: ['**/*.php'],
tasks: ['phpunit'],
options: {
spawn: false
}
}
},
compress: {
main: {
options: {
archive: BUILD_DIR + '/<%= pkg.version %>/mangapress-next.zip'
},
files: [
{
expand: true,
cwd: BUILD_DIR,
src: ['**'],
dest: 'mangapress-next',
filter: 'isFile'
}
]
}
}
});
// Testing tasks.
grunt.registerMultiTask('phpunit', 'Runs PHPUnit tests, including the ajax, external-http, and multisite tests.', function() {
grunt.util.spawn({
cmd: this.data.cmd,
args: this.data.args,
opts: {stdio: 'inherit'}
}, this.async());
});
grunt.registerTask('build', ['update-readmes', 'pot', 'copy', 'compress']);
grunt.registerTask('update-readmes', updateReadmes);
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-compress');
grunt.loadNpmTasks('grunt-pot');
/**
* Reads the main plugin file and returns a version number
* @returns {string}
*/
function getVersion() {
var pluginInfo = fs.readFileSync('mangapress-next.php', 'utf8'),
pluginHeaders = {
'Version' : ""
},
e = pluginInfo.substr(0, 8196).replace("\r", "\n");
for (var regex in pluginHeaders) {
var regString = '^[ \t\/*#@]*\/var/\:(.*)$'.replace('/var/', regex),
reg = new RegExp(regString, 'mi'),
matches = e.match(reg);
pluginHeaders[regex] = matches[1].trim();
}
return pluginHeaders.Version;
}
/**
* Update readme.txt with new version number
* @todo Add comparison for version numbers to determine if update is necessary
* @todo Find a way to use version number from package.json to keep plugin and readmes updated`
*/
function updateReadmes() {
var version = getVersion(),
readMeTxt = fs.readFileSync('readme.txt', 'utf8'),
regString = '^[ \t\/*#@]*\Stable tag\:(.*)$',
reg = new RegExp(regString, 'mi'),
matches = readMeTxt.match(reg),
newStable = matches[0].replace(/:(.*)$/mi, ': ' + version),
newReadmeTxt = readMeTxt.replace(matches[0], newStable);
fs.writeFileSync('readme.txt', newReadmeTxt, 'utf8');
console.info('readme.txt updated!');
}
};