Skip to content

Commit

Permalink
add build command
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgeny Zakharov committed Nov 14, 2021
1 parent 299ae1a commit bb0776c
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@medusa-frontends/cli",
"version": "1.0.1",
"version": "1.1.0",
"description": "A CLI interface for bootstrapping and managing MFEs",
"main": "bin/medusa.js",
"repository": "[email protected]:mfe-playground/medusa-cli.git",
Expand Down
43 changes: 43 additions & 0 deletions src/actions/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import 'zx/globals'
import { readEnvironment } from '../configs/environment'
import { foreachApp } from '../lib/apps/foreach'
import { appHasScript, runAppScript } from '../lib/apps/scripts'
import { readCLIConfig } from '../lib/config'
import { EnvironmentNotFoundException } from '../lib/exceptions'
import { showStatus } from '../model/status'
import { AppMeta, ScriptKey } from '../types'
import { generate } from './generate'

type BuildOptions = {
buildScriptKey: ScriptKey
prebuildScriptKey: ScriptKey
}

export async function build({ buildScriptKey, prebuildScriptKey }: BuildOptions) {
await generate()

const { apps } = await readCLIConfig()

const buildApp = async ({ app }: AppMeta) => {
const environment = await readEnvironment(app)
if (!environment) throw new EnvironmentNotFoundException(app)

const { port } = environment

if (await appHasScript(app, prebuildScriptKey)) {
showStatus({ text: `Running prebuild for "${app}"..` })
const wrapped = await runAppScript(app, prebuildScriptKey)
await wrapped.processPromise()
}

showStatus({ text: `Building "${app}"..` })
const wrapped = await runAppScript(app, buildScriptKey, { port })
await wrapped.processPromise()
}

await foreachApp({
apps,
deep: true,
callback: buildApp,
})
}
1 change: 1 addition & 0 deletions src/actions/start/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export async function start({ startScriptKey, prestartScriptKey }: StartOptions)
const { port } = environment

if (await appHasScript(app, prestartScriptKey)) {
appSummaryUpdated({ app, status: 'Running prestart..' })
const wrapped = await runAppScript(app, prestartScriptKey)
await wrapped.processPromise()
}
Expand Down
56 changes: 56 additions & 0 deletions src/routes.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { program } from 'commander'
import { useStore } from 'effector-react'
import React from 'react'
import { build } from './actions/build'
import { generate } from './actions/generate'
import { install } from './actions/install'
import { pull } from './actions/pull'
import { start } from './actions/start'
import { $activeRoute, RouteConfig } from './model'
import { BootstrapScreen } from './ui/screens/bootstrap'
import { BuildScreen } from './ui/screens/build'
import { GenerateScreen } from './ui/screens/generate'
import { InstallScreen } from './ui/screens/install'
import { PullScreen } from './ui/screens/pull'
Expand Down Expand Up @@ -41,6 +43,16 @@ export const routes: RouteConfig[] = [
prestartScriptKey: 'prestart',
}),
},
{
name: 'start:dev',
command: program.command('start:dev'),
component: StartScreen,
action: () =>
start({
startScriptKey: 'start:dev',
prestartScriptKey: 'prestart:dev',
}),
},
{
name: 'start:prod',
command: program.command('start:prod'),
Expand All @@ -51,6 +63,36 @@ export const routes: RouteConfig[] = [
prestartScriptKey: 'prestart:prod',
}),
},
{
name: 'build',
command: program.command('build'),
component: BuildScreen,
action: () =>
build({
buildScriptKey: 'build',
prebuildScriptKey: 'prebuild',
}),
},
{
name: 'build:dev',
command: program.command('build:dev'),
component: BuildScreen,
action: () =>
build({
buildScriptKey: 'build:dev',
prebuildScriptKey: 'prebuild:dev',
}),
},
{
name: 'build:prod',
command: program.command('build:prod'),
component: BuildScreen,
action: () =>
build({
buildScriptKey: 'build:prod',
prebuildScriptKey: 'prebuild:prod',
}),
},
{
name: 'bootstrap',
command: program.command('bootstrap'),
Expand All @@ -62,6 +104,20 @@ export const routes: RouteConfig[] = [
await start({ startScriptKey: 'start', prestartScriptKey: 'prestart' })
},
},
{
name: 'bootstrap:dev',
command: program.command('bootstrap:dev'),
component: BootstrapScreen,
action: async () => {
await pull()
await install()
await generate()
await start({
startScriptKey: 'start:dev',
prestartScriptKey: 'prestart:dev',
})
},
},
{
name: 'bootstrap:prod',
command: program.command('bootstrap:prod'),
Expand Down
4 changes: 4 additions & 0 deletions src/ui/screens/build.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import React from 'react'
import { DefaultTemplate } from '../templates'

export const BuildScreen = () => <DefaultTemplate />

0 comments on commit bb0776c

Please sign in to comment.