-
Notifications
You must be signed in to change notification settings - Fork 3
/
move-dts.js
89 lines (85 loc) · 2.17 KB
/
move-dts.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/** @format */
import path from 'path';
import fs from 'fs';
const writeFiles = (path, name, data, callback = () => {}) => {
fs.writeFile(path + name, data, (err) => {
if (err) {
if (err.code === 'ENOENT') {
fs.mkdirSync(path, { recursive: true });
} else {
console.error(err);
}
writeFiles(path, name, data);
} else {
callback();
}
});
};
fs.readdir('./components', function (err, files) {
var dirs = [];
(function iterator(i) {
if (i == files.length) {
dirs.forEach((oneDir) => {
if (oneDir.indexOf('.d.ts') > -1) {
fs.readFile(
`./components/${oneDir}`,
{ encoding: 'utf8' },
(err, data) => {
if (err) {
console.error(err);
return;
}
writeFiles('./dist/types', `/${oneDir}`, data, () => {});
},
);
}
});
dirs.forEach((oneDir) => {
if (oneDir.indexOf('.d.ts') > -1) {
fs.unlinkSync(`./components/${oneDir}`);
}
});
return;
}
fs.stat(path.join('./components', files[i]), function (err, data) {
if (data.isFile()) {
dirs.push(files[i]);
}
iterator(i + 1);
});
})(0);
});
fs.readdir('./components/ajax', function (err, files) {
var dirs = [];
(function iterator(i) {
if (i == files.length) {
dirs.forEach((oneDir) => {
if (oneDir.indexOf('.d.ts') > -1) {
fs.readFile(
`./components/ajax/${oneDir}`,
{ encoding: 'utf8' },
(err, data) => {
if (err) {
console.error(err);
return;
}
writeFiles('./dist/types/ajax', `/${oneDir}`, data, () => {});
},
);
}
});
dirs.forEach((oneDir) => {
if (oneDir.indexOf('.d.ts') > -1) {
fs.unlinkSync(`./components/ajax/${oneDir}`);
}
});
return;
}
fs.stat(path.join('./components/ajax', files[i]), function (err, data) {
if (data.isFile()) {
dirs.push(files[i]);
}
iterator(i + 1);
});
})(0);
});