From 764eaa81675b06445879f4b1b0603363a7d5cf5d Mon Sep 17 00:00:00 2001 From: Gustavo Date: Fri, 17 Nov 2017 13:33:15 -0200 Subject: [PATCH 01/16] initial samsung tizen support --- examples/navigation/package.json | 1 + .../bootstrap/react-tv/tizen/config.xml | 12 +++ packages/react-tv-cli/scripts/tizen/run.js | 100 ++++++++++++++++++ packages/react-tv-cli/shared/index.js | 10 ++ 4 files changed, 123 insertions(+) create mode 100644 packages/react-tv-cli/bootstrap/react-tv/tizen/config.xml create mode 100644 packages/react-tv-cli/scripts/tizen/run.js diff --git a/examples/navigation/package.json b/examples/navigation/package.json index 6d5aa6f..739d1c2 100644 --- a/examples/navigation/package.json +++ b/examples/navigation/package.json @@ -16,6 +16,7 @@ "build-prod": "NODE_ENV=production yarn build", "react-tv-cli": "react-tv-cli", "start": "yarn build-prod && react-tv-cli run-webos", + "start-tizen": "yarn build && react-tv run-tizen", "start-dev": "webpack-dev-server --progress --colors" }, "dependencies": { diff --git a/packages/react-tv-cli/bootstrap/react-tv/tizen/config.xml b/packages/react-tv-cli/bootstrap/react-tv/tizen/config.xml new file mode 100644 index 0000000..c29b8dc --- /dev/null +++ b/packages/react-tv-cli/bootstrap/react-tv/tizen/config.xml @@ -0,0 +1,12 @@ + + + + {{REACTTVAPP}} + + + + + + + + diff --git a/packages/react-tv-cli/scripts/tizen/run.js b/packages/react-tv-cli/scripts/tizen/run.js new file mode 100644 index 0000000..523dbbd --- /dev/null +++ b/packages/react-tv-cli/scripts/tizen/run.js @@ -0,0 +1,100 @@ +const path = require('path'); +const fs = require('fs'); +const chalk = require('chalk'); +const execSync = require('child_process').execSync; + +function copy(from, to) { + fs.writeFileSync(to, fs.readFileSync(from)); +} + +function defaultCLIEnv() { + //return '/opt/tizen/tools/ide/bin'; + return 'E:/Ferramentas/tizen/tools/ide/bin'; +} + +function isReactTVTizenProject(root) { + const appinfo = path.resolve(root, 'react-tv/tizen/config.xml'); + if (fs.existsSync(appinfo)) { + return true; + } + return false; +} + +function runTizen(root) { + let tizen_CLI_ENV = process.env['TIZEN_CLI'] || false; + if (!tizen_CLI_ENV) { + tizen_CLI_ENV = defaultCLIEnv(); + } + + process.env['PATH'] = `${tizen_CLI_ENV}:${process.env['PATH']}`; + + if (!isReactTVTizenProject(root)) { + const msg = `This project isn\'t a React-TV WebOS Project: + Just run "react-tv init"`; + return console.log(chalk.dim('[react-tv]'), msg); + } + + const packageJson = require(path.resolve(root, 'package.json')); + const ReactTVConfig = packageJson['react-tv']; + if (!ReactTVConfig) { + return console.log( + chalk.dim('[react-tv]'), + 'You should set react-tv properties on package.json' + ); + } + + if (!ReactTVConfig.files || !ReactTVConfig.files.length) { + return console.log(chalk.dim('[react-tv]'), 'You should add files'); + } + + // TODO: option to create/select profiles? + const securityProfiles = execSync(`${tizen_CLI_ENV}/tizen security-profiles list`).toString().trim().split("\n"); + if (!securityProfiles) { + return console.log(chalk.dim('[react-tv]'), 'No tizen security profiles found'); + } + + // Select the last profile + const selectedProfile = securityProfiles[securityProfiles.length - 1]; + + const tizenPath = path.resolve(root, 'react-tv/tizen'); + try { + copy(`${root}/react-tv/icon.png`, `${tizenPath}/icon.png`); + + ReactTVConfig.files.forEach(file => { + const filePath = path.resolve(root, file); + copy(`${filePath}`, `${tizenPath}/${file}`); + }); + } catch (e) { + return console.log('FAIL TO MOUNT', e.toString()); + } + + console.log(''); + console.log(chalk.dim('Up Emulator...')); + + const vms = execSync( + `${tizen_CLI_ENV}/../../emulator/bin/em-cli list-vm` + ).toString(); + + if (vms.indexOf('react-tv-tizen') < 0) { + execSync( + `${tizen_CLI_ENV}/../../emulator/bin/em-cli create -n react-tv-tizen` + ); + } + + execSync( + `${tizen_CLI_ENV}/../../emulator/bin/em-cli launch -n react-tv-tizen` + ); + + console.log(chalk.yellow(' Tizen Emulator successful running')); + + console.log(chalk.dim('Packing...')); + execSync(`cd ${tizenPath} && ${tizen_CLI_ENV}/tizen package -t wgt -s ${selectedProfile}`); + console.log(chalk.yellow(` succefull pack from ${root}`)); + + console.log(chalk.dim('Running...')); + console.log(packageJson['name']); + execSync(`cd ${tizenPath} && ${tizen_CLI_ENV}/tizen install -n ${packageJson['name']}.wgt -t react-tv-tizen`); + console.log(chalk.yellow(` done`)); +} + +module.exports = runTizen; diff --git a/packages/react-tv-cli/shared/index.js b/packages/react-tv-cli/shared/index.js index add9c2a..cc250c9 100644 --- a/packages/react-tv-cli/shared/index.js +++ b/packages/react-tv-cli/shared/index.js @@ -96,6 +96,16 @@ function createReactTVApp(appName) { recursive: true, silent: true, }); + + var randomstring = require("randomstring"); + + replace({ + regex: '{{PACKAGE}}', + replacement: randomstring.generate(10), + paths: ['./react-tv'], + recursive: true, + silent: true, + }); } catch (e) { return process.exit(1); } From cfd43ee26b97419ad4b68caf0729c2b812cf2690 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Fri, 17 Nov 2017 14:06:21 -0200 Subject: [PATCH 02/16] minor fixes --- packages/react-tv-cli/scripts/tizen/run.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-tv-cli/scripts/tizen/run.js b/packages/react-tv-cli/scripts/tizen/run.js index 523dbbd..6d975c7 100644 --- a/packages/react-tv-cli/scripts/tizen/run.js +++ b/packages/react-tv-cli/scripts/tizen/run.js @@ -29,7 +29,7 @@ function runTizen(root) { process.env['PATH'] = `${tizen_CLI_ENV}:${process.env['PATH']}`; if (!isReactTVTizenProject(root)) { - const msg = `This project isn\'t a React-TV WebOS Project: + const msg = `This project isn\'t a React-TV Tizen Project: Just run "react-tv init"`; return console.log(chalk.dim('[react-tv]'), msg); } From a0eb749fc0aab9ba83c8e9a97bc9175e0e5085d0 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Fri, 17 Nov 2017 21:36:33 -0200 Subject: [PATCH 03/16] Run application --- packages/react-tv-cli/scripts/tizen/run.js | 104 ++++++++++++++++++--- 1 file changed, 90 insertions(+), 14 deletions(-) diff --git a/packages/react-tv-cli/scripts/tizen/run.js b/packages/react-tv-cli/scripts/tizen/run.js index 6d975c7..569f4c8 100644 --- a/packages/react-tv-cli/scripts/tizen/run.js +++ b/packages/react-tv-cli/scripts/tizen/run.js @@ -12,6 +12,20 @@ function defaultCLIEnv() { return 'E:/Ferramentas/tizen/tools/ide/bin'; } +function getPackageId(root) { + const appinfo = path.resolve(root, 'react-tv/tizen/config.xml'); + const content = fs.readFileSync(appinfo, {encoding: 'utf-8'}); + + const re = new RegExp(/tizen:application id="(.*?)"/); + const matches = content.match(re); + + if (!matches) { + return null; + } + + return matches[1]; +} + function isReactTVTizenProject(root) { const appinfo = path.resolve(root, 'react-tv/tizen/config.xml'); if (fs.existsSync(appinfo)) { @@ -48,13 +62,23 @@ function runTizen(root) { } // TODO: option to create/select profiles? - const securityProfiles = execSync(`${tizen_CLI_ENV}/tizen security-profiles list`).toString().trim().split("\n"); + const securityProfiles = execSync( + `${tizen_CLI_ENV}/tizen security-profiles list` + ) + .toString() + .trim() + .split('\n'); if (!securityProfiles) { - return console.log(chalk.dim('[react-tv]'), 'No tizen security profiles found'); + return console.log( + chalk.dim('[react-tv]'), + 'No tizen security profiles found' + ); } // Select the last profile - const selectedProfile = securityProfiles[securityProfiles.length - 1]; + const selectedProfile = securityProfiles[securityProfiles.length - 1] + .split(' ', 1)[0] + .trim(); const tizenPath = path.resolve(root, 'react-tv/tizen'); try { @@ -69,7 +93,7 @@ function runTizen(root) { } console.log(''); - console.log(chalk.dim('Up Emulator...')); + console.log(chalk.dim('Setting up Emulator...')); const vms = execSync( `${tizen_CLI_ENV}/../../emulator/bin/em-cli list-vm` @@ -77,24 +101,76 @@ function runTizen(root) { if (vms.indexOf('react-tv-tizen') < 0) { execSync( - `${tizen_CLI_ENV}/../../emulator/bin/em-cli create -n react-tv-tizen` + `${ + tizen_CLI_ENV + }/../../emulator/bin/em-cli create -n react-tv-tizen -p tv-samsung-3.0-x86` ); } - execSync( - `${tizen_CLI_ENV}/../../emulator/bin/em-cli launch -n react-tv-tizen` - ); + const runningVms = execSync( + `${tizen_CLI_ENV}/../../sdb devices` + ).toString(); - console.log(chalk.yellow(' Tizen Emulator successful running')); + if (runningVms.indexOf('react-tv-tizen') < 0) { + console.log(chalk.dim('Running Emulator...')); + execSync( + `${tizen_CLI_ENV}/../../emulator/bin/em-cli launch -n react-tv-tizen` + ); + console.log(chalk.yellow(' Tizen Emulator successful running')); + } + else { + console.log(chalk.yellow(' already running.')); + } console.log(chalk.dim('Packing...')); - execSync(`cd ${tizenPath} && ${tizen_CLI_ENV}/tizen package -t wgt -s ${selectedProfile}`); + execSync( + `cd ${tizenPath} && ${tizen_CLI_ENV}/tizen package -t wgt -s ${ + selectedProfile + }` + ); console.log(chalk.yellow(` succefull pack from ${root}`)); - console.log(chalk.dim('Running...')); - console.log(packageJson['name']); - execSync(`cd ${tizenPath} && ${tizen_CLI_ENV}/tizen install -n ${packageJson['name']}.wgt -t react-tv-tizen`); - console.log(chalk.yellow(` done`)); + console.log(chalk.dim('Running App...')); + + let attemps = 0; + const task = setInterval(function() { + if (attemps > 15) { + console.log('FAILED TO UP Tizen emulator'); + clearInterval(task); + } + + try { + execSync( + `${tizen_CLI_ENV}/../../sdb devices` + ).toString(); + + execSync( + `cd ${tizenPath} && ${tizen_CLI_ENV}/tizen install -n ${ + packageJson['name'] + }.wgt -t react-tv-tizen` + ); + } + catch (error) { + if (error.stdout.toString().indexOf('install completed') < 0) { + attemps += 1; + return false; + } + } + + clearInterval(task); + + const packageId = getPackageId(root); + + if (!packageId) { + return console.log('Invalid package id!'); + } + + execSync( + `cd ${tizenPath} && ${tizen_CLI_ENV}/tizen run -p ${ + packageId + } -t react-tv-tizen` + ); + }, 500); } module.exports = runTizen; From 0e3fe2120df3d9a259cb6f08792f18759bc4039a Mon Sep 17 00:00:00 2001 From: Gustavo Date: Fri, 17 Nov 2017 22:14:37 -0200 Subject: [PATCH 04/16] Custom tizen app name --- .../react-tv-cli/bootstrap/react-tv/tizen/config.xml | 2 +- packages/react-tv-cli/shared/index.js | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/react-tv-cli/bootstrap/react-tv/tizen/config.xml b/packages/react-tv-cli/bootstrap/react-tv/tizen/config.xml index c29b8dc..a05f053 100644 --- a/packages/react-tv-cli/bootstrap/react-tv/tizen/config.xml +++ b/packages/react-tv-cli/bootstrap/react-tv/tizen/config.xml @@ -1,6 +1,6 @@ - + {{REACTTVAPP}} diff --git a/packages/react-tv-cli/shared/index.js b/packages/react-tv-cli/shared/index.js index cc250c9..455e980 100644 --- a/packages/react-tv-cli/shared/index.js +++ b/packages/react-tv-cli/shared/index.js @@ -100,9 +100,17 @@ function createReactTVApp(appName) { var randomstring = require("randomstring"); replace({ - regex: '{{PACKAGE}}', + regex: '{{TIZEN_PACKAGE}}', replacement: randomstring.generate(10), - paths: ['./react-tv'], + paths: ['./react-tv/tizen'], + recursive: true, + silent: true, + }); + + replace({ + regex: '{{TIZEN_REACTTVAPP}}', + replacement: appName.replace(/-/g, "").replace(/\./g, ""), + paths: ['./react-tv/tizen'], recursive: true, silent: true, }); From 74560acce18766da0bc7857c88ca3f5da19409ad Mon Sep 17 00:00:00 2001 From: Gustavo Date: Fri, 17 Nov 2017 22:29:16 -0200 Subject: [PATCH 05/16] add tizen to platform --- packages/react-tv/modules/Platform.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-tv/modules/Platform.js b/packages/react-tv/modules/Platform.js index c700f52..59b70ce 100644 --- a/packages/react-tv/modules/Platform.js +++ b/packages/react-tv/modules/Platform.js @@ -12,7 +12,7 @@ function isLGWebOS() { } function isSamsungTizen() { - return false; + return tizen ? true : false; } function isSamsungOrsay() { From 72ee6ad4a054cb61d501d294a8593cf0be456c8d Mon Sep 17 00:00:00 2001 From: Gustavo Date: Fri, 17 Nov 2017 22:29:27 -0200 Subject: [PATCH 06/16] add tizen to clock example --- examples/clock-app/src/App.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/clock-app/src/App.js b/examples/clock-app/src/App.js index 1bf47ae..bf3df5b 100644 --- a/examples/clock-app/src/App.js +++ b/examples/clock-app/src/App.js @@ -16,6 +16,9 @@ class Clock extends React.Component { if (Platform('webos')) currentPlatform = 'LG WebOS' + if (Platform('tizen')) + currentPlatform = 'Samsung Tizen' + return (
From c9c68fc0f5b93274186b6a7de47b8e5553a3fe16 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Fri, 17 Nov 2017 22:30:59 -0200 Subject: [PATCH 07/16] prettier code --- packages/react-tv-cli/scripts/tizen/run.js | 14 ++++---------- packages/react-tv-cli/shared/index.js | 4 ++-- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/packages/react-tv-cli/scripts/tizen/run.js b/packages/react-tv-cli/scripts/tizen/run.js index 569f4c8..5920fbe 100644 --- a/packages/react-tv-cli/scripts/tizen/run.js +++ b/packages/react-tv-cli/scripts/tizen/run.js @@ -107,9 +107,7 @@ function runTizen(root) { ); } - const runningVms = execSync( - `${tizen_CLI_ENV}/../../sdb devices` - ).toString(); + const runningVms = execSync(`${tizen_CLI_ENV}/../../sdb devices`).toString(); if (runningVms.indexOf('react-tv-tizen') < 0) { console.log(chalk.dim('Running Emulator...')); @@ -117,8 +115,7 @@ function runTizen(root) { `${tizen_CLI_ENV}/../../emulator/bin/em-cli launch -n react-tv-tizen` ); console.log(chalk.yellow(' Tizen Emulator successful running')); - } - else { + } else { console.log(chalk.yellow(' already running.')); } @@ -140,17 +137,14 @@ function runTizen(root) { } try { - execSync( - `${tizen_CLI_ENV}/../../sdb devices` - ).toString(); + execSync(`${tizen_CLI_ENV}/../../sdb devices`).toString(); execSync( `cd ${tizenPath} && ${tizen_CLI_ENV}/tizen install -n ${ packageJson['name'] }.wgt -t react-tv-tizen` ); - } - catch (error) { + } catch (error) { if (error.stdout.toString().indexOf('install completed') < 0) { attemps += 1; return false; diff --git a/packages/react-tv-cli/shared/index.js b/packages/react-tv-cli/shared/index.js index 455e980..0026f98 100644 --- a/packages/react-tv-cli/shared/index.js +++ b/packages/react-tv-cli/shared/index.js @@ -97,7 +97,7 @@ function createReactTVApp(appName) { silent: true, }); - var randomstring = require("randomstring"); + var randomstring = require('randomstring'); replace({ regex: '{{TIZEN_PACKAGE}}', @@ -109,7 +109,7 @@ function createReactTVApp(appName) { replace({ regex: '{{TIZEN_REACTTVAPP}}', - replacement: appName.replace(/-/g, "").replace(/\./g, ""), + replacement: appName.replace(/-/g, '').replace(/\./g, ''), paths: ['./react-tv/tizen'], recursive: true, silent: true, From 814c87649e144a12ad18aa426daca183fc002d1a Mon Sep 17 00:00:00 2001 From: Gustavo Date: Sat, 18 Nov 2017 02:00:10 -0200 Subject: [PATCH 08/16] Move randomstring require to top --- packages/react-tv-cli/shared/index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/react-tv-cli/shared/index.js b/packages/react-tv-cli/shared/index.js index 0026f98..c7919ad 100644 --- a/packages/react-tv-cli/shared/index.js +++ b/packages/react-tv-cli/shared/index.js @@ -2,6 +2,7 @@ const fs = require('fs-extra'); const path = require('path'); const chalk = require('chalk'); const replace = require('node-replace'); +const randomstring = require('randomstring'); function debug(msg) { console.log(chalk.dim('[react-tv]'), msg); @@ -97,8 +98,6 @@ function createReactTVApp(appName) { silent: true, }); - var randomstring = require('randomstring'); - replace({ regex: '{{TIZEN_PACKAGE}}', replacement: randomstring.generate(10), From 2c5ee6b7c999865f0a7fa33a82843bfdf2467a2c Mon Sep 17 00:00:00 2001 From: Gustavo Date: Sat, 18 Nov 2017 02:01:19 -0200 Subject: [PATCH 09/16] Update README --- README.md | 15 ++++++++++++--- examples/clock-app/README.md | 7 +++++++ examples/navigation/README.md | 8 +++++++- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e24e6ab..1f85805 100644 --- a/README.md +++ b/README.md @@ -240,6 +240,16 @@ See [examples/navigation](examples/navigation) for more details about usage. - http://webostv.developer.lge.com/develop/app-developer-guide/web-app-lifecycle/ - http://webostv.developer.lge.com/develop/js-services/calling-js-service/ +### Tizen + +- http://developer.samsung.com/tv/develop/tools/tizen-studio +- http://developer.samsung.com/tv/develop/getting-started/setting-up-sdk/installing-tv-sdk +- http://developer.samsung.com/tv/develop/getting-started/setting-up-sdk/creating-certificates +- http://developer.samsung.com/tv/develop/getting-started/creating-tv-applications +- http://developer.samsung.com/tv/design/design-principles +- http://developer.samsung.com/tv/develop/specifications/general-specifications +- http://developer.samsung.com/tv/develop/specifications/web-engine-specifications + #### Videos ##### Windows @@ -252,7 +262,6 @@ See [examples/navigation](examples/navigation) for more details about usage. ### Essentials to beginner -- http://developer.samsung.com/tv/develop/getting-started/setup-sdk/installing-tv-sdk/ - http://developer.samsung.com/tv/develop/getting-started/using-sdk/tv-simulator - http://developer.samsung.com/tv/develop/getting-started/essentials-for-beginner @@ -289,7 +298,7 @@ Implement essential functionality needed for daily use by early adopters. - [ ] Support render to Canvas instead DOM using `React.CanvasComponent` - [x] `run-webos` support TV device as param - [ ] Optmizate DOMRenderer for TV -- [ ] Start CLI for Tizen +- [x] Start CLI for Tizen - [x] Develop helpers for WebOS debbug (e.g: Log System). - [x] Support Cross Platform - [x] Check executable bin path for Windows, OSX and Linux @@ -307,7 +316,7 @@ Add additional features users expect from a Renderer. Then fix bugs and stabiliz - [ ] Reactive Renderer - [ ] Testing and stability ----------------------------------------------------- +---------------------------------------------------- See ReactTV's [Changelog](https://github.com/raphamorim/react-tv/blob/master/CHANGELOG.md). diff --git a/examples/clock-app/README.md b/examples/clock-app/README.md index 1963c4e..a20ab62 100644 --- a/examples/clock-app/README.md +++ b/examples/clock-app/README.md @@ -20,8 +20,15 @@ yarn To run it: +WebOS: ```shell yarn start ``` +Tizen: +```shell +yarn start-tizen +``` + + ![Screenshot](screenshot.png) diff --git a/examples/navigation/README.md b/examples/navigation/README.md index e7c9b5f..c3dcaf9 100644 --- a/examples/navigation/README.md +++ b/examples/navigation/README.md @@ -26,6 +26,12 @@ yarn start-dev To run it on TV WebOS: +WebOS: ```shell -yarn start +yarn start-webos +``` + +Tizen: +```shell +yarn start-tizen ``` From 55f89288cf08d9c15edd97b55954fb282a375ad9 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Sat, 18 Nov 2017 02:04:23 -0200 Subject: [PATCH 10/16] add setup tizen doc --- docs/setup-tizen-environment.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 docs/setup-tizen-environment.md diff --git a/docs/setup-tizen-environment.md b/docs/setup-tizen-environment.md new file mode 100644 index 0000000..1f98574 --- /dev/null +++ b/docs/setup-tizen-environment.md @@ -0,0 +1,7 @@ +# Setup Tizen Environment + +[Install the Tizen Studio](http://developer.samsung.com/tv/develop/tools/tizen-studio) + +[Install the TV SDK](http://developer.samsung.com/tv/develop/getting-started/setting-up-sdk/installing-tv-sdk/) + +Using the Package Manager install the Web CLI, Native CLI and Baseline SDK packages under the Tizen SDK Tools From c33aa9a927fad82789b8e4302844d5bad17e2779 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Sat, 18 Nov 2017 03:51:50 -0200 Subject: [PATCH 11/16] add randomstring to package.json --- packages/react-tv-cli/package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/react-tv-cli/package.json b/packages/react-tv-cli/package.json index e8accb5..118ce91 100644 --- a/packages/react-tv-cli/package.json +++ b/packages/react-tv-cli/package.json @@ -16,7 +16,8 @@ "chalk": "^2.1.0", "fs-extra": "^4.0.3", "node-replace": "^0.3.1", - "node-webos": "^0.3.0" + "node-webos": "^0.3.0", + "randomstring": "^1.1.5" }, "repository": { "type": "git", From f6ac626b4962a46fc9be36047e2ac6f204513f82 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Tue, 19 Dec 2017 02:19:11 -0200 Subject: [PATCH 12/16] fix stuff after rebase --- examples/navigation/package.json | 3 +- packages/react-tv-cli/index.js | 8 +++++ packages/react-tv-cli/scripts/tizen/index.js | 5 ++++ packages/react-tv-cli/scripts/tizen/run.js | 31 ++++++++++++++------ packages/react-tv-cli/shared/index.js | 17 +++++++++++ 5 files changed, 54 insertions(+), 10 deletions(-) create mode 100644 packages/react-tv-cli/scripts/tizen/index.js diff --git a/examples/navigation/package.json b/examples/navigation/package.json index 739d1c2..d21e68e 100644 --- a/examples/navigation/package.json +++ b/examples/navigation/package.json @@ -13,7 +13,7 @@ }, "scripts": { "build": "webpack", - "build-prod": "NODE_ENV=production yarn build", + "build-prod": "cross-env NODE_ENV=production yarn build", "react-tv-cli": "react-tv-cli", "start": "yarn build-prod && react-tv-cli run-webos", "start-tizen": "yarn build && react-tv run-tizen", @@ -30,6 +30,7 @@ "babel-loader": "^6.2.1", "babel-polyfill": "^6.26.0", "babel-preset-react": "^6.3.13", + "cross-env": "^5.1.1", "webpack": "^1.12.12", "webpack-dev-server": "^1.12.1" } diff --git a/packages/react-tv-cli/index.js b/packages/react-tv-cli/index.js index 6bde05d..117d421 100755 --- a/packages/react-tv-cli/index.js +++ b/packages/react-tv-cli/index.js @@ -41,6 +41,14 @@ switch (command) { WebOS.getKey(device); break; + case 'run-tizen': + if (argv.length > 3) { + device = argv[3]; + } + + Tizen.run(process.cwd()); + break; + case '--version': version(); break; diff --git a/packages/react-tv-cli/scripts/tizen/index.js b/packages/react-tv-cli/scripts/tizen/index.js new file mode 100644 index 0000000..c6f3ada --- /dev/null +++ b/packages/react-tv-cli/scripts/tizen/index.js @@ -0,0 +1,5 @@ +const run = require('./run'); + +module.exports = { + run +}; diff --git a/packages/react-tv-cli/scripts/tizen/run.js b/packages/react-tv-cli/scripts/tizen/run.js index 5920fbe..dc3cf30 100644 --- a/packages/react-tv-cli/scripts/tizen/run.js +++ b/packages/react-tv-cli/scripts/tizen/run.js @@ -1,12 +1,8 @@ const path = require('path'); -const fs = require('fs'); +const fs = require('fs-extra'); const chalk = require('chalk'); const execSync = require('child_process').execSync; -function copy(from, to) { - fs.writeFileSync(to, fs.readFileSync(from)); -} - function defaultCLIEnv() { //return '/opt/tizen/tools/ide/bin'; return 'E:/Ferramentas/tizen/tools/ide/bin'; @@ -34,7 +30,7 @@ function isReactTVTizenProject(root) { return false; } -function runTizen(root) { +function run(root) { let tizen_CLI_ENV = process.env['TIZEN_CLI'] || false; if (!tizen_CLI_ENV) { tizen_CLI_ENV = defaultCLIEnv(); @@ -81,12 +77,29 @@ function runTizen(root) { .trim(); const tizenPath = path.resolve(root, 'react-tv/tizen'); + + process.on('exit', cleanup); + process.on('SIGINT', cleanup); + process.on('SIGUSR1', cleanup); + process.on('SIGUSR2', cleanup); + process.on('uncaughtException', cleanup); + + function cleanup() { + fs.removeSync(`${tizenPath}/icon.png`); + ReactTVConfig.files.forEach(file => { + fs.removeSync(`${tizenPath}/${file}`); + }); + } + try { - copy(`${root}/react-tv/icon.png`, `${tizenPath}/icon.png`); + cleanup(); + fs.copySync(`${root}/react-tv/icon-large.png`, `${tizenPath}/icon.png`); ReactTVConfig.files.forEach(file => { const filePath = path.resolve(root, file); - copy(`${filePath}`, `${tizenPath}/${file}`); + const toFile = path.resolve(tizenPath, file); + fs.ensureDirSync(path.dirname(toFile)); + fs.copySync(`${filePath}`, `${toFile}`); }); } catch (e) { return console.log('FAIL TO MOUNT', e.toString()); @@ -167,4 +180,4 @@ function runTizen(root) { }, 500); } -module.exports = runTizen; +module.exports = run; diff --git a/packages/react-tv-cli/shared/index.js b/packages/react-tv-cli/shared/index.js index c7919ad..2b88cca 100644 --- a/packages/react-tv-cli/shared/index.js +++ b/packages/react-tv-cli/shared/index.js @@ -49,6 +49,7 @@ https://medium.com/@raphamorim/developing-for-tvs-with-react-tv-b5b5204964ef`) } function createReactTVApp(appName) { + console.log('tizen'); let appPath = process.cwd(); const packageJson = path.resolve(appPath, 'package.json'); @@ -67,6 +68,22 @@ function createReactTVApp(appName) { recursive: true, silent: true, }); + + replace({ + regex: '{{TIZEN_PACKAGE}}', + replacement: randomstring.generate(10), + paths: [appName], + recursive: true, + silent: true, + }); + + replace({ + regex: '{{TIZEN_REACTTVAPP}}', + replacement: appName.replace(/-/g, '').replace(/\./g, ''), + paths: [appName], + recursive: true, + silent: true, + }); } catch (e) { return process.exit(1); } From c0cc3cbd9c567a217ec9796c1d37bfd645816ca9 Mon Sep 17 00:00:00 2001 From: Raphael Amorim Date: Fri, 29 Dec 2017 14:17:37 -0200 Subject: [PATCH 13/16] all: fix lint errors --- packages/react-tv-cli/index.js | 2 +- packages/react-tv-cli/scripts/tizen/index.js | 2 +- packages/react-tv-cli/scripts/tizen/run.js | 6 +++--- packages/react-tv/modules/Platform.js | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/react-tv-cli/index.js b/packages/react-tv-cli/index.js index 117d421..a8845c5 100755 --- a/packages/react-tv-cli/index.js +++ b/packages/react-tv-cli/index.js @@ -2,7 +2,7 @@ const argv = process.argv; const {help, version, createReactTVApp} = require('./shared'); -const {WebOS} = require('./scripts'); +const {WebOS, Tizen} = require('./scripts'); if (argv.length < 2) { return help(); diff --git a/packages/react-tv-cli/scripts/tizen/index.js b/packages/react-tv-cli/scripts/tizen/index.js index c6f3ada..503717d 100644 --- a/packages/react-tv-cli/scripts/tizen/index.js +++ b/packages/react-tv-cli/scripts/tizen/index.js @@ -1,5 +1,5 @@ const run = require('./run'); module.exports = { - run + run, }; diff --git a/packages/react-tv-cli/scripts/tizen/run.js b/packages/react-tv-cli/scripts/tizen/run.js index dc3cf30..0e034cf 100644 --- a/packages/react-tv-cli/scripts/tizen/run.js +++ b/packages/react-tv-cli/scripts/tizen/run.js @@ -31,12 +31,12 @@ function isReactTVTizenProject(root) { } function run(root) { - let tizen_CLI_ENV = process.env['TIZEN_CLI'] || false; + let tizen_CLI_ENV = process.env.TIZEN_CLI || false; if (!tizen_CLI_ENV) { tizen_CLI_ENV = defaultCLIEnv(); } - process.env['PATH'] = `${tizen_CLI_ENV}:${process.env['PATH']}`; + process.env.PATH = `${tizen_CLI_ENV}:${process.env.PATH}`; if (!isReactTVTizenProject(root)) { const msg = `This project isn\'t a React-TV Tizen Project: @@ -154,7 +154,7 @@ function run(root) { execSync( `cd ${tizenPath} && ${tizen_CLI_ENV}/tizen install -n ${ - packageJson['name'] + packageJson.name }.wgt -t react-tv-tizen` ); } catch (error) { diff --git a/packages/react-tv/modules/Platform.js b/packages/react-tv/modules/Platform.js index 59b70ce..fc8c1f6 100644 --- a/packages/react-tv/modules/Platform.js +++ b/packages/react-tv/modules/Platform.js @@ -12,7 +12,7 @@ function isLGWebOS() { } function isSamsungTizen() { - return tizen ? true : false; + return window.tizen; } function isSamsungOrsay() { From 3b6ac3bf47f12ca4ff4ef9f36d01e930b505faca Mon Sep 17 00:00:00 2001 From: Raphael Amorim Date: Fri, 29 Dec 2017 14:18:10 -0200 Subject: [PATCH 14/16] all: fix prettier erros --- packages/react-tv-cli/index.js | 12 ++++++------ packages/react-tv-cli/scripts/tizen/run.js | 12 +++--------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/packages/react-tv-cli/index.js b/packages/react-tv-cli/index.js index a8845c5..2a9760c 100755 --- a/packages/react-tv-cli/index.js +++ b/packages/react-tv-cli/index.js @@ -41,13 +41,13 @@ switch (command) { WebOS.getKey(device); break; - case 'run-tizen': - if (argv.length > 3) { - device = argv[3]; - } + case 'run-tizen': + if (argv.length > 3) { + device = argv[3]; + } - Tizen.run(process.cwd()); - break; + Tizen.run(process.cwd()); + break; case '--version': version(); diff --git a/packages/react-tv-cli/scripts/tizen/run.js b/packages/react-tv-cli/scripts/tizen/run.js index 0e034cf..7b77d7f 100644 --- a/packages/react-tv-cli/scripts/tizen/run.js +++ b/packages/react-tv-cli/scripts/tizen/run.js @@ -114,9 +114,7 @@ function run(root) { if (vms.indexOf('react-tv-tizen') < 0) { execSync( - `${ - tizen_CLI_ENV - }/../../emulator/bin/em-cli create -n react-tv-tizen -p tv-samsung-3.0-x86` + `${tizen_CLI_ENV}/../../emulator/bin/em-cli create -n react-tv-tizen -p tv-samsung-3.0-x86` ); } @@ -134,9 +132,7 @@ function run(root) { console.log(chalk.dim('Packing...')); execSync( - `cd ${tizenPath} && ${tizen_CLI_ENV}/tizen package -t wgt -s ${ - selectedProfile - }` + `cd ${tizenPath} && ${tizen_CLI_ENV}/tizen package -t wgt -s ${selectedProfile}` ); console.log(chalk.yellow(` succefull pack from ${root}`)); @@ -173,9 +169,7 @@ function run(root) { } execSync( - `cd ${tizenPath} && ${tizen_CLI_ENV}/tizen run -p ${ - packageId - } -t react-tv-tizen` + `cd ${tizenPath} && ${tizen_CLI_ENV}/tizen run -p ${packageId} -t react-tv-tizen` ); }, 500); } From e03218b053e5196280cb8261905031979fb3c8c4 Mon Sep 17 00:00:00 2001 From: Raphael Amorim Date: Wed, 3 Jan 2018 14:15:50 -0200 Subject: [PATCH 15/16] fixup! all: fix prettier erros --- packages/react-tv/modules/Platform.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-tv/modules/Platform.js b/packages/react-tv/modules/Platform.js index fc8c1f6..7c91a7e 100644 --- a/packages/react-tv/modules/Platform.js +++ b/packages/react-tv/modules/Platform.js @@ -12,7 +12,7 @@ function isLGWebOS() { } function isSamsungTizen() { - return window.tizen; + return !!(window && window.tizen); } function isSamsungOrsay() { From 12273ad5ba132da0b4f2a4e38a30456093b9c4fa Mon Sep 17 00:00:00 2001 From: Raphael Amorim Date: Tue, 23 Jan 2018 15:49:30 -0200 Subject: [PATCH 16/16] docs: update webos docs --- README.md | 6 ++++++ docs/setup-tizen-environment.md | 6 ++++++ docs/setup-webos-environment.md | 8 ++++++++ 3 files changed, 20 insertions(+) diff --git a/README.md b/README.md index 1f85805..f4106a8 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ ReactTV.render(, document.getElementById('root')) - [About React-TV](#about-react-tv) - [Understanding the Problem](#understanding-the-problem) + - [Setup for TV SKDs](#setup-for-tv-sdks) - [Articles](#articles) - [react-tv-cli](#react-tv-cli) - [Developing for WebOS](#developing-for-webos) @@ -72,6 +73,11 @@ These restrictions make super responsive 60fps experiences especially tricky. Th In addition: Unify the build for multiple TV platforms. +### Setup for TV SKDs + +- [Setup LG WebOS SDK](docs/setup-webos-environment.md) +- [Setup Samsung Tizen SDK](docs/setup-tizen-environment.md) + ### Articles Friendly list of tutorials and articles: diff --git a/docs/setup-tizen-environment.md b/docs/setup-tizen-environment.md index 1f98574..2456155 100644 --- a/docs/setup-tizen-environment.md +++ b/docs/setup-tizen-environment.md @@ -1,7 +1,13 @@ # Setup Tizen Environment +Alternative guides: + +- [Developing for “old” Samsung TVs in Tizen Studio 2.x](https://medium.com/@ibazzva/developing-for-old-samsung-tvs-in-tizen-studio-2-x-5aa3f853db09) + [Install the Tizen Studio](http://developer.samsung.com/tv/develop/tools/tizen-studio) +[Install Tizen Studio 2.1](http://download.tizen.org/sdk/Installer/tizen-studio_2.1/) + [Install the TV SDK](http://developer.samsung.com/tv/develop/getting-started/setting-up-sdk/installing-tv-sdk/) Using the Package Manager install the Web CLI, Native CLI and Baseline SDK packages under the Tizen SDK Tools diff --git a/docs/setup-webos-environment.md b/docs/setup-webos-environment.md index 7333004..384ab66 100644 --- a/docs/setup-webos-environment.md +++ b/docs/setup-webos-environment.md @@ -24,6 +24,12 @@ Execute your Installer (If you're in Linux or Mac the Installer will ask for be ![Executing OSX Installer](resources/webos/1-executing-osx-installer.png) +For OSX: Note if you doesn’t have `/opt` folder, you must to create manual. + +```bash +sudo mkdir /opt +``` + You pop the SDK Installer, select "Agree" about LG Agreement and choose the destination folder for this installation to continue. ![WebOS Introduction](resources/webos/2-webos-introduction.png) @@ -39,3 +45,5 @@ You'll install all packages. After installation step, restart your machine. ![WebOS Complete](resources/webos/5-webos-complete.png) + +SDK Installed!