Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add listTarget api #1602

Merged
merged 2 commits into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/Api.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,12 @@ class Api {
});
}

listTargets (options) {
return require('./check_reqs').check_android().then(() => {
return require('./run').runListDevices.call(this, options);
});
}

/**
* Cleans out the build artifacts from platform's directory, and also
* cleans out the platform www directory if called without options specified.
Expand Down
46 changes: 46 additions & 0 deletions lib/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,49 @@ module.exports.run = async function (runOptions = {}) {

return target.install(resolvedTarget, { manifest, buildResults, cordovaGradleConfigParser });
};

async function listDevices () {
events.emit('log', `\nAvailable ${this.platform} devices:`);

const { list } = require('./target');

await list().then(targets => {
const deviceIds = targets
.filter(({ type }) => type === 'device')
.map(({ id }) => id);

console.log(deviceIds.join('\n'));
}, function (err) {
console.error('ERROR: ' + err);
process.exit(2);
});
}

async function listEmulators () {
events.emit('log', `\nAvailable ${this.platform} virtual devices:`);
const emulators = require('./emulator');

await emulators.list_images().then(function (emulator_list) {
emulator_list && emulator_list.forEach(function (emu) {
console.log(emu.name);
});
}, function (err) {
console.error('ERROR: ' + err);
process.exit(2);
});
}

module.exports.runListDevices = async function (options) {
const { options: cliArgs } = options;

if (cliArgs.device) {
await listDevices.call(this);
} else if (cliArgs.emulator) {
await listEmulators.call(this);
} else {
await listDevices.call(this);
await listEmulators.call(this);
}

return true;
};