Skip to content

Commit

Permalink
feat: add update command
Browse files Browse the repository at this point in the history
  • Loading branch information
rpidanny committed Jul 3, 2024
1 parent 8ec4f7d commit 19a1aaa
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
4 changes: 2 additions & 2 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
Updating Darwin is straightforward. Execute the following command:

```bash
npm i -g @rpidanny/darwin@latest
darwin update
```

This command will globally install the latest version of Darwin from the npm registry, ensuring you have the most up-to-date features and improvements available.
This command will install the latest version of Darwin, ensuring you have the most up-to-date features and improvements available.

## How do I configure Darwin to work with a local LLM?

Expand Down
24 changes: 24 additions & 0 deletions src/commands/update/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { spawn } from 'child_process'

import { BaseCommand } from '../../base.command.js'

export default class Update extends BaseCommand<typeof Update> {
static override description = 'Update Darwin to the latest version.'

static override examples = ['<%= config.bin %> <%= command.id %>']

public async run(): Promise<void> {
this.logger.info('Updating Darwin...')

const shell = spawn('npm install -g @rpidanny/darwin@latest', {
stdio: 'inherit',
shell: true,
})

shell.on('close', (code: number | null) => {
if (code !== null && code !== 0) {
this.exit(code)
}
})
}
}
2 changes: 1 addition & 1 deletion src/hooks/init/check-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import semver from 'semver'
import ui from '../../utils/ui/output.js'

const hook: Hook<'init'> = async function (opts) {
if (opts.id && ['autocomplete:script', 'readme'].includes(opts.id)) return
if (opts.id && ['autocomplete:script', 'readme', 'update'].includes(opts.id)) return

try {
const { version: latestVersion } = await got(
Expand Down
2 changes: 1 addition & 1 deletion src/utils/ui/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function printUpdateBanner(version: string, log: (msg: string) => void): void {
log(
`${chalk.hex('#cf402f')(
`A new version (v${version}) of darwin is available. Please run ${chalk.bold(
'npm install -g @rpidanny/darwin@latest',
'darwin update',
)} to update and enjoy the latest features!`,
)}`,
)
Expand Down

0 comments on commit 19a1aaa

Please sign in to comment.