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');
|
2023-01-12 03:43:25 -06:00
|
|
|
const replace = require('gulp-replace');
|
|
|
|
const template = require('gulp-template');
|
|
|
|
const tap = require('gulp-tap');
|
|
|
|
const rename = require('gulp-rename');
|
2019-10-30 10:28:25 -05:00
|
|
|
const tsProject = tsc.createProject('./tsconfig.json');
|
2019-01-08 00:50:50 -06:00
|
|
|
|
2020-06-30 03:39:41 -05:00
|
|
|
gulp.task('clean', function () {
|
2021-07-16 10:26:13 -05:00
|
|
|
return del('lib');
|
2019-01-08 00:50:50 -06:00
|
|
|
});
|
|
|
|
|
2019-06-03 03:49:05 -05:00
|
|
|
/**
|
|
|
|
* Compile all typescript files
|
|
|
|
* and copy to the destination
|
|
|
|
*/
|
2020-06-30 03:39:41 -05:00
|
|
|
gulp.task('compile', function () {
|
2021-07-16 10:26:13 -05:00
|
|
|
return tsProject
|
|
|
|
.src()
|
|
|
|
.pipe(sourcemaps.init())
|
|
|
|
.pipe(tsProject())
|
|
|
|
.pipe(sourcemaps.write('.', { sourceRoot: './', includeContent: false }))
|
|
|
|
.on('error', (err) => console.log(err))
|
|
|
|
.pipe(gulp.dest('lib'));
|
2019-01-08 00:50:50 -06:00
|
|
|
});
|
|
|
|
|
2019-01-02 04:19:50 -06:00
|
|
|
gulp.task('less', function () {
|
2021-07-16 10:26:13 -05:00
|
|
|
return gulp
|
|
|
|
.src('./src/**/*.less')
|
|
|
|
.pipe(sourcemaps.init())
|
|
|
|
.pipe(less())
|
|
|
|
.pipe(sourcemaps.write())
|
|
|
|
.pipe(gulp.dest(path.join(__dirname, 'lib/src')));
|
2019-01-08 00:50:50 -06:00
|
|
|
});
|
|
|
|
|
2023-01-12 03:43:25 -06:00
|
|
|
const extractFileNameFromPath = (filePath) => {
|
|
|
|
const basename = path.basename(filePath);
|
|
|
|
const filename = basename.split('.');
|
|
|
|
return filename[0];
|
|
|
|
};
|
|
|
|
|
|
|
|
gulp.task('templates', () => {
|
|
|
|
return (
|
|
|
|
gulp
|
|
|
|
.src('./lib/src/renderer/components/*.js', { base: './lib' })
|
|
|
|
// tap into the stream to get the current file and compile
|
|
|
|
// the template according to that
|
|
|
|
.pipe(
|
|
|
|
tap(function (file) {
|
|
|
|
const jsFilename = extractFileNameFromPath(file.path);
|
|
|
|
return gulp
|
|
|
|
.src('./src/renderer/react-window.html')
|
|
|
|
.pipe(
|
|
|
|
template({
|
|
|
|
sourcefile: file.path,
|
|
|
|
}),
|
|
|
|
)
|
|
|
|
.pipe(
|
|
|
|
replace(
|
|
|
|
/(<link rel="stylesheet" href="*"[^>]*>)/g,
|
|
|
|
function (_s, _match) {
|
|
|
|
const cssFilePath = `lib/src/renderer/styles/${jsFilename}.css`;
|
|
|
|
const doesFileExist = fs.existsSync(cssFilePath);
|
|
|
|
if (doesFileExist) {
|
|
|
|
const style = fs.readFileSync(cssFilePath, 'utf8');
|
|
|
|
return '<style>\n' + style + '\n</style>';
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
},
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.pipe(rename(`${jsFilename}.html`))
|
|
|
|
.pipe(gulp.dest('./lib/src/renderer'));
|
|
|
|
}),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
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 () {
|
2021-07-16 10:26:13 -05:00
|
|
|
return gulp
|
|
|
|
.src(
|
|
|
|
[
|
2023-02-28 04:02:43 -06:00
|
|
|
'./src/renderer/assets/**',
|
2019-01-08 04:21:52 -06:00
|
|
|
'./src/renderer/*.html',
|
2019-10-30 10:28:25 -05:00
|
|
|
'./src/locale/*',
|
2021-07-16 10:26:13 -05:00
|
|
|
'./package.json',
|
|
|
|
],
|
|
|
|
{
|
|
|
|
base: './src',
|
|
|
|
},
|
|
|
|
)
|
|
|
|
.pipe(gulp.dest('lib/src'));
|
2019-01-08 00:50:50 -06:00
|
|
|
});
|
|
|
|
|
2019-06-03 03:49:05 -05:00
|
|
|
/**
|
|
|
|
* Set expiry time for test builds
|
|
|
|
*/
|
|
|
|
gulp.task('setExpiry', function (done) {
|
2021-07-16 10:26:13 -05:00
|
|
|
// Set expiry of 15 days for test builds we create from CI
|
|
|
|
const expiryDays = process.argv[4] || 15;
|
|
|
|
if (expiryDays < 1) {
|
|
|
|
console.log(`Not setting expiry as the value provided is ${expiryDays}`);
|
|
|
|
done();
|
|
|
|
return;
|
|
|
|
}
|
2020-04-06 06:12:39 -05:00
|
|
|
|
2021-07-16 10:26:13 -05:00
|
|
|
console.log(`Setting expiry to ${expiryDays} days`);
|
|
|
|
const milliseconds = 24 * 60 * 60 * 1000;
|
|
|
|
const expiryTime = new Date().getTime() + expiryDays * milliseconds;
|
|
|
|
console.log(`Setting expiry time to ${expiryTime}`);
|
2019-06-03 03:49:05 -05:00
|
|
|
|
2021-07-16 10:26:13 -05:00
|
|
|
const ttlHandlerFile = path.join(__dirname, 'src/app/ttl-handler.ts');
|
|
|
|
fs.readFile(ttlHandlerFile, 'utf8', function (err, data) {
|
|
|
|
if (err) {
|
|
|
|
console.error(err);
|
|
|
|
return done(err);
|
|
|
|
}
|
2019-06-03 03:49:05 -05:00
|
|
|
|
2021-07-16 10:26:13 -05:00
|
|
|
// Do a simple search and replace in the `ttl-handler.ts` file
|
|
|
|
const replacementString = `const ttlExpiryTime = ${expiryTime}`;
|
|
|
|
const result = data.replace(/const ttlExpiryTime = -1/g, replacementString);
|
2019-06-03 03:49:05 -05:00
|
|
|
|
2021-07-16 10:26:13 -05:00
|
|
|
fs.writeFile(ttlHandlerFile, result, 'utf8', function (err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
done();
|
2019-06-03 03:49:05 -05:00
|
|
|
});
|
2021-07-16 10:26:13 -05:00
|
|
|
});
|
2019-06-03 03:49:05 -05:00
|
|
|
});
|
|
|
|
|
2023-01-12 03:43:25 -06:00
|
|
|
gulp.task(
|
|
|
|
'build',
|
|
|
|
gulp.series('clean', 'compile', 'less', 'templates', 'copy'),
|
|
|
|
);
|