-
Notifications
You must be signed in to change notification settings - Fork 0
/
createfile.js
31 lines (24 loc) · 927 Bytes
/
createfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const { exec } = require('child_process'),
path = require('path'),
fs = require('fs');
module.exports = {
write: (root,directory,desiredFilename,rawFile,msg) => {
let folder = path.resolve(root,directory);
let mypath = path.resolve(root,directory,desiredFilename);
try{
fs.lstatSync(folder).isDirectory();
exec('curl -o ' + mypath + ' ' + rawFile);
process.stdout.write(msg + ' in ' + mypath + ' \n');
}catch(err){
fs.mkdirSync(folder);
exec('curl -o' + path + ' ' + rawFile);
process.stdout.write( msg + ' in: ' + mypath + ' \n');
}
}
}
/*
--directory must be in the following form: '/dirname/', i.e: '/model'
--desiredFileName must be in the following form: 'file.ext'
--rawFile must be in the following form: https://<link> and must be a raw document
--msg must be in the following form: 'your message explaining what you did' with no spaces at the end of the string
*/