diff --git a/command/start.js b/command/start.js index 42631b1..965e8c6 100644 --- a/command/start.js +++ b/command/start.js @@ -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 }); diff --git a/command/watch.js b/command/watch.js index 657dd49..141bb6c 100644 --- a/command/watch.js +++ b/command/watch.js @@ -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 }); diff --git a/lib/appLaunchHelper.js b/lib/appLaunchHelper.js index e64f950..82fc168 100644 --- a/lib/appLaunchHelper.js +++ b/lib/appLaunchHelper.js @@ -22,10 +22,19 @@ 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(); } @@ -33,8 +42,10 @@ module.exports = { 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`); @@ -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.' @@ -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.' @@ -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) { diff --git a/lib/cli.js b/lib/cli.js index 2c3c0c6..b1964f8 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -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'); @@ -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); @@ -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; +} diff --git a/lib/deviceConnectHelper.js b/lib/deviceConnectHelper.js index 287ed61..339a603 100644 --- a/lib/deviceConnectHelper.js +++ b/lib/deviceConnectHelper.js @@ -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}`); @@ -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] + '/'; @@ -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')) { diff --git a/lib/util.js b/lib/util.js index 8b4a690..abd84ba 100644 --- a/lib/util.js +++ b/lib/util.js @@ -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(); }, @@ -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; diff --git a/lib/watchHelper.js b/lib/watchHelper.js index 436bc82..89ba3dc 100644 --- a/lib/watchHelper.js +++ b/lib/watchHelper.js @@ -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)) { @@ -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) { @@ -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) { diff --git a/package.json b/package.json index f1af20a..4e1a625 100644 --- a/package.json +++ b/package.json @@ -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.",