mirror of
https://github.com/pawelmalak/flame.git
synced 2025-07-19 11:39:36 +02:00
Changed initial files creation process
This commit is contained in:
parent
591824dd0c
commit
459523dfd2
9 changed files with 109 additions and 38 deletions
32
utils/init/createFile.js
Normal file
32
utils/init/createFile.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
const fs = require('fs');
|
||||
const { join } = require('path');
|
||||
|
||||
const Logger = require('../Logger');
|
||||
const logger = new Logger();
|
||||
|
||||
const createFile = async (file) => {
|
||||
const { name, msg, template, isJSON, paths } = file;
|
||||
|
||||
const srcPath = join(__dirname, paths.src, name);
|
||||
const destPath = join(__dirname, paths.dest, name);
|
||||
|
||||
// Check if file exists
|
||||
if (fs.existsSync(srcPath)) {
|
||||
fs.copyFileSync(srcPath, destPath);
|
||||
|
||||
if (process.env.NODE_ENV == 'development') {
|
||||
logger.log(msg.found);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Create file if not
|
||||
fs.writeFileSync(destPath, isJSON ? JSON.stringify(template) : template);
|
||||
|
||||
if (process.env.NODE_ENV == 'development') {
|
||||
logger.log(msg.created);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = createFile;
|
Loading…
Add table
Add a link
Reference in a new issue