diff --git a/packages/sui-widget-embedder/bin/sui-widget-embedder-build.js b/packages/sui-widget-embedder/bin/sui-widget-embedder-build.js index 0f2ea0b66..4f609feb0 100755 --- a/packages/sui-widget-embedder/bin/sui-widget-embedder-build.js +++ b/packages/sui-widget-embedder/bin/sui-widget-embedder-build.js @@ -21,10 +21,7 @@ const suiWidgetEmbedderConfig = config['sui-widget-embedder'] || {} program .option('-C, --clean', 'Remove public folder before create a new one') - .option( - '-R --remoteCdn ', - 'Remote url where the downloader will be placed' - ) + .option('-R --remoteCdn ', 'Remote url where the downloader will be placed') .on('--help', () => { console.log(' Description:') console.log('') @@ -34,12 +31,8 @@ program console.log('') console.log(' $ sui-widget-embedder build') console.log('') - console.log( - ' You can even choose where should the downloader going to get the files:' - ) - console.log( - ' $ sui-widget-embedder build -remoteCdn http://mysourcedomain.com' - ) + console.log(' You can even choose where should the downloader going to get the files:') + console.log(' $ sui-widget-embedder build -remoteCdn http://mysourcedomain.com') console.log('') }) .parse(process.argv) @@ -71,17 +64,11 @@ const build = ({page, remoteCdn}) => { }) } -const pagesFor = ({path}) => - readdirSync(path).filter(file => statSync(resolve(path, file)).isDirectory()) +const pagesFor = ({path}) => readdirSync(path).filter(file => statSync(resolve(path, file)).isDirectory()) const manifests = () => pagesFor({path: PUBLIC_PATH}).reduce((acc, page) => { - acc[page] = require(resolve( - process.cwd(), - 'public', - page, - 'asset-manifest.json' - )) + acc[page] = require(resolve(process.cwd(), 'public', page, 'asset-manifest.json')) return acc }, {}) @@ -89,12 +76,7 @@ const pageConfigs = () => pagesFor({path: PAGES_PATH}).reduce( (acc, page) => ({ ...acc, - [page]: require(resolve( - process.cwd(), - PAGES_FOLDER, - page, - 'package.json' - )) + [page]: require(resolve(process.cwd(), PAGES_FOLDER, page, 'package.json')) }), {} ) @@ -113,10 +95,7 @@ const createDownloader = async () => { output, downloader .replace("require('static-manifests')", JSON.stringify(staticManifests)) - .replace( - "require('static-pageConfigs')", - JSON.stringify(staticPageConfigs) - ) + .replace("require('static-pageConfigs')", JSON.stringify(staticPageConfigs)) ) console.log(`Created a new ${FILE_DOWNLOADER} file`) @@ -126,11 +105,8 @@ const createDownloader = async () => { } } -const serialPromiseExecution = promises => - promises.reduce((acc, func) => acc.then(() => func()), Promise.resolve([])) +const serialPromiseExecution = promises => promises.reduce((acc, func) => acc.then(() => func()), Promise.resolve([])) -serialPromiseExecution( - pagesFor({path: PAGES_FOLDER}).map(page => () => build({page, remoteCdn})) -) +serialPromiseExecution(pagesFor({path: PAGES_FOLDER}).map(page => () => build({page, remoteCdn}))) .then(createDownloader) .catch(showError) diff --git a/packages/sui-widget-embedder/bin/sui-widget-embedder-dev.js b/packages/sui-widget-embedder/bin/sui-widget-embedder-dev.js index 56c3f8293..dfe561c22 100755 --- a/packages/sui-widget-embedder/bin/sui-widget-embedder-dev.js +++ b/packages/sui-widget-embedder/bin/sui-widget-embedder-dev.js @@ -4,8 +4,7 @@ const program = require('commander') const ncp = require('copy-paste') const appFactory = require('../development/index.js') -const config = - require(`${process.cwd()}/package.json`).config['sui-widget-embedder'] || {} +const config = require(`${process.cwd()}/package.json`).config['sui-widget-embedder'] || {} const PORT = process.env.PORT || config.devPort || 3000 config.port = PORT @@ -14,11 +13,7 @@ program .usage('-p detail -a address -b') .option('-b, --browser', 'Enable the dev mode inside a html file') .option('-p, --page ', 'Name of the page') - .option( - '-a, --address ', - 'Local ip address to lookup statics, useful for virtual machines', - 'localhost' - ) + .option('-a, --address ', 'Local ip address to lookup statics, useful for virtual machines', 'localhost') .on('--help', () => { console.log(' Description:') console.log('') @@ -27,9 +22,7 @@ program console.log(' Examples:') console.log('') console.log(' $ sui-widget-embedder development --page detail') - console.log( - ' $ sui-widget-embedder development --page detail --address 10.0.2.2' - ) + console.log(' $ sui-widget-embedder development --page detail --address 10.0.2.2') console.log('') }) .parse(process.argv) diff --git a/packages/sui-widget-embedder/bin/sui-widget-embedder-generate.js b/packages/sui-widget-embedder/bin/sui-widget-embedder-generate.js index 50f846b9d..ea578a00f 100755 --- a/packages/sui-widget-embedder/bin/sui-widget-embedder-generate.js +++ b/packages/sui-widget-embedder/bin/sui-widget-embedder-generate.js @@ -23,16 +23,12 @@ program console.log('') console.log(' $ sui-widget-embedder generate ') console.log(' $ sui-widget-embedder generate detailPage') - console.log( - " $ sui-widget-embedder generate detailPage -E '/d\\\\w+\\\\.html'" - ) + console.log(" $ sui-widget-embedder generate detailPage -E '/d\\\\w+\\\\.html'") console.log(' $ custom-help --help') console.log(' $ custom-help -h') console.log('') console.log( - colors.cyan( - ' IMPORTANT - Regexp (-E) must be with commas ALWAYS to avoid terminal escape or interpretation' - ) + colors.cyan(' IMPORTANT - Regexp (-E) must be with commas ALWAYS to avoid terminal escape or interpretation') ) console.log('') }) @@ -74,14 +70,7 @@ Promise.all([ writeFile(PAGE_PACKAGE_JSON_FILE, packageJSON(pageRegExpIdentifier)), writeFile(PAGE_ENTRY_JS_POINT_FILE, indexJS()), writeFile(PAGE_ENTRY_SCSS_POINT_FILE, indexSCSS(sitePrefix)), - writeFile( - PAGE_BASE_PROJECT_JSON_FILE, - JSON.stringify(packageInfo, null, ' ') - ) + writeFile(PAGE_BASE_PROJECT_JSON_FILE, JSON.stringify(packageInfo, null, ' ')) ]).then(() => { - console.log( - colors.green( - `➜ [${page}]: Your page files have been generated successfully.` - ) - ) + console.log(colors.green(`➜ [${page}]: Your page files have been generated successfully.`)) }) diff --git a/packages/sui-widget-embedder/bin/sui-widget-embedder.js b/packages/sui-widget-embedder/bin/sui-widget-embedder.js index cdda78303..ec58c60eb 100755 --- a/packages/sui-widget-embedder/bin/sui-widget-embedder.js +++ b/packages/sui-widget-embedder/bin/sui-widget-embedder.js @@ -11,11 +11,6 @@ program.command('dev', 'Start a development server for a page').alias('d') program.command('build', 'Build all statics by page').alias('b') -program - .command( - 'generate', - 'Generate a new page folder and main files with your first widget' - ) - .alias('g') +program.command('generate', 'Generate a new page folder and main files with your first widget').alias('g') program.parse(process.argv) diff --git a/packages/sui-widget-embedder/compiler/production.js b/packages/sui-widget-embedder/compiler/production.js index e0a1b907c..70c5f5935 100644 --- a/packages/sui-widget-embedder/compiler/production.js +++ b/packages/sui-widget-embedder/compiler/production.js @@ -31,9 +31,7 @@ module.exports = ({page, remoteCdn, globalConfig = {}}) => { output: { ...prodConfig.output, path: path.resolve(process.cwd(), 'public', page), - publicPath: remoteCdn - ? `${remoteCdn}/${page}/` - : prodConfig.output.publicPath, + publicPath: remoteCdn ? `${remoteCdn}/${page}/` : prodConfig.output.publicPath, chunkLoadingGlobal: `webpackJsonp-${page}` }, plugins: pipe(removePlugin('HtmlWebpackPlugin'))(prodConfig.plugins) diff --git a/packages/sui-widget-embedder/compiler/utils.js b/packages/sui-widget-embedder/compiler/utils.js index d1964ef31..4ba305f45 100644 --- a/packages/sui-widget-embedder/compiler/utils.js +++ b/packages/sui-widget-embedder/compiler/utils.js @@ -1,7 +1,5 @@ const removePlugin = name => plugins => { - const pos = plugins - .map(p => p.constructor.toString()) - .findIndex(string => string.match(name)) + const pos = plugins.map(p => p.constructor.toString()).findIndex(string => string.match(name)) return [...plugins.slice(0, pos), ...plugins.slice(pos + 1)] } diff --git a/packages/sui-widget-embedder/downloader/index.js b/packages/sui-widget-embedder/downloader/index.js index 2912cd5ba..02d985820 100644 --- a/packages/sui-widget-embedder/downloader/index.js +++ b/packages/sui-widget-embedder/downloader/index.js @@ -94,12 +94,7 @@ return css ? load.css(css) : Promise.resolve() } - var loadScripts = [ - manifest['runtime~app.js'], - manifest['main.js'], - manifest['vendor.js'], - manifest['app.js'] - ] + var loadScripts = [manifest['runtime~app.js'], manifest['main.js'], manifest['vendor.js'], manifest['app.js']] .filter(Boolean) .map(function (script) { return function () { @@ -133,9 +128,7 @@ } function match(pathnameRegExp, hrefRegExp) { - return ( - matchPathnameWithRegExp(pathnameRegExp) || matchhRefWithRegExp(hrefRegExp) - ) + return matchPathnameWithRegExp(pathnameRegExp) || matchhRefWithRegExp(hrefRegExp) } var pages = [] diff --git a/packages/sui-widget-embedder/src-react/Widget.js b/packages/sui-widget-embedder/src-react/Widget.js index 5cb2072a9..44ce62984 100644 --- a/packages/sui-widget-embedder/src-react/Widget.js +++ b/packages/sui-widget-embedder/src-react/Widget.js @@ -8,38 +8,24 @@ import Context from '@s-ui/react-context' import {useMount} from '@s-ui/react-hooks' function renderWidgetOnDOM({children, context, node}) { - ReactDOM.render( - {children}, - node - ) + ReactDOM.render({children}, node) } -export default function Widget({ - children, - context = {}, - isVisible = true, - selector, - renderMultiple = false -}) { +export default function Widget({children, context = {}, isVisible = true, selector, renderMultiple = false}) { useMount(function () { if (!selector) { - return console.warn( - `[Widget] You must define a selector to use the Widget` - ) + return console.warn(`[Widget] You must define a selector to use the Widget`) } const nodes = document.querySelectorAll(selector) if (!nodes.length) { - return console.warn( - `[Widget] unable find nodes using selector ${selector}` - ) + return console.warn(`[Widget] unable find nodes using selector ${selector}`) } // depending on renderMultiple, get the full array or only the first one const nodesToRender = renderMultiple ? [].slice.call(nodes) : [nodes[0]] - isVisible && - nodesToRender.map(node => renderWidgetOnDOM({children, context, node})) + isVisible && nodesToRender.map(node => renderWidgetOnDOM({children, context, node})) }) return null