-
Notifications
You must be signed in to change notification settings - Fork 103
/
build.ts
54 lines (48 loc) · 1.65 KB
/
build.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import {build} from '../../services/build.js'
import {hydrogenFlags} from '../../flags.js'
import {Flags} from '@oclif/core'
import {path, cli} from '@shopify/cli-kit'
import Command from '@shopify/cli-kit/node/base-command'
const PLATFORM_ENTRIES = {
node: `@shopify/hydrogen/platforms/node`,
worker: `@shopify/hydrogen/platforms/worker`,
}
export default class Build extends Command {
static description = 'Builds a Hydrogen storefront for production'
static flags = {
...cli.globalFlags,
path: hydrogenFlags.path,
base: Flags.string({
description: ' the public path when served in production',
env: 'SHOPIFY_FLAG_BUILD_BASE',
}),
client: Flags.boolean({
description: 'build the client code',
// env: 'SHOPIFY_FLAG_BUILD_CLIENT',
allowNo: true,
default: true,
}),
target: Flags.string({
char: 't',
description: 'the target platform to build for (worker or node)',
options: ['node', 'worker'],
default: 'worker',
env: 'SHOPIFY_FLAG_BUILD_TARGET',
}),
entry: Flags.string({
description: 'produce Server Side Rendering (SSR) build for node environments',
env: 'SHOPIFY_FLAG_BUILD_SSR_ENTRY',
}),
}
async run(): Promise<void> {
const {flags} = await this.parse(Build)
const directory = flags.path ? path.resolve(flags.path) : process.cwd()
const entry = flags.entry || PLATFORM_ENTRIES[flags.target as 'node' | 'worker']
const targets = {
client: flags.client,
worker: flags.target === 'worker' ? entry : false,
node: flags.target === 'node' ? entry : false,
}
await build({...flags, directory, targets})
}
}