-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcopy-assets.mjs
30 lines (27 loc) · 1.08 KB
/
copy-assets.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { globby } from "globby";
import { dirname, join } from "path";
import { copyFile, mkdir } from "fs/promises";
const toShortTime = timespan => {
if ( timespan > 1000 ) {
return ( timespan / 1000 ).toFixed( 3 )
.replace( /[.,]?0+$/i, "" ) + "s";
}
return timespan + "ms";
};
const performCopy = async(source, target, patterns) => {
const started = Date.now();
try {
console.log( `copying "${ source }" to "${ target }"...` );
const found = await globby( patterns, { cwd: source } );
await Promise.all( found.map( file => {
const output = join( target, file );
return mkdir( dirname( output ), { recursive: true } )
.then( () => copyFile( join( source, file ), output ) );
} ) );
console.log( `copied "${ source }" in ${ toShortTime( Date.now() - started ) }` );
} catch ( err ) {
console.error( `copy error: ${ err.message }` );
}
};
await performCopy( "./src/media", "./assets/media", [ '**/*' ] );
await performCopy( "./src/admin", "./assets/admin", [ '**/*' ] );