diff --git a/CliClient/gulpfile.js b/CliClient/gulpfile.js index 191e81dfe..55d2c4509 100644 --- a/CliClient/gulpfile.js +++ b/CliClient/gulpfile.js @@ -4,9 +4,10 @@ const utils = require('../Tools/gulp/utils'); const tasks = { copyLib: require('../Tools/gulp/tasks/copyLib'), tsc: require('../Tools/gulp/tasks/tsc'), + updateIgnoredTypeScriptBuild: require('../Tools/gulp/tasks/updateIgnoredTypeScriptBuild'), }; -tasks.build = { +tasks.prepareBuild = { fn: async () => { const buildDir = `${__dirname}/build`; await utils.copyDir(`${__dirname}/app`, buildDir, { @@ -28,7 +29,7 @@ tasks.build = { }, }; -tasks.buildTests = { +tasks.prepareTestBuild = { fn: async () => { const testBuildDir = `${__dirname}/tests-build`; @@ -46,16 +47,14 @@ tasks.buildTests = { }, }; -const buildTestSeries = [ - tasks.buildTests.fn, -]; +utils.registerGulpTasks(gulp, tasks); -if (require('os').platform() === 'win32') { - gulp.task('copyLib', tasks.copyLib.fn); - gulp.task('tsc', tasks.tsc.fn); - buildTestSeries.push('copyLib'); - buildTestSeries.push('tsc'); -} +gulp.task('build', gulp.series([ + 'prepareBuild', + 'copyLib', +])); -gulp.task('build', tasks.build.fn); -gulp.task('buildTests', gulp.series(...buildTestSeries)); +gulp.task('buildTests', gulp.series([ + 'prepareTestBuild', + 'copyLib', +])); diff --git a/ElectronClient/gulpfile.js b/ElectronClient/gulpfile.js index 1191c65ee..728e30c4a 100644 --- a/ElectronClient/gulpfile.js +++ b/ElectronClient/gulpfile.js @@ -19,6 +19,7 @@ const tasks = { }, copyLib: require('../Tools/gulp/tasks/copyLib'), tsc: require('../Tools/gulp/tasks/tsc'), + updateIgnoredTypeScriptBuild: require('../Tools/gulp/tasks/updateIgnoredTypeScriptBuild'), }; utils.registerGulpTasks(gulp, tasks); @@ -40,6 +41,7 @@ const buildParallel = [ 'compilePackageInfo', 'copyPluginAssets', 'copyTinyMceLangs', + 'updateIgnoredTypeScriptBuild', ]; gulp.task('build', gulp.parallel(...buildParallel)); diff --git a/ReactNativeClient/gulpfile.js b/ReactNativeClient/gulpfile.js index 88459120d..828cd2d38 100644 --- a/ReactNativeClient/gulpfile.js +++ b/ReactNativeClient/gulpfile.js @@ -1,5 +1,4 @@ const gulp = require('gulp'); -// const execa = require('execa'); const utils = require('../Tools/gulp/utils'); const tasks = { @@ -14,24 +13,10 @@ const tasks = { }, }; -// tasks.jetify = { -// fn: async () => { -// try { -// const promise = execa('npx', ['jetify']); -// promise.stdout.pipe(process.stdout); -// await promise; -// } catch (error) { -// console.warn('Jetify failed:', error); -// } -// return Promise.resolve(); -// }, -// }; - utils.registerGulpTasks(gulp, tasks); gulp.task('build', gulp.series( 'buildReactNativeInjectedJs', - // 'jetify', 'encodeAssets', 'podInstall', )); diff --git a/Tools/gulp/tasks/updateIgnoredTypeScriptBuild.js b/Tools/gulp/tasks/updateIgnoredTypeScriptBuild.js new file mode 100644 index 000000000..2216eeda2 --- /dev/null +++ b/Tools/gulp/tasks/updateIgnoredTypeScriptBuild.js @@ -0,0 +1,35 @@ +const utils = require('../utils'); +const glob = require('glob'); +const rootDir = utils.rootDir(); + +module.exports = { + src: '', + fn: async function() { + const tsFiles = glob.sync(`${rootDir}{/**/*.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(rootDir.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 Promise.all([ + utils.replaceFileText(`${rootDir}/.gitignore`, regex, replacement), + utils.replaceFileText(`${rootDir}/.eslintignore`, regex, replacement), + ]); + }, +}; diff --git a/gulpfile.js b/gulpfile.js index 3be54374c..3299ea485 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,52 +1,12 @@ 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'), + updateIgnoredTypeScriptBuild: require('./Tools/gulp/tasks/updateIgnoredTypeScriptBuild'), }; -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.dev.json'], { cwd: `${__dirname}` }); - promise.stdout.pipe(process.stdout); -}); +utils.registerGulpTasks(gulp, tasks); gulp.task('build', gulp.series('copyLib', 'tsc', 'updateIgnoredTypeScriptBuild')); diff --git a/package.json b/package.json index 396d91a6a..3083770ab 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "scripts": { "linter": "./node_modules/.bin/eslint --fix --ext .js --ext .jsx --ext .ts --ext .tsx", "linter-ci": "./node_modules/.bin/eslint --ext .js --ext .jsx --ext .ts --ext .tsx", - "watch": "gulp watch", + "watch": "node_modules/typescript/bin/tsc --watch --project tsconfig.dev.json", "build": "gulp build", "postinstall": "cd Tools && npm i && cd .. && cd ReactNativeClient && npm i && cd .. && cd ElectronClient && npm i && cd .. && cd CliClient && npm i && cd .. && gulp build" },