1
- import colors from 'kleur ' ;
1
+ import pc from 'picocolors ' ;
2
2
import fs from 'node:fs' ;
3
3
import process from 'node:process' ;
4
- import prompts from 'prompts' ;
4
+ import * as p from '@clack/ prompts' ;
5
5
import semver from 'semver' ;
6
6
import glob from 'tiny-glob/sync.js' ;
7
- import { bail , check_git , update_svelte_file } from '../../utils.js' ;
7
+ import { bail , check_git , migration_succeeded , update_svelte_file } from '../../utils.js' ;
8
8
import { transform_svelte_code , update_pkg_json } from './migrate.js' ;
9
9
10
10
export async function migrate ( ) {
@@ -16,66 +16,61 @@ export async function migrate() {
16
16
17
17
const svelte_dep = pkg . devDependencies ?. svelte ?? pkg . dependencies ?. svelte ;
18
18
if ( svelte_dep && semver . validRange ( svelte_dep ) && semver . gtr ( '5.0.0' , svelte_dep ) ) {
19
- console . log (
20
- colors
21
- . bold ( )
22
- . red ( '\nYou need to upgrade to Svelte version 5 first (`npx sv migrate svelte-5`).\n' )
19
+ p . log . error (
20
+ pc . bold ( pc . red ( 'You need to upgrade to Svelte version 5 first (`npx sv migrate svelte-5`).' ) )
23
21
) ;
24
22
process . exit ( 1 ) ;
25
23
}
26
24
27
25
const kit_dep = pkg . devDependencies ?. [ '@sveltejs/kit' ] ?? pkg . dependencies ?. [ '@sveltejs/kit' ] ;
28
26
if ( kit_dep && semver . validRange ( kit_dep ) && semver . gtr ( '2.0.0' , kit_dep ) ) {
29
- console . log (
30
- colors
31
- . bold ( )
32
- . red ( '\nYou need to upgrade to SvelteKit version 2 first (`npx sv migrate sveltekit-2`).\n' )
27
+ p . log . error (
28
+ pc . bold (
29
+ pc . red ( 'You need to upgrade to SvelteKit version 2 first (`npx sv migrate sveltekit-2`).' )
30
+ )
33
31
) ;
34
32
process . exit ( 1 ) ;
35
33
}
36
34
37
- console . log (
38
- colors
39
- . bold ( )
40
- . yellow (
41
- '\nThis will update files in the current directory\n' +
42
- "If you're inside a monorepo, don't run this in the root directory, rather run it in all projects independently.\n"
35
+ p . log . warning (
36
+ pc . bold ( pc . yellow ( 'This will update files in the current directory.' ) ) +
37
+ '\n' +
38
+ pc . bold (
39
+ pc . yellow (
40
+ "If you're inside a monorepo, don't run this in the root directory, rather run it in all projects independently."
41
+ )
43
42
)
44
43
) ;
45
44
46
45
const use_git = check_git ( ) ;
47
46
48
- const response = await prompts ( {
49
- type : 'confirm' ,
50
- name : 'value' ,
47
+ const response = await p . confirm ( {
51
48
message : 'Continue?' ,
52
- initial : false
49
+ initialValue : false
53
50
} ) ;
54
51
55
- if ( ! response . value ) {
52
+ if ( p . isCancel ( response ) || ! response ) {
56
53
process . exit ( 1 ) ;
57
54
}
58
55
59
- const folders = await prompts ( {
60
- type : 'multiselect' ,
61
- name : 'value' ,
56
+ const folders = await p . multiselect ( {
62
57
message : 'Which folders should be migrated?' ,
63
- choices : fs
58
+ options : fs
64
59
. readdirSync ( '.' )
65
60
. filter (
66
61
( dir ) => fs . statSync ( dir ) . isDirectory ( ) && dir !== 'node_modules' && ! dir . startsWith ( '.' )
67
62
)
68
63
. map ( ( dir ) => ( { title : dir , value : dir , selected : true } ) )
69
64
} ) ;
70
65
71
- if ( ! folders . value ?. length ) {
66
+ if ( p . isCancel ( folders ) || ! folders ?. length ) {
72
67
process . exit ( 1 ) ;
73
68
}
74
69
75
70
update_pkg_json ( ) ;
76
71
77
72
// For some reason {folders.value.join(',')} as part of the glob doesn't work and returns less files
78
- const files = folders . value . flatMap (
73
+ const files = folders . flatMap (
79
74
/** @param {string } folder */ ( folder ) =>
80
75
glob ( `${ folder } /**` , { filesOnly : true , dot : true } )
81
76
. map ( ( file ) => file . replace ( / \\ / g, '/' ) )
@@ -96,24 +91,15 @@ export async function migrate() {
96
91
) ;
97
92
}
98
93
99
- console . log ( colors . bold ( ) . green ( '✔ Your project has been migrated' ) ) ;
100
-
101
- console . log ( '\nRecommended next steps:\n' ) ;
102
-
103
- const cyan = colors . bold ( ) . cyan ;
104
-
105
- const tasks = [
106
- "install the updated dependencies ('npm i' / 'pnpm i' / etc) " + use_git &&
107
- cyan ( 'git commit -m "migration to $app/state"' )
108
- ] . filter ( Boolean ) ;
109
-
110
- tasks . forEach ( ( task , i ) => {
111
- console . log ( ` ${ i + 1 } : ${ task } ` ) ;
112
- } ) ;
113
-
114
- console . log ( '' ) ;
94
+ /** @type {(s: string) => string } */
95
+ const cyan = ( s ) => pc . bold ( pc . cyan ( s ) ) ;
115
96
97
+ // TODO: use package-manager-detector here
98
+ const tasks = [ "install the updated dependencies ('npm i' / 'pnpm i' / etc)" ] ;
116
99
if ( use_git ) {
117
- console . log ( `Run ${ cyan ( 'git diff' ) } to review changes.\n` ) ;
100
+ tasks . push ( cyan ( 'git commit -m "migration to $app/state"' ) ) ;
101
+ tasks . push ( `Run ${ cyan ( 'git diff' ) } to review changes.` ) ;
118
102
}
103
+
104
+ migration_succeeded ( tasks ) ;
119
105
}
0 commit comments