Skip to content

Commit

Permalink
Merge pull request #76 from Samsung/logger
Browse files Browse the repository at this point in the history
Add the logger.js to support multiple output
  • Loading branch information
prozanne authored Oct 27, 2020
2 parents 081f979 + c7ee698 commit 6adbec0
Show file tree
Hide file tree
Showing 14 changed files with 211 additions and 129 deletions.
51 changes: 27 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,34 +88,55 @@ We will not describe how to do these installations as there are many ways to do

.witsconfig.json, .witsignore files are only added at the your tizen web application.

### WITs command options
### WITs CLI

#### 1. `wits`
#### `wits`

For showing which options you can use

#### 2. `wits -i` / `wits --init`
#### `wits -i` / `wits --init`

For configuring WITs
Please note that, It should be run when you use first time on your tizen application project.
.witsconfig.json and .witsignore files are generated on your tizen app project.
After then, you can modify your information to them.

#### 3. `wits -c` / `wits --certificate`
![witsi](https://user-images.githubusercontent.com/1733182/77503919-3ddef280-6ea2-11ea-9bb4-06f3cb9ebbc6.gif)

#### `wits -c` / `wits --certificate`

For creating a certification(Supported Tizen certification only).
As following steps, you can create a certification on `~/{path-to}/wits/resource/profiles.xml`.

#### 4. `wits -s` / `wits --start`
![witsc](https://user-images.githubusercontent.com/1733182/92706471-7fe7ec00-f38f-11ea-8d47-47b13f956906.gif)

#### `wits -s` / `wits --start`

All in one. For connecting to TV, installing and launching your app and using Live Reload
If `wits -i` hasn't run before, It is not allowed to run.

#### 5. `wits -w` / `wits --watch`
![witss](https://user-images.githubusercontent.com/1733182/77503927-420b1000-6ea2-11ea-88f5-49ab0c5fc227.gif)

#### `wits -w` / `wits --watch`

For conneting to TV, using Live Reload
After connecting, every time you make changes on `your tizen app project`, It is reflected to TV device instantly.

![witsw](https://user-images.githubusercontent.com/1733182/77503928-43d4d380-6ea2-11ea-8ece-4f5182cb7d6d.gif)

### WITs API

WITs supports the following APIs

- [setWitsconfigInfo(WitsInfoData data)](https://github.com/Samsung/Wits/wiki/How-to-use-WITs-as-APIs#setwitsconfiginfo) : This API is for setting WITs environment, It should be called before start function or watch function.
- [start()](https://github.com/Samsung/Wits/wiki/How-to-use-WITs-as-APIs#start) : This API is a sequence for building and installing your application, connecting PC and Target TV, pushing files, supporting live-reload feature.
- [watch()](https://github.com/Samsung/Wits/wiki/How-to-use-WITs-as-APIs#watch) : This API is a sequence for connecting PC and Target TV, pushing files, supporting live-reload feature. (Except for re-building and re-installing your application.)
- [disconnect()](https://github.com/Samsung/Wits/wiki/How-to-use-WITs-as-APIs#disconnect) : This API is for disconnecting communications between PC and Target TV.
- [setOutputChannel(OutputCallback callback)](https://github.com/Samsung/Wits/wiki/How-to-use-WITs-as-APIs#setoutputchannel) : This is for getting WITs' log information. The return value is integer value between 1000 and 9999, and this value will be used to unsetOutputChannel().
- [unsetOutputChannel()](https://github.com/Samsung/Wits/wiki/How-to-use-WITs-as-APIs#unsetoutputchannel) : This is for unregistering the output callback. Call the unsetOutputChannel() with the return value of the setOutputChannel().

For detail, check whole APIs in [How to use WITs as APIs](https://github.com/Samsung/Wits/wiki/How-to-use-WITs-as-APIs).

### .witsconfig.json of WITs

For details, [Sample data for .witsconfig.json](https://github.com/Samsung/Wits/wiki/Set-Wits-Environment#data-structure-of-witsconfigjson)
Expand Down Expand Up @@ -145,24 +166,6 @@ deprecated
stglib
```

## Running Your App

### wits -i

![witsi](https://user-images.githubusercontent.com/1733182/77503919-3ddef280-6ea2-11ea-9bb4-06f3cb9ebbc6.gif)

### wits -c

![witsc](https://user-images.githubusercontent.com/1733182/92706471-7fe7ec00-f38f-11ea-8d47-47b13f956906.gif)

### wits -s

![witss](https://user-images.githubusercontent.com/1733182/77503927-420b1000-6ea2-11ea-88f5-49ab0c5fc227.gif)

### wits -w

![witsw](https://user-images.githubusercontent.com/1733182/77503928-43d4d380-6ea2-11ea-8ece-4f5182cb7d6d.gif)

## FAQ

- [WITs FAQ](https://github.com/Samsung/Wits/wiki/Frequently-Asked-Questions)
Expand Down
11 changes: 6 additions & 5 deletions command/certificate.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ const common = require('@tizentv/webide-common-tizentv');
const chalk = require('chalk');
const util = require('../lib/util');
const path = require('path');
const { logger } = require('../lib/logger');

module.exports = {
run: async () => {
console.log(chalk.cyanBright('Generate a certification............\n'));
logger.log(chalk.cyanBright('Generate a certification............\n'));

const resourceDir = util.RESOURCE_PATH;

Expand All @@ -33,7 +34,7 @@ module.exports = {
emailInfo: certInfo.emailInfo ? certInfo.emailInfo : ''
};
tizenCertManager.createCert(authorInfo);
console.log(
logger.log(
chalk.cyanBright(
'[Certification] Completed to generate a Tizen certification'
)
Expand All @@ -59,23 +60,23 @@ module.exports = {
authorProfile,
distributorProfile
);
console.log(
logger.log(
chalk.cyanBright(
'[Certification] Completed to register a profile'
)
);

profileManager.setActivateProfile(profileName);

console.log(
logger.log(
chalk.cyanBright(
`[Certification] Completed to genarate a certification. ${path.resolve(
path.join(resourceDir, 'profiles.xml')
)}. Please "wits -i" to config your profile path.`
)
);
} catch (e) {
console.error(chalk.red(`[Certification] Failed to run: ${e}`));
logger.error(chalk.red(`[Certification] Failed to run: ${e}`));
}
}
};
17 changes: 9 additions & 8 deletions command/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ const chalk = require('chalk');
const xml2js = require('xml2js');
const util = require('../lib/util.js');
const userInfoHelper = require('../lib/userInfoHelper.js');
const { logger } = require('../lib/logger');

let WITSCONFIG_PATH = '';
let WITSIGNORE_PATH = '';

module.exports = {
run: async () => {
console.log(
logger.log(
chalk.cyanBright(`Start configuration for Wits............\n`)
);

Expand All @@ -20,7 +21,7 @@ module.exports = {
const wInfo = userInfoHelper.getRefinedData();
await userInfoHelper.askQuestion(wInfo.connectionInfo);
} catch (e) {
console.error(chalk.red(`Failed to run: ${e}`));
logger.error(chalk.red(`Failed to run: ${e}`));
}
},
prepareConfigure: async () => {
Expand Down Expand Up @@ -66,27 +67,27 @@ module.exports = {
function makeWitsignoreFile() {
try {
if (util.isFileExist(WITSIGNORE_PATH)) {
console.log('.witsignore is already exist.');
logger.log('.witsignore is already exist.');
return;
}

util.createEmptyFile(WITSIGNORE_PATH, 'node_modules');
console.log('witsignore is prepared.');
logger.log('witsignore is prepared.');
} catch (error) {
console.error(chalk.red(`Failed to makeWitsignoreFile ${error}`));
logger.error(chalk.red(`Failed to makeWitsignoreFile ${error}`));
}
}

function makeWitsconfigFile() {
try {
if (util.isFileExist(WITSCONFIG_PATH) && isExistCustomFile()) {
console.log('.witsconfig.json is already exist.');
logger.log('.witsconfig.json is already exist.');
return;
}
util.createEmptyFile(WITSCONFIG_PATH, '{}');
console.log('.witsconfig.json is prepared.');
logger.log('.witsconfig.json is prepared.');
} catch (error) {
console.error(chalk.red(`Failed to makeWitsconfigFile ${error}`));
logger.error(chalk.red(`Failed to makeWitsconfigFile ${error}`));
}
}

Expand Down
11 changes: 6 additions & 5 deletions command/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ const userInfoHelper = require('../lib/userInfoHelper.js');
const hostAppHelper = require('../lib/hostAppHelper.js');
const appLaunchHelper = require('../lib/appLaunchHelper.js');
const watchHelper = require('../lib/watchHelper.js');
const { logger } = require('../lib/logger');

module.exports = {
run: async () => {
console.log(chalk.cyanBright(`Start running Wits............\n`));
logger.log(chalk.cyanBright(`Start running Wits............\n`));

await util.initTools();

Expand All @@ -17,14 +18,14 @@ module.exports = {
try {
deviceInfo = await userInfoHelper.getDeviceInfo(data.deviceIp);
} catch (error) {
console.log(`Failed to getDeviceInfo: ${error}`);
logger.log(`Failed to getDeviceInfo: ${error}`);
}

await hostAppHelper.setHostAppEnv(data, deviceInfo);
hostAppHelper
.buildPackage()
.then(() => {
console.log(
logger.log(
chalk.cyanBright(
'============================== Start to install the package'
)
Expand All @@ -46,12 +47,12 @@ module.exports = {
)
: appLaunchHelper.launchApp(deviceName, hostAppId);
} catch (e) {
console.log(e);
logger.log(e);
util.exit();
}
})
.catch(e => {
console.error(chalk.red(`Failed to buildPackage: ${e}`));
logger.error(chalk.red(`Failed to buildPackage: ${e}`));
util.exit();
});
}
Expand Down
5 changes: 3 additions & 2 deletions command/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ const appLaunchHelper = require('../lib/appLaunchHelper.js');
const watchHelper = require('../lib/watchHelper.js');
const util = require('../lib/util.js');
const chalk = require('chalk');
const { logger } = require('../lib/logger');

module.exports = {
run: async () => {
console.log(
logger.log(
chalk.cyanBright(`Start running Wits watch mode............\n`)
);

Expand Down Expand Up @@ -35,7 +36,7 @@ module.exports = {
)
: appLaunchHelper.launchApp(deviceName, hostAppId);
} catch (e) {
console.log(e);
logger.log(e);
util.exit();
}
}
Expand Down
23 changes: 15 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
const util = require('./lib/util.js');
const userInfoHelper = require('./lib/userInfoHelper.js');
const {
setOutputChannel,
unsetOutputChannel,
logger
} = require('./lib/logger');

const setWitsconfigInfo = async data => {
try {
const initCommand = require('./command/init.js');
console.log('WITs::setWitsconfigInfo');
logger.log('WITs::setWitsconfigInfo');

if (data.hasOwnProperty('baseAppPath')) {
util.CURRENT_PROJECT_PATH = userInfoHelper.getBaseAppPath(
Expand Down Expand Up @@ -34,7 +39,7 @@ const setWitsconfigInfo = async data => {
}
*/
} catch (error) {
console.log(`setWitsconfigInfo:::${error}`);
logger.log(`setWitsconfigInfo:::${error}`);
}
};

Expand All @@ -44,12 +49,12 @@ const start = async () => {
throw new Error('There is invalid WITS_USER_DATA');
}
const startCommand = require('./command/start.js');
console.log('WITs::start');
logger.log('WITs::start');

await startCommand.run();
return;
} catch (error) {
console.log(`start:::${error}`);
logger.log(`start:::${error}`);
}
};

Expand All @@ -59,12 +64,12 @@ const watch = async () => {
throw new Error('There is invalid WITS_USER_DATA');
}
const watchCommand = require('./command/watch.js');
console.log('WITs::watch');
logger.log('WITs::watch');

await watchCommand.run();
return;
} catch (error) {
console.log(`watch:::${error}`);
logger.log(`watch:::${error}`);
}
};

Expand All @@ -74,13 +79,15 @@ const disconnect = () => {
try {
watchHelper.closeSocketServer();
} catch (error) {
console.log(`disconnect:::${error}`);
logger.log(`disconnect:::${error}`);
}
};

module.exports = {
setWitsconfigInfo,
start,
watch,
disconnect
disconnect,
setOutputChannel,
unsetOutputChannel
};
13 changes: 7 additions & 6 deletions lib/appLaunchHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { execSync } = require('child_process');
const chromeLauncher = require('chrome-launcher');
const regExp = require('./regexp.js');
const util = require('./util.js');
const { logger } = require('./logger');

const PACKAGE_BASE_PATH = path.join(util.WITS_BASE_PATH, '../', 'container');
const WITS_PACKAGE = 'WITs.wgt';
Expand All @@ -25,7 +26,7 @@ module.exports = {
const result = execSync(APP_INSTALL_COMMAND).toString();

if (result.includes('failed[')) {
console.error(chalk.red(`\nFailed to install Wits`));
logger.error(chalk.red(`\nFailed to install Wits`));
util.exit();
}
},
Expand All @@ -36,7 +37,7 @@ module.exports = {
}).toString();

if (result.includes('failed[')) {
console.warn(`\n[warning] Failed to uninstall Wits`);
logger.warn(`\n[warning] Failed to uninstall Wits`);
}
},
launchApp: (deviceName, hostAppId) => {
Expand Down Expand Up @@ -77,7 +78,7 @@ module.exports = {
try {
launchChrome(debugIP + ':' + debugPort);
} catch (e) {
console.log(
logger.log(
`Please install a Chrome browser or input ${debugIP}:${debugPort} into the address bar of the chromium based browser. ${e}`
);
}
Expand All @@ -99,7 +100,7 @@ function setPortForward(deviceName, port) {
try {
launchChrome(LOCAL_HOST + ':' + port);
} catch (e) {
console.log(
logger.log(
`Please install a Chrome browser or input ${LOCAL_HOST}:${port} into the address bar of the chromium based browser. ${e}`
);
}
Expand All @@ -115,9 +116,9 @@ function launchChrome(url) {
]
})
.then(chrome => {
console.log(`Chrome debugging port running on ${chrome.port}`);
logger.log(`Chrome debugging port running on ${chrome.port}`);
})
.catch(e => {
console.log(chalk.red(`Please install a Chrome browser. ${e}`));
logger.log(chalk.red(`Please install a Chrome browser. ${e}`));
});
}
Loading

0 comments on commit 6adbec0

Please sign in to comment.