Skip to content

Commit ca69a07

Browse files
committed
Module to handle the template actions
1 parent 41f5386 commit ca69a07

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/template/index.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
};

0 commit comments

Comments
 (0)