-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathGruntfile.js
259 lines (243 loc) · 7.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
const copy = require( "grunt-contrib-copy" );
const fs = require( 'fs' );
const path = require( 'path' );
module.exports = function ( grunt ) {
'use strict';
// Function to get the current WordPress version from the installation
function getCurrentWordPressVersion() {
const wpVersionFile = path.join( __dirname, '../../../wp-includes/version.php' );
if (fs.existsSync( wpVersionFile )) {
const content = fs.readFileSync( wpVersionFile, 'utf8' );
const match = content.match( /\$wp_version = '([^']+)'/ );
return match ? match[1] : null;
}
return null;
}
// Function to get the minimum required PHP version from the installation
function getMinimumPHPVersion() {
const wpVersionFile = path.join( __dirname, '../../../wp-includes/version.php' );
if (fs.existsSync( wpVersionFile )) {
const content = fs.readFileSync( wpVersionFile, 'utf8' );
const match = content.match( /\$required_php_version = '([^']+)'/ );
return match ? match[1] : null;
}
return null;
}
// Project configuration
grunt.initConfig(
{
pkg: grunt.file.readJSON( 'package.json' ),
addtextdomain: {
options: {
textdomain: 'wrap',
},
update_all_domains: {
options: {
updateDomains: true
},
src: [ '*.php', '**/*.php', '!\.git/**/*', '!bin/**/*', '!node_modules/**/*', '!tests/**/*' ]
}
},
wp_readme_to_markdown: {
your_target: {
files: {
'readme.txt': 'readme-temp1-unknown',
}
},
},
concat: {
md: {
options: {
separator: '\n\n', // Ajoutez une nouvelle ligne entre les fichiers
},
src: ['README.md', 'CHANGELOG.md', 'FAQ.md'],
dest: 'readme-temp-md-1-concat.md',
},
combine: {
options: {
separator: '\n',
},
src: ['readme-temp-header-2-update.txt', 'readme-temp-md-3-clean.txt'],
dest: 'readme.txt',
},
},
replace: {
format: {
src: ['readme-temp-md-1-concat.md'],
dest: 'readme-temp-md-2-format.txt',
replacements: [{
from: /^# *(.*) *$/gm,
to: '=== $1 ==='
}, {
from: /^## *(.*) *$/gm,
to: '== $1 =='
}, {
from: /^### *(.*) *$/gm,
to: '= $1 ='
}, {
from: /^- /gm,
to: '* '
}]
},
updateinfo: {
src: ['readme-temp-header-1-copy.txt'],
dest: 'readme-temp-header-2-update.txt',
replacements: [{
from: /Plugin Name: .*/g,
to: function (matchedWord) {
const content = grunt.file.read( 'wrap.php' );
const match = content.match( /Plugin Name: (.*)/ );
return match ? `Plugin Name: ${match[1]}` : matchedWord;
}
}, {
from: /Plugin URI: .*/g,
to: function (matchedWord) {
const content = grunt.file.read( 'wrap.php' );
const match = content.match( /Plugin URI: (.*)/ );
return match ? `Plugin URI: ${match[1]}` : matchedWord;
}
}, {
from: /Description: .*/g,
to: function (matchedWord) {
const content = grunt.file.read( 'wrap.php' );
const match = content.match( /Description: (.*)/ );
return match ? `Description: ${match[1]}` : matchedWord;
}
}, {
from: /Version: .*/g,
to: function (matchedWord) {
const content = grunt.file.read( 'wrap.php' );
const match = content.match( /Version: (.*)/ );
return match ? `Version: ${match[1]}` : matchedWord;
}
}, {
from: /Author: .*/g,
to: function (matchedWord) {
const content = grunt.file.read( 'wrap.php' );
const match = content.match( /Author: (.*)/ );
return match ? `Author: ${match[1]}` : matchedWord;
}
}, {
from: /Author URI: .*/g,
to: function (matchedWord) {
const content = grunt.file.read( 'wrap.php' );
const match = content.match( /Author URI: (.*)/ );
return match ? `Author URI: ${match[1]}` : matchedWord;
}
}, {
from: /License: .*/g,
to: function (matchedWord) {
const content = grunt.file.read( 'wrap.php' );
const match = content.match( /License: (.*)/ );
return match ? `License: ${match[1]}` : matchedWord;
}
}, {
from: /License URI: .*/g,
to: function (matchedWord) {
const content = grunt.file.read( 'wrap.php' );
const match = content.match( /License URI: (.*)/ );
return match ? `License URI: ${match[1]}` : matchedWord;
}
}, {
from: /Requires at least: .*/g,
to: function (matchedWord) {
const content = grunt.file.read( 'wrap.php' );
const match = content.match( /Requires at least: (.*)/ );
return match ? `Requires at least: ${match[1]}` : matchedWord;
}
}, {
from: /Requires PHP: .*/g,
to: function (matchedWord) {
const content = grunt.file.read( 'wrap.php' );
const match = content.match( /Requires PHP: (.*)/ );
return match ? `Requires PHP: ${match[1]}` : matchedWord;
}
}, {
from: /Tested up to: .*/g,
to: function (matchedWord) {
const version = getCurrentWordPressVersion();
return version ? `Tested up to: ${version}` : matchedWord;
}
}, {
from: /^\n\n*(.*)\n*\n==/gm,
to: function (match, p1) {
const content = grunt.file.read( 'wrap.php' );
const descriptionMatch = content.match( /Description: (.*)/ );
return descriptionMatch ? `\n${descriptionMatch[1]}\n\n==` : `\n${p1}\n\n==`;
}
}]
},
removeTitle: {
src: ['readme-temp-md-2-format.txt'],
dest: 'readme-temp-md-3-clean.txt',
replacements: [{
from: /^=== .* ===\n*/,
to: ''
}]
}
},
copy: {
header: {
src: 'readme.txt',
dest: 'readme-temp-header-1-copy.txt',
options: {
process: function (content) {
const parts = content.split( '== Description ==' );
return parts[0] + '== Description ==\n';
}
}
},
append: {
src: 'readme-temp-md-2-format.txt',
dest: 'readme-temp-header-2-update.txt',
options: {
process: function (content) {
const existingContent = grunt.file.read( 'readme-temp-header-2-update.txt' );
return existingContent + '\n\n' + content;
}
}
},
},
clean: {
temp: ['readme-temp-header-1-copy.txt', 'readme-temp-md-1-concat.md', 'readme-temp-md-2-format.txt', 'readme-temp-header-2-update.txt', 'readme-temp-md-3-clean.txt']
},
makepot: {
target: {
options: {
domainPath: '/languages',
exclude: [ '\.git/*', 'bin/*', 'node_modules/*', 'tests/*' ],
mainFile: 'wrap.php',
potFilename: 'wrap.pot',
potHeaders: {
poedit: true,
'x-poedit-keywordslist': true
},
type: 'wp-plugin',
updateTimestamp: true
}
}
},
}
);
grunt.loadNpmTasks( 'grunt-contrib-concat' );
grunt.loadNpmTasks( 'grunt-text-replace' );
grunt.loadNpmTasks( 'grunt-contrib-copy' );
grunt.loadNpmTasks( 'grunt-contrib-clean' );
grunt.loadNpmTasks( 'grunt-wp-i18n' );
grunt.loadNpmTasks( 'grunt-wp-readme-to-markdown' );
grunt.registerTask( 'default', [ 'i18n','readme' ] );
grunt.registerTask( 'i18n', ['addtextdomain', 'makepot'] );
grunt.registerTask(
'readme',
[
'copy:header',
'replace:updateinfo',
'concat:md',
'replace:format',
'replace:removeTitle',
'concat:combine',
'clean:temp'
]
);
grunt.util.linefeed = '\n';
};