-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
43 lines (35 loc) · 1.29 KB
/
index.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
const path = require('path'), fs = require('fs');
const { generateFile } = require('./generateFile');
let counter = 0;
function fromDir(startPath, fileExt) {
if (!fs.existsSync(startPath)) {
console.log("no dir ", startPath);
return Promise.reject();
}
const files = fs.readdirSync(startPath);
return Promise.all(files.map(file => {
const filename = file;
const filePath = path.join(startPath, file);
const stat = fs.lstatSync(filePath);
if (stat.isDirectory()) {
return fromDir(filePath, fileExt); //recurse
}
else if (filename.indexOf(fileExt) >= 0) {
return generateFile(`./${filePath}`, filename, startPath)
.then((numberOfCreatedFiles) => counter = counter + numberOfCreatedFiles);
} else {
return Promise.resolve();
}
})
);
};
const projectPath = process.argv[2];
if (!projectPath) {
throw Error("Not path given");
}
const ext = process.argv[3] || '.js';
fromDir(projectPath, ext)
.then(() => {
console.log(`Finished, created ${counter} jest snapshot files`);
})
.catch(err => console.log('neivel', err));