@ -1,6 +1,16 @@
// Creates a test from the existing playground. cwd needs to be playground/sandbox
// Creates a test from the existing playground. Can be called from anywhere.
import fs from 'fs' ;
import path from 'path' ;
import { fileURLToPath } from 'url' ;
// Get the directory where this script is located
const _ _filename = fileURLToPath ( import . meta . url ) ;
const _ _dirname = path . dirname ( _ _filename ) ;
// Base paths relative to this script's location
const sandbox _dir = path . resolve ( _ _dirname , '..' ) ;
const src _dir = path . join ( sandbox _dir , 'src' ) ;
const tests _dir = path . resolve ( _ _dirname , '../../../packages/svelte/tests' ) ;
// Get target folder from command line arguments
let target _folder = process . argv [ 2 ] ;
@ -20,7 +30,7 @@ if (!target_folder.startsWith('runtime-')) {
process . exit ( 1 ) ;
}
target _folder = path . join (
path . resolve ( '../../packages/svelte/tests' , target _folder . split ( '/' ) [ 0 ] ) ,
path . resolve ( tests _dir , target _folder . split ( '/' ) [ 0 ] ) ,
'samples' ,
target _folder . split ( '/' ) [ 1 ]
) ;
@ -56,8 +66,8 @@ if (exists) {
const files = fs . readdirSync ( target _folder ) ;
for ( const file of files ) {
if ( file !== '_config.js' ) {
const file P ath = path . join ( target _folder , file ) ;
fs . rmSync ( file P ath, { recursive : true , force : true } ) ;
const file _p ath = path . join ( target _folder , file ) ;
fs . rmSync ( file _p ath, { recursive : true , force : true } ) ;
}
}
} else {
@ -65,7 +75,7 @@ if (exists) {
}
// Starting file
const app _svelte _path = path . resolve( './src/ App.svelte') ;
const app _svelte _path = path . join( src _dir , ' App.svelte') ;
const collected _files = new Set ( ) ;
const processed _files = new Set ( ) ;
@ -117,7 +127,7 @@ collect_imports(app_svelte_path);
// Copy collected files to target folder
for ( const file _path of collected _files ) {
const relative _path = path . relative ( path. resolve ( './src' ) , file _path ) ;
const relative _path = path . relative ( src_dir , file _path ) ;
let target _path = path . join ( target _folder , relative _path ) ;
// Rename App.svelte to main.svelte