-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c4decf5
commit e96be15
Showing
1 changed file
with
19 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,25 @@ | ||
import { Argument, Command } from 'commander'; | ||
import { COMMANDS, constructCommand, detect } from 'package-manager-detector'; | ||
import { execSync } from 'node:child_process'; | ||
import { exec } from 'tinyexec'; | ||
import { Command } from 'commander'; | ||
import { COMMANDS, constructCommand } from 'package-manager-detector'; | ||
import * as common from '../common.js'; | ||
|
||
const migrationChoices = ['sveltekit-2', 'svelte-4', 'svelte-5', 'package', 'routes']; | ||
const migrationOption = new Argument('<migration>', 'migration to run').choices(migrationChoices); | ||
|
||
export const migrate = new Command('migrate') | ||
.description('A CLI for migrating Svelte(Kit) codebases.') | ||
.addArgument(migrationOption) | ||
.configureHelp(common.helpConfig) | ||
.action((migration) => { | ||
common.runCommand(async () => { | ||
const cwd = process.cwd(); | ||
|
||
const detectedPm = await detect({ cwd }); | ||
const selectedPm = detectedPm?.agent ?? null; | ||
|
||
if (!selectedPm) throw new Error('Unable to detect package manage'); | ||
|
||
const { command, args } = constructCommand(COMMANDS[selectedPm].execute, [ | ||
'svelte-migrate@latest', | ||
migration | ||
])!; | ||
.description('A CLI for migrating Svelte(Kit) codebases') | ||
.argument('<migration>', 'migration to run') | ||
.configureHelp({ | ||
formatHelp() { | ||
execSync('npx svelte-migrate@latest --help', { stdio: 'inherit', encoding: 'utf8' }); | ||
return ''; | ||
} | ||
}) | ||
.action(async (migration) => { | ||
const cwd = process.cwd(); | ||
const pm = await common.guessPackageManager(cwd); | ||
const { command, args } = constructCommand(COMMANDS[pm].execute, [ | ||
'svelte-migrate@latest', | ||
migration | ||
])!; | ||
|
||
await exec(command, args, { nodeOptions: { cwd, stdio: 'inherit' } }); | ||
}); | ||
await exec(command, args, { nodeOptions: { cwd, stdio: 'inherit' } }); | ||
}); |