-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpushFile.js
20 lines (20 loc) · 953 Bytes
/
pushFile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
const fs = require("fs").promises;
const path = require("path")
let issets = [];
module.exports.pushFile = (name, data, dirname = './') => {
console.log('Processing request: ', name);
name = name.replace(/(\(|\)|:| )/g,'');
if(issets.includes(name)){
console.log(`Duplicate found: `,name);
return fs.appendFile(`${path.join(__dirname,dirname)}/${name}.css`,data, function(error){
if(error) throw error; // если возникла ошибка
console.log(`Asynchronous recording of a take to a file ${name}.css complited.`);
});
}else{
issets.push(name); // сбор пройденых запросов
return fs.writeFile(`${path.join(__dirname,dirname)}/${name}.css`,data, function(error){
if(error) throw error; // если возникла ошибка
console.log(`Writing a file asynchronously ${name}.css complited.`);
});
}
}