Skip to content

Commit

Permalink
Merge pull request #93 from Samsung/verbose
Browse files Browse the repository at this point in the history
Verbose feature
  • Loading branch information
pwsses authored Jan 13, 2021
2 parents 807fd7a + 35398b8 commit aa46cc1
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 42 deletions.
3 changes: 3 additions & 0 deletions command/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ async function supportDeviceIpOption(data, option) {

if (optionDeviceIp) {
data.deviceIp = optionDeviceIp;
logger.log(
chalk.cyanBright(`WITs tries connecting with ${optionDeviceIp}\n`)
);
await userInfoHelper.updateLatestUserAnswer({
deviceIp: optionDeviceIp
});
Expand Down
3 changes: 3 additions & 0 deletions command/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ async function supportDeviceIpOption(data, option) {

if (optionDeviceIp) {
data.deviceIp = optionDeviceIp;
logger.log(
chalk.cyanBright(`WITs tries connecting with ${optionDeviceIp}\n`)
);
await userInfoHelper.updateLatestUserAnswer({
deviceIp: optionDeviceIp
});
Expand Down
65 changes: 52 additions & 13 deletions lib/appLaunchHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,30 @@ module.exports = {
)}" "${appInstallPath}"`;
const APP_INSTALL_COMMAND = `${util.TOOLS_SDB_PATH} -s ${deviceName} shell 0 vd_appinstall ${hostAppName} ${appInstallPath}${WITS_PACKAGE}`;

execSync(WGT_FILE_PUSH_COMMAND, { silent: true });
const result = execSync(APP_INSTALL_COMMAND).toString();
const pushResult = execSync(WGT_FILE_PUSH_COMMAND, {
encoding: 'utf-8',
stdio: 'pipe'
});
util.displayOutput(pushResult);

if (result.includes('failed[')) {
const installResult = execSync(APP_INSTALL_COMMAND, {
encoding: 'utf-8',
stdio: 'pipe'
});
util.displayOutput(installResult);

if (installResult.includes('failed[')) {
logger.error(chalk.red(`\nFailed to install Wits`));
util.exit();
}
},
unInstallPackage: (deviceName, hostAppName) => {
const APP_UNINSTALL_COMMAND = `${util.TOOLS_SDB_PATH} -s ${deviceName} shell 0 vd_appuninstall ${hostAppName}`;
const result = execSync(APP_UNINSTALL_COMMAND, {
silent: true
}).toString();
encoding: 'utf-8',
stdio: 'pipe'
});
util.displayOutput(result);

if (result.includes('failed[')) {
logger.warn(`\n[warning] Failed to uninstall Wits`);
Expand All @@ -43,7 +54,12 @@ module.exports = {
launchApp: (deviceName, hostAppId) => {
const APP_LAUNCH_COMMAND = `${util.TOOLS_SDB_PATH} -s ${deviceName} shell 0 was_execute ${hostAppId}`;

const result = execSync(APP_LAUNCH_COMMAND).toString();
const result = execSync(APP_LAUNCH_COMMAND, {
encoding: 'utf-8',
stdio: 'pipe'
});
util.displayOutput(result);

if (result === null || result.includes('failed[')) {
throw new Error(
'Failed to launchApp. Please check the application is already installed on the Target.'
Expand All @@ -55,8 +71,16 @@ module.exports = {
const APP_LAUNCH_DEBUG_MODE_COMMAND_TIMEOUT = `${APP_LAUNCH_DEBUG_MODE_COMMAND} 300`;

const result =
execSync(APP_LAUNCH_DEBUG_MODE_COMMAND).toString() ||
execSync(APP_LAUNCH_DEBUG_MODE_COMMAND_TIMEOUT).toString();
execSync(APP_LAUNCH_DEBUG_MODE_COMMAND, {
encoding: 'utf-8',
stdio: 'pipe'
}) ||
execSync(APP_LAUNCH_DEBUG_MODE_COMMAND_TIMEOUT, {
encoding: 'utf-8',
stdio: 'pipe'
});
util.displayOutput(result);

if (result === null || result.includes('failed')) {
throw new Error(
'Failed to launchDebugMode. Please check the application is already installed on the Target.'
Expand Down Expand Up @@ -85,18 +109,33 @@ module.exports = {
},
terminateApp: (deviceName, hostAppId) => {
const APP_TERMINATE_COMMAND = `${util.TOOLS_SDB_PATH} -s ${deviceName} shell 0 was_kill ${hostAppId}`;
execSync(APP_TERMINATE_COMMAND, { silent: true });
const result = execSync(APP_TERMINATE_COMMAND, {
encoding: 'utf-8',
stdio: 'pipe'
});
util.displayOutput(result);
}
};

function setPortForward(deviceName, port) {
const LOCAL_HOST = '127.0.0.1';
execSync(
`${util.TOOLS_SDB_PATH} -s ${deviceName} forward --remove tcp:${port}`
const removeResult = execSync(
`${util.TOOLS_SDB_PATH} -s ${deviceName} forward --remove tcp:${port}`,
{
encoding: 'utf-8',
stdio: 'pipe'
}
);
execSync(
`${util.TOOLS_SDB_PATH} -s ${deviceName} forward tcp:${port} tcp:${port}`
util.displayOutput(removeResult);

const tcpResult = execSync(
`${util.TOOLS_SDB_PATH} -s ${deviceName} forward tcp:${port} tcp:${port}`,
{
encoding: 'utf-8',
stdio: 'pipe'
}
);
util.displayOutput(tcpResult);
try {
launchChrome(LOCAL_HOST + ':' + port);
} catch (e) {
Expand Down
30 changes: 23 additions & 7 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const commander = require('commander');
const program = new commander.Command();
const package = require('../package.json');
const { logger } = require('./logger');

const util = require('./util.js');

Expand All @@ -15,29 +16,31 @@ process.on('SIGINT', () => {

util.displayBanner();

program.version(`wits v${package.version}`);
program.option('-i, --init', 'Set configuration for running WITs');
program.version(`wits v${package.version}`, '-v, --version', 'WITs version');
program.allowUnknownOption();

program.option('-i, --init', 'Set configuration for running WITs.');
program.option(
'-c, --certificate',
'Generate a certification for signing Tizen web app'
'Generate a certification for signing Tizen web app. You can set a log level for debugging. ex) wits -c --verbose'
);
program.option(
'-s, --start [deviceIp]',
'Install, launch app and enable live reload feature in a sequence. ex) wits -s / wits -s deviceIp=192.168.250.250'
'Install, launch app and enable live reload feature in a sequence. ex) wits -s / wits -s deviceIp=192.168.250.250 / wits -s --verbose'
);
program.option(
'-w, --watch [deviceIp]',
'Launch app and enable live reload feature without reinstalling. ex) wits -w / wits -w deviceIp=192.168.250.250'
'Launch app and enable live reload feature without reinstalling. ex) wits -w / wits -w deviceIp=192.168.250.250 / wits -w --verbose'
);

program.parse(process.argv);
util.ISVERVOSE = checkVerbose(process.argv);

if (program.init) {
const initCommand = require('../command/init.js');
initCommand.run();
} else if (program.certificate) {
const certificateCommand = require('../command/certificate.js');
certificateCommand.run();
certificateCommand.run(program.certificate);
} else if (program.start) {
const startCommand = require('../command/start.js');
startCommand.run(program.start);
Expand All @@ -47,3 +50,16 @@ if (program.init) {
} else {
program.help();
}

function checkVerbose(arguments) {
const last = arguments.length - 1;
if (arguments.includes('--verbose')) {
if (arguments[last] !== '--verbose') {
logger.log(
`[Warning] Please check the options' order. "--verbose" should be at the end of command.`
);
}
return true;
}
return false;
}
21 changes: 14 additions & 7 deletions lib/deviceConnectHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ module.exports = {
if (deviceIpAddress !== EMULATOR_IP) {
logger.log(`connect to....${deviceIpAddress}`);
const CONNECT_TV_COMMAND = `${util.TOOLS_SDB_PATH} connect ${deviceIpAddress}:${TV_CONNECT_PORT}`;
const connectResult = execSync(CONNECT_TV_COMMAND).toString();
const connectResult = execSync(CONNECT_TV_COMMAND, {
encoding: 'utf-8',
stdio: 'pipe'
});
util.displayOutput(connectResult);

if (connectResult.includes('connected')) {
logger.log(`Success to connect ${deviceIpAddress}`);
Expand Down Expand Up @@ -67,11 +71,11 @@ module.exports = {

const capability = execSync(
`${util.TOOLS_SDB_PATH} -s ${deviceName} capability`,
{ silent: true }
)
.toString()
.split('\n');
{ encoding: 'utf-8', stdio: 'pipe' }
).split('\n');

capability.forEach(value => {
util.displayOutput(value);
if (value.indexOf('sdk_toolpath') !== -1) {
appInstallPath =
value.replace(regExp.FIND_CR, '').split(':')[1] + '/';
Expand All @@ -83,8 +87,11 @@ module.exports = {

function getConnectedDeviceList(deviceIpAddress) {
const devices = execSync(`${util.TOOLS_SDB_PATH} devices`, {
silent: true
}).toString();
encoding: 'utf-8',
stdio: 'pipe'
});
util.displayOutput(devices);

let devicesInfo = [];
let deviceNameList = [];
if (!devices.includes('offline')) {
Expand Down
6 changes: 6 additions & 0 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module.exports = {
RESOURCE_PATH: path.resolve(__dirname, '../', 'resource'),
TOOLS_SDB_PATH: '',
PLATFORM: platform,
ISVERVOSE: false,
initTools: async () => {
module.exports.TOOLS_SDB_PATH = await tools.getSdbPath();
},
Expand Down Expand Up @@ -135,6 +136,11 @@ module.exports = {
return data.replace(regExp.COMMENT, '');
},

displayOutput: logs => {
if (module.exports.ISVERVOSE === true) {
logger.log(logs);
}
},
getSocketPort: () => {
const REMIND_SOCKET_PORT_LEN = 3;
const MAX_DIGIT = 9;
Expand Down
39 changes: 25 additions & 14 deletions lib/watchHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,11 @@ function pushFile(baseAppPath, hostAppPath, filesInfo) {
const CONTENT_FILE_PUSH_COMMAND = `${util.TOOLS_SDB_PATH} -s ${deviceName} push "${filePath}" "${hostAppPath}${fileName}"`;
const pushResult = exec(CONTENT_FILE_PUSH_COMMAND, {
async: true,
silent: true
encoding: 'utf-8',
stdio: 'pipe'
});
// util.displayOutput(pushResult);

pushResult.stderr.on('data', data => {
const COMPATIBILITY_ERROR = 'version compatibility problems';
if (!data.includes(COMPATIBILITY_ERROR)) {
Expand Down Expand Up @@ -225,19 +228,25 @@ function pushUpdated(basePath, destPath, filePath) {
}
}
const UPDATE_FILE_PUSH_COMMAND = `${util.TOOLS_SDB_PATH} -s ${deviceName} push "${fileFullPath}" "${destPath}${filePath}"`;
exec(UPDATE_FILE_PUSH_COMMAND, (code, stdout, stderr) => {
if (stderr) {
const COMPATIBILITY_ERROR = 'version compatibility problems';
if (!stderr.includes(COMPATIBILITY_ERROR)) {
logger.log(`Failed ${stderr}`);
util.exit();
const result = exec(
UPDATE_FILE_PUSH_COMMAND,
{ encoding: 'utf-8', stdio: 'pipe' },
(code, stdout, stderr) => {
if (stderr) {
const COMPATIBILITY_ERROR = 'version compatibility problems';
if (!stderr.includes(COMPATIBILITY_ERROR)) {
logger.log(`Failed ${stderr}`);
util.exit();
}
}
logger.log(`Program output : ${stdout}`);
if (stdout.includes('file(s) pushed')) {
mediator.emit('changed');
}
}
logger.log(`Program output : ${stdout}`);
if (stdout.includes('file(s) pushed')) {
mediator.emit('changed');
}
});
);

// util.displayOutput(result);
}

function emitRemoved(basePath, destPath, filePath) {
Expand Down Expand Up @@ -269,10 +278,12 @@ function pushFsWrapperFile(hostAppPath) {
.join(util.WITS_BASE_PATH, WRAPPER_FILE)
.replace(regExp.BACKSLASH, '/');
const WRAPPER_FILE_PUSH_COMMAND = `${util.TOOLS_SDB_PATH} -s ${deviceName} push "${WRAPPER_FILE_PATH}" "${hostAppPath}/${WRAPPER_FILE}"`;
exec(WRAPPER_FILE_PUSH_COMMAND, {
const result = exec(WRAPPER_FILE_PUSH_COMMAND, {
async: true,
silent: true
encoding: 'utf-8',
stdio: 'pipe'
});
// util.displayOutput(result);
}

function getWrappedContentFiles(filePath, fileName) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tizentv/wits",
"version": "2.4.8",
"version": "2.5.0",
"description": "Instant live reload tool for Tizen Web Application development",
"main": "index.js",
"author": "Samsung Electronics Co., Ltd.",
Expand Down

0 comments on commit aa46cc1

Please sign in to comment.