-
Notifications
You must be signed in to change notification settings - Fork 618
/
Copy pathcreateSrc.js
39 lines (33 loc) · 1.31 KB
/
createSrc.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
'use strict';
const { FileSystem, Import } = require('@rushstack/node-core-library');
const DTS_EXTENSION = '.d.ts';
module.exports = {
runAsync: async ({ heftConfiguration: { buildFolderPath } }) => {
const rushLibPath = Import.resolvePackage({
packageName: '@microsoft/rush-lib',
baseFolderPath: __dirname
});
async function* collectDtsPaths(absoluteFolderPath, relativeFolderPath) {
const folderItems = FileSystem.readFolderItems(absoluteFolderPath);
for (const folderItem of folderItems) {
const folderItemName = folderItem.name;
if (folderItem.isDirectory()) {
yield* collectDtsPaths(
`${absoluteFolderPath}/${folderItemName}`,
`${relativeFolderPath}/${folderItemName}`
);
} else if (folderItemName.endsWith(DTS_EXTENSION)) {
yield `${relativeFolderPath}/${folderItemName.slice(0, -DTS_EXTENSION.length)}`;
}
}
}
const indexFileLines = [];
for await (const dtsPath of collectDtsPaths(`${rushLibPath}/lib`, '@microsoft/rush-lib/lib')) {
indexFileLines.push(`import '${dtsPath}';`);
}
const srcFolderPath = `${buildFolderPath}/src`;
await FileSystem.writeFileAsync(`${srcFolderPath}/index.ts`, indexFileLines.join('\n'), {
ensureFolderExists: true
});
}
};