forked from romannurik/MaterialColorsApp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
125 lines (109 loc) · 3.2 KB
/
gulpfile.js
File metadata and controls
125 lines (109 loc) · 3.2 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
/*
* Copyright 2016 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';
const gulp = require('gulp');
const $ = require('gulp-load-plugins')();
const del = require('del');
const merge = require('merge-stream');
const runSequence = require('run-sequence');
const electronPackager = require('electron-packager');
const argv = require('yargs').argv;
const fs = require('fs');
const colorsFile = argv.colorsFile;
const packageInfoDeltaFile = argv.packageInfoDeltaFile;
gulp.task('scripts', function () {
if (colorsFile) {
return merge(
gulp.src([
'app/**/*.js',
'!app/**/colors.js'
])
.pipe(gulp.dest('build')),
gulp.src(colorsFile)
.pipe($.rename('colors.js'))
.pipe(gulp.dest('build'))
);
} else {
return gulp.src('app/**/*.js')
.pipe(gulp.dest('build'));
}
});
gulp.task('copy', function () {
var packageInfo = require('./package.json');
if (packageInfoDeltaFile) {
var packageInfoDelta = JSON.parse(fs.readFileSync(packageInfoDeltaFile));
for (var k in packageInfoDelta) {
let m;
if (m = k.match(/(.+)\.suffix$/)) {
packageInfo[m[1]] += packageInfoDelta[k];
} else {
packageInfo[k] = packageInfoDelta[k];
}
}
}
fs.writeFileSync('./build/package.json', JSON.stringify(packageInfo, null, 2));
return merge([
gulp.src('app/*.html').pipe(gulp.dest('build')),
gulp.src('app/assets/*').pipe(gulp.dest('build/assets'))
]);
});
gulp.task('styles', function () {
return gulp.src('app/app.scss')
.pipe($.sass({
style: 'expanded',
precision: 10,
quiet: true
}))
.pipe(gulp.dest('build'));
});
gulp.task('install-packages', ['build'], $.shell.task([
'npm install --production'
], { cwd: 'build' }));
gulp.task('clean', function() {
del(['.tmp', 'build', 'dist']);
$.cache.clearAll();
});
gulp.task('build', function(cb) {
runSequence(
'clean', 'styles', 'scripts', 'copy',
cb);
});
gulp.task('run-electron', ['build'], $.shell.task([
'electron ./build/ --dev'
]));
gulp.task('dist', ['build', 'install-packages'], function(cb) {
let packageInfo = require('./build/package.json');
electronPackager({
'arch': 'x64',
'dir': 'build',
'out': 'dist',
'asar': true,
'platform': 'linux',
'app-bundle-id': packageInfo.appBundleId,
'app-category-type': 'app-category-type=public.app-category.developer-tools',
'app-version': packageInfo.version,
'icon': 'icon_128x128x32.png',
'name': packageInfo.appDisplayName,
'overwrite': true,
}, (err, appPath) => {
if (err) {
console.error(err);
cb();
return;
}
});
});
gulp.task('default', ['run-electron']);