-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
49 lines (42 loc) · 1.26 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
var shell = require('shelljs');
var inquirer = require('inquirer');
module.exports = function(grunt) {
grunt.registerTask('npm:publish', 'Publish package to npm.', function() {
var done = this.async();
grunt.log.write('Creating package...');
var result = shell.exec('npm pack', { silent: true });
if (result.code == 0) {
grunt.log.ok();
} else {
grunt.log.error().error('Error creating package:\n' + result.output);
done();
return;
}
var archive = result.output.trim();
shell.exec('tar -ztvf "' + archive + '"');
var question = {
type: 'confirm',
name: 'publish',
message: 'Publish package?',
default: false
};
inquirer.prompt([question], function(answers) {
try {
if (answers.publish) {
grunt.log.write('Publishing package...');
var result = shell.exec('npm publish "' + archive + '"', { silent: true });
if (result.code == 0) {
grunt.log.ok();
} else {
grunt.log.error().error('Error publishing package:\n' + result.output);
}
}
} finally {
grunt.log.write('Removing temporary package...');
shell.rm(archive);
grunt.log.ok();
}
done();
});
});
};