Skip to content

Commit

Permalink
Merge pull request #460 from isleofcode/feat/android-devices
Browse files Browse the repository at this point in the history
Add Android device support to start
  • Loading branch information
alexblom authored Feb 22, 2018
2 parents 70a799b + 3ecffc5 commit 1688649
Show file tree
Hide file tree
Showing 38 changed files with 574 additions and 171 deletions.
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,3 @@ before_install:
install:
- npm install
- bower install

script:
- node_modules/.bin/ember try:each --skip-cleanup
2 changes: 1 addition & 1 deletion lib/commands/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ module.exports = Command.extend({

//lets for live reload addon service
this.project.targetIsCordova = true;
this.project.CORDOVA_PLATFORM = options.platform;
this.project.CORBER_PLATFORM = options.platform;

let hook = new Hook({
project: this.project
Expand Down
31 changes: 19 additions & 12 deletions lib/commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const CreateProject = require('../tasks/create-project');
const PlatformTask = require('../targets/cordova/tasks/platform');
const logger = require('../utils/logger');
const RSVP = require('rsvp');
const _pick = require('lodash').pick;
const Promise = RSVP.Promise;

module.exports = Command.extend({
Expand All @@ -13,7 +14,9 @@ module.exports = Command.extend({
{ name: 'name', type: String },
{ name: 'cordovaid', type: String },
{ name: 'template-path', type: String },
{ name: 'platform', type: String }
{ name: 'platform', type: String },
{ name: 'crosswalk', type: Boolean, default: false },
{ name: 'uiwebview', type: Boolean, default: false }
],

getPlatforms(platformStr) {
Expand All @@ -35,39 +38,43 @@ module.exports = Command.extend({
return this.ui.prompt(promptOpts);
},

installPlatforms(platforms) {
installPlatforms(platforms, options) {
let installs = [];
let installOpts = _pick(options, 'crosswalk', 'uiwebview');
installOpts.save = true;

let addPlatform = new PlatformTask({ project: this.project });

platforms.forEach((platform) => {
logger.info(`Installing ${platform}`);
installs.push(addPlatform.run('add', platform, { save: true }));
installs.push(addPlatform.run('add', platform, installOpts));
});

return RSVP.allSettled(installs);
},

run(options) {
run(opts) {
let create = new CreateProject({
project: this.project,
ui: this.ui,
cordovaId: options.cordovaId,
name: options.name,
templatePath: options.templatePath
cordovaId: opts.cordovaId,
name: opts.name,
templatePath: opts.templatePath
});


return new Promise((resolve, reject) => {
create.run().then(() => {
if (options.platform) {
let platforms = this.getPlatforms(options.platform);
return this.installPlatforms(platforms);
if (opts.platform) {
let platforms = this.getPlatforms(opts.platform);
this.installPlatforms(platforms);
} else {
return this.promptPlatform().then((selected) => {
if (selected.platforms[0] === 'none') {
let platforms = selected.platforms;
if (platforms[0] === 'none') {
logger.success('Project created with no platforms');
} else {
return this.installPlatforms(selected.platforms).then(() => {
return this.installPlatforms(platforms, opts).then(() => {
logger.success('Project created');
});
}
Expand Down
1 change: 0 additions & 1 deletion lib/commands/platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ module.exports = Command.extend({
/* eslint-disable max-len */
availableOptions: [
{ name: 'save', type: Boolean, default: true },
{ name: 'default-webview', type: Boolean, default: false },
{ name: 'crosswalk', type: Boolean, default: false },
{ name: 'uiwebview', type: Boolean, default: false },
{ name: 'link', type: String, default: undefined }
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ module.exports = Command.extend({
//lets for live reload addon service
this.project.targetIsCordova = true;
this.project.targetIsCordovaLivereload = true;
this.project.CORDOVA_PLATFORM = opts.platform;
this.project.CORBER_PLATFORM = opts.platform;


let hook = new Hook({
Expand Down
102 changes: 63 additions & 39 deletions lib/commands/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ const CordovaRaw = require('../targets/cordova/tasks/raw');
const editXml = require('../targets/cordova/utils/edit-xml');
const getNetworkIp = require('../utils/get-network-ip');
const requireFramework = require('../utils/require-framework');
const Promise = require('rsvp').Promise;
const RSVP = require('rsvp');
const Promise = RSVP.Promise;
const flatten = require('lodash').flatten;

const listAndroidEms = require('../targets/android/tasks/list-emulators');
const listAndroidDevices = require('../targets/android/tasks/list-devices');
const AndroidTarget = require('../targets/android/target');
const listIOSEms = require('../targets/ios/tasks/list-emulators');
const IOSTarget = require('../targets/ios/target');
Expand All @@ -22,14 +24,18 @@ module.exports = Command.extend({
description: 'Run app on device/emulator /w livereload',
works: 'insideProject',

/* eslint-disable max-len */
availableOptions: [
{ name: 'platform', type: String },
{ name: 'emulator', type: String, default: '' },
{ name: 'emulatorid', type: String },
{ name: 'build', type: Boolean },
{ name: 'reload-url', type: String, aliases: ['r'] },
{ name: 'port', type: Number, aliases: ['p'] }
{ name: 'port', type: Number, aliases: ['p'] },
{ name: 'skip-framework-build', type: Boolean, default: false, aliases: ['sfb'] },
{ name: 'skip-cordova-build', type: Boolean, default: false, aliases: ['scb'] }
],
/* eslint-enable max-len */

getReloadUrl(port, reloadUrl, framework) {
if (reloadUrl) { return reloadUrl; }
Expand All @@ -42,28 +48,29 @@ module.exports = Command.extend({
return 'http://' + networkAddress + ':' + port;
},

selectEmulator(opts) {
let getEmulators = [];
if (opts.platform !== 'ios') {
getEmulators.push(listAndroidEms());
selectDevice(opts, installedPlatforms) {
let foundDevices = [];
if (opts.platform !== 'ios' && installedPlatforms.includes('android')) {
foundDevices.push(listAndroidEms());
foundDevices.push(listAndroidDevices());
}

if (opts.platform !== 'android') {
getEmulators.push(listIOSEms());
if (opts.platform !== 'android' && installedPlatforms.includes('ios')) {
foundDevices.push(listIOSEms());
}

return Promise.all(getEmulators).then((emulators) => {
emulators = flatten(emulators);
return RSVP.all(foundDevices).then((devices) => {
devices = flatten(devices);
if (opts.emulator === '') {
let promptOpts = {
type: 'list',
name: 'emulator',
message: 'Select an emulator',
name: 'device',
message: 'Select a device/emulator',
pageSize: 30,
choices: []
};

emulators.forEach((em, i) => {
devices.forEach((em, i) => {
promptOpts.choices.push({
key: i,
name: em.label(),
Expand All @@ -72,45 +79,59 @@ module.exports = Command.extend({
});

return this.ui.prompt(promptOpts).then((selected) => {
return selected.emulator;
return selected.device;
});
} else {
//Preference --emulator vs emulatorID if passed
let emulator;
let device;
if (opts.emulator) {
emulator = emulators.find(function(em) {
if (em.name === opts.emulator) { return em; }
});
} else {
emulator = emulators.find(function(em) {
if (em.id === opts.emulatorid) { return em; }
device = devices.find(function(d) {
if (d.name === opts.emulator) { return d; }
});
}

return Promise.resolve(emulator);
return Promise.resolve(device);
}
});
},

validatePlatform(installedPlatforms, targetPlatform) {
//If no target platfor mshow all installed platforms
if (targetPlatform && !installedPlatforms.includes(targetPlatform)) {
logger.error(`
You are passing platform=${targetPlatform} which is not installed.
Try running corber platform add ${targetPlatform}`);
}
},

run(opts) {
this._super.apply(this, arguments);
logger.info('Corber Starting');

return this.selectEmulator(opts).then((emulator) => {
let cdvTarget = new CordovaTarget({
project: this.project
});

let installedPlatforms = cdvTarget.installedPlatforms();
this.validatePlatform(installedPlatforms, opts.platform);

return this.selectDevice(opts, installedPlatforms).then((device) => {
//supports webpack addon
this.project.targetIsCordova = true;
this.project.CORDOVA_PLATFORM = emulator.platform;
this.project.CORBER_PLATFORM = device.platform;
this.project.targetIsCordovaLivereload = true;

cdvTarget.platform = device.platform;

let platformTarget;
if (emulator.platform === 'ios') {
if (device.platform === 'ios') {
platformTarget = new IOSTarget({
emulator: emulator,
device: device,
project: this.project
});
} else if (emulator.platform === 'android') {
} else if (device.platform === 'android') {
platformTarget = new AndroidTarget({
emulator: emulator,
device: device,
project: this.project
});
}
Expand All @@ -122,11 +143,6 @@ module.exports = Command.extend({
project: this.project
});

let cdvTarget = new CordovaTarget({
platform: emulator.platform,
project: this.project
});

let prepare = new CordovaRaw({
project: this.project,
api: 'prepare'
Expand All @@ -137,16 +153,24 @@ module.exports = Command.extend({
});

return new Promise((resolve, reject) => {
framework.validateServe(opts)
hook.run('beforeBuild')
.then(() => editXml.addNavigation(this.project, reloadUrl))
.then(() => createLivereloadShell.run(reloadUrl))
.then(() => prepare.run({ platforms: [emulator.platform] }))
.then(() => hook.run('beforeBuild'))
.then(() => cdvTarget.validateServe())
.then(() => platformTarget.build())
.then(() => framework.validateServe(opts))
.then(() => createLivereloadShell.run(reloadUrl))
.then(() => prepare.run({ platforms: [device.platform] }))
.then(function() {
if (opts.skipCordovaBuild !== true) {
return platformTarget.build();
}
})
.then(() => hook.run('afterBuild'))
.then(() => platformTarget.run())
.then(() => framework.serve(opts, this.ui))
.then(() => {
if (opts.skipFrameworkBuild !== true) {
return framework.serve(opts, this.ui);
}
})
.then(resolve).catch(reject);
});
});
Expand Down
2 changes: 1 addition & 1 deletion lib/frameworks/ember/tasks/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module.exports = Task.extend({
treeFor(treeName) {
if (treeName !== 'addon') { return; }

let platform = cloneProject.CORDOVA_PLATFORM;
let platform = cloneProject.CORBER_PLATFORM;
let projectPath = getPath(cloneProject);
let assets = cordovaAssets.getPaths(platform, projectPath);

Expand Down
4 changes: 3 additions & 1 deletion lib/frameworks/react/validators/homepage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const Task = require('../../../tasks/-task');
const path = require('path');
const getPackage = require('../../../utils/get-package');
const Promise = require('rsvp').Promise;
const chalk = require('chalk');
Expand All @@ -17,7 +18,8 @@ module.exports = Task.extend({
},

run() {
let packageJSON = getPackage(this.root);
let packagePath = path.join(this.root, 'package.json');
let packageJSON = getPackage(packagePath);
let homepage = packageJSON.homepage;

if (homepage === undefined || homepage && homepage[0] === '/') {
Expand Down
19 changes: 19 additions & 0 deletions lib/objects/device.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const CoreObject = require('core-object');

module.exports = CoreObject.extend({
id: undefined,
uuid: undefined,
name: undefined,
platform: undefined,
deviceType: undefined,
state: undefined,

label() {
let display = `${this.platform} ${this.deviceType} - ${this.name}`;
if (this.apiVersion) {
display += ` API: ${this.apiVersion}`
}

return display;
}
});
11 changes: 0 additions & 11 deletions lib/objects/emulator.js

This file was deleted.

12 changes: 0 additions & 12 deletions lib/objects/emulator/ios.js

This file was deleted.

Loading

0 comments on commit 1688649

Please sign in to comment.