-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
138 lines (123 loc) · 4.05 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
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
var gulp = require('gulp-help')(require('gulp')),
jshint = require('gulp-jshint'),
gutil = require('gulp-util'),
inject = require('gulp-inject'),
shell = require('gulp-shell'),
sass = require('gulp-sass'),
del = require('del'),
path = require('path'),
fs = require('fs-extra'),
wiredep = require('wiredep').stream,
webpack = require('webpack'),
webpackConfig = require('./webpack.config'),
pkg = require('./package.json'),
runSequence = require('run-sequence');
// Files that will be run against JSHint
var allSrcFiles = [
'app/**/*.js',
'jsx/**/*.jsx',
'root/**/*.js'
],
// The CSS files what will be injected into the index
cssFiles = 'css/**/*.css',
// Files that will be bundled with webpack
jsFiles = 'app/**/*.js',
// Files that will be built into CSS
scssFiles = './sass/**/*.scss',
// Files that will be compiled into the ZXP
buildFiles = [
'bundle/bundle.js',
'CSXS/manifest.xml',
'ext/**/*',
'jsx/**/*',
'root/**/*',
'bower_components/**/*'
],
// The selfSigned certificate used to compile the extension
certPath = path.join('./bin', 'monkeyWrenchCert.p12'),
// The path and name of the compiled ZXP file
zxpPath = path.join('./build', 'monkeyWrench.zxp'),
// The path to the zxpSignCmd binary
binPath = path.join('./bin', 'ZXPSignCmd');
gulp.task('hint', 'Run JSHint against your project files', function () {
return gulp.src(allSrcFiles)
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'));
});
gulp.task('wire', 'Wire dependencies to index.html', function () {
var libs = gulp.src('ext/**/*.js', {read: false});
var frontEnd = gulp.src(['bundle/bundle.js', cssFiles], {read: false});
var backEnd = gulp.src(['root/**/*.js'], {read: false});
return gulp.src('./root/index.html')
.pipe(inject(libs, {name: 'ext', relative: true}))
.pipe(inject(frontEnd, {relative: true}))
.pipe(inject(backEnd, {name: 'node', relative: true}))
.pipe(wiredep({exclude:'jquery'}))
.pipe(gulp.dest('./root'));
});
gulp.task('sass', 'Build sass files', function () {
return gulp.src(scssFiles)
.pipe(sass.sync().on('error', sass.logError))
.pipe(gulp.dest('./css'));
});
gulp.task('webpack', 'Compile your webpack bundle', function (callback) {
webpack(webpackConfig, function(err, stats) {
if(err) throw new gutil.PluginError("webpack", err);
gutil.log("[webpack]", stats.toString({
}));
callback();
});
});
gulp.task('watch', 'Build based on file changes', function () {
gulp.watch(jsFiles, ['webpack']);
gulp.watch(scssFiles, ['sass']);
var dependencyFiles = ['bower.json', 'package.json', 'root/**/*.js'];
dependencyFiles.forEach(function(files) {
gulp.watch(files, ['wire']);
});
});
gulp.task('cert', 'Create a signing cert for your extension', shell.task([
InsertSpaces(binPath,
'-selfSignedCert',
'US',
'NA',
'codearoni',
'monkeyWrench',
'01189998819991197253',
path.join('./bin', 'monkeyWrenchCert.p12'))
]));
gulp.task('build', 'Compile the bundled ZXP', function (cb) {
runSequence('build:clean', 'sass', 'webpack', 'wire', 'build:dist', 'build:pkgDeps', 'build:compile', cb);
});
gulp.task('build:clean', false, function () {
del.sync(['build/**/*', '!build', 'dist/**/*', '!dist']);
});
gulp.task('build:dist', false, function () {
return gulp.src(buildFiles, {base: './'})
.pipe(gulp.dest('dist'));
});
gulp.task('build:pkgDeps', false, function () {
for(var dep in pkg.dependencies) {
fs.copy(path.join('./node_modules/', dep), path.join('./dist', 'node_modules', dep), function (err) {
if(err) {
throw new gutil.PluginError('pkgDeps', err);
}
});
}
});
gulp.task('build:compile', false, shell.task([
InsertSpaces(binPath,
'-sign',
'./dist',
zxpPath,
certPath,
'01189998819991197253')
]));
function InsertSpaces () {
var builtString = '';
var args = Array.prototype.slice.call(arguments);
args.forEach(function(val) {
builtString = builtString + val + ' ';
});
return builtString;
};