-
Notifications
You must be signed in to change notification settings - Fork 146
/
gruntfile.js
141 lines (130 loc) · 2.98 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
module.exports = function( grunt ) {
'use strict';
const pkg = grunt.file.readJSON( 'package.json' );
grunt.initConfig( {
pkg,
clean: {
build: [
'build/',
'dist/**/*.map',
],
},
copy: {
build: {
files: [
{
expand: true,
src: [
'!**/*.{ai,eps,psd}',
'LICENSE',
'class-' + pkg.name + '.php',
'assets/**',
'dist/**',
'includes/**',
'readme.txt',
'src/**/*.php',
'src/blocks/**/*.json',
'src/blocks/icon/svgs/*',
],
dest: 'build/<%= pkg.name %>',
},
],
},
},
compress: {
coblocks: {
options: {
archive: 'build/coblocks-v<%= pkg.version %>.zip',
},
files: [
{
cwd: 'build/<%= pkg.name %>/',
dest: '<%= pkg.name %>/',
src: [ '**' ],
},
],
},
},
replace: {
php: {
src: [
'class-' + pkg.name + '.php',
'includes/**/*.php',
],
overwrite: true,
replacements: [
{
from: /Version:(\s*?)[a-zA-Z0-9\.\-\+]+$/m,
to: 'Version:$1' + pkg.version,
},
{
from: /@since(.*?)NEXT/mg,
to: '@since$1' + pkg.version,
},
{
from: /Version:(\s*?)[a-zA-Z0-9\.\-\+]+$/m,
to: 'Version:$1' + pkg.version,
},
{
from: /define\(\s*'COBLOCKS_VERSION',\s*'(.*)'\s*\);/,
to: 'define( \'COBLOCKS_VERSION\', \'<%= pkg.version %>\' );',
},
{
from: /Tested up to:(\s*?)[a-zA-Z0-9\.\-\+]+$/m,
to: 'Tested up to:$1' + pkg.tested_up_to,
},
{
from: /Requires at least:(\s*?)[a-zA-Z0-9\.\-\+]+$/m,
to: 'Requires at least:$1' + pkg.requires_at_least,
},
],
},
readme: {
src: 'readme.*',
overwrite: true,
replacements: [
{
from: /^(\*\*|)Stable tag:(\*\*|)(\s*?)[a-zA-Z0-9.-]+(\s*?)$/mi,
to: '$1Stable tag:$2$3<%= pkg.version %>$4',
},
{
from: /Tested up to:(\s*?)[a-zA-Z0-9\.\-\+]+$/m,
to: 'Tested up to:$1' + pkg.tested_up_to,
},
{
from: /Requires at least:(\s*?)[a-zA-Z0-9\.\-\+]+$/m,
to: 'Requires at least:$1' + pkg.requires_at_least,
},
],
},
tests: {
src: '.dev/tests/phpunit/**/*.php',
overwrite: true,
replacements: [
{
from: /\'version\'(\s*?)\=\>(\s*?)\'(.*)\'/,
to: '\'version\' \=\> \'<%= pkg.version %>\'',
},
],
},
languages: {
src: 'languages/coblocks.pot',
overwrite: true,
replacements: [
{
from: /(Project-Id-Version: CoBlocks )[0-9\.]+/,
to: '$1' + pkg.version,
},
],
},
},
shell: {
build: [ 'npm run build' ].join( ' && ' ),
translations: [ 'npm run makepot' ].join( ' && ' ),
},
} );
require( 'matchdep' ).filterDev( 'grunt-*' ).forEach( grunt.loadNpmTasks );
grunt.registerTask( 'build', [ 'shell:build', 'update-pot', 'replace', 'clean:build', 'copy:build' ] );
grunt.registerTask( 'update-pot', [ 'shell:translations', 'replace:languages' ] );
grunt.registerTask( 'version', [ 'replace' ] );
};