This repository was archived by the owner on Mar 31, 2019. It is now read-only.
forked from rev087/ng-inspector
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
132 lines (110 loc) · 4.45 KB
/
gulpfile.js
File metadata and controls
132 lines (110 loc) · 4.45 KB
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
var gulp = require('gulp');
var concat = require('gulp-concat');
var less = require('gulp-less');
var replace = require('gulp-replace');
var wrap = require('gulp-wrap');
var semver = require('semver');
var fs = require('fs');
var colors = require('colors');
var plist = require('plist');
var spawn = require('child_process').spawn;
function run(cmd, args, callback) {
var child = spawn(cmd, args);
var buffer = '';
child.stdout.on('data', function (data) { buffer = buffer + data; });
child.stderr.on('data', function (data) { console.error(data.toString()); });
child.on('close', function(code) {
if (code !== 0) throw cmd + ' process exited with code ' + code;
else callback.apply(this, [buffer]);
});
}
function bump(release) {
// Check if the stage is clean
run('git', ['diff', '--staged'], function(res) {
if (res.length > 0) {
return console.error('\n ' + ' BUMP ERROR '.redBG.bold.black +
' Cannot update manifests with a dirty Git stage. \n'.red);
}
// Bump the version in package.json
var pkg = require('./package.json');
var old = pkg.version;
pkg.version = 'v' + semver.inc(pkg.version, release);
var pkgStr = JSON.stringify(pkg, null, 2);
fs.writeFileSync('package.json', pkgStr);
// Bump the version in Info.plist
var info = plist.parseFileSync('ng-inspector.safariextension/Info.plist');
info.CFBundleShortVersionString = pkg.version;
info.CFBundleVersion = pkg.version;
var plistStr = plist.build(info).toString();
fs.writeFileSync('ng-inspector.safariextension/Info.plist', plistStr);
// Bump the version in manifest.json
var manifest = require('./ng-inspector.chrome/manifest.json');
manifest.version = semver.inc(manifest.version, release);
var manifestStr = JSON.stringify(manifest, null, 2);
fs.writeFileSync('./ng-inspector.chrome/manifest.json', manifestStr);
// Git add
run('git', ['add', 'package.json', 'ng-inspector.safariextension/Info.plist', 'ng-inspector.chrome/manifest.json'], function() {
// Git commit
var commitMsg = 'Prepare for ' + pkg.version;
run('git', ['commit', '-m', commitMsg], function() {
// Git tag
run('git', ['tag', pkg.version], function() {
// Print a virtual congratulatory pat on the back
var msg = ('\n "' + pkg.name + '"').cyan.bold +
' bumped from ' + old.green.underline + ' to ' +
pkg.version.magenta.underline + '\n';
console.log(msg);
}); // tag
}); // commit
}); // add
}); // check stage
}
gulp.task('bump:major', function() { bump('major'); });
gulp.task('bump:minor', function() { bump('minor'); });
gulp.task('bump:patch', function() { bump('patch'); });
gulp.task('build:icons', function() {
return gulp.src(['src/icons/*.png'])
.pipe(gulp.dest('ng-inspector.safariextension/icons/'))
.pipe(gulp.dest('ng-inspector.chrome/icons/'));
});
gulp.task('build:js', function() {
return gulp.src([
'src/js/Inspector.js',
'src/js/InspectorAgent.js',
'src/js/InspectorPane.js',
'src/js/TreeView.js',
'src/js/Highlighter.js',
'src/js/Service.js',
'src/js/App.js',
'src/js/Module.js',
'src/js/ModelMixin.js',
'src/js/Scope.js',
'src/js/Model.js',
'src/js/bootstrap.js'
])
.pipe(concat('ng-inspector.js', {newLine:"\n\n"}))
.pipe(wrap("\"use strict\";\n(function(window) {\n<%= contents %>\n})(window);"), {variable:'data'})
.pipe(gulp.dest('ng-inspector.safariextension/'))
.pipe(gulp.dest('ng-inspector.chrome/'))
.pipe(gulp.dest('test/e2e/scenarios/lib/'));
});
gulp.task('build:css', function() {
return gulp.src(['src/less/stylesheet.less'])
.pipe(less())
.pipe(gulp.dest('ng-inspector.safariextension/'))
.pipe(replace(/url\(/g, 'url(chrome-extension://__MSG_@@extension_id__/')) // Add path prefix for Chrome
.pipe(gulp.dest('ng-inspector.chrome/'))
.pipe(replace(/(\s*)(.+url\(.+)/g, '$1/* $2 */$1background-image: none !important;')) // Remove images from the test build
.pipe(gulp.dest('test/e2e/scenarios/lib/'));
});
// Here would be a good place to build the Safari archive. But it requires a
// custom build of the `xar` executable to extract certificates from a
// Safari-built .safariextz, then signing the .xar archive (renamed .safariextz)
// Steps to build from the command line:
// http://developer.streak.com/2013/01/how-to-build-safari-extension-using.html
gulp.task('watch', function() {
gulp.watch('src/icons/*.png', ['build:icons']);
gulp.watch('src/js/*.js', ['build:js']);
gulp.watch('src/less/*.less', ['build:css']);
});
gulp.task('default', ['build:icons', 'build:js', 'build:css']);