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 projectRoot = getGlobalVariable ( 'projects-root' ) ;
23+ const tempRoot = join ( projectRoot , 'assets' , `${ assetName } -${ seed } ` ) ;
2524 const root = assetDir ( assetName ) ;
25+ const destinationPath = to !== undefined ? resolve ( projectRoot , 'test-project' , to ) : tempRoot ;
2626
27- return Promise . resolve ( )
28- . then ( ( ) => {
29- const allFiles = glob . sync ( '**/*' , { dot : true , cwd : root } ) ;
27+ await cp ( root , destinationPath , { recursive : true , mode : 0o777 } ) ;
3028
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 ) ;
36-
37- return promise
38- . then ( ( ) => copyFile ( join ( root , filePath ) , toPath ) )
39- . then ( ( ) => chmod ( toPath , 0o777 ) ) ;
40- } , Promise . resolve ( ) ) ;
41- } )
42- . then ( ( ) => tempRoot ) ;
29+ return destinationPath ;
4330}
4431
4532/**
@@ -59,6 +46,7 @@ export async function createProjectFromAsset(
5946 if ( ! useNpmPackages ) {
6047 await useBuiltPackagesVersions ( ) ;
6148 }
49+
6250 if ( ! skipInstall ) {
6351 await installWorkspacePackages ( ) ;
6452 }
0 commit comments