From 3a5d23546041b314e1c8115aff9ccee72a19e3d7 Mon Sep 17 00:00:00 2001 From: carloscarvallo Date: Tue, 26 Jan 2021 14:22:43 -0300 Subject: [PATCH] fix: some improvements for example onboarding --- .env.example | 5 ++- build-utils/webpack.development.js | 53 ++++++++++++++++-------------- example/main.js | 6 ++++ webpack.config.js | 7 ++-- 4 files changed, 43 insertions(+), 28 deletions(-) diff --git a/.env.example b/.env.example index d10ee16..33d6d6e 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,6 @@ TOKY_API_URL="https://api.toky.co" TOKY_RESOURCES_URL="https://app.toky.co" -PUSHER_KEY="" \ No newline at end of file +PUSHER_KEY="" +# only for development +# your Toky Agent id account +AGENT_ID="" \ No newline at end of file diff --git a/build-utils/webpack.development.js b/build-utils/webpack.development.js index c31cae8..1a41330 100644 --- a/build-utils/webpack.development.js +++ b/build-utils/webpack.development.js @@ -4,27 +4,32 @@ const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin') const BundleAnalyzerPlugin = require('webpack-bundle-analyzer') .BundleAnalyzerPlugin -module.exports = () => ({ - plugins: [ - new BundleAnalyzerPlugin({ analyzerPort: 8889 }), - new HtmlWebpackPlugin({ - // target template to copy the structure from - template: 'example/template.html', - // insert the bundle to the head so we can run the initialization script after it - inject: 'head', - // used for cache refreshing - hash: true, - }), - new ForkTsCheckerWebpackPlugin({ - async: true, - }), - ], - devServer: { - // since our index.html is located in the dist folder, we need to provide different content bases - contentBase: ['example/'], - port: 8080, - publicPath: 'http://localhost:8080/', - hot: true, - watchContentBase: true, - }, -}) +module.exports = (mode, dotenv) => { + const agent_id = JSON.parse(dotenv.definitions['process.env.AGENT_ID']) + return { + plugins: [ + new BundleAnalyzerPlugin({ analyzerPort: 8889, openAnalyzer: false }), + new HtmlWebpackPlugin({ + // target template to copy the structure from + template: 'example/template.html', + // insert the bundle to the head so we can run the initialization script after it + inject: 'head', + // used for cache refreshing + hash: true, + }), + new ForkTsCheckerWebpackPlugin({ + async: true, + }), + ], + devServer: { + // since our index.html is located in the dist folder, we need to provide different content bases + contentBase: ['example/'], + port: 8080, + publicPath: 'http://localhost:8080/', + hot: true, + watchContentBase: true, + open: true, + openPage: `?agent_id=${agent_id}`, + }, + } +} diff --git a/example/main.js b/example/main.js index b6c1fcc..0b6c01e 100644 --- a/example/main.js +++ b/example/main.js @@ -353,6 +353,12 @@ async function main() { * REDIRECT BEGIN * ref: https://toky-js-sdk.toky.co/docs/single-sign-on */ + if (!currentAppId) { + generalMessage.textContent = + 'app_id has to be provided in the main.js example file, contact Toky support for more details' + generalArticle.classList.add('is-danger') + return + } window.location.replace( `${tokySsoURL}/auth/sso/login/${currentAppId}?redirect_url=${encodeURIComponent( window.location.href diff --git a/webpack.config.js b/webpack.config.js index 443c524..7abc753 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -7,7 +7,8 @@ const gitRevisionPlugin = new GitRevisionPlugin() const libraryName = 'toky-sdk-alpha' -const modeConfig = (env) => require(`./build-utils/webpack.${env}`)(env) +const modeConfig = (env, dotenv) => + require(`./build-utils/webpack.${env}`)(env, dotenv) const getEnvFile = function (key) { const files = { @@ -17,7 +18,7 @@ const getEnvFile = function (key) { 'dev-bundle': '.env.dev', } - return files[key] || files.master + return files[key] || files.dev } module.exports = ({ mode, presets } = { mode: 'production', presets: [] }) => { @@ -69,6 +70,6 @@ module.exports = ({ mode, presets } = { mode: 'production', presets: [] }) => { */ // externals: ['sip.js'], }, - modeConfig(mode) + modeConfig(mode, dotenv) ) }