Skip to content

Commit

Permalink
fix: use kebab-case command flags, loosen device target typing for bu…
Browse files Browse the repository at this point in the history
…ild/run commands (#196)

* fix: command flags are kebab case, not camelCase

* fix: configure target platform as string to accommodate sub-targets

* refactor: prettier formatting changes
  • Loading branch information
HipsterBrown authored Dec 22, 2024
1 parent df44e16 commit 8f47ef2
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 55 deletions.
20 changes: 10 additions & 10 deletions src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import { DEVICE_ALIAS } from '../toolbox/prompt/devices'
type Mode = 'development' | 'production'

interface BuildOptions {
device?: Device
device?: string
port?: string
example?: string
listExamples?: boolean
listDevices?: boolean
'list-examples'?: boolean
'list-devices'?: boolean
mode?: Mode
output?: string
deploy?: boolean
Expand All @@ -35,14 +35,14 @@ const command = buildCommand({
device = currentPlatform,
deploy = false,
example,
listExamples = false,
listDevices = false,
'list-examples': listExamples = false,
'list-devices': listDevices = false,
mode = (process.env.NODE_ENV as Mode) ?? 'development',
output,
port,
config = [],
} = flags
const targetPlatform: string = DEVICE_ALIAS[device] ?? device
const targetPlatform: string = DEVICE_ALIAS[device as Device] ?? device
projectPath = filesystem.resolve(projectPath)
const parsedConfig = config.reduce<Record<string, string>>(
(result, setting) => {
Expand Down Expand Up @@ -81,8 +81,8 @@ const command = buildCommand({
},
flags: {
device: {
kind: 'enum',
values: Object.keys(DEVICE_ALIAS) as NonNullable<Device[]>,
kind: 'parsed',
parse: String,
brief:
'Target device or platform for the project, use --list-devices to select from interactive list; defaults to current OS simulator',
optional: true,
Expand All @@ -99,12 +99,12 @@ const command = buildCommand({
'Name of example project to run, use --list-examples to select from an interactive list',
optional: true,
},
listExamples: {
'list-examples': {
kind: 'boolean',
brief: 'Select an example project from an interactive list',
optional: true,
},
listDevices: {
'list-devices': {
kind: 'boolean',
brief: 'Select a target device or platform from an interactive list',
optional: true,
Expand Down
20 changes: 10 additions & 10 deletions src/commands/clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import { DEVICE_ALIAS } from '../toolbox/prompt/devices'
type Mode = 'development' | 'production'

interface CleanOptions {
device?: Device
device?: string
example?: string
listExamples?: boolean
listDevices?: boolean
'list-examples'?: boolean
'list-devices'?: boolean
mode?: Mode
output?: string
config?: string[]
Expand All @@ -32,13 +32,13 @@ const command = buildCommand({
const {
device = currentPlatform,
example,
listExamples = false,
listDevices = false,
'list-examples': listExamples = false,
'list-devices': listDevices = false,
mode = (process.env.NODE_ENV as Mode) ?? 'development',
output,
config = [],
} = flags
const targetPlatform: string = DEVICE_ALIAS[device] ?? device
const targetPlatform: string = DEVICE_ALIAS[device as Device] ?? device
projectPath = filesystem.resolve(projectPath)
const parsedConfig = config.reduce<Record<string, string>>(
(result, setting) => {
Expand Down Expand Up @@ -76,8 +76,8 @@ const command = buildCommand({
},
flags: {
device: {
kind: 'enum',
values: Object.keys(DEVICE_ALIAS) as NonNullable<Device[]>,
kind: 'parsed',
parse: String,
brief:
'Target device or platform for the project, use --list-devices to select from interactive list; defaults to current OS simulator',
optional: true,
Expand All @@ -89,12 +89,12 @@ const command = buildCommand({
'Name of example project to run, use --list-examples to select from an interactive list',
optional: true,
},
listExamples: {
'list-examples': {
kind: 'boolean',
brief: 'Select an example project from an interactive list',
optional: true,
},
listDevices: {
'list-devices': {
kind: 'boolean',
brief: 'Select a target device or platform from an interactive list',
optional: true,
Expand Down
20 changes: 10 additions & 10 deletions src/commands/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import { DEVICE_ALIAS } from '../toolbox/prompt/devices'
type Mode = 'development' | 'production'

interface DebugOptions {
device?: Device
device?: string
port?: string
example?: string
listExamples?: boolean
listDevices?: boolean
'list-examples'?: boolean
'list-devices'?: boolean
log?: boolean
mode?: Mode
output?: string
Expand All @@ -33,14 +33,14 @@ const command = buildCommand({
device = currentPlatform,
port,
example,
listExamples = false,
listDevices = false,
'list-examples': listExamples = false,
'list-devices': listDevices = false,
log = false,
mode = (process.env.NODE_ENV as Mode) ?? 'development',
output,
} = flags
const { build } = await import('../toolbox/build/index')
const targetPlatform: string = DEVICE_ALIAS[device] ?? device
const targetPlatform: string = DEVICE_ALIAS[device as Device] ?? device
projectPath = filesystem.resolve(projectPath)

await build({
Expand Down Expand Up @@ -71,8 +71,8 @@ const command = buildCommand({
},
flags: {
device: {
kind: 'enum',
values: Object.keys(DEVICE_ALIAS) as NonNullable<Device[]>,
kind: 'parsed',
parse: String,
brief:
'Target device or platform for the project, use --list-devices to select from interactive list; defaults to current OS simulator',
optional: true,
Expand All @@ -84,12 +84,12 @@ const command = buildCommand({
'Name of example project to run, use --list-examples to select from an interactive list',
optional: true,
},
listExamples: {
'list-examples': {
kind: 'boolean',
brief: 'Select an example project from an interactive list',
optional: true,
},
listDevices: {
'list-devices': {
kind: 'boolean',
brief: 'Select a target device or platform from an interactive list',
optional: true,
Expand Down
6 changes: 3 additions & 3 deletions src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface InitOptions {
typescript?: boolean
io?: boolean
example?: string
listExamples?: boolean
'list-examples'?: boolean
overwrite?: boolean
asyncMain?: boolean
}
Expand All @@ -27,7 +27,7 @@ const command = buildCommand({
typescript = false,
io = false,
example,
listExamples = false,
'list-examples': listExamples = false,
overwrite = false,
asyncMain = false,
} = flags
Expand Down Expand Up @@ -157,7 +157,7 @@ const command = buildCommand({
parse: String,
optional: true,
},
listExamples: {
'list-examples': {
kind: 'boolean',
brief: 'Select an example project from the Moddable SDK',
optional: true,
Expand Down
20 changes: 10 additions & 10 deletions src/commands/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import { DEVICE_ALIAS } from '../toolbox/prompt/devices'
type Mode = 'development' | 'production'

interface RunOptions {
device?: Device
device?: string
port?: string
example?: string
listExamples?: boolean
listDevices?: boolean
'list-examples'?: boolean
'list-devices'?: boolean
log?: boolean
mode?: Mode
output?: string
Expand All @@ -30,15 +30,15 @@ const command = buildCommand({
const {
device = currentPlatform,
example,
listExamples = false,
listDevices = false,
'list-examples': listExamples = false,
'list-devices': listDevices = false,
log = false,
mode = (process.env.NODE_ENV as Mode) ?? 'development',
output,
port,
config = [],
} = flags
const targetPlatform: string = DEVICE_ALIAS[device] ?? device
const targetPlatform: string = DEVICE_ALIAS[device as Device] ?? device
projectPath = filesystem.resolve(projectPath)
const parsedConfig = config.reduce<Record<string, string>>(
(result, setting) => {
Expand Down Expand Up @@ -78,8 +78,8 @@ const command = buildCommand({
},
flags: {
device: {
kind: 'enum',
values: Object.keys(DEVICE_ALIAS) as NonNullable<Device[]>,
kind: 'parsed',
parse: String,
brief:
'Target device or platform for the project, use --list-devices to select from interactive list; defaults to current OS simulator',
optional: true,
Expand All @@ -91,12 +91,12 @@ const command = buildCommand({
'Name of example project to run, use --list-examples to select from an interactive list',
optional: true,
},
listExamples: {
'list-examples': {
kind: 'boolean',
brief: 'Select an example project from an interactive list',
optional: true,
},
listDevices: {
'list-devices': {
kind: 'boolean',
brief: 'Select a target device or platform from an interactive list',
optional: true,
Expand Down
18 changes: 9 additions & 9 deletions src/commands/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import type { SetupArgs } from '../toolbox/setup/types'

interface SetupOptions {
device?: Device
listDevices?: boolean
'list-devices'?: boolean
tool?: 'ejectfix'
targetBranch?: SetupArgs['targetBranch']
sourceRepo?: string
'target-branch'?: SetupArgs['targetBranch']
'source-repo'?: string
}
const command = buildCommand({
docs: {
Expand All @@ -23,10 +23,10 @@ const command = buildCommand({
const currentPlatform: Device = platformType().toLowerCase() as Device
const {
device,
listDevices = false,
'list-devices': listDevices = false,
tool,
targetBranch = 'latest-release',
sourceRepo = MODDABLE_REPO,
'target-branch': targetBranch = 'latest-release',
'source-repo': sourceRepo = MODDABLE_REPO,
} = flags
let target: Device = device ?? DEVICE_ALIAS[currentPlatform]

Expand Down Expand Up @@ -88,7 +88,7 @@ const command = buildCommand({
'Target device or platform SDK to set up; defaults to Moddable SDK for current OS; use --list-devices for interactive selection',
optional: true,
},
listDevices: {
'list-devices': {
kind: 'boolean',
brief:
'Select target device or platform SDK to set up from a list; defaults to false',
Expand All @@ -100,14 +100,14 @@ const command = buildCommand({
brief: 'Install additional tooling to support common development tasks',
optional: true,
},
targetBranch: {
'target-branch': {
kind: 'parsed',
parse: String,
brief:
'The remote branch or release to use as source for Moddable SDK set up; defaults to `latest-release`',
optional: true,
},
sourceRepo: {
'source-repo': {
kind: 'parsed',
parse: String,
brief:
Expand Down
6 changes: 3 additions & 3 deletions src/commands/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { DEVICE_ALIAS } from '../toolbox/prompt/devices'

interface UpdateOptions {
device?: Device
targetBranch?: 'public' | 'latest-release'
'target-branch'?: 'public' | 'latest-release'
}

const command = buildCommand({
Expand All @@ -17,7 +17,7 @@ const command = buildCommand({
const currentPlatform: Device = platformType().toLowerCase() as Device
const {
device = DEVICE_ALIAS[currentPlatform],
targetBranch = 'latest-release',
'target-branch': targetBranch = 'latest-release',
} = flags
const { default: update } = await import(`../toolbox/update/${device}`)
await update({ targetBranch })
Expand All @@ -31,7 +31,7 @@ const command = buildCommand({
'Target device or platform SDK to set up; defaults to Moddable SDK for current OS',
optional: true,
},
targetBranch: {
'target-branch': {
kind: 'enum',
values: ['public', 'latest-release'],
brief:
Expand Down

0 comments on commit 8f47ef2

Please sign in to comment.