Skip to content

Commit

Permalink
feat: #1150 Served web component themes over CDN
Browse files Browse the repository at this point in the history
  • Loading branch information
trankhacvy committed May 6, 2020
1 parent d856abc commit 87f859b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 118 deletions.
118 changes: 2 additions & 116 deletions packages/demo-site/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -28,121 +28,7 @@
<script src="<%= CDN_URL %>/search-widget.js"></script>
<script src="<%= CDN_URL %>/appointment-bookings.js"></script>
<script src="<%= CDN_URL %>/viewing-booking.js"></script>
<script>
const variantDefault = {
// appointment-bookings's specific styles
dateCellHeaderBackgroundColor: '#ececec',
timeCellBackgroundColor: '#dfdfdf',
timeCellBackgroundColorHover: '#d3d3d3',
timeCellsContainerBackgroundColor: '#f9f9f9',
formLabelColor: '#737373',
formHrSeparatorFontColor: '#e6e6e6',
formButtonFontSize: '1.2rem',
// base
baseBackgroundColor: '#f9fbfd',
basefontSize: '16px',
basefontColor: '#12263f',
secondaryfontColor: '#1e2554',
primaryHeadingFontSize: '24px',
secondaryHeadingFontSize: '20px',
baseFontFamily: '"Roboto", sans-serif',
headingFontFamily: '"Open Sans", sans-serif',
primaryAccentColor: '#0061a8',
secondaryAccentColor: '#6c757d',
mapAccentColor: '#7bc9eb',
breakPoints: {
mobile: '',
tablet: '',
laptop: '',
desktop: '',
},
}
const variantA = {
baseBackgroundColor: '#fff',
basefontSize: '16px',
basefontColor: '#556986',
inverseFontColor: '#fff',
secondaryfontColor: '#95aac9',
primaryHeadingFontSize: '22px',
secondaryHeadingFontSize: '18px',
baseFontFamily: '"Open Sans", sans-serif',
headingFontFamily: '"Montserrat", sans-serif',
primaryAccentColor: '#887e96',
secondaryAccentColor: '#7d9d88',
mapAccentColor: '',
breakPoints: {
mobile: '',
tablet: '',
laptop: '',
desktop: '',
},
searchPlaceholder: 'e.g. London or EC1N',
}
const variantB = {
baseBackgroundColor: '#f9fbfd',
basefontSize: '14px',
basefontColor: '#12263f',
inverseFontColor: '#f9fbfd',
secondaryfontColor: '#1e2554',
primaryHeadingFontSize: '24px',
secondaryHeadingFontSize: '20px',
baseFontFamily: '"Roboto", sans-serif',
headingFontFamily: '"Open Sans", sans-serif',
primaryAccentColor: '#0061a8',
secondaryAccentColor: '#1e2554',
mapAccentColor: '#7bc9eb',
breakPoints: {
mobile: '',
tablet: '',
laptop: '',
desktop: '',
},
searchPlaceholder: 'e.g. London or EC1N',
}
const variantC = {
baseBackgroundColor: '#4C566A',
basefontSize: '14px',
basefontColor: '#fff',
inverseFontColor: '#4C566A',
secondaryfontColor: '#88C0D0',
primaryHeadingFontSize: '28px',
secondaryHeadingFontSize: '24px',
baseFontFamily: '"Open Sans", sans-serif',
headingFontFamily: '"Roboto Slab", serif',
primaryAccentColor: '#A3BE8C',
secondaryAccentColor: '##88C0D0',
mapAccentColor: '#8FBCBB',
breakPoints: {
mobile: '',
tablet: '',
laptop: '',
desktop: '',
},
searchPlaceholder: 'e.g. London or EC1N',
}
const params = new URLSearchParams(window.location.search)
const variant = params.get('variant')
switch (variant) {
case 'A':
window.theme = variantA
break
case 'B':
window.theme = variantB
break
case 'C':
window.theme = variantC
break
default:
window.theme = variantDefault
}
</script>
<script src="<%= CDN_URL %>/search-widget-theme.js"></script>
<script>
ReapitSearchWidgetComponent &&
new ReapitSearchWidgetComponent({
Expand All @@ -160,4 +46,4 @@
})
</script>
</body>
</html>
</html>
30 changes: 29 additions & 1 deletion packages/web-components/src/scripts/build-prod.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
#!/usr/bin/env node
const path = require('path')
const { runCommand } = require('../../../../scripts/release/utils')

const releaseDevThemes = () => {
try {
const packageName = 'web-components'
const bucketName = 'reapit-web-components'

const themesDistPath = path.resolve(__dirname, '../../', 'packages', packageName, 'public', 'themes')
// Copy new version to the bucket
runCommand('aws', [
's3',
'cp',
themesDistPath,
`s3://${bucketName}`,
'--grants',
'read=uri=http://acs.amazonaws.com/groups/global/AllUsers',
'--recursive',
])
} catch (err) {
console.error(err)
throw new Error(err)
}
}

return (() => {
const { execSync } = require('child_process')
const { setEnv } = require('./get-env')
Expand All @@ -8,7 +33,7 @@ return (() => {
}
setEnv()

const clearPublic = 'rimraf ./public/dist'
const clearPublic = 'rimraf ./public/dist && rimraf ./public/themes'
execSync(clearPublic, opts)

packages.forEach(package => {
Expand All @@ -20,5 +45,8 @@ return (() => {
process.exit(1)
}
})
// the pull request is WIP so temporary
// releaseDevThemes()

process.exit(0)
})()
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import path from 'path'
const config = require(path.resolve(__dirname, '../..', 'config.json'))
const production = !process.env.ROLLUP_WATCH

export default {
const widgetConfig = {
...baseConfig,
input: 'src/search-widget/client/core/index.ts',
output: {
Expand All @@ -33,3 +33,17 @@ export default {
...baseConfig.plugins,
],
}

const themeConfig = {
...baseConfig,
input: 'src/common/styles/__themes__/search-widget.js',
output: {
sourcemap: !production,
format: 'iife',
name: 'theme',
file: './public/themes/search-widget-theme.js',
},
plugins: [...baseConfig.plugins],
}

export default [widgetConfig, themeConfig]

0 comments on commit 87f859b

Please sign in to comment.