This repository has been archived by the owner on Sep 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
169 lines (162 loc) · 6.18 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
module.exports = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
cmp: grunt.file.readJSON('composer.json'),
bumpup: {
options: {
updateProps: {
pkg: 'package.json'
}
},
files: ['package.json', 'composer.json']
},
composer: {
options: {
usePhp: true,
composerLocation: './composer.phar'
},
default: {
options: {
cwd: '.'
}
}
},
copy: {
update: {
files: [
{
expand: true,
src: [
'public/css/**',
'public/images/**',
'public/js/**',
'public/patches/',
'sql/**',
'src/**',
'vendor/**',
'templates/**',
'config/**',
'cables-wpplugin.php',
'README.md'
],
dest: '<%= cmp.name %>/'
}
]
}
},
compress: {
main: {
options: {
archive: 'target/cables-wpplugin.zip',
mode: 'zip'
},
expand: true,
src: [
'public/css/**',
'public/images/**',
'public/js/**',
'public/patches/',
'sql/**',
'src/**',
'vendor/**',
'templates/**',
'config/**',
'cables-wpplugin.php',
'README.md'
]
},
update: {
options: {
archive: 'target/update/cables-wpplugin.zip',
mode: 'zip'
},
src: [
'<%= cmp.name %>/**'
]
}
},
replace: {
versions: {
options: {
patterns: [
{
match: /Version:\s*(.*)/,
replacement: 'Version: <%= pkg.version %>'
}
]
},
files: [
{
expand: true,
flatten: true,
src: ['README.md', 'cables-wpplugin.php']
}
]
}
},
clean: [
'target',
'<%= cmp.name %>',
'vendor',
'release.json'
]
}
);
// Alias task for release
grunt.registerTask('release', function (type) {
grunt.task.run('clean'); // clean previous builds
type = type ? type : 'patch'; // default release type
grunt.task.run('bumpup:' + type); // bump up the version
grunt.task.run('replace'); // replace version number in plugin file and readme
grunt.task.run('composer:default:install'); // get php dependencies
grunt.task.run('compress:main'); // build a release zip
grunt.task.run('copy:update'); // copy files over to build an update zip
grunt.task.run('compress:update'); // build a release zip
});
// Alias task for release with buildmeta suffix support
grunt.registerTask('release', function (type, build) {
grunt.task.run('clean'); // clean previous builds
var bumpParts = ['bumpup'];
if (type) {
bumpParts.push(type);
}
if (build) {
bumpParts.push(build);
}
grunt.task.run(bumpParts.join(':')); // bump up the version
grunt.task.run('replace'); // replace version number in plugin file and readme
grunt.task.run('composer:default:install'); // get php dependencies
grunt.task.run('compress:main'); // build a release zip
grunt.task.run('copy:update'); // copy files over to build an update zip
grunt.task.run('compress:update'); // build a release zip
});
grunt.registerTask('strider:releasefile', function (type) {
var artifcatId = process.env.STRIDER_ARTIFACT_ID;
var branch = process.env.STRIDER_BRANCH;
if (!artifcatId || !branch) {
grunt.fail.fatal("got no information in environment: STRIDER_ARTIFACT_ID or STRIDER_BRANCH missing!", 1);
}
var name = process.env.STRIDER_PROJECT_NAME;
var cmp = grunt.config.get("cmp");
var projectName = name ? name : cmp.name;
var releaseJson = {
"name": projectName,
"version": cmp.version,
"download_url": cmp.extra.release.baseurl + projectName + "/api/artifact-repository/dl/" + artifcatId + "?branch=" + branch,
"sections": {
"description": cmp.description
}
};
grunt.file.write('release.json', JSON.stringify(releaseJson, null, 2));
});
grunt.registerTask('build', ['clean', 'composer:default:install']);
grunt.registerTask('package', ['default', 'compress:main', 'copy:update', 'compress:update']);
grunt.registerTask('default', ['build']);
// needed modules
grunt.loadNpmTasks('grunt-composer');
grunt.loadNpmTasks('grunt-replace');
grunt.loadNpmTasks('grunt-contrib-compress');
grunt.loadNpmTasks('grunt-bumpup');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-copy');
};