2019-06-03 03:49:05 -05:00
|
|
|
const fs = require('fs');
|
2019-01-02 04:19:50 -06:00
|
|
|
const gulp = require('gulp');
|
|
|
|
const less = require('gulp-less');
|
|
|
|
const sourcemaps = require('gulp-sourcemaps');
|
2019-10-30 10:28:25 -05:00
|
|
|
const tsc = require('gulp-typescript');
|
2019-01-08 00:50:50 -06:00
|
|
|
const del = require('del');
|
2019-01-02 04:19:50 -06:00
|
|
|
const path = require('path');
|
|
|
|
|
2019-10-30 10:28:25 -05:00
|
|
|
const tsProject = tsc.createProject('./tsconfig.json');
|
2019-01-08 00:50:50 -06:00
|
|
|
|
|
|
|
gulp.task('clean', function() {
|
|
|
|
return del('lib');
|
|
|
|
});
|
|
|
|
|
2019-06-03 03:49:05 -05:00
|
|
|
/**
|
|
|
|
* Compile all typescript files
|
|
|
|
* and copy to the destination
|
|
|
|
*/
|
2019-01-08 00:50:50 -06:00
|
|
|
gulp.task('compile', function() {
|
2019-10-30 10:28:25 -05:00
|
|
|
return tsProject.src()
|
|
|
|
.pipe(tsProject())
|
|
|
|
.on('error', (err) => console.log(err))
|
2019-01-08 00:50:50 -06:00
|
|
|
.pipe(gulp.dest('lib/'))
|
|
|
|
});
|
|
|
|
|
2019-01-02 04:19:50 -06:00
|
|
|
gulp.task('less', function () {
|
|
|
|
return gulp.src('./src/**/*.less')
|
|
|
|
.pipe(sourcemaps.init())
|
|
|
|
.pipe(less())
|
|
|
|
.pipe(sourcemaps.write())
|
2019-01-08 00:50:50 -06:00
|
|
|
.pipe(gulp.dest(path.join(__dirname, 'lib/src')));
|
|
|
|
});
|
|
|
|
|
2019-06-03 03:49:05 -05:00
|
|
|
/**
|
|
|
|
* Copy all assets to JS codebase
|
|
|
|
*/
|
2019-01-08 00:50:50 -06:00
|
|
|
gulp.task('copy', function () {
|
|
|
|
return gulp.src([
|
|
|
|
'./src/renderer/assets/*',
|
2019-01-08 04:21:52 -06:00
|
|
|
'./src/renderer/*.html',
|
2019-10-30 10:28:25 -05:00
|
|
|
'./src/locale/*',
|
|
|
|
'./package.json'
|
2019-01-08 00:50:50 -06:00
|
|
|
], {
|
|
|
|
"base": "./src"
|
|
|
|
}).pipe(gulp.dest('lib/src'))
|
|
|
|
});
|
|
|
|
|
2019-06-03 03:49:05 -05:00
|
|
|
/**
|
|
|
|
* Set expiry time for test builds
|
|
|
|
*/
|
|
|
|
gulp.task('setExpiry', function (done) {
|
|
|
|
// Set expiry of 15 days for test builds we create from CI
|
2019-06-25 03:05:40 -05:00
|
|
|
const expiryDays = process.argv[4] || 15;
|
|
|
|
console.log(`Setting expiry to ${expiryDays} days`);
|
2019-06-03 03:49:05 -05:00
|
|
|
const milliseconds = 24*60*60*1000;
|
|
|
|
const expiryTime = new Date().getTime() + (expiryDays * milliseconds);
|
2019-06-25 03:05:40 -05:00
|
|
|
console.log(`Setting expiry time to ${expiryTime}`);
|
2019-06-03 03:49:05 -05:00
|
|
|
|
|
|
|
const ttlHandlerFile = path.join(__dirname, 'src/app/ttl-handler.ts');
|
|
|
|
fs.readFile(ttlHandlerFile, 'utf8', function (err,data) {
|
|
|
|
if (err) {
|
2019-06-25 03:05:40 -05:00
|
|
|
console.error(err);
|
2019-06-03 03:49:05 -05:00
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do a simple search and replace in the `ttl-handler.ts` file
|
|
|
|
const replacementString = `const ttlExpiryTime = ${expiryTime}`;
|
2019-06-25 03:05:40 -05:00
|
|
|
const result = data.replace(/const ttlExpiryTime = -1/g, replacementString);
|
2019-06-03 03:49:05 -05:00
|
|
|
|
|
|
|
fs.writeFile(ttlHandlerFile, result, 'utf8', function (err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-03-19 05:52:39 -05:00
|
|
|
gulp.task('build', gulp.series('clean', 'compile', 'less', 'copy'));
|