Skip to content

Commit

Permalink
feat(cli): plugin start script
Browse files Browse the repository at this point in the history
  • Loading branch information
mediremi authored and KaiVandivier committed Aug 23, 2022
1 parent 3f1b1f2 commit 9fea158
Show file tree
Hide file tree
Showing 8 changed files with 344 additions and 664 deletions.
3 changes: 3 additions & 0 deletions cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@dhis2/app-shell": "10.0.0",
"@dhis2/cli-helpers-engine": "^3.2.0",
"@jest/core": "^27.0.6",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.4",
"@yarnpkg/lockfile": "^1.1.0",
"archiver": "^3.1.1",
"axios": "^0.25.0",
Expand All @@ -57,9 +58,11 @@
"parse-author": "^2.0.0",
"parse-gitignore": "^1.0.1",
"react-dev-utils": "^12.0.0",
"react-refresh": "^0.11.0",
"styled-jsx": "^4.0.1",
"terser-webpack-plugin": "^5.3.1",
"webpack": "^5.41.1",
"webpack-dev-server": "^4.7.4",
"workbox-build": "^6.1.5"
},
"bin": {
Expand Down
8 changes: 5 additions & 3 deletions cli/src/commands/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ const handler = async ({
const shellStartPromise = shell.start({ port: newPort })

if (config.entryPoints.plugin) {
const pluginPort = await detectPort(newPort)
const pluginPort = await detectPort(newPort + 1)
reporter.print(
`The plugin is now available on port ${pluginPort}`
)
Expand All @@ -149,8 +149,10 @@ const handler = async ({
},
{
name: 'start',
onError: () =>
reporter.error('Start script exited with non-zero exit code'),
onError: err => {
reporter.error(err)
reporter.error('Start script exited with non-zero exit code')
},
}
)
}
Expand Down
13 changes: 7 additions & 6 deletions cli/src/lib/plugin/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
process.env.BABEL_ENV = 'production'
process.env.NODE_ENV = 'production'

const { reporter } = require('@dhis2/cli-helpers-engine')
const webpack = require('webpack')
const webpackConfigFactory = require('./webpack.config')

module.exports = async ({ paths }) => {
console.log('Building plugin...')
reporter.debug('Building plugin...')

const webpackConfig = webpackConfigFactory({ env: 'production', paths })
const compiler = webpack(webpackConfig)
Expand Down Expand Up @@ -43,11 +44,11 @@ module.exports = async ({ paths }) => {
return
}

/*if (stats.hasWarnings()) {
console.warn(
info.warnings.map(warning => warning.message).join('\n')
)
}*/
if (stats.hasWarnings()) {
for (const warning of info.warnings) {
reporter.warn(warning.message)
}
}

resolve()
})
Expand Down
13 changes: 1 addition & 12 deletions cli/src/lib/plugin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,6 @@ const build = require('./build')
const start = require('./start')

module.exports = ({ config, paths }) => ({
// build: () => build({ config, paths }),
// XXX
build: async () => {
try {
await build({ config, paths })
} catch (error) {
console.log('\n\nerror building plugin:')
console.error(error)
console.log('\n')
throw error
}
},
build: () => build({ config, paths }),
start: ({ port }) => start({ port, config, paths }),
})
Loading

0 comments on commit 9fea158

Please sign in to comment.