-
Notifications
You must be signed in to change notification settings - Fork 140
/
update-indexes.cjs
61 lines (51 loc) · 1.67 KB
/
update-indexes.cjs
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
#!/usr/bin/env node
const glob = require("glob");
const yargs = require("yargs");
const fs = require("fs");
const path = require("path");
const argv = yargs.default("src", "src/**").argv;
const ignorePatterns = ["**/node_modules/**", "**/*.old*", "**/*.test*", "**/editor/**"];
function createIndexFile (folder) {
//console.info(`index: ${folder}`);
const indexFile = `${folder}/exports.ts`;
const tsFiles = glob.sync(`${folder}/*.ts`, {
ignore: [`${folder}/exports.ts`, `${folder}/index.ts`].concat(ignorePatterns)
});
const tsSubFiles = glob.sync(`${folder}/*/exports.ts`, {
ignore: ["**/node_modules/**", "**/*.old*"]
});
if (tsFiles.length === 0 && tsSubFiles.length === 0) {
console.info(`No exports: ${folder}`);
return;
}
let code = "";
for (const tsFile of tsSubFiles) {
const relativeName = path.relative(folder, tsFile);
const parsed = path.parse(relativeName);
const relativeNameNoExt = parsed.dir + "/" + parsed.name;
code += `export * from "./${relativeNameNoExt}";\n`;
}
for (const tsFile of tsFiles) {
const baseName = path.basename(tsFile, ".ts");
code += `export * from "./${baseName}";\n`;
}
fs.writeFileSync(indexFile, code);
}
let files = glob.sync(argv.src, { ignore: ignorePatterns });
for (const folder of files) {
console.log(`Scanning ${folder}`);
//const rcFile = folder + ".index.json";
// if (fs.existsSync(rcFile) == false) {
// continue;
// }
createIndexFile(folder);
}
files = glob.sync(argv.src, { ignore: ignorePatterns });
for (const folder of files) {
console.log(`Scanning ${folder}`);
//const rcFile = folder + ".index.json";
// if (fs.existsSync(rcFile) == false) {
// continue;
// }
createIndexFile(folder);
}