-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscripts.js
62 lines (55 loc) · 1.87 KB
/
scripts.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
var fs = require( 'fs' );
var path = require( 'path' );
var dailyChallenges = "./daily-challenges/";
var exercises = "./exercises/"
const fileName = "/package.json"
const codeToAdd = `
{
"name": "code-challenges",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "jest"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"jest": "^23.6.0"
}
}
`
function addFiles(pathName, fileName, codeToAdd){
fs.readdir( pathName, function( err, folders ) {
console.log(folders)
if( err ) {
console.error( "Could not list the directory.", err );
process.exit( 1 );
}
folders.forEach( function( folder, index ) {
console.dir(folder)
fs.stat( "./" + pathName + folder, function( error, stat ) {
if( error ) {
console.error( "Error stating file.", error );
return;
}
if( stat.isFile() )
console.log( "'%s' is a file.");
else if( stat.isDirectory() ){
console.log( "'%s' is a directory.");
console.log("NEW FILE___________________________")
console.log(pathName + folder + fileName)
fs.writeFile(pathName + folder + fileName, codeToAdd, function(err) {
if(err) {
return console.log(err);
}
console.log("The file was saved!");
});
}
} );
} );
} );
}
addFiles(exercises, fileName, codeToAdd)
addFiles(dailyChallenges, fileName, codeToAdd)