1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-11-24 08:12:24 +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,
// it's not possible to run watch on Windows while testing the desktop app.
if (require('os').platform() === 'win32') {
buildSeries.push('tsc');
// buildSeries.push('tsc');
}
const buildParallel = [

View File

@ -1,4 +1,4 @@
const fs = require('fs-extra');
const utils = require('../../Tools/gulp/utils');
async function main() {
const rootDir = `${__dirname}/..`;
@ -10,16 +10,7 @@ async function main() {
for (const destDir of destDirs) {
console.info(`Copying to ${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);
}
await utils.copyDir(sourceDir, destDir);
}
}

View File

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

View File

@ -5,7 +5,13 @@ const rootDir = utils.rootDir();
module.exports = {
src: `${rootDir}/ReactNativeClient/lib/**/*`,
fn: async function() {
await utils.copyDir(`${rootDir}/ReactNativeClient/lib`, `${rootDir}/CliClient/build/lib`, { delete: false });
await utils.copyDir(`${rootDir}/ReactNativeClient/lib`, `${rootDir}/ElectronClient/lib`, { delete: false });
const copyOptions = {
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) => {
exec(command, { maxBuffer: 1024 * 1024 }, (error, stdout) => {
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') {
resolve('Process was killed');
} else {
@ -76,8 +84,6 @@ utils.replaceFileText = async function(filePath, regex, toInsert) {
};
utils.copyDir = async function(src, dest, options) {
const os = require('os');
options = Object.assign({}, {
excluded: [],
delete: true,
@ -86,22 +92,21 @@ utils.copyDir = async function(src, dest, options) {
src = utils.toSystemSlashes(src);
dest = utils.toSystemSlashes(dest);
await fs.mkdirp(dest);
await utils.mkdir(dest);
if (utils.isWindows()) {
let excludedFlag = '';
let tempFile = null;
let cmd = ['robocopy'];
cmd.push(`"${src}"`);
cmd.push(`"${dest}"`);
cmd.push('/e');
if (options.delete) cmd.push('/purge');
if (options.excluded.length) {
tempFile = `${os.tmpdir()}\\xcopy_excluded_${Date.now()}.txt`;
await fs.writeFile(tempFile, options.excluded.join('\n'));
excludedFlag = `/EXCLUDE:${tempFile}`;
cmd.push('/xd');
cmd = cmd.concat(options.excluded.map(p => `"${utils.toSystemSlashes(p)}"`).join(' '));
}
// TODO: add support for delete flag
await utils.execCommand(`xcopy /C /I /H /R /Y /S ${excludedFlag} "${src}" "${dest}"`);
if (tempFile) await fs.remove(tempFile);
await utils.execCommand(cmd.join(' '));
} else {
let excludedFlag = '';
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) {
await fs.copy(src, dest);
};