@@ -2,11 +2,10 @@ import { promises as fs } from 'fs';
2
2
import path from 'path' ;
3
3
4
4
const PACKAGE_FOLDER = process . env . PACKAGE_FOLDER || 'package' ;
5
- const TARGETS = [ 'components' , 'config' , 'src' , 'stores' ] ;
6
- const BASE_DIR = path . join ( process . cwd ( ) , PACKAGE_FOLDER ) ;
5
+ const CWD = process . cwd ( ) ;
7
6
8
7
const getFolder = async ( folder , depth = 0 ) => {
9
- const contents = await fs . readdir ( path . join ( process . cwd ( ) , PACKAGE_FOLDER , folder ) , {
8
+ const contents = await fs . readdir ( path . join ( CWD , folder ) , {
10
9
withFileTypes : true
11
10
} ) ;
12
11
@@ -24,7 +23,7 @@ const getFolder = async (folder, depth = 0) => {
24
23
const transformFolder = async ( { folders, files, depth } ) => {
25
24
await Promise . all (
26
25
files . map ( async ( f ) => {
27
- const filepath = path . join ( BASE_DIR , f ) ;
26
+ const filepath = path . join ( CWD , f ) ;
28
27
const contents = await fs . readFile ( filepath , 'utf-8' ) ;
29
28
const base = depth ? [ ...Array ( depth + 1 ) . fill ( '..' ) ] . join ( '/' ) : './' ;
30
29
const updated = contents . replace ( / f r o m ' \$ l i b ( .* ) ' / g, `from '${ base } $1'` ) ;
@@ -38,4 +37,7 @@ const transformFolder = async ({ folders, files, depth }) => {
38
37
) ;
39
38
} ;
40
39
41
- Promise . all ( TARGETS . map ( ( t ) => getFolder ( t ) . then ( transformFolder ) ) ) ;
40
+ getFolder ( PACKAGE_FOLDER )
41
+ . then ( transformFolder )
42
+ . catch ( console . error )
43
+ . finally ( ( ) => process . exit ( ) ) ;
0 commit comments