mirror of
https://github.com/laurent22/joplin.git
synced 2025-01-02 12:47:41 +02:00
Tools: Cleaned up and improve build config, and fixed TypeScript Watch high CPU usage
This commit is contained in:
parent
eb42a5f34b
commit
98905f6892
@ -4,9 +4,10 @@ const utils = require('../Tools/gulp/utils');
|
|||||||
const tasks = {
|
const tasks = {
|
||||||
copyLib: require('../Tools/gulp/tasks/copyLib'),
|
copyLib: require('../Tools/gulp/tasks/copyLib'),
|
||||||
tsc: require('../Tools/gulp/tasks/tsc'),
|
tsc: require('../Tools/gulp/tasks/tsc'),
|
||||||
|
updateIgnoredTypeScriptBuild: require('../Tools/gulp/tasks/updateIgnoredTypeScriptBuild'),
|
||||||
};
|
};
|
||||||
|
|
||||||
tasks.build = {
|
tasks.prepareBuild = {
|
||||||
fn: async () => {
|
fn: async () => {
|
||||||
const buildDir = `${__dirname}/build`;
|
const buildDir = `${__dirname}/build`;
|
||||||
await utils.copyDir(`${__dirname}/app`, buildDir, {
|
await utils.copyDir(`${__dirname}/app`, buildDir, {
|
||||||
@ -28,7 +29,7 @@ tasks.build = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
tasks.buildTests = {
|
tasks.prepareTestBuild = {
|
||||||
fn: async () => {
|
fn: async () => {
|
||||||
const testBuildDir = `${__dirname}/tests-build`;
|
const testBuildDir = `${__dirname}/tests-build`;
|
||||||
|
|
||||||
@ -46,16 +47,14 @@ tasks.buildTests = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const buildTestSeries = [
|
utils.registerGulpTasks(gulp, tasks);
|
||||||
tasks.buildTests.fn,
|
|
||||||
];
|
|
||||||
|
|
||||||
if (require('os').platform() === 'win32') {
|
gulp.task('build', gulp.series([
|
||||||
gulp.task('copyLib', tasks.copyLib.fn);
|
'prepareBuild',
|
||||||
gulp.task('tsc', tasks.tsc.fn);
|
'copyLib',
|
||||||
buildTestSeries.push('copyLib');
|
]));
|
||||||
buildTestSeries.push('tsc');
|
|
||||||
}
|
|
||||||
|
|
||||||
gulp.task('build', tasks.build.fn);
|
gulp.task('buildTests', gulp.series([
|
||||||
gulp.task('buildTests', gulp.series(...buildTestSeries));
|
'prepareTestBuild',
|
||||||
|
'copyLib',
|
||||||
|
]));
|
||||||
|
@ -19,6 +19,7 @@ const tasks = {
|
|||||||
},
|
},
|
||||||
copyLib: require('../Tools/gulp/tasks/copyLib'),
|
copyLib: require('../Tools/gulp/tasks/copyLib'),
|
||||||
tsc: require('../Tools/gulp/tasks/tsc'),
|
tsc: require('../Tools/gulp/tasks/tsc'),
|
||||||
|
updateIgnoredTypeScriptBuild: require('../Tools/gulp/tasks/updateIgnoredTypeScriptBuild'),
|
||||||
};
|
};
|
||||||
|
|
||||||
utils.registerGulpTasks(gulp, tasks);
|
utils.registerGulpTasks(gulp, tasks);
|
||||||
@ -40,6 +41,7 @@ const buildParallel = [
|
|||||||
'compilePackageInfo',
|
'compilePackageInfo',
|
||||||
'copyPluginAssets',
|
'copyPluginAssets',
|
||||||
'copyTinyMceLangs',
|
'copyTinyMceLangs',
|
||||||
|
'updateIgnoredTypeScriptBuild',
|
||||||
];
|
];
|
||||||
|
|
||||||
gulp.task('build', gulp.parallel(...buildParallel));
|
gulp.task('build', gulp.parallel(...buildParallel));
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
const gulp = require('gulp');
|
const gulp = require('gulp');
|
||||||
// const execa = require('execa');
|
|
||||||
const utils = require('../Tools/gulp/utils');
|
const utils = require('../Tools/gulp/utils');
|
||||||
|
|
||||||
const tasks = {
|
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);
|
utils.registerGulpTasks(gulp, tasks);
|
||||||
|
|
||||||
gulp.task('build', gulp.series(
|
gulp.task('build', gulp.series(
|
||||||
'buildReactNativeInjectedJs',
|
'buildReactNativeInjectedJs',
|
||||||
// 'jetify',
|
|
||||||
'encodeAssets',
|
'encodeAssets',
|
||||||
'podInstall',
|
'podInstall',
|
||||||
));
|
));
|
||||||
|
35
Tools/gulp/tasks/updateIgnoredTypeScriptBuild.js
Normal file
35
Tools/gulp/tasks/updateIgnoredTypeScriptBuild.js
Normal file
@ -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),
|
||||||
|
]);
|
||||||
|
},
|
||||||
|
};
|
44
gulpfile.js
44
gulpfile.js
@ -1,52 +1,12 @@
|
|||||||
const gulp = require('gulp');
|
const gulp = require('gulp');
|
||||||
const glob = require('glob');
|
|
||||||
const execa = require('execa');
|
|
||||||
const utils = require('./Tools/gulp/utils');
|
const utils = require('./Tools/gulp/utils');
|
||||||
|
|
||||||
const tasks = {
|
const tasks = {
|
||||||
copyLib: require('./Tools/gulp/tasks/copyLib'),
|
copyLib: require('./Tools/gulp/tasks/copyLib'),
|
||||||
tsc: require('./Tools/gulp/tasks/tsc'),
|
tsc: require('./Tools/gulp/tasks/tsc'),
|
||||||
|
updateIgnoredTypeScriptBuild: require('./Tools/gulp/tasks/updateIgnoredTypeScriptBuild'),
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateIgnoredTypeScriptBuildTask = async function() {
|
utils.registerGulpTasks(gulp, tasks);
|
||||||
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);
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('build', gulp.series('copyLib', 'tsc', 'updateIgnoredTypeScriptBuild'));
|
gulp.task('build', gulp.series('copyLib', 'tsc', 'updateIgnoredTypeScriptBuild'));
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"linter": "./node_modules/.bin/eslint --fix --ext .js --ext .jsx --ext .ts --ext .tsx",
|
"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",
|
"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",
|
"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"
|
"postinstall": "cd Tools && npm i && cd .. && cd ReactNativeClient && npm i && cd .. && cd ElectronClient && npm i && cd .. && cd CliClient && npm i && cd .. && gulp build"
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user