11const { tmpdir } = require ( 'os' )
2+ const { stat, rm, mkdir, mkdtemp, cp, readdir } = require ( 'fs/promises' )
23const { join } = require ( 'path' )
34const Debug = require ( '../debug' )
45const Settings = require ( '../settings' )
56const createDecorator = require ( './decorator' )
6- const { atomicReplace, atomicFS } = require ( '../lib/fileSystemHelpers' )
7+ const { atomicReplace } = require ( '../lib/fileSystemHelpers' )
78const {
89 ASSETS ,
910 PARTIALS ,
@@ -41,7 +42,7 @@ const Methods = (() => {
4142
4243 const customThemeExists = async ( customThemePath ) => {
4344 try {
44- return await atomicFS . stat ( customThemePath )
45+ return await stat ( customThemePath )
4546 } catch {
4647 return false
4748 }
@@ -50,12 +51,10 @@ const Methods = (() => {
5051 const refreshCustomTheme = async ( customThemePath ) => {
5152 const backupKeepDir = async ( keepPath ) => {
5253 try {
53- if ( await atomicFS . stat ( keepPath ) ) {
54- const tempPath = await atomicFS . mkdtemp (
55- join ( tmpdir ( ) , 'writ-theme-keep' )
56- )
54+ if ( await stat ( keepPath ) ) {
55+ const tempPath = await mkdtemp ( join ( tmpdir ( ) , 'writ-theme-keep' ) )
5756 Debug . debugLog ( 'refresh theme temp dir' , tempPath )
58- await atomicFS . cp ( keepPath , tempPath )
57+ await cp ( keepPath , tempPath , { recursive : true } )
5958 return tempPath
6059 }
6160 } catch {
@@ -65,7 +64,10 @@ const Methods = (() => {
6564 }
6665
6766 const applyKeepOverrides = async ( keepBackupPath , themePath ) => {
68- const entries = await atomicFS . readdirRecursive ( keepBackupPath )
67+ const entries = await readdir ( keepBackupPath , {
68+ recursive : true ,
69+ withFileTypes : true
70+ } )
6971
7072 await Promise . all (
7173 entries
@@ -75,7 +77,7 @@ const Methods = (() => {
7577 entry . parentPath . replace ( keepBackupPath , '' ) ,
7678 entry . name
7779 )
78- return atomicFS . cp (
80+ return cp (
7981 join ( keepBackupPath , relativePath ) ,
8082 join ( themePath , relativePath )
8183 )
@@ -96,8 +98,10 @@ const Methods = (() => {
9698 } )
9799
98100 if ( keepBackupPath ) {
99- await atomicFS . mkdir ( join ( tempPath , KEEP_PATH ) )
100- await atomicFS . cp ( keepBackupPath , join ( tempPath , KEEP_PATH ) )
101+ await mkdir ( join ( tempPath , KEEP_PATH ) , { recursive : true } )
102+ await cp ( keepBackupPath , join ( tempPath , KEEP_PATH ) , {
103+ recursive : true
104+ } )
101105 await applyKeepOverrides ( keepBackupPath , tempPath )
102106 }
103107 } )
@@ -106,13 +110,13 @@ const Methods = (() => {
106110 throw e
107111 } finally {
108112 if ( keepBackupPath ) {
109- await atomicFS . rm ( keepBackupPath )
113+ await rm ( keepBackupPath , { recursive : true , force : true } )
110114 }
111115 }
112116 }
113117
114118 const collectCustomizerPaths = async ( customThemePath ) => {
115- const paths = await atomicFS . readdir ( customThemePath )
119+ const paths = await readdir ( customThemePath )
116120 const customizerPaths = paths . filter ( p => {
117121 return p . endsWith ( '.css' ) || p . endsWith ( '.js' )
118122 } )
@@ -121,11 +125,12 @@ const Methods = (() => {
121125
122126 const copyCommonResources = ( targetPath ) => {
123127 return Promise . all ( [
124- atomicFS . cp (
128+ cp (
125129 join ( __dirname , 'common' , PARTIALS . from ) ,
126- join ( targetPath , PARTIALS . to )
130+ join ( targetPath , PARTIALS . to ) ,
131+ { recursive : true }
127132 ) ,
128- atomicFS . cp (
133+ cp (
129134 join ( __dirname , 'common' , TEMPLATE_HELPERS . from ) ,
130135 join ( targetPath , PARTIALS . to , TEMPLATE_HELPERS . to )
131136 )
@@ -136,15 +141,17 @@ const Methods = (() => {
136141 const { theme } = Settings . getSettings ( )
137142 const themeSrcPath = join ( __dirname , '..' , '..' , 'packages' , `theme-${ theme } ` )
138143 return Promise . all ( [
139- atomicFS . cp (
144+ cp (
140145 join ( themeSrcPath , ASSETS ) ,
141- join ( customThemePath , ASSETS , theme )
146+ join ( customThemePath , ASSETS , theme ) ,
147+ { recursive : true }
142148 ) ,
143- atomicFS . cp (
149+ cp (
144150 join ( themeSrcPath , PARTIALS . from ) ,
145- join ( customThemePath , PARTIALS . to )
151+ join ( customThemePath , PARTIALS . to ) ,
152+ { recursive : true }
146153 ) ,
147- atomicFS . cp (
154+ cp (
148155 join ( themeSrcPath , THEME_SETTINGS ) ,
149156 join ( customThemePath , THEME_SETTINGS )
150157 )
@@ -156,14 +163,14 @@ const Methods = (() => {
156163 }
157164
158165 const copyCustomizers = async ( customThemePath ) => {
159- const paths = await atomicFS . readdir ( join ( __dirname , 'customizers' ) )
166+ const paths = await readdir ( join ( __dirname , 'customizers' ) )
160167 const customizers = paths . filter ( p => {
161168 return p . endsWith ( '.css' ) || p . endsWith ( '.js' )
162169 } )
163170 State . customizers . push ( ...customizers )
164171 return Promise . all (
165172 paths . map ( path => {
166- return atomicFS . cp (
173+ return cp (
167174 join ( __dirname , 'customizers' , path ) ,
168175 join ( customThemePath , path )
169176 )
@@ -173,12 +180,12 @@ const Methods = (() => {
173180
174181 const makeCustomThemeDirectory = async ( customThemePath , options = { } ) => {
175182 if ( ! options . skipContainer ) {
176- await atomicFS . mkdir ( customThemePath )
183+ await mkdir ( customThemePath )
177184 }
178185
179186 await Promise . all ( [
180- atomicFS . mkdir ( join ( customThemePath , ASSETS ) ) ,
181- atomicFS . mkdir ( join ( customThemePath , PARTIALS . to ) )
187+ mkdir ( join ( customThemePath , ASSETS ) ) ,
188+ mkdir ( join ( customThemePath , PARTIALS . to ) )
182189 ] )
183190
184191 await copyCommonResources ( customThemePath )
0 commit comments