1- import fs from 'node:fs/promises'
21import { KIT_FIRST_PATH } from '../core/utils.js'
32
43async function downloadAndSetupExamples ( ) {
@@ -10,46 +9,35 @@ async function downloadAndSetupExamples() {
109
1110 let source = path . join ( destination , 'kit-examples-main' )
1211 let newDestination = kenvPath ( 'kenvs' , 'examples' )
13- await fs . rename ( source , newDestination )
12+ await rename ( source , newDestination )
13+ }
1414
15- let files = await fs . readdir ( path . join ( newDestination , 'scripts' ) )
16- let firstFile = path . join ( newDestination , 'scripts' , files [ 0 ] )
17- if ( await fs . stat ( firstFile ) ) {
18- await wait ( 1000 )
19- await fs . utimes ( firstFile , new Date ( ) , new Date ( ) )
20- }
15+ async function pnpmInstallExamples ( ) {
16+ await exec ( 'pnpm i' , {
17+ cwd : kenvPath ( 'kenvs' , 'examples' ) ,
18+ env : {
19+ ...global . env ,
20+ PATH : KIT_FIRST_PATH
21+ }
22+ } ) . catch ( ( error ) => {
23+ console . error ( error )
24+ } )
2125}
2226
2327let examplesDir = kenvPath ( 'kenvs' , 'examples' )
24- if ( await isDir ( examplesDir ) ) {
25- cd ( examplesDir )
2628
27- if ( isDir ( kenvPath ( 'kenvs' , 'examples' , '.git' ) ) ) {
28- await exec ( 'git stash' , {
29- cwd : examplesDir
30- } )
31- await exec ( 'git pull' , {
32- cwd : examplesDir
33- } )
34- }
35- } else if ( await isBin ( 'git' ) ) {
29+ if ( await isDir ( examplesDir ) ) {
30+ await exec ( 'git pull --rebase --autostash --stat' , {
31+ cwd : examplesDir
32+ } )
33+ } else {
3634 try {
37- await exec ( 'git clone --depth 1 --verbose --progress git ://github.com/johnlindquist/kit-examples-ts.git examples' , {
35+ await exec ( 'git clone --depth 1 https ://github.com/johnlindquist/kit-examples-ts examples' , {
3836 cwd : kenvPath ( 'kenvs' )
3937 } )
4038 } catch ( error ) {
4139 await downloadAndSetupExamples ( )
4240 }
43- } else {
44- await downloadAndSetupExamples ( )
4541}
4642
47- try {
48- await exec ( 'pnpm i' , {
49- cwd : kenvPath ( 'kenvs' , 'examples' ) ,
50- env : {
51- ...global . env ,
52- PATH : KIT_FIRST_PATH
53- }
54- } )
55- } catch ( error ) { }
43+ await pnpmInstallExamples ( )
0 commit comments