mirror of
https://github.com/gosticks/web.git
synced 2026-10-07 07:07:07 +00:00
Create directories if they don't exist when generating fake data
Signed-off-by: Mcat12 <newtoncat12@yahoo.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
const faker = require('faker');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
function list(listType) {
|
||||
const result = {};
|
||||
@@ -158,6 +159,11 @@ function remove(path) {
|
||||
}
|
||||
|
||||
function write(path, data) {
|
||||
const dir = path.dirname(path);
|
||||
|
||||
if(!fs.existsSync(dir))
|
||||
fs.mkdirSync(dir);
|
||||
|
||||
fs.writeFileSync(path, JSON.stringify(data));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user