Skip to content

Commit

Permalink
feat(scripts): add generation of proxy for core types
Browse files Browse the repository at this point in the history
  • Loading branch information
katywings committed Jul 25, 2020
1 parent 29db670 commit aca0349
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions scripts/create-type-proxies.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
#!/usr/bin/env node

const { writeFile, pkgDir } = require("./lib");
const { writeFile, pkgDir, resolve, exists } = require("./lib");

const createProxy = async (
module,
const createProxy = async ({
moduleName,
exportDefault = false,
exportNamed = true
) => {
const mainPath = `./${module}/lib/main`;
exportNamed = true,
} = {}) => {
const distPath = moduleName ? pkgDir(moduleName, "dist") : pkgDir("dist");
const mainDtsPath = resolve(distPath, "lib", "main.d.ts");

if (!(await exists(mainDtsPath))) {
return;
}

const mainPath = moduleName ? `./${moduleName}/lib/main` : "./lib/main";
let proxySrc = "";
if (exportNamed) {
proxySrc += `export * from "${mainPath}";\n`;
Expand All @@ -18,9 +25,10 @@ const createProxy = async (
export default DefaultProxy;\n`;
}

await writeFile(pkgDir(module, "dist", "main.d.ts"), proxySrc);
const proxyPath = resolve(distPath, "main.d.ts");
await writeFile(proxyPath, proxySrc);
};

(async () => {
// await createProxy("some-module");
await createProxy();
})();

0 comments on commit aca0349

Please sign in to comment.