Skip to content

Commit cb230cf

Browse files
author
sakshamsaxena
committed
Almost done with the release task.
1 parent 5779199 commit cb230cf

File tree

3 files changed

+72
-24
lines changed

3 files changed

+72
-24
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
"jscs-stylish": "^0.3.1",
4242
"marked": "^0.3.5",
4343
"mocha": "^3.2.0",
44-
"phantomjs": "^2.1.7"
44+
"phantomjs": "^2.1.7",
45+
"request": "^2.81.0"
4546
},
4647
"license": "LGPL-2.1",
4748
"dependencies": {

tasks/release/release-github.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/* Grunt task to release p5.js on GitHub */
2+
3+
const fs = require('fs');
4+
const req = require('request');
5+
6+
module.exports = function(grunt) {
7+
grunt.registerTask('release-github', 'Publish a Release on GitHub', function(args) {
8+
9+
// Async Task
10+
var done = this.async();
11+
12+
// Prepare the data
13+
var data = {
14+
"tag_name": "",
15+
"target_commitish": "master",
16+
"name": "",
17+
"body": "",
18+
"draft": true,
19+
"prerelease": false
20+
};
21+
22+
var newTag = require('../../package.json').version;
23+
data.tag_name = newTag;
24+
data.name = newTag;
25+
26+
// Set up vars for requests
27+
const createURL = 'https://api.github.com/repos/sakshamsaxena/p5.js/releases' + accessTokenParam;
28+
const uploadURL = 'https://uploads.github.com/repos/sakshamsaxena/p5.js/releases/';
29+
const accessTokenParam = '?access_token=' + process.env.GITHUB_TOKEN;
30+
var releaseID = '';
31+
32+
var createReleaseData = {
33+
url: createURL,
34+
headers: { 'User-Agent': 'Grunt Task' },
35+
body: JSON.stringify(data)
36+
}
37+
38+
new Promise(function(resolve, reject) {
39+
// Create the release
40+
req.post(createReleaseData, function(error, response, body) {
41+
if (error)
42+
reject(error);
43+
// Got the release ID
44+
releaseID = JSON.parse(body).id;
45+
resolve();
46+
})
47+
}).then(function() {
48+
// Upload assets
49+
req.post({
50+
url: uploadURL + releaseID + '/assets' + accessTokenParam + '&name=p5.dom.js',
51+
headers: {
52+
'User-Agent': 'Grunt',
53+
'Content-Type': 'application/javascript',
54+
'Content-Length': fs.statSync('./lib/addons/p5.dom.js').size
55+
},
56+
body: fs.createReadStream('./lib/addons/p5.dom.js')
57+
}, function(err, resp, body) {
58+
if (err)
59+
throw err;
60+
console.log(JSON.parse(body));
61+
done();
62+
});
63+
});
64+
});
65+
};

tasks/release/release-p5.js

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,7 @@ module.exports = function(grunt) {
3333
'archive': 'p5.zip'
3434
},
3535
'files': [
36-
{ cwd: 'dist/', src: ['**/*'], expand: true }
37-
]
38-
}
39-
},
40-
'copy': {
41-
'main': {
42-
'files': [
43-
{expand: true, src: ['lib/addons/*'], dest: 'dist/', filter: 'isFile', flatten: true},
44-
{expand: true, src: ['lib/*.js'], dest: 'dist/', filter: 'isFile', flatten: true},
45-
{expand: true, src: ['lib/empty-example/*'], dest: 'dist/empty-example', flatten: true}
36+
{ cwd: 'lib/', src: ['**/*'], expand: true }
4637
]
4738
}
4839
}
@@ -52,11 +43,10 @@ module.exports = function(grunt) {
5243
grunt.registerTask('release-p5', 'Drafts and Publishes a fresh release of p5.js', function(args) {
5344

5445
// 0. Setup Config
55-
// Default increment is minor (x.y.z+1)
46+
// Default increment is patch (x.y.z+1)
5647
opts.releaseIt.options.increment = args;
5748
grunt.config.set('release-it', opts.releaseIt);
5849
grunt.config.set('compress', opts.compress);
59-
grunt.config.set('copy', opts.copy);
6050

6151
// 1. Test Suite
6252
grunt.task.run('test');
@@ -70,18 +60,10 @@ module.exports = function(grunt) {
7060
// 4. Push the docs out to the website
7161
grunt.task.run('release-docs');
7262

73-
// 5. Copy the library files and example to a new folder 'dist' and zip the folder
74-
// p5.zip File List:
75-
// - p5.js
76-
// - p5.min.js
77-
// - p5.dom.js
78-
// - p5.dom.min.js
79-
// - p5.sound.js
80-
// - p5.sound.min.js
81-
// - empty-example/index.html
82-
// - empty-example/sketch.js
83-
grunt.task.run('copy');
63+
// 5. Zip the lib folder
8464
grunt.task.run('compress');
8565

66+
// 6. Draft a Release for GitHub
67+
grunt.task.run('release-github');
8668
});
8769
};

0 commit comments

Comments
 (0)