forked from laurent22/joplin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
52 lines (43 loc) · 1.77 KB
/
gulpfile.js
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
const gulp = require('gulp');
const glob = require('glob');
const execa = require('execa');
const utils = require('./Tools/gulp/utils');
const tasks = {
copyLib: require('./Tools/gulp/tasks/copyLib'),
tsc: require('./Tools/gulp/tasks/tsc'),
};
const updateIgnoredTypeScriptBuildTask = async function() {
const tsFiles = glob.sync(`${__dirname}{/**/*.ts,/**/*.tsx}`, {
ignore: [
'**/node_modules/**',
'**/.git/**',
'**/ElectronClient/lib/**',
'**/CliClient/build/lib/**',
'**/CliClient/tests-build/lib/**',
'**/ElectronClient/dist/**',
'**/Modules/TinyMCE/JoplinLists/**',
'**/Modules/TinyMCE/IconPack/**',
],
}).map(f => f.substr(__dirname.length + 1));
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`;
await utils.replaceFileText(`${__dirname}/.gitignore`, regex, replacement);
await utils.replaceFileText(`${__dirname}/.eslintignore`, regex, replacement);
};
gulp.task('tsc', tasks.tsc.fn);
gulp.task('copyLib', tasks.copyLib.fn);
gulp.task('updateIgnoredTypeScriptBuild', updateIgnoredTypeScriptBuildTask);
gulp.task('watch', function() {
gulp.watch(tasks.copyLib.src, tasks.copyLib.fn);
gulp.watch(tasks.tsc.src, updateIgnoredTypeScriptBuildTask);
// For watching, we use the actual tsc tool because it's more robust and
// doesn't crash when there's an error
const promise = execa('node', ['node_modules/typescript/bin/tsc', '--watch', '--project', 'tsconfig.json'], { cwd: `${__dirname}` });
promise.stdout.pipe(process.stdout);
});
gulp.task('build', gulp.series('copyLib', 'tsc', 'updateIgnoredTypeScriptBuild'));