-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ts): implement exports generation
refs #akash-network/console/566, #akash-network/support#212
- Loading branch information
1 parent
f441e78
commit 9202462
Showing
98 changed files
with
620 additions
and
5,175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#!/usr/bin/env node | ||
|
||
const fs = require("fs/promises"); | ||
const path = require("path"); | ||
|
||
async function getAllPaths(dir) { | ||
let results = []; | ||
|
||
const entries = await fs.readdir(dir, { withFileTypes: true }); | ||
|
||
for (const entry of entries) { | ||
const fullPath = path.join(dir, entry.name); | ||
if (entry.isDirectory()) { | ||
const subEntries = await getAllPaths(fullPath); | ||
results = results.concat(subEntries); | ||
} else { | ||
results.push(fullPath); | ||
} | ||
} | ||
|
||
return results; | ||
} | ||
|
||
const EXCLUSIONS = ["genesis", "params", "service", "query"]; | ||
|
||
(async () => { | ||
const directory = path.resolve(__dirname, "../src/generated"); // Replace this with your directory path | ||
const allPaths = await getAllPaths(directory); | ||
const root = `${process.cwd()}/ts/src/generated/`; | ||
const nsWithExports = allPaths | ||
.filter((path) => !path.endsWith("d.ts") && path.endsWith(".ts")) | ||
.reduce((acc, path) => { | ||
const relativePath = path.replace(root, "").replace(".ts", ""); | ||
const pathParts = relativePath.split("/"); | ||
const [fileName] = pathParts.splice(pathParts.length - 1, 1); | ||
|
||
const ns = pathParts.join("."); | ||
|
||
if (!ns || !ns.includes("akash")) { | ||
return acc; | ||
} | ||
|
||
if (!acc[ns]) { | ||
acc[ns] = []; | ||
} | ||
|
||
acc[ns].push(relativePath); | ||
|
||
const version = pathParts[pathParts.length - 1]; | ||
|
||
if (EXCLUSIONS.includes(fileName)) { | ||
return acc; | ||
} | ||
|
||
if (!acc[version]) { | ||
acc[version] = []; | ||
} | ||
|
||
acc[version].push(relativePath); | ||
|
||
return acc; | ||
}, {}); | ||
|
||
const namespaces = Object.keys(nsWithExports); | ||
|
||
namespaces.forEach((ns) => { | ||
const nsExports = nsWithExports[ns]; | ||
const content = nsExports.reduce((acc, file) => { | ||
return `${acc}export * from "./${file}";\n`; | ||
}, ""); | ||
|
||
fs.writeFile( | ||
path.resolve(__dirname, `../src/generated/index.${ns}.ts`), | ||
content, | ||
"utf8", | ||
); | ||
}); | ||
})(); |
Oops, something went wrong.