1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-06-27 23:28:38 +02:00

Tools: Fixed building Android app on Windows

This commit is contained in:
Laurent Cozic
2019-10-13 01:21:56 +02:00
parent 9f5da92ab4
commit a3e7f0b5ef
2 changed files with 50 additions and 18 deletions

View File

@ -1,5 +1,5 @@
const fs = require('fs-extra'); const fs = require('fs-extra');
const { execCommand, githubRelease, githubOauthToken, fileExists, readline } = require('./tool-utils.js'); const { execCommand, execCommandWithPipes, githubRelease, githubOauthToken, fileExists } = require('./tool-utils.js');
const path = require('path'); const path = require('path');
const fetch = require('node-fetch'); const fetch = require('node-fetch');
const uriTemplate = require('uri-template'); const uriTemplate = require('uri-template');
@ -9,16 +9,16 @@ const rnDir = `${__dirname}/../ReactNativeClient`;
const rootDir = path.dirname(__dirname); const rootDir = path.dirname(__dirname);
const releaseDir = `${rootDir}/_releases`; const releaseDir = `${rootDir}/_releases`;
function wslToWinPath(wslPath) { // function wslToWinPath(wslPath) {
const s = wslPath.split('/'); // const s = wslPath.split('/');
if (s.length < 3) return s.join('\\'); // if (s.length < 3) return s.join('\\');
s.splice(0, 1); // s.splice(0, 1);
if (s[0] !== 'mnt' || s[1].length !== 1) return s.join('\\'); // if (s[0] !== 'mnt' || s[1].length !== 1) return s.join('\\');
s.splice(0, 1); // s.splice(0, 1);
s[0] = `${s[0].toUpperCase()}:`; // s[0] = `${s[0].toUpperCase()}:`;
while (s.length && !s[s.length - 1]) s.pop(); // while (s.length && !s[s.length - 1]) s.pop();
return s.join('\\'); // return s.join('\\');
} // }
function increaseGradleVersionCode(content) { function increaseGradleVersionCode(content) {
const newContent = content.replace(/versionCode\s+(\d+)/, function(a, versionCode) { const newContent = content.replace(/versionCode\s+(\d+)/, function(a, versionCode) {
@ -97,12 +97,21 @@ async function createRelease(name, tagName, version) {
// So we need to manually run the command from DOS, and then coming back here to finish the process once it's done. // So we need to manually run the command from DOS, and then coming back here to finish the process once it's done.
console.info('Run this command from DOS:'); // console.info('Run this command from DOS:');
console.info(''); // console.info('');
console.info(`cd "${wslToWinPath(rootDir)}\\ReactNativeClient\\android" && gradlew.bat ${apkBuildCmd}"`); // console.info(`cd "${wslToWinPath(rootDir)}\\ReactNativeClient\\android" && gradlew.bat ${apkBuildCmd}"`);
console.info(''); // console.info('');
await readline('Press Enter when done:'); // await readline('Press Enter when done:');
apkBuildCmd = ''; // Clear the command because we've already ran it // apkBuildCmd = ''; // Clear the command because we've already ran it
// process.chdir(`${rnDir}/android`);
// apkBuildCmd = `/mnt/c/Windows/System32/cmd.exe /c "cd ReactNativeClient\\android && gradlew.bat ${apkBuildCmd}"`;
// restoreDir = rootDir;
// apkBuildCmd = `/mnt/c/Windows/System32/cmd.exe /c "cd ReactNativeClient\\android && gradlew.bat ${apkBuildCmd}"`;
await execCommandWithPipes('/mnt/c/Windows/System32/cmd.exe', ['/c', `cd ReactNativeClient\\android && gradlew.bat ${apkBuildCmd}`]);
apkBuildCmd = '';
} else { } else {
process.chdir(`${rnDir}/android`); process.chdir(`${rnDir}/android`);
apkBuildCmd = `./gradlew ${apkBuildCmd}`; apkBuildCmd = `./gradlew ${apkBuildCmd}`;

View File

@ -4,7 +4,7 @@ toolUtils.execCommand = function(command) {
const exec = require('child_process').exec; const exec = require('child_process').exec;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
exec(command, (error, stdout) => { const child = exec(command, (error, stdout) => {
if (error) { if (error) {
if (error.signal == 'SIGTERM') { if (error.signal == 'SIGTERM') {
resolve('Process was killed'); resolve('Process was killed');
@ -15,6 +15,29 @@ toolUtils.execCommand = function(command) {
resolve(stdout.trim()); resolve(stdout.trim());
} }
}); });
child.stdout.pipe(process.stdout);
child.stderr.pipe(process.stderr);
});
};
toolUtils.execCommandWithPipes = function(executable, args) {
var spawn = require('child_process').spawn;
return new Promise((resolve, reject) => {
const child = spawn(executable, args, { stdio: 'inherit'});
child.on('error', (error) => {
reject(error);
});
child.on('close', (code) => {
if (code !== 0) {
reject(`Ended with code ${code}`);
} else {
resolve();
}
});
}); });
}; };