-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreset-data.js
59 lines (51 loc) · 1.71 KB
/
reset-data.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
import * as fs from 'fs';
async function resetData(dataDirectory) {
try {
// clean up data directory
await fs.rmSync(dataDirectory, { recursive: true, force: true });
// create directories
fs.mkdirSync(dataDirectory, { recursive: true });
fs.chmodSync(dataDirectory, '00777');
fs.mkdirSync(`${dataDirectory}/testDir1/nestedDir`, { recursive: true });
// create files
[
{
'fileName': 'test1.txt',
'fileData': 'Here is some top secret data. '
},
{
'fileName': 'watchTest.txt',
'fileData': 'Test watching files'
},
{
'fileName': 'chmod.txt',
'fileData': 'Test access changes'
},
{
'fileName': 'testDir1/test2.txt',
'fileData': 'Test file in sub-directory'
},
{
'fileName': 'testDir1/test3.txt',
'fileData': 'Test file in sub-directory'
}
].forEach(file =>
fs.writeFileSync(`${dataDirectory}/${file.fileName}`, file.fileData));
// create symbolic links
try {
fs.symlinkSync(`test1.txt`, `${dataDirectory}/test1-sym-link`);
} catch(err) {
if(err.code == 'EPERM') {
console.log('Failed to create symbolic link with EPERM error. If this is running on Windows, some examples are expected to fail.');
return;
}
throw err;
}
} catch (err) {
console.log('Failed to reset data...')
throw err;
}
}
export {
resetData
};