1
1
const { promises : fs , existsSync, rmdirSync } = require ( 'fs' ) ;
2
2
const path = require ( 'path' ) ;
3
+ const reactAppRewired = require ( 'react-app-rewired' ) ;
3
4
4
- const mkdir = ( dir ) => fs . mkdir ( dir , { recursive : true } ) ;
5
+ const mkdir = dir => fs . mkdir ( dir , { recursive : true } ) ;
5
6
const isDirectory = async ( source ) => {
6
7
const stat = await fs . stat ( source ) ;
7
8
return stat . isDirectory ( ) ;
@@ -31,7 +32,7 @@ const copyFolder = async (src, dest) => {
31
32
} else {
32
33
await copyFile ( srcFile , destFile ) ;
33
34
}
34
- } )
35
+ } ) ,
35
36
) ;
36
37
} ;
37
38
@@ -58,31 +59,10 @@ const copyTemplateTo = async (template, pathToFolder) => {
58
59
59
60
const getDirsFrom = async ( source ) => {
60
61
const paths = await fs . readdir ( source ) ;
61
- return paths . map ( ( name ) => path . join ( source , name ) ) . filter ( isDirectory ) ;
62
+ return paths . map ( name => path . join ( source , name ) ) . filter ( isDirectory ) ;
62
63
} ;
63
64
64
- const getReactAppRewiredPath = async ( ) => {
65
- const options = [
66
- `${ __dirname } /../../../../react-app-rewired/bin/index.js` ,
67
- `${ __dirname } /../../../node_modules/react-app-rewired/bin/index.js` ,
68
- ] ;
69
-
70
- const libInfos = await Promise . all (
71
- options . map ( async ( option ) => ( {
72
- option,
73
- exists : await ( async ( ) => {
74
- try {
75
- await fs . access ( option ) ;
76
- return true ;
77
- } catch ( e ) {
78
- return false ;
79
- }
80
- } ) ( ) ,
81
- } ) )
82
- ) ;
83
-
84
- return libInfos . find ( ( lib ) => lib . exists ) . option ;
85
- } ;
65
+ const getReactAppRewiredPath = async ( ) => `${ reactAppRewired . paths . ownPath } /../react-app-rewired/bin/index.js` ;
86
66
87
67
const rm = async ( pathTo ) => {
88
68
if ( ! existsSync ( pathTo ) ) return Promise . resolve ( ) ;
@@ -99,10 +79,10 @@ const rm = async (pathTo) => {
99
79
const getDirectories = async ( source ) => {
100
80
const all = await fs . readdir ( source ) ;
101
81
const mappedFolders = await Promise . all (
102
- all . map ( async ( fileOrFolder ) => ( {
82
+ all . map ( async fileOrFolder => ( {
103
83
fileOrFolder,
104
84
isDirectory : await isDirectory ( path . join ( source , fileOrFolder ) ) ,
105
- } ) )
85
+ } ) ) ,
106
86
) ;
107
87
108
88
return mappedFolders . filter ( ( { isDirectory : isDir } ) => isDir ) . map ( ( { fileOrFolder : folder } ) => folder ) ;
@@ -120,7 +100,7 @@ const getAllFilesFromDir = async (dir, allFiles = []) => {
120
100
} else {
121
101
allFiles . push ( fullDir ) ;
122
102
}
123
- } )
103
+ } ) ,
124
104
) ;
125
105
return allFiles ;
126
106
} ;
0 commit comments