Skip to content

Commit

Permalink
Version 2.2.2
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 82b121f4866bb649b51e5dc239ce38081f705b75
  • Loading branch information
Interfaced authored and l1bbcsg committed Feb 3, 2020
1 parent 3f29a4e commit 1bfa523
Show file tree
Hide file tree
Showing 19 changed files with 520 additions and 236 deletions.
25 changes: 23 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
const currentYear = (new Date).getFullYear();
const copyrightHeader = [
'',
' * This file is part of the ZombieBox package.',
' *',
` * Copyright © 2014-${currentYear}, Interfaced`,
' *',
' * For the full copyright and license information, please view the LICENSE',
' * file that was distributed with this source code.',
' '
];

module.exports = {
extends: 'interfaced',
plugins: [
'header'
],
overrides: [
{
files: ['lib/**/*.js'],
extends: 'interfaced/esm',
settings: {
'import/resolver': 'zombiebox'
'import/resolver': 'zombiebox',
},
rules: {
'header/header': ['error', 'block', copyrightHeader]
},
globals: {
// see externs
Expand All @@ -15,7 +33,10 @@ module.exports = {
},
{
files: ['index.js', 'cli/**/*.js'],
extends: 'interfaced/node'
extends: 'interfaced/node',
rules: {
'header/header': ['error', 'block', copyrightHeader]
}
},
{
files: ['externs/**/*.js'],
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 2.2.2 (03.02.2020)
* Support ZombieBox 2.6
* Better logging and output

## 2.2.1 (17.01.2020)
* Init gracefully if some platform data could not be fetched.

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright © 2014-2019 Interfaced
Copyright © 2014-2020 Interfaced

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
Expand Down
12 changes: 2 additions & 10 deletions cli/ares.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of the ZombieBox package.
*
* Copyright (c) 2014-2019, Interfaced
* Copyright © 2014-2020, Interfaced
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down Expand Up @@ -40,10 +40,7 @@ async function exec(toolsDir, command, args, expectedSuccessMessage) {
);

if (expectedSuccessMessage && !result.stdout.includes(expectedSuccessMessage)) {
console.log(result.stdout);
console.error(result.stderr);

throw new Error(`${command} failed`);
throw new Error(`${command} failed\n${result.stdout}\n${result.stderr}`);
}

return result.all;
Expand Down Expand Up @@ -78,8 +75,6 @@ async function build(toolsDir, srcDir, outDir = srcDir) {
'ares-package',
[srcDir, '--outdir', outDir, '--no-minify']
);

console.log(`The ipk package was built into ${outDir}`);
}


Expand All @@ -96,7 +91,6 @@ async function install(toolsDir, ipk, deviceName) {
[ipk, '-d', deviceName],
'Success'
);
console.log(`Installed ${path.basename(ipk)}`);
}


Expand All @@ -113,7 +107,6 @@ async function launch(toolsDir, appId, deviceName) {
[appId, '-d', deviceName],
'Launched'
);
console.log(`Launched ${appId}`);
}


Expand Down Expand Up @@ -151,7 +144,6 @@ async function uninstall(toolsDir, appId, deviceName) {
'ares-install',
['-d', deviceName, '--remove', appId]
);
console.log(`Uninstalled ${appId}`);
}


Expand Down
106 changes: 54 additions & 52 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of the ZombieBox package.
*
* Copyright (c) 2014-2019, Interfaced
* Copyright © 2014-2020, Interfaced
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -12,7 +12,7 @@ const fse = require('fs-extra');
const imageSize = require('image-size');
const path = require('path');
const inquirer = require('inquirer');
const {AbstractPlatform, utils: {mergeConfigs}} = require('zombiebox');
const {AbstractPlatform, utils: {mergeConfigs}, logger: zbLogger} = require('zombiebox');
const {
getInstalledApps,
build,
Expand All @@ -22,6 +22,8 @@ const {
uninstall
} = require('./cli/ares');

const logger = zbLogger.createChild('webOS');


/**
*/
Expand Down Expand Up @@ -83,6 +85,8 @@ class PlatformWebOS extends AbstractPlatform {
const selectAppFromDevice = async (toolsDir, deviceName) => {
const installedApps = await getInstalledApps(toolsDir, deviceName);

logger.silly(`Installed apps: ${installedApps.join(', ')}`);

if (!installedApps.length) {
throw new Error('No apps installed on device');
}
Expand All @@ -97,13 +101,6 @@ class PlatformWebOS extends AbstractPlatform {
return appId;
};

const logify = (promise) => promise
.catch((error) => {
if (error) {
console.error(error.message);
}
});

/**
* @param {Yargs} yargs
* @return {Yargs}
Expand All @@ -121,14 +118,14 @@ class PlatformWebOS extends AbstractPlatform {
.middleware(
async (argv) => {
if (!argv.appId) {
console.info('Application identifier was not provided.');
logger.info('Application identifier was not provided.');

try {
argv.appId = await this._findAppId(distPath);

console.warn(`Using application ID ${argv.appId} from local build folder`);
logger.info(`Using application ID ${argv.appId} from local build folder`);
} catch (e) {
console.error(`Could not extract application ID from local build: ${e.message}`);
logger.error(`Could not extract application ID from local build: ${e.message}`);

argv.appId = await selectAppFromDevice(toolsDir, argv.device);
}
Expand All @@ -152,9 +149,13 @@ class PlatformWebOS extends AbstractPlatform {
'Install app on a device',
demandDevice,
async ({device}) => {
logger.verbose(`Installing application`);
const ipk = await this._findIpk(distPath);

logify(install(toolsDir, ipk, device));
logger.debug(`Found ipk file: ${ipk}`);

await install(toolsDir, ipk, device);
logger.info(`Installation successful`);
}
)
.command(
Expand All @@ -164,7 +165,11 @@ class PlatformWebOS extends AbstractPlatform {
demandDevice(yargs);
demandAppId(yargs);
},
({device, appId}) => logify(launch(toolsDir, appId, device))
async ({device, appId}) => {
logger.verbose(`Launching ${appId} on ${device}`);
await launch(toolsDir, appId, device);
logger.info(`Application launched`);
}
)
.command(
'inspect <device> [appId]',
Expand All @@ -173,7 +178,10 @@ class PlatformWebOS extends AbstractPlatform {
demandDevice(yargs);
demandAppId(yargs);
},
({device, appId}) => logify(inspect(toolsDir, appId, device))
async ({device, appId}) => {
logger.verbose(`Starting ${appId} on ${device} with inspector`);
await inspect(toolsDir, appId, device);
}
)
.command(
'uninstall <device> [appId]',
Expand All @@ -182,22 +190,23 @@ class PlatformWebOS extends AbstractPlatform {
demandDevice(yargs);
demandAppId(yargs);
},
({device, appId}) => logify(uninstall(toolsDir, appId, device))
async ({device, appId}) => {
logger.verbose(`Uninstalling ${appId} from ${device}`);
await uninstall(toolsDir, appId, device);
logger.info(`Application uninstalled`);
}
)
.command(
'list <device>',
'List installed applications on a device',
demandDevice,
async ({device}) => {
const apps = await logify(getInstalledApps(toolsDir, device));
if (!apps) {
return;
}
logger.verbose(`Querying installed apps on ${device}`);
const apps = await getInstalledApps(toolsDir, device);
if (apps.length) {
console.log('Installed applications:');
console.log(apps.join('\n'));
logger.output(`Installed applications: \n\t${apps.join('\n\t')}`);
} else {
console.log('No apps installed');
logger.output('No apps installed');
}
}
)
Expand All @@ -206,10 +215,11 @@ class PlatformWebOS extends AbstractPlatform {
'Remove all installed apps from a device',
demandDevice,
async ({device}) => {
logger.verbose(`Cleaning installed apps from ${device}`);
const installedApps = await getInstalledApps(toolsDir, device);

if (!installedApps.length) {
console.log('No apps installed');
logger.output('No apps installed, nothing to clean');
return;
}

Expand All @@ -221,37 +231,38 @@ class PlatformWebOS extends AbstractPlatform {
default: installedApps
});

return Promise.all(confirmed.map((appId) => logify(uninstall(toolsDir, appId, device))));
await Promise.all(confirmed.map((appId) => uninstall(toolsDir, appId, device)));
logger.info(`Cleanup done`);
}
)
.demandCommand(1, 1, 'No command specified');
.demandCommand(1, 1, 'No command specified')
.fail((message, error) => {
if (message) {
logger.error(message);
}
if (error instanceof Error) {
logger.error(error.toString());
logger.debug(error.stack);
}
process.exit(1);
});
}

/**
* @override
*/
async buildApp(app, distDir) {
/**
* @type {Array<string>}
*/
const warnings = [];
const buildHelper = app.getBuildHelper();
async pack(app, distDir) {
const config = app.getConfig();
const {name, version} = app.getAppPackageJson();
/**
* @type {PlatformWebOS.Config}
*/
const originalUserConfig = config.platforms.webos;

warnings.push(
await buildHelper.writeIndexHTML(path.join(distDir, 'index.html'))
);

const defaultAppInfo = this._createDefaultAppInfo(name, version);

const userImgConfig = await this._createUserImgConfig(originalUserConfig.img);
const {images, warnings: imagesCheckWarnings} = await this._checkAndFilterImages(userImgConfig);
warnings.push(imagesCheckWarnings.join('\n'));
const images = await this._checkAndFilterImages(userImgConfig);

const defaultImgConfig = this._generateDefaultImageFullPathObject(__dirname);
const resultImgConfig = mergeConfigs(defaultImgConfig, images);
Expand All @@ -264,13 +275,9 @@ class PlatformWebOS extends AbstractPlatform {
PlatformWebOS.ImageDistPath
);

buildHelper.copyStaticFiles(distDir);

await fse.writeJson(path.join(distDir, 'appinfo.json'), resultAppInfo);

await build(config.platforms.webos.toolsDir, distDir);

return warnings.filter(Boolean).join('\n');
}

/**
Expand Down Expand Up @@ -314,10 +321,7 @@ class PlatformWebOS extends AbstractPlatform {

/**
* @param {Object<string, string>} files
* @return {{
* images: Object<PlatformWebOS.ImageName, string>,
* warnings: Array<string>
* }}
* @return {Object<PlatformWebOS.ImageName, string>}
* @protected
*/
async _checkAndFilterImages(files) {
Expand Down Expand Up @@ -384,16 +388,13 @@ class PlatformWebOS extends AbstractPlatform {
try {
await check(createImageChecks(imageName, imagePath));

accumulator.images[imageName] = imagePath;
accumulator[imageName] = imagePath;
} catch (warning) {
accumulator.warnings.push(warning);
logger.warn(warning);
}

return Promise.resolve(accumulator);
}, Promise.resolve({
images: {},
warnings: []
}));
}, Promise.resolve({}));
}

/**
Expand Down Expand Up @@ -437,6 +438,7 @@ class PlatformWebOS extends AbstractPlatform {
.map((sourcePath) => {
const destinationPath = path.join(imagesDist, path.basename(sourcePath));

logger.silly(`Copying, ${sourcePath} to ${destinationPath}`);
return fse.copy(sourcePath, destinationPath);
});

Expand Down
8 changes: 8 additions & 0 deletions lib/abstract-drm-hook.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
/*
* This file is part of the ZombieBox package.
*
* Copyright © 2014-2020, Interfaced
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import EventPublisher from 'zb/events/event-publisher';
import {Type} from 'zb/device/drm/drm';
import IDrmClient from 'zb/device/interfaces/i-drm-client';
Expand Down
2 changes: 1 addition & 1 deletion lib/device.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of the ZombieBox package.
*
* Copyright © 2014-2019, Interfaced
* Copyright © 2014-2020, Interfaced
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
Loading

0 comments on commit 1bfa523

Please sign in to comment.