native-run
Advanced tools
Comparing version 0.0.14 to 0.0.15
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const json_1 = require("../utils/json"); | ||
const sdk_1 = require("./utils/sdk"); | ||
const api_1 = require("./utils/sdk/api"); | ||
async function run(args) { | ||
const sdk = await sdk_1.getSDK(); | ||
const packages = await sdk_1.findAllSDKPackages(sdk); | ||
const sdkinfo = Object.assign({}, sdk, { packages }); | ||
const apis = await api_1.getAPILevels(packages); | ||
const platforms = apis.map(api => { | ||
const schema = api_1.API_LEVEL_SCHEMAS.find(s => s.apiLevel === api.apiLevel); | ||
return Object.assign({}, api, { missingPackages: schema ? api_1.findUnsatisfiedPackages(packages, schema) : [] }); | ||
}); | ||
const sdkinfo = { | ||
root: sdk.root, | ||
avdHome: sdk.avdHome, | ||
platforms, | ||
tools: packages.filter(pkg => typeof pkg.apiLevel === 'undefined'), | ||
}; | ||
if (args.includes('--json')) { | ||
process.stdout.write(JSON.stringify(sdkinfo, undefined, 2)); | ||
process.stdout.write(json_1.stringify(sdkinfo)); | ||
return; | ||
@@ -17,13 +29,20 @@ } | ||
return ` | ||
SDK: ${sdk.root} | ||
${sdk.packages.map(p => formatSDKPackage(p)).join('')} | ||
SDK Location: ${sdk.root} | ||
AVD Home: ${sdk.avdHome} | ||
${sdk.platforms.map(platform => `${formatPlatform(platform)}\n\n`).join('\n')} | ||
Tools: | ||
${sdk.tools.map(tool => formatPackage(tool)).join('\n')} | ||
`.trim(); | ||
} | ||
function formatSDKPackage(p) { | ||
function formatPlatform(platform) { | ||
return ` | ||
Name: ${p.name} | ||
Path: ${p.path} | ||
Version: ${p.version}${p.apiLevel ? ` (API ${p.apiLevel})` : ''} | ||
Location: ${p.location} | ||
`; | ||
API Level: ${platform.apiLevel} | ||
Packages: ${platform.packages.map(p => formatPackage(p)).join('\n' + ' '.repeat(22))} | ||
${platform.missingPackages.length > 0 ? `(!) Missing Packages: ${platform.missingPackages.map(p => formatPackage(p)).join('\n' + ' '.repeat(22))}` : ''} | ||
`.trim(); | ||
} | ||
function formatPackage(p) { | ||
return `${p.name} ${p.path} ${typeof p.version === 'string' ? p.version : ''}`; | ||
} |
@@ -74,3 +74,2 @@ "use strict"; | ||
const apis = await api_1.getAPILevels(packages); | ||
const installations = []; | ||
for (const api of apis) { | ||
@@ -86,17 +85,16 @@ try { | ||
} | ||
debug('Issue with API %s: %s', api.level, e.message); | ||
installations.push({ apiLevel: api.level, packages: api.packages, errors: [e] }); | ||
debug('Issue with API %s: %s', api.apiLevel, e.message); | ||
} | ||
} | ||
throw new errors_1.AVDException('No suitable API installation found.', errors_1.ERR_UNSUITABLE_API_INSTALLATION, 1, { installations }); | ||
throw new errors_1.AVDException('No suitable API installation found.', errors_1.ERR_UNSUITABLE_API_INSTALLATION, 1); | ||
} | ||
exports.getDefaultAVDSchematic = getDefaultAVDSchematic; | ||
async function getAVDSchematicFromAPILevel(sdk, packages, api) { | ||
const schema = api_1.API_LEVEL_SCHEMAS.find(s => s.level === api.level); | ||
const schema = api_1.API_LEVEL_SCHEMAS.find(s => s.apiLevel === api.apiLevel); | ||
if (!schema) { | ||
throw new errors_1.AVDException(`Unsupported API level: ${api.level}`, errors_1.ERR_UNSUPPORTED_API_LEVEL); | ||
throw new errors_1.AVDException(`Unsupported API level: ${api.apiLevel}`, errors_1.ERR_UNSUPPORTED_API_LEVEL); | ||
} | ||
const missingPackages = api_1.findUnsatisfiedPackages(packages, schema); | ||
if (missingPackages.length > 0) { | ||
throw new errors_1.AVDException(`Unsatisfied packages within API ${api.level}: ${missingPackages.map(pkg => pkg.path).join(', ')}`, errors_1.ERR_SDK_UNSATISFIED_PACKAGES, 1, { apiLevel: api.level, missingPackages }); | ||
throw new errors_1.AVDException(`Unsatisfied packages within API ${api.apiLevel}: ${missingPackages.map(pkg => pkg.path).join(', ')}`, errors_1.ERR_SDK_UNSATISFIED_PACKAGES, 1); | ||
} | ||
@@ -103,0 +101,0 @@ return createAVDSchematic(sdk, await schema.loadPartialAVDSchematic()); |
@@ -12,23 +12,30 @@ "use strict"; | ||
].sort((a, b) => a <= b ? 1 : -1); | ||
const apiLevels = levels.map(level => ({ | ||
level, | ||
packages: packages.filter(pkg => pkg.apiLevel === level), | ||
const apis = levels.map(apiLevel => ({ | ||
apiLevel, | ||
packages: packages.filter(pkg => pkg.apiLevel === apiLevel), | ||
})); | ||
debug('Discovered installed API Levels: %O', apiLevels.map(level => (Object.assign({}, level, { packages: level.packages.map(pkg => pkg.path) })))); | ||
return apiLevels; | ||
debug('Discovered installed API Levels: %O', apis.map(api => (Object.assign({}, api, { packages: api.packages.map(pkg => pkg.path) })))); | ||
return apis; | ||
} | ||
exports.getAPILevels = getAPILevels; | ||
function findUnsatisfiedPackages(packages, schema) { | ||
return schema.packages.filter(schemaPkg => { | ||
const apiPkg = findPackageBySchemaPath(packages, schemaPkg.path); | ||
if (!apiPkg) { | ||
return true; | ||
return schema.packages.filter(pkg => !findPackageBySchema(packages, pkg)); | ||
} | ||
exports.findUnsatisfiedPackages = findUnsatisfiedPackages; | ||
function findPackageBySchema(packages, pkg) { | ||
const apiPkg = findPackageBySchemaPath(packages, pkg.path); | ||
if (apiPkg) { | ||
if (typeof pkg.version === 'string') { | ||
if (pkg.version === apiPkg.version) { | ||
return apiPkg; | ||
} | ||
} | ||
if (typeof schemaPkg.version !== 'string') { | ||
return !apiPkg.version.match(schemaPkg.version); | ||
else { | ||
if (apiPkg.version.match(pkg.version)) { | ||
return apiPkg; | ||
} | ||
} | ||
return schemaPkg.version !== apiPkg.version; | ||
}); | ||
} | ||
} | ||
exports.findUnsatisfiedPackages = findUnsatisfiedPackages; | ||
exports.findPackageBySchema = findPackageBySchema; | ||
function findPackageBySchemaPath(packages, path) { | ||
@@ -44,3 +51,3 @@ return packages.find(pkg => { | ||
exports.API_LEVEL_28 = Object.freeze({ | ||
level: '28', | ||
apiLevel: '28', | ||
packages: [ | ||
@@ -54,3 +61,3 @@ { name: 'Android Emulator', path: 'emulator', version: /.+/ }, | ||
exports.API_LEVEL_27 = Object.freeze({ | ||
level: '27', | ||
apiLevel: '27', | ||
packages: [ | ||
@@ -64,3 +71,3 @@ { name: 'Android Emulator', path: 'emulator', version: /.+/ }, | ||
exports.API_LEVEL_26 = Object.freeze({ | ||
level: '26', | ||
apiLevel: '26', | ||
packages: [ | ||
@@ -74,3 +81,3 @@ { name: 'Android Emulator', path: 'emulator', version: /.+/ }, | ||
exports.API_LEVEL_25 = Object.freeze({ | ||
level: '25', | ||
apiLevel: '25', | ||
packages: [ | ||
@@ -84,3 +91,3 @@ { name: 'Android Emulator', path: 'emulator', version: /.+/ }, | ||
exports.API_LEVEL_24 = Object.freeze({ | ||
level: '24', | ||
apiLevel: '24', | ||
packages: [ | ||
@@ -87,0 +94,0 @@ { name: 'Android Emulator', path: 'emulator', version: /.+/ }, |
@@ -6,2 +6,3 @@ "use strict"; | ||
const errors_1 = require("./errors"); | ||
const json_1 = require("./utils/json"); | ||
const debug = Debug('native-run'); | ||
@@ -64,5 +65,5 @@ async function run() { | ||
if (process.argv.includes('--json')) { | ||
return JSON.stringify(e instanceof errors_1.Exception ? e : { error: stack }, (k, v) => v instanceof RegExp ? v.toString() : v); | ||
return json_1.stringify(e instanceof errors_1.Exception ? e : { error: stack }); | ||
} | ||
return (e instanceof errors_1.Exception ? e.serialize() : stack) + '\n'; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const errors_1 = require("../errors"); | ||
const json_1 = require("./json"); | ||
function list(args, devices, virtualDevices) { | ||
@@ -21,3 +22,3 @@ const virtualOnly = args.includes('--virtual'); | ||
} | ||
return JSON.stringify(result, undefined, 2) + '\n'; | ||
return json_1.stringify(result) + '\n'; | ||
} | ||
@@ -24,0 +25,0 @@ let output = ''; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const json_1 = require("./json"); | ||
function log(message) { | ||
if (process.argv.includes('--json')) { | ||
message = JSON.stringify({ message }); | ||
message = json_1.stringify({ message }); | ||
} | ||
@@ -7,0 +8,0 @@ process.stdout.write(message); |
{ | ||
"name": "native-run", | ||
"version": "0.0.14", | ||
"version": "0.0.15", | ||
"description": "A CLI for running apps on iOS/Android devices and simulators/emulators", | ||
@@ -46,5 +46,6 @@ "bin": { | ||
"@types/debug": "0.0.31", | ||
"@types/elementtree": "^0.1.0", | ||
"@types/fs-extra": "^5.0.4", | ||
"@types/ini": "^1.3.30", | ||
"@types/jest": "^23.3.11", | ||
"@types/jest": "^23.3.13", | ||
"@types/node": "^8.10.39", | ||
@@ -55,8 +56,8 @@ "@types/split2": "^2.1.6", | ||
"husky": "^1.3.1", | ||
"jest": "^23.5.0", | ||
"jest-cli": "^23.5.0", | ||
"jest": "^24.0.0", | ||
"jest-cli": "^24.0.0", | ||
"ts-jest": "^23.10.5", | ||
"tslint": "^5.12.0", | ||
"tslint": "^5.12.1", | ||
"tslint-ionic-rules": "0.0.21", | ||
"typescript": "^3.2.2" | ||
"typescript": "^3.2.4" | ||
}, | ||
@@ -63,0 +64,0 @@ "keywords": [ |
114895
44
2823
16