Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add update command #75

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading