-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
101 lines (83 loc) · 2.85 KB
/
gulpfile.js
File metadata and controls
101 lines (83 loc) · 2.85 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
let fs = require('fs'),
split = require('split'),
gulp = require('gulp'),
sass = require('gulp-sass'),
clean = require('gulp-clean'),
rename = require('gulp-rename'),
zip = require('gulp-zip'),
watch = require('gulp-watch'),
insert = require('gulp-insert');
let getThemeInfo = () => JSON.parse(fs.readFileSync('theme.json'));
let beepOnError = function(done) {
return err => {
if (err) process.stdout.write('\u0007');
done(err);
}
};
let deployPathValid = function(path) {
if (!path) return false;
return fs.existsSync(`${path}\\zEdit.exe`);
};
let setDeployPath = function(resolve, reject) {
process.stdout.write('Enter the path to the zEdit installation you would like to deploy to:');
process.stdin.pipe(split()).on('data', line => {
deployPathValid(line) ?
resolve(process.env['ZEDIT_DEPLOY_PATH'] = line) :
reject(`"${line}" is not a valid zEdit Deploy Path.`);
});
};
let initializeDeployPath = function() {
return new Promise((resolve, reject) => {
deployPathValid(process.env.ZEDIT_DEPLOY_PATH) ?
resolve() : setDeployPath(resolve, reject);
});
};
const watchPatterns = ['index.css', 'src/**/*.scss'];
gulp.task('clean', function() {
return gulp.src('dist', {read: false})
.pipe(clean());
});
gulp.task('build', ['clean'], function() {
let themeInfo = getThemeInfo(),
themeId = themeInfo.id;
delete themeInfo.id;
let themeText = JSON.stringify(themeInfo, null, 2);
return gulp.src('index.scss')
.on('error', console.error)
.pipe(sass())
.pipe(insert.prepend(`/*${themeText}*/\n\n`))
.pipe(rename(path => path.basename = themeId))
.pipe(gulp.dest(`dist`));
});
gulp.task('release', ['build'], function() {
let themeInfo = getThemeInfo(),
themeId = themeInfo.id,
themeVersion = themeInfo.version,
zipFileName = `${themeId}-v${themeVersion}.zip`;
console.log(`Packaging ${zipFileName}`);
return gulp.src(`dist/${themeId}.css`)
.pipe(zip(zipFileName))
.pipe(gulp.dest('.'));
});
gulp.task('watch', function() {
watch(watchPatterns, batch(function(events, done) {
gulp.start('build', beepOnError(done));
}));
});
gulp.task('deploy', ['build'], function() {
initializeDeployPath().then(() => {
let themeInfo = getThemeInfo(),
themeId = themeInfo.id,
deployPath = process.env.ZEDIT_DEPLOY_PATH;
gulp.src(`dist/${themeId}.css`)
.pipe(gulp.dest(`${deployPath}\\themes\\.`));
}, console.error);
});
gulp.task('integrate', function() {
initializeDeployPath().then(() => {
watch(watchPatterns, batch(function(events, done) {
gulp.start('deploy', beepOnError(done));
}));
}, console.error);
});
gulp.task('default', ['build']);