Skip to content

Commit

Permalink
Merge pull request #1110 from botpress/ya-optimise-build
Browse files Browse the repository at this point in the history
 fix(build): optimized for packaging
  • Loading branch information
slvnperron committed Nov 13, 2018
2 parents 26030fe + a3b0be1 commit 396e606
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 27 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ Botpress is on a mission to make useful bots ubiquitous by powering developers w

If you have errors when building modules (timeout, random errors, etc), try the following:

1. Set the environment variable GULP_SERIES=true before starting the build
1. If it doesn't work, go in each module folder and type `yarn && yarn build`
1. Go in each module folder and type `yarn && yarn build`

## Target a specific Botpress Edition

Expand Down
13 changes: 8 additions & 5 deletions build/gulp.modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,12 @@ const getTargetOSConfig = () => {

const buildModule = (modulePath, cb) => {
const targetOs = getTargetOSConfig()
const linkCmd = process.env.LINK ? ` && yarn link "module-builder"` : ''
const linkCmd = process.env.LINK ? `&& yarn link "module-builder"` : ''
const buildForProd = process.argv.find(x => x.toLowerCase() === '--prod') ? `cross-env NODE_ENV=production` : ''
const removeMap = process.argv.find(x => x.toLowerCase() === '--nomap') ? `--nomap` : ''

exec(
`cross-env npm_config_target_platform=${targetOs} yarn${linkCmd} && yarn build`,
`cross-env npm_config_target_platform=${targetOs} yarn ${linkCmd} && ${buildForProd} yarn build ${removeMap}`,
{ cwd: modulePath },
(err, stdout, stderr) => {
if (err) {
Expand Down Expand Up @@ -100,11 +103,11 @@ const buildModules = () => {
return taskName
})

if (yn(process.env.GULP_SERIES)) {
return gulp.series(tasks)
if (yn(process.env.GULP_PARALLEL)) {
return gulp.parallel(tasks)
}

return gulp.parallel(tasks)
return gulp.series(tasks)
}

const packageModules = () => {
Expand Down
1 change: 1 addition & 0 deletions build/module-builder/src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,6 @@ export async function buildConfigSchema(modulePath: string) {
const definition = generateSchema(program, 'Config', settings)
const schema = JSON.stringify(definition, undefined, 2) + os.EOL + os.EOL

mkdirp.sync(path.resolve(modulePath, 'assets'))
fs.writeFileSync(path.resolve(modulePath, 'assets', 'config.schema.json'), schema)
}
2 changes: 1 addition & 1 deletion build/module-builder/src/webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function config(projectPath) {

const web: webpack.Configuration = {
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
devtool: process.env.NODE_ENV === 'production' ? false : 'source-map',
devtool: process.argv.find(x => x.toLowerCase() === '--nomap') ? false : 'source-map',
entry: ['./src/views/index.jsx'],
output: {
path: path.resolve(projectPath, './assets/web'),
Expand Down
1 change: 0 additions & 1 deletion buildspec-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ version: 0.2
env:
variables:
CHILD_CONCURRENCY: 1
GULP_SERIES: true
parameter-store:
GIT_PRO_SSH: 'bp_git_pro_ssh_codebuild'

Expand Down
12 changes: 5 additions & 7 deletions buildspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ version: 0.2
env:
variables:
CHILD_CONCURRENCY: 1
GULP_SERIES: true
YARN_CACHE_DIR_WIN: /codebuild/output/.cache/yarn-win
YARN_CACHE_DIR_LINUX: /codebuild/output/.cache/yarn-linux
YARN_CACHE_DIR_DARWIN: /codebuild/output/.cache/yarn-darwin
Expand Down Expand Up @@ -35,9 +34,8 @@ phases:
- echo "BUILDING FOR '$ARTIFACT_NAME' edition '$EDITION'. GIT TAG = '$CODEBUILD_GIT_TAG'"
- yarn
- yarn build:modules-builder
- yarn build:core
- yarn build:admin
- yarn build:studio
- yarn build:studio-prod
- yarn build:admin-prod

build:
commands:
Expand All @@ -47,7 +45,7 @@ phases:
# Twice because of potential OS-specific errors
- yarn install --force --ignore-engines
- yarn install --force --ignore-engines
- yarn run build --mac
- yarn run build-prod --mac
- yarn run package --mac
- mkdir -p out/binaries/data/storage
- touch out/binaries/data/storage/.keep
Expand All @@ -60,7 +58,7 @@ phases:
- export npm_config_target_platform=windows
- yarn install --force --ignore-engines
- yarn install --force --ignore-engines
- yarn run build --win32
- yarn run build-prod --win32
- yarn run package --win32
- mkdir -p out/binaries/data/storage
- touch out/binaries/data/storage/.keep
Expand All @@ -72,7 +70,7 @@ phases:
- yarn config set cache-folder $YARN_CACHE_DIR_LINUX
- export npm_config_target_platform=linux
- yarn install --force --ignore-engines
- yarn run build --linux
- yarn run build-prod --linux
- yarn run package --linux
- mkdir -p out/binaries/data/storage
- touch out/binaries/data/storage/.keep
Expand Down
2 changes: 1 addition & 1 deletion modules/channel-web/src/views/web/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ export default class Web extends React.Component {
handleSessionReset = () => {
const userId = window.__BP_VISITOR_ID
const url = `/mod/channel-web/conversations/${userId}/${this.state.currentConversationId}/reset`
return this.props.bp.axios.post(url, {}, ...this.axiosConfig).then()
return this.props.bp.axios.post(url, {}, this.axiosConfig).then()
}

renderOpenIcon() {
Expand Down
19 changes: 11 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,28 @@
"license": "AGPL-3.0",
"private": true,
"scripts": {
"bootstrap": "yarn build:modules-builder && yarn build",
"start": "cd ./out/bp && cross-env NODE_PATH=./ cross-env BP_MODULES_PATH=../../modules node index.js",
"start:guide": "cd docs/guide/website && yarn && yarn start",
"start:admin": "cd src/bp/ui-admin && yarn start:dev",
"start:studio": "yarn run gulp create-studio-symlink && cd src/bp/ui-studio && yarn watch",
"build": "yarn build:core && yarn build:modules && yarn build:studio && yarn build:admin",
"build-prod": "yarn build:core && yarn build:modules --prod --nomap",
"build:core": "./node_modules/.bin/gulp clean-build",
"build:watch": "./node_modules/.bin/gulp build-watch",
"build:modules": "./node_modules/.bin/gulp modules",
"build:modules-builder": "cd build/module-builder/ && yarn && yarn build",
"bootstrap": "yarn build:modules-builder && yarn build",
"build:admin": "cd src/bp/ui-admin && yarn && yarn build && ../../../node_modules/.bin/gulp copy-admin",
"build:admin-prod": "cd src/bp/ui-admin && yarn && yarn build --nomap && ../../../node_modules/.bin/gulp copy-admin",
"build:studio": "cd src/bp/ui-studio && yarn && yarn build && ../../../node_modules/.bin/gulp copy-studio",
"build:studio-prod": "cd src/bp/ui-studio && yarn && yarn build:prod --nomap && ../../../node_modules/.bin/gulp copy-studio",
"build:guide": "cd docs/guide/website && yarn && yarn run build",
"build:reference": "gulp build-reference",
"watch": "./node_modules/.bin/gulp watch",
"test": "./node_modules/.bin/jest -i --detectOpenHandles -c jest.config.js",
"clean": "./node_modules/.bin/gulp clean",
"package": "./node_modules/.bin/gulp package",
"package:core": "./node_modules/.bin/gulp package --skip-modules",
"build:reference": "gulp build-reference",
"start:guide": "cd docs/guide/website && yarn && yarn start",
"build:guide": "cd docs/guide/website && yarn && yarn run build",
"start:admin": "cd src/bp/ui-admin && yarn start:dev",
"build:admin": "cd src/bp/ui-admin && yarn && yarn build && ../../../node_modules/.bin/gulp copy-admin",
"start:studio": "yarn run gulp create-studio-symlink && cd src/bp/ui-studio && yarn watch",
"build:studio": "cd src/bp/ui-studio && yarn && yarn build && ../../../node_modules/.bin/gulp copy-studio",
"commitmsg": "commitlint -e $GIT_PARAMS",
"tslint": "node_modules/.bin/tslint --project tslint.json"
},
Expand Down
2 changes: 2 additions & 0 deletions src/bp/ui-admin/config-overrides.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin')
module.exports = function override(config, env) {
config.resolve.alias['common'] = path.join(__dirname, '../../../out/bp/common')
config.resolve.plugins = config.resolve.plugins.filter(p => !p instanceof ModuleScopePlugin)
config.devtool = process.argv.find(x => x.toLowerCase() === '--nomap') ? false : 'source-map'

return config
}
2 changes: 1 addition & 1 deletion src/bp/ui-admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"start": "cross-env PUBLIC_URL=/admin npm-run-all -p watch-css start-js",
"start:dev": "cross-env PUBLIC_URL=/admin cross-env REACT_APP_API_URL=http://localhost:3000 cross-env PORT=3001 npm-run-all -p watch-css start-js",
"build-js": "react-app-rewired build",
"build": "cross-env PUBLIC_URL=/admin npm-run-all build-css build-js",
"build": "yarn build-css && cross-env PUBLIC_URL=/admin yarn build-js",
"test": "react-app-rewired test --env=jsdom",
"eject": "react-scripts eject"
},
Expand Down
2 changes: 1 addition & 1 deletion src/bp/ui-studio/webpack.web.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const isProduction = process.env.NODE_ENV === 'production'
const webConfig = {
mode: isProduction ? 'production' : 'development',
bail: true,
devtool: isProduction ? 'source-map' : 'eval-source-map',
devtool: process.argv.find(x => x.toLowerCase() === '--nomap') ? false : 'source-map',
entry: {
web: './src/web/index.jsx',
lite: './src/web/lite.jsx'
Expand Down

0 comments on commit 396e606

Please sign in to comment.