-
Notifications
You must be signed in to change notification settings - Fork 7
/
gulpfile.js
56 lines (48 loc) · 1.29 KB
/
gulpfile.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
var gulp = require('gulp');
var shell = require('shelljs');
var inquirer = require('inquirer');
var log = require('gulp-util').log;
var colors = require('gulp-util').colors;
function error(message) {
console.log('[' + colors.red('Error') + '] ' + message);
}
gulp.task('npm:publish', function(next, err) {
log('Creating package...');
var result = shell.exec('npm pack', { silent: true });
if (result.code == 0) {
log('OK');
} else {
// TODO: Better error.
error('Error creating package:\n' + result.output);
next();
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) {
log('Publishing package...');
var result = shell.exec('npm publish "' + archive + '"', { silent: true });
if (result.code == 0) {
log('OK');
} else {
// TODO: Better error.
log('Error publishing package:\n' + result.output);
}
}
} finally {
log('Removing temporary package...');
shell.rm(archive);
log('OK');
}
next();
});
});
gulp.task('default', []);