Skip to content

Commit

Permalink
feat(setup/update): add interactive mode (#206)
Browse files Browse the repository at this point in the history
* feat(setup): add interactive mode

* docs(setup/update): add note about interactive input
  • Loading branch information
HipsterBrown authored Jan 5, 2025
1 parent f90a3df commit 66f948e
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 26 deletions.
6 changes: 6 additions & 0 deletions docs/src/content/docs/features/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ The [`moddable` git repo](https://github.com/Moddable-OpenSource/moddable) is cl

This command will create (and update) an environment configuration file called `~/.local/share/xs-dev-export.sh` (on Mac & Linux) or `Moddable.bat` (on Windows). This file will be sourced by `xs-dev` when running commands (on Mac & Linux) or through the custom command prompt (on Windows), to set environment variables and call other "exports" files for embedded tooling.

## Interactive Input

By default, this command may prompt during the setup process. To override this behavior, use the `--noInteractive` flag.

If there is a environment variable called `CI` set to `true`, then this command will be non-interactive and automatically accept all prompts.

## Tagged Release

The default behavior of this command for Moddable developer tooling pulls the [latest release tooling](https://github.com/Moddable-OpenSource/moddable/releases) and source code for the associated tagged branch. This provides a known-working state for the SDK and avoids needing to build the tooling on the local machine.
Expand Down
6 changes: 6 additions & 0 deletions docs/src/content/docs/features/update.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ Stay up to date with the latest tooling from Moddable and supported device targe
xs-dev update
```

## Interactive Input

By default, this command may prompt during the update process. To override this behavior, use the `--noInteractive` flag.

If there is a environment variable called `CI` set to `true`, then this command will be non-interactive and automatically accept all prompts.

## Tagged Release

The default behavior of this command for Moddable developer tooling pulls the [latest release tooling](https://github.com/Moddable-OpenSource/moddable/releases) and source code for the associated tagged branch. This provides a known-working state for the SDK and avoids needing to build the tooling on the local machine.
Expand Down
15 changes: 14 additions & 1 deletion src/commands/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface SetupOptions {
branch?: SetupArgs['branch']
release?: SetupArgs['release']
'source-repo'?: string
interactive?: boolean
}
const command = buildCommand({
docs: {
Expand All @@ -29,6 +30,7 @@ const command = buildCommand({
branch,
release = 'latest',
'source-repo': sourceRepo = MODDABLE_REPO,
interactive = true,
} = flags
let target: Device =
DEVICE_ALIAS[device ?? ('' as Device)] ?? DEVICE_ALIAS[currentPlatform]
Expand Down Expand Up @@ -78,7 +80,12 @@ const command = buildCommand({
]
const { default: setup } = await import(`../toolbox/setup/${target}`)
if (platformDevices.includes(target)) {
await setup({ branch, release, sourceRepo })
await setup({
branch,
release,
sourceRepo,
interactive: Boolean(process.env.CI) || interactive,
})
} else {
await setup({ branch, release })
}
Expand Down Expand Up @@ -124,6 +131,12 @@ const command = buildCommand({
'URL for remote repository to use as source for Moddable SDK set up; defaults to upstream project',
optional: true,
},
interactive: {
kind: 'boolean',
brief:
'Choose whether to show any prompts or automatically accept them; defaults to true unless CI environment variable is true.',
optional: true,
},
},
},
})
Expand Down
20 changes: 18 additions & 2 deletions src/commands/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface UpdateOptions {
device?: Device
branch?: 'public' | string
release?: 'latest' | string
interactive?: boolean
}

const command = buildCommand({
Expand All @@ -16,11 +17,20 @@ const command = buildCommand({
},
async func(this: LocalContext, flags: UpdateOptions) {
const currentPlatform: Device = platformType().toLowerCase() as Device
const { device = currentPlatform, branch, release = 'latest' } = flags
const {
device = currentPlatform,
branch,
release = 'latest',
interactive = true,
} = flags
const { default: update } = await import(
`../toolbox/update/${DEVICE_ALIAS[device]}`
)
await update({ branch, release })
await update({
branch,
release,
interactive: Boolean(process.env.CI) || interactive,
})
},
parameters: {
flags: {
Expand All @@ -45,6 +55,12 @@ const command = buildCommand({
'The tagged release to use as source for Moddable SDK update; defaults to `latest`',
optional: true,
},
interactive: {
kind: 'boolean',
brief:
'Choose whether to show any prompts or automatically accept them; defaults to true unless CI environment variable is true.',
optional: true,
},
},
},
})
Expand Down
11 changes: 7 additions & 4 deletions src/toolbox/setup/linux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default async function ({
sourceRepo,
branch,
release,
interactive,
}: PlatformSetupArgs): Promise<void> {
print.info('Setting up Linux tools!')

Expand Down Expand Up @@ -80,10 +81,12 @@ export default async function ({
print.warning(
`Moddable release ${release} does not have any pre-built assets.`,
)
buildTools = await prompt.confirm(
'Would you like to continue setting up and build the SDK locally?',
true,
)
buildTools =
!interactive ||
(await prompt.confirm(
'Would you like to continue setting up and build the SDK locally?',
true,
))

if (!buildTools) {
print.info(
Expand Down
11 changes: 7 additions & 4 deletions src/toolbox/setup/mac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default async function ({
sourceRepo,
branch,
release,
interactive,
}: PlatformSetupArgs): Promise<void> {
print.info('Setting up the mac tools!')

Expand Down Expand Up @@ -84,10 +85,12 @@ export default async function ({
print.warning(
`Moddable release ${release} does not have any pre-built assets.`,
)
buildTools = await prompt.confirm(
'Would you like to continue setting up and build the SDK locally?',
true,
)
buildTools =
!interactive ||
(await prompt.confirm(
'Would you like to continue setting up and build the SDK locally?',
true,
))

if (!buildTools) {
print.info(
Expand Down
2 changes: 1 addition & 1 deletion src/toolbox/setup/moddable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const finishedPromise = promisify(finished)

export function moddableExists(): boolean {
const OS = platformType().toLowerCase() as Device
const platformDir = DEVICE_ALIAS[OS].substr(0,3)
const platformDir = DEVICE_ALIAS[OS].substr(0, 3)
const releaseTools = filesystem.exists(
filesystem.resolve(INSTALL_PATH, 'build', 'bin', platformDir, 'release'),
)
Expand Down
1 change: 1 addition & 0 deletions src/toolbox/setup/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export interface SetupArgs {
branch: 'public' | string
release: 'latest' | string
interactive: boolean
}

export interface PlatformSetupArgs extends SetupArgs {
Expand Down
11 changes: 7 additions & 4 deletions src/toolbox/setup/windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export default async function ({
sourceRepo,
branch,
release,
interactive,
}: PlatformSetupArgs): Promise<void> {
const BIN_PATH = filesystem.resolve(
INSTALL_PATH,
Expand Down Expand Up @@ -227,10 +228,12 @@ export default async function ({
print.warning(
`Moddable release ${release} does not have any pre-built assets.`,
)
buildTools = await prompt.confirm(
'Would you like to continue setting up and build the SDK locally?',
true,
)
buildTools =
!interactive ||
(await prompt.confirm(
'Would you like to continue setting up and build the SDK locally?',
true,
))

if (!buildTools) {
print.info(
Expand Down
16 changes: 11 additions & 5 deletions src/toolbox/update/linux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ import { execWithSudo, sourceEnvironment } from '../system/exec'

const chmodPromise = promisify(chmod)

export default async function ({ branch, release }: SetupArgs): Promise<void> {
export default async function ({
branch,
release,
interactive,
}: SetupArgs): Promise<void> {
await sourceEnvironment()

// 0. ensure Moddable exists
Expand Down Expand Up @@ -51,10 +55,12 @@ export default async function ({ branch, release }: SetupArgs): Promise<void> {
print.warning(
`Moddable release ${release} does not have any pre-built assets.`,
)
rebuildTools = await prompt.confirm(
'Would you like to continue updating and build the SDK locally?',
false,
)
rebuildTools =
!interactive ||
(await prompt.confirm(
'Would you like to continue updating and build the SDK locally?',
false,
))

if (!rebuildTools) {
print.info(
Expand Down
16 changes: 11 additions & 5 deletions src/toolbox/update/mac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ import { sourceEnvironment } from '../system/exec'

const chmodPromise = promisify(chmod)

export default async function ({ branch, release }: SetupArgs): Promise<void> {
export default async function ({
branch,
release,
interactive,
}: SetupArgs): Promise<void> {
print.info('Checking for SDK changes')

await sourceEnvironment()
Expand Down Expand Up @@ -46,10 +50,12 @@ export default async function ({ branch, release }: SetupArgs): Promise<void> {
print.warning(
`Moddable release ${release} does not have any pre-built assets.`,
)
rebuildTools = await prompt.confirm(
'Would you like to continue updating and build the SDK locally?',
false,
)
rebuildTools =
!interactive ||
(await prompt.confirm(
'Would you like to continue updating and build the SDK locally?',
false,
))

if (!rebuildTools) {
print.info(
Expand Down

0 comments on commit 66f948e

Please sign in to comment.