Skip to content

Commit

Permalink
chore: apply code review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
erisu committed Jan 9, 2020
1 parent 00d0949 commit 97738da
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
21 changes: 18 additions & 3 deletions bin/templates/scripts/cordova/lib/Podfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
const fs = require('fs');
const path = require('path');
const util = require('util');
const split2 = require('split2');
const events = require('cordova-common').events;
const Q = require('q');
const execa = require('execa');
Expand Down Expand Up @@ -391,9 +392,23 @@ Podfile.prototype.install = function (requirementsCheckerFunction) {
.then(toolOptions => {
events.emit('verbose', '==== pod install start ====\n');

return toolOptions.ignore
? Promise.resolve(toolOptions.ignoreMessage)
: execa('pod', ['install', '--verbose'], opts).then(({ stdout }) => stdout);
if (!toolOptions.ignore) return Promise.resolve(toolOptions.ignoreMessage);

const subprocess = execa('pod', ['install', '--verbose'], opts);

subprocess.stdout
.pipe(split2())
.on('data', line => {
events.emit('verbose', line);
});

subprocess.stderr
.pipe(split2())
.on('data', line => {
events.emit('error', line);
});

return subprocess;
})
.then((results) => {
events.emit('verbose', results);
Expand Down
6 changes: 3 additions & 3 deletions bin/templates/scripts/cordova/lib/list-devices
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ function listDevices () {
targetDeviceType = detectedDevice[0];
}
} else if (targetDeviceType && line.includes('USB Serial Number')) {
const reuslt = line.match(/"USB Serial Number" = "(.*)"/);
const result = line.match(/"USB Serial Number" = "(.*)"/);

if (reuslt && !detectedDevices.includes(reuslt[1])) {
detectedDevices.push(`${reuslt[1]} ${targetDeviceType}`);
if (result) {
detectedDevices.push(`${result[1]} ${targetDeviceType}`);
}

targetDeviceType = null;
Expand Down
9 changes: 4 additions & 5 deletions bin/templates/scripts/cordova/lib/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,11 @@ function iossimLaunch (appPath, devicetypeid, log, exit) {
.pipe(split2())
.on('data', transformOutput.bind(this, 'error'));

return (async () => {
const { stderr } = await subprocess;
const hasError = !!stderr;
subprocess.then(() => {
events.emit('log', 'Simulator successfully started via `ios-sim`.');
});

events.emit('log', `Simulator ${hasError ? 'had an error while starting' : 'successfully started'} via "ios-sim".`);
})();
return subprocess;
}

function listDevices () {
Expand Down
3 changes: 2 additions & 1 deletion tests/spec/unit/lib/list-devices.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const path = require('path');
const execa = require('execa');
const list_devices = require('../../../../bin/templates/scripts/cordova/lib/list-devices');

const sampleData = fs.readFileSync(path.resolve('tests/spec/unit/fixtures/sample-ioreg-output.txt'), 'utf-8');
const sampleData = fs.readFileSync(path.resolve(`${__dirname}/../fixtures/sample-ioreg-output.txt`), 'utf-8');

describe('cordova/lib/list-devices', () => {
describe('run method', () => {
Expand All @@ -33,6 +33,7 @@ describe('cordova/lib/list-devices', () => {
it('should trim and split standard output and return as array', () => {
return list_devices.run()
.then(results => {
expect(execa.command).toHaveBeenCalledWith('ioreg -p IOUSB -l');
expect(results.includes('THE_IPHONE_SERIAL iPhone')).toBe(true);
expect(results.includes('THE_IPAD_SERIAL iPad')).toBe(true);
});
Expand Down

0 comments on commit 97738da

Please sign in to comment.