-
Notifications
You must be signed in to change notification settings - Fork 1
/
Gruntfile.js
186 lines (182 loc) · 6.27 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
'use strict';
module.exports = function (grunt) {
grunt.initConfig({
opts: {
/* Filename of the compiled JavaScript file */
jsName: 'markdown-block',
/* Filename of the compiled CSS file */
cssName: 'markdown-block',
companyName: 'Ryan Nutt',
companySite: 'https://www.nutt.net',
langDomain: 'markdown-gutenberg-block',
bugsURL: 'https://www.github.com/ryannutt/wordpress-markdown-gutenberg-block',
/* Name of the plugin boot file. This is the one with the plugin header for WordPress. */
pluginFile: 'markdown-block.php'
},
pkg: grunt.file.readJSON('package.json'),
concat: {
options: {
separator: ';\r\n'
},
dist: {
src: [
'js/src/*.js',
'js/src/**/*.js'
],
dest: 'js/dist/<%= opts.jsName %>.js'
}
},
uglify: {
options: {
banner: '/* (c) <%= grunt.template.today("yyyy") %> <%= opts.companyName %> - <%= opts.companySite %> */\n',
report: 'min',
compress: {
drop_console: false,
sequences: false
}
},
dist: {
files: {
'js/dist/<%= opts.jsName %>.min.js': ['<%= concat.dist.dest %>']
}
}
},
watch: {
js: {
files: ['<%= concat.dist.src %>'],
tasks: ['concat', 'uglify', 'notify:done']
},
css: {
files: ['**/*.scss', '!node_modules/**', '!vendor/**'],
tasks: ['sass', 'notify:css']
},
php: {
files: ['*.php', '**/*.php', '!node_modules/**'],
tasks: ['makepot', 'notify:php']
}
},
notify: {
done: {
options: {
title: '"JavaScript"',
message: '"JavaScript code combined and uglified"'
}
},
php: {
options: {
title: '"PHP tasks complete"',
message: '"All PHP tasks complete"'
}
},
css: {
options: {
title: '"SCSS tasks complete"',
message: '"SCSS files compressed"'
}
}
},
makepot: {
target: {
options: {
cwd: '',
domainPath: 'lang',
exclude: [],
include: [],
mainFile: '',
potComments: '',
potFilename: '',
potHeaders: {
poedit: true,
'x-poedit-keywordslist': true,
'Report-Msgid-Bugs-To': '<%= opts.bugsURL %>'
},
processPot: null,
type: 'wp-plugin',
updateTimestamp: true,
updatePoFiles: false
}
}
},
addtextdomain: {
options: {
textdomain: '<%= opts.langDomain %>',
updateDomains: true
},
target: {
files: {
src: [
'*.php',
'**/*.php',
'!node_modules/**',
'!tests/**'
]
}
}
},
sass: {
all: {
options: {
style: 'compressed'
},
files: {
'css/dist/markdown-block.min.css': 'css/src/markdown-block.scss'
}
}
},
bump: {
options: {
files: ['package.json'],
updateConfigs: [],
commit: false,
commitMessage: 'Release v%VERSION%',
commitFiles: ['package.json'],
createTag: false,
tagName: 'v%VERSION%',
tagMessage: 'Version %VERSION%',
push: false,
pushTo: 'upstream',
gitDescribeOptions: '--tags --always --abbrev=1 --dirty=-d',
globalReplace: false,
prereleaseName: false,
metadata: '',
regExp: false
}
},
replace: {
plugin_php: {
src: ['<%= opts.pluginFile %>'],
overwrite: true,
replacements: [{
from: /Version:\s*(.*)/,
to: "Version: <%= pkg.version %>"
}]
}
}
});
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-notify');
grunt.loadNpmTasks('grunt-wp-i18n');
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-bump');
grunt.loadNpmTasks('grunt-text-replace');
grunt.registerTask('default', ['concat', 'uglify', 'watch', 'notify:done']);
grunt.registerTask('watchJS', ['watch']);
grunt.registerTask('lang', ['addtextdomain', 'makepot']);
grunt.registerTask('version', 'Updates version for the plugin', function (step) {
if (step === undefined) {
step = 'patch';
}
if (!['patch', 'minor', 'major'].includes(step)) {
grunt.log.writeln('Invalid step for version upgrade:' + step);
grunt.log.writeln('\n');
grunt.log.writeln('grunt version - updates patch version\ngrunt version:patch - updates patch version\ngrunt version:minor - updates to next minor version\ngrunt version:major - updates to next major version\n\n');
return;
}
grunt.task.run(['lang', 'bump:' + step, 'readpkg', 'replace:plugin_php']);
});
grunt.registerTask('readpkg', 'Read in the package.json file', function () {
grunt.config.set('pkg', grunt.file.readJSON('./package.json'));
});
};