File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change 1+ const fs = require ( 'fs' ) ;
2+
3+ const utils = require ( '../utils' ) ;
4+
5+ function updateFile ( filePath = '' , dictionary ) {
6+ const resolvedFilePath = utils . fs . resolvePath ( filePath ) ;
7+ let originalFile ;
8+ try {
9+ originalFile = fs . readFileSync ( resolvedFilePath , 'utf8' ) ;
10+ } catch ( error ) {
11+ throw error ;
12+ }
13+
14+ const generatedFile = utils . string . replaceByDictionary ( originalFile , dictionary ) ;
15+ fs . writeFile ( resolvedFilePath , generatedFile , ( err ) => {
16+ if ( err ) {
17+ throw err ;
18+ }
19+ console . log ( `File updated: ${ resolvedFilePath } ` ) ;
20+ } ) ;
21+ }
22+
23+ function copy ( templatePath , destPath ) {
24+ utils . fs . copyDirRecursive ( templatePath , destPath ) ;
25+ }
26+
27+ module . exports = {
28+ updateFile,
29+ copy,
30+ } ;
You can’t perform that action at this time.
0 commit comments