1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-02-13 19:42:36 +02:00

Tools: Improve building and testing app on Windows

This commit is contained in:
Laurent Cozic 2020-06-22 23:06:47 +01:00
parent f61c4c1374
commit 5143870d3b
5 changed files with 39 additions and 30 deletions

View File

@ -31,7 +31,7 @@ const buildSeries = [
// which makes the copyPluginAssets command fail. For that reason, // which makes the copyPluginAssets command fail. For that reason,
// it's not possible to run watch on Windows while testing the desktop app. // it's not possible to run watch on Windows while testing the desktop app.
if (require('os').platform() === 'win32') { if (require('os').platform() === 'win32') {
buildSeries.push('tsc'); // buildSeries.push('tsc');
} }
const buildParallel = [ const buildParallel = [

View File

@ -1,4 +1,4 @@
const fs = require('fs-extra'); const utils = require('../../Tools/gulp/utils');
async function main() { async function main() {
const rootDir = `${__dirname}/..`; const rootDir = `${__dirname}/..`;
@ -10,16 +10,7 @@ async function main() {
for (const destDir of destDirs) { for (const destDir of destDirs) {
console.info(`Copying to ${destDir}`); console.info(`Copying to ${destDir}`);
await utils.copyDir(sourceDir, destDir);
try {
await fs.remove(destDir);
await fs.copy(sourceDir, destDir);
} catch (error) {
// These calls randomly fail on Windows when the folders are being
// watch by TypeScript. As these files aren't always needed for
// development, only print a warning.
console.warn(`Could not copy to ${destDir}`, error);
}
} }
} }

View File

@ -1,13 +1,12 @@
const fs = require('fs-extra'); const fs = require('fs-extra');
const glob = require('glob'); const glob = require('glob');
const utils = require('../../Tools/gulp/utils');
async function main() { async function main() {
const sourceDir = `${__dirname}/../../Modules/TinyMCE/langs`; const sourceDir = `${__dirname}/../../Modules/TinyMCE/langs`;
const destDir = `${__dirname}/../node_modules/tinymce/langs`; const destDir = `${__dirname}/../node_modules/tinymce/langs`;
console.info(`Copying ${sourceDir} => ${destDir}`); console.info(`Copying ${sourceDir} => ${destDir}`);
await fs.remove(destDir); await utils.copyDir(sourceDir, destDir);
await fs.mkdirp(destDir);
await fs.copy(sourceDir, destDir);
const supportedLocales = glob.sync(`${sourceDir}/*.js`).map(s => { const supportedLocales = glob.sync(`${sourceDir}/*.js`).map(s => {
s = s.split('/'); s = s.split('/');

View File

@ -5,7 +5,13 @@ const rootDir = utils.rootDir();
module.exports = { module.exports = {
src: `${rootDir}/ReactNativeClient/lib/**/*`, src: `${rootDir}/ReactNativeClient/lib/**/*`,
fn: async function() { fn: async function() {
await utils.copyDir(`${rootDir}/ReactNativeClient/lib`, `${rootDir}/CliClient/build/lib`, { delete: false }); const copyOptions = {
await utils.copyDir(`${rootDir}/ReactNativeClient/lib`, `${rootDir}/ElectronClient/lib`, { delete: false }); excluded: [
`${rootDir}/ReactNativeClient/lib/joplin-renderer/node_modules`,
],
};
await utils.copyDir(`${rootDir}/ReactNativeClient/lib`, `${rootDir}/CliClient/build/lib`, copyOptions);
await utils.copyDir(`${rootDir}/ReactNativeClient/lib`, `${rootDir}/ElectronClient/lib`, copyOptions);
}, },
}; };

View File

@ -20,6 +20,14 @@ utils.execCommand = function(command) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
exec(command, { maxBuffer: 1024 * 1024 }, (error, stdout) => { exec(command, { maxBuffer: 1024 * 1024 }, (error, stdout) => {
if (error) { if (error) {
// Special case for robocopy, which will return an error code of "1"
// if successful - https://ss64.com/nt/robocopy-exit.html
if (command.indexOf('robocopy') === 0 && error.code <= 1) {
resolve(stdout.trim());
return;
}
if (error.signal == 'SIGTERM') { if (error.signal == 'SIGTERM') {
resolve('Process was killed'); resolve('Process was killed');
} else { } else {
@ -76,8 +84,6 @@ utils.replaceFileText = async function(filePath, regex, toInsert) {
}; };
utils.copyDir = async function(src, dest, options) { utils.copyDir = async function(src, dest, options) {
const os = require('os');
options = Object.assign({}, { options = Object.assign({}, {
excluded: [], excluded: [],
delete: true, delete: true,
@ -86,22 +92,21 @@ utils.copyDir = async function(src, dest, options) {
src = utils.toSystemSlashes(src); src = utils.toSystemSlashes(src);
dest = utils.toSystemSlashes(dest); dest = utils.toSystemSlashes(dest);
await fs.mkdirp(dest); await utils.mkdir(dest);
if (utils.isWindows()) { if (utils.isWindows()) {
let excludedFlag = ''; let cmd = ['robocopy'];
let tempFile = null; cmd.push(`"${src}"`);
cmd.push(`"${dest}"`);
cmd.push('/e');
if (options.delete) cmd.push('/purge');
if (options.excluded.length) { if (options.excluded.length) {
tempFile = `${os.tmpdir()}\\xcopy_excluded_${Date.now()}.txt`; cmd.push('/xd');
await fs.writeFile(tempFile, options.excluded.join('\n')); cmd = cmd.concat(options.excluded.map(p => `"${utils.toSystemSlashes(p)}"`).join(' '));
excludedFlag = `/EXCLUDE:${tempFile}`;
} }
// TODO: add support for delete flag await utils.execCommand(cmd.join(' '));
await utils.execCommand(`xcopy /C /I /H /R /Y /S ${excludedFlag} "${src}" "${dest}"`);
if (tempFile) await fs.remove(tempFile);
} else { } else {
let excludedFlag = ''; let excludedFlag = '';
if (options.excluded.length) { if (options.excluded.length) {
@ -117,6 +122,14 @@ utils.copyDir = async function(src, dest, options) {
} }
}; };
utils.mkdir = async function(dir) {
if (utils.isWindows()) {
return utils.execCommand(`if not exist "${utils.toSystemSlashes(dir)}" mkdir "${utils.toSystemSlashes(dir)}"`);
} else {
return fs.mkdir(dir);
}
};
utils.copyFile = async function(src, dest) { utils.copyFile = async function(src, dest) {
await fs.copy(src, dest); await fs.copy(src, dest);
}; };