1- import { join } from 'node:path' ;
2- import { chmod } from 'node:fs/promises' ;
3- import glob from 'fast-glob' ;
1+ import { join , resolve } from 'node:path' ;
2+ import { cp } from 'node:fs/promises' ;
43import { getGlobalVariable } from './env' ;
5- import { resolve } from 'node:path' ;
64import { copyFile } from './fs' ;
75import { installWorkspacePackages , setRegistry } from './packages' ;
86import { useBuiltPackagesVersions } from './project' ;
97
10- export function assetDir ( assetName : string ) {
8+ export function assetDir ( assetName : string ) : string {
119 return join ( __dirname , '../e2e/assets' , assetName ) ;
1210}
1311
14- export function copyProjectAsset ( assetName : string , to ?: string ) {
12+ export function copyProjectAsset ( assetName : string , to ?: string ) : Promise < void > {
1513 const tempRoot = join ( getGlobalVariable ( 'projects-root' ) , 'test-project' ) ;
1614 const sourcePath = assetDir ( assetName ) ;
1715 const targetPath = join ( tempRoot , to || assetName ) ;
1816
1917 return copyFile ( sourcePath , targetPath ) ;
2018}
2119
22- export function copyAssets ( assetName : string , to ?: string ) {
20+ export async function copyAssets ( assetName : string , to ?: string ) : Promise < string > {
2321 const seed = + Date . now ( ) ;
24- const tempRoot = join ( getGlobalVariable ( 'projects-root' ) , 'assets' , assetName + '-' + seed ) ;
22+ const tempRoot = join ( getGlobalVariable ( 'projects-root' ) , 'assets' , ` ${ assetName } - ${ seed } ` ) ;
2523 const root = assetDir ( assetName ) ;
2624
27- return Promise . resolve ( )
28- . then ( ( ) => {
29- const allFiles = glob . sync ( '**/*' , { dot : true , cwd : root } ) ;
25+ const destinationPath =
26+ to !== undefined ? resolve ( getGlobalVariable ( 'projects-root' ) , 'test-project' , to ) : tempRoot ;
3027
31- return allFiles . reduce ( ( promise , filePath ) => {
32- const toPath =
33- to !== undefined
34- ? resolve ( getGlobalVariable ( 'projects-root' ) , 'test-project' , to , filePath )
35- : join ( tempRoot , filePath ) ;
28+ await cp ( root , destinationPath , { recursive : true , mode : 0o777 } ) ;
3629
37- return promise
38- . then ( ( ) => copyFile ( join ( root , filePath ) , toPath ) )
39- . then ( ( ) => chmod ( toPath , 0o777 ) ) ;
40- } , Promise . resolve ( ) ) ;
41- } )
42- . then ( ( ) => tempRoot ) ;
30+ return destinationPath ;
4331}
4432
4533/**
@@ -59,6 +47,7 @@ export async function createProjectFromAsset(
5947 if ( ! useNpmPackages ) {
6048 await useBuiltPackagesVersions ( ) ;
6149 }
50+
6251 if ( ! skipInstall ) {
6352 await installWorkspacePackages ( ) ;
6453 }
0 commit comments