-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
154 lines (138 loc) · 4.3 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
var gulp = require('gulp-help')(require('gulp')),
jshint = require('gulp-jshint'),
gutil = require('gulp-util'),
inject = require('gulp-inject'),
env = require('gulp-env'),
shell = require('gulp-shell'),
sourcemaps = require('gulp-sourcemaps'),
sass = require('gulp-sass'),
del = require('del'),
path = require('path'),
fs = require('fs-extra'),
wiredep = require('wiredep').stream,
pkg = require('./package.json'),
concat = require('gulp-concat'),
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
jsFiles = 'app/**/*.js',
// Files that will be built into CSS
scssFiles = './sass/**/*.scss',
templateFiles = 'templates/**/*.html',
// Files that will be compiled into the ZXP
buildFiles = [
'bundle/bundle.js',
'CSXS/manifest.xml',
'ext/**/*',
'jsx/**/*',
'root/**/*',
'bower_components/**/*',
'templates/**/*',
'css/**/*',
'icons/**/*'
],
// The selfSigned certificate used to compile the extension
certPath = path.join('./bin', 'TestCert.p12'),
// The path and name of the compiled ZXP file
zxpPath = path.join('./build', 'universalimages.zxp'),
// The path to the zxpSignCmd binary
binPath = path.join('./bin', 'ZXPSignCmd');
env({
file: '.env' // stores secret information
});
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('scripts', function() {
return gulp.src(jsFiles)
.pipe(sourcemaps.init())
.pipe(concat('bundle.js'))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./bundle'));
});
gulp.task('watch', 'Build based on file changes', function () {
gulp.watch([jsFiles], ['scripts']);
gulp.watch(scssFiles, ['sass']);
var dependencyFiles = ['bower.json', 'package.json'];
dependencyFiles.forEach(function(files) {
gulp.watch(files, ['wire']);
});
});
gulp.task('cert', 'Create a signing cert for your extension', shell.task([
insertSpaces(binPath,
'-selfSignedCert',
'CH',
'NA',
'none',
'"Simon Bächler"',
'"'+process.env.TEST_CERT_PW+'"',
certPath,
'-email [email protected]'
)
]));
gulp.task('build', 'Compile the bundled ZXP', function (cb) {
runSequence('build:clean', 'sass', 'scripts', '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 () {
function onError(err) {
if(err) {
throw new gutil.PluginError('pkgDeps', err);
}
}
for(var dep in pkg.dependencies) {
fs.copy(path.join('./node_modules/', dep), path.join('./dist', 'node_modules', dep),
onError);
}
});
gulp.task('build:compile', false, shell.task([
insertSpaces(binPath,
'-sign',
'./dist',
zxpPath,
certPath,
'"'+process.env.TEST_CERT_PW+'"',
'-tsa http://timestamp.digicert.com'
)
]));
function insertSpaces () {
var builtString = '';
var args = Array.prototype.slice.call(arguments);
args.forEach(function(val) {
builtString = builtString + val + ' ';
});
return builtString;
}
// The default task (called when you run `gulp` from cli)
gulp.task('default', ['watch', 'scripts', 'sass']);