2020-02-17 22:55:09 +02:00
|
|
|
const gulp = require('gulp');
|
2020-02-21 00:59:18 +02:00
|
|
|
const glob = require('glob');
|
2020-02-22 13:20:41 +02:00
|
|
|
const execa = require('execa');
|
2020-02-21 00:59:18 +02:00
|
|
|
const utils = require('./Tools/gulp/utils');
|
2020-02-17 22:55:09 +02:00
|
|
|
|
2020-02-21 00:59:18 +02:00
|
|
|
const tasks = {
|
|
|
|
copyLib: require('./Tools/gulp/tasks/copyLib'),
|
2020-03-23 02:47:25 +02:00
|
|
|
tsc: require('./Tools/gulp/tasks/tsc'),
|
2020-02-17 22:55:09 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const updateIgnoredTypeScriptBuildTask = async function() {
|
2020-02-21 00:59:18 +02:00
|
|
|
const tsFiles = glob.sync(`${__dirname}{/**/*.ts,/**/*.tsx}`, {
|
|
|
|
ignore: [
|
|
|
|
'**/node_modules/**',
|
|
|
|
'**/.git/**',
|
|
|
|
'**/ElectronClient/lib/**',
|
|
|
|
'**/CliClient/build/lib/**',
|
2020-03-04 02:54:27 +02:00
|
|
|
'**/CliClient/tests-build/lib/**',
|
2020-02-21 00:59:18 +02:00
|
|
|
'**/ElectronClient/dist/**',
|
2020-03-23 02:47:25 +02:00
|
|
|
'**/Modules/TinyMCE/JoplinLists/**',
|
2020-02-21 00:59:18 +02:00
|
|
|
],
|
|
|
|
}).map(f => f.substr(__dirname.length + 1));
|
2020-02-17 22:55:09 +02:00
|
|
|
|
|
|
|
const ignoredFiles = tsFiles.map(f => {
|
|
|
|
const s = f.split('.');
|
|
|
|
s.pop();
|
|
|
|
return `${s.join('.')}.js`;
|
|
|
|
});
|
|
|
|
|
|
|
|
const regex = /(# AUTO-GENERATED - EXCLUDED TYPESCRIPT BUILD)[\s\S]*(# AUTO-GENERATED - EXCLUDED TYPESCRIPT BUILD)/;
|
|
|
|
const replacement = `$1\n${ignoredFiles.join('\n')}\n$2`;
|
|
|
|
|
2020-02-21 00:59:18 +02:00
|
|
|
await utils.replaceFileText(`${__dirname}/.gitignore`, regex, replacement);
|
|
|
|
await utils.replaceFileText(`${__dirname}/.eslintignore`, regex, replacement);
|
2020-02-17 22:55:09 +02:00
|
|
|
};
|
|
|
|
|
2020-03-23 02:47:25 +02:00
|
|
|
gulp.task('tsc', tasks.tsc.fn);
|
2020-02-21 00:59:18 +02:00
|
|
|
gulp.task('copyLib', tasks.copyLib.fn);
|
|
|
|
gulp.task('updateIgnoredTypeScriptBuild', updateIgnoredTypeScriptBuildTask);
|
2020-02-17 22:55:09 +02:00
|
|
|
|
|
|
|
gulp.task('watch', function() {
|
2020-02-21 00:59:18 +02:00
|
|
|
gulp.watch(tasks.copyLib.src, tasks.copyLib.fn);
|
2020-03-23 02:47:25 +02:00
|
|
|
gulp.watch(tasks.tsc.src, updateIgnoredTypeScriptBuildTask);
|
2020-02-22 13:20:41 +02:00
|
|
|
|
|
|
|
// For watching, we use the actual tsc tool because it's more robust and
|
|
|
|
// doesn't crash when there's an error
|
2020-03-31 23:40:38 +02:00
|
|
|
const promise = execa('node', ['node_modules/typescript/bin/tsc', '--watch', '--project', 'tsconfig.json'], { cwd: `${__dirname}` });
|
2020-02-22 13:20:41 +02:00
|
|
|
promise.stdout.pipe(process.stdout);
|
2020-02-17 22:55:09 +02:00
|
|
|
});
|
|
|
|
|
2020-02-21 00:59:18 +02:00
|
|
|
gulp.task('build', gulp.series('copyLib', 'tsc', 'updateIgnoredTypeScriptBuild'));
|