forked from winjs/react-winjs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Gruntfile.js
201 lines (177 loc) · 6.8 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
// Copyright (c) Microsoft Corp. All Rights Reserved. Licensed under the MIT License. See License.txt in the project root for license information.
"use strict";
var exec = require('child_process').exec;
var execSync = require('child_process').execSync;
module.exports = function(grunt) {
var publishRoot = 'dist/';
var npmPublishRoot = publishRoot + 'npm/';
// All version number information is derived from package.json. This includes the version
// info used with npm, bower, NuGet, and the GitHub release.
var pkg = grunt.file.readJSON('package.json');
var fullWinjsVersion = pkg.peerDependencies.winjs;
if (!fullWinjsVersion) {
grunt.fail.fatal('Unable to determine WinJS version required by react-winjs');
}
// package.json version contains <major>.<minor>.<patch>. We just want <major>.<minor>
var winjsVersion = fullWinjsVersion.split(".").slice(0, 2).join(".");
var currentGitCommitHash = execSync('git rev-parse HEAD').toString().trim();
var bomGlob = "**/*.+(js|css|htm|html)";
// Project configuration.
grunt.initConfig({
pkg: pkg,
clean: {
publish: [publishRoot]
},
copy: {
publish: {
files: [{
expand: true,
src: [
'react-winjs.js',
'LICENSE.txt',
'package.json',
'README.md'
],
dest: npmPublishRoot
}]
}
},
compress: {
publish: {
options: {
archive: publishRoot + 'react-winjs.zip'
},
files: [{
expand: true,
cwd: npmPublishRoot,
src: ["**"]
}]
}
},
"check-bom": {
publish: {
files: [{
src: "react-winjs.js",
expand: true,
nocase: true
}, {
cwd: publishRoot,
src: bomGlob,
expand: true,
nocase: true
}]
}
},
nugetpack: {
publish: {
src: 'React.WinJS.nuspec',
dest: publishRoot,
options: {
version: '<%= pkg.version %>'
}
}
},
// Publishes nuget package
nugetpush: {
// Requires NuGet API key to be set. You can do this with:
// grunt nugetkey --key=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
publish: {
src: publishRoot + '*.nupkg',
}
},
// Publishes GitHub release and bower package (bower consumes GitHub tags/releases)
'github-release': {
// Requires this environment variable to be set: GITHUB_ACCESS_TOKEN
// GITHUB_ACCESS_TOKEN can be generated from https://help.github.com/articles/creating-an-access-token-for-command-line-use/
publish: {
options: {
repository: 'winjs/react-winjs',
auth: {
user: process.env.GITHUB_ACCESS_TOKEN
},
release: {
tag_name: 'v<%= pkg.version %>', // Must follow semver syntax in order for bower to pick it up
target_commitish: currentGitCommitHash,
name: '<%= pkg.version %>',
body:
'Release of react-winjs <%= pkg.version %>.\n' +
'\n' +
'Compatible with WinJS ' + winjsVersion + '.\n'
}
},
files: {
src: [publishRoot + 'react-winjs.zip']
}
}
}
});
grunt.loadTasks('tasks/');
var plugins = [
'grunt-contrib-clean',
'grunt-contrib-compress',
'grunt-contrib-copy',
'grunt-nuget',
'grunt-github-releaser'
];
plugins.forEach(function (plugin) {
grunt.loadNpmTasks(plugin);
});
// Publishes npm package
grunt.registerTask('npm-release', function (mode) {
var done = this.async();
var cmd = 'npm publish ' + npmPublishRoot;
exec(cmd, function (err, stdout) {
if (err) {
grunt.fatal('npm publish failed using command: ' + cmd);
}
done();
});
});
// Sets up all of the state necessary to do a publish but doesn't actually publish
// to any of the package managers.
grunt.registerTask('prepare-publish', [
'clean:publish',
'copy:publish',
'compress:publish',
'nugetpack:publish',
'check-bom:publish',
]);
grunt.registerTask('finished-publish', function (mode) {
grunt.log.writeln('');
grunt.log.writeln('Publish complete. Hand tweak the GitHub release description if necessary (https://github.com/winjs/react-winjs/releases)');
grunt.log.writeln('');
});
//
// Public tasks designed to be run from the command line
//
// Populates the 'dist' folder and then uses it to:
// - Create a GitHub release
// - Publish to npm
// - Publish to bower
// - Publish to NuGet
// When debugging publish, it's helpful to run just the 'prepare-publish'
// task which puts all of the publication data into the 'dist' folder but
// doesn't actually send the data to the package managers.
grunt.registerTask('publish', function (mode) {
if (!process.env.GITHUB_ACCESS_TOKEN) {
grunt.fail.fatal('The GITHUB_ACCESS_TOKEN environment variable must be set in order to create GitHub releases');
}
if (!mode) {
grunt.log.writeln('');
grunt.log.writeln('Will publish version ' + pkg.version + ' of react-winjs to npm, NuGet, etc. Double check that:');
grunt.log.writeln(' * You are on the branch you\'d like to publish');
grunt.log.writeln(' * The branch has been pushed to GitHub');
grunt.log.writeln(' * You don\'t have any local edits');
grunt.log.writeln('');
grunt.log.writeln('If everything is in order, run "grunt publish:force" to proceed');
} else if (mode === 'force') {
grunt.task.run([
'prepare-publish',
'nugetpush:publish',
'github-release:publish',
'npm-release',
'finished-publish',
]);
}
});
};