11const { promises : fs , existsSync, rmdirSync } = require ( 'fs' ) ;
22const path = require ( 'path' ) ;
3+ const reactAppRewired = require ( 'react-app-rewired' ) ;
34
4- const mkdir = ( dir ) => fs . mkdir ( dir , { recursive : true } ) ;
5+ const mkdir = dir => fs . mkdir ( dir , { recursive : true } ) ;
56const isDirectory = async ( source ) => {
67 const stat = await fs . stat ( source ) ;
78 return stat . isDirectory ( ) ;
@@ -31,7 +32,7 @@ const copyFolder = async (src, dest) => {
3132 } else {
3233 await copyFile ( srcFile , destFile ) ;
3334 }
34- } )
35+ } ) ,
3536 ) ;
3637} ;
3738
@@ -58,31 +59,10 @@ const copyTemplateTo = async (template, pathToFolder) => {
5859
5960const getDirsFrom = async ( source ) => {
6061 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 ) ;
6263} ;
6364
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` ;
8666
8767const rm = async ( pathTo ) => {
8868 if ( ! existsSync ( pathTo ) ) return Promise . resolve ( ) ;
@@ -99,10 +79,10 @@ const rm = async (pathTo) => {
9979const getDirectories = async ( source ) => {
10080 const all = await fs . readdir ( source ) ;
10181 const mappedFolders = await Promise . all (
102- all . map ( async ( fileOrFolder ) => ( {
82+ all . map ( async fileOrFolder => ( {
10383 fileOrFolder,
10484 isDirectory : await isDirectory ( path . join ( source , fileOrFolder ) ) ,
105- } ) )
85+ } ) ) ,
10686 ) ;
10787
10888 return mappedFolders . filter ( ( { isDirectory : isDir } ) => isDir ) . map ( ( { fileOrFolder : folder } ) => folder ) ;
@@ -120,7 +100,7 @@ const getAllFilesFromDir = async (dir, allFiles = []) => {
120100 } else {
121101 allFiles . push ( fullDir ) ;
122102 }
123- } )
103+ } ) ,
124104 ) ;
125105 return allFiles ;
126106} ;
0 commit comments