Skip to content

Instantly share code, notes, and snippets.

@remorses
Last active November 9, 2020 10:29
Show Gist options
  • Save remorses/d88ebc6213df8a23502595784a35a170 to your computer and use it in GitHub Desktop.
Save remorses/d88ebc6213df8a23502595784a35a170 to your computer and use it in GitHub Desktop.
import path from "path";
import fs from "fs";
import { getPackages } from "@monorepo-utils/package-utils";
const sourceDir = "src";
getPackages(__dirname).map(x => {
let types = getTypesFile({
sourceDir: path.resolve(x.location, sourceDir)
});
if (!types) {
console.log(`Could not find a types file for '${x.location}'`);
return;
}
types = path.relative(x.location, types);
console.log(`Using ${types} for ${x.location}`);
const oldTypes = x.packageJSON["types"];
delete x.packageJSON["types"];
delete x.packageJSON["publishConfig"];
const publishConfig = oldTypes && { types: oldTypes };
const newJSON = JSON.stringify(
{
name: x.packageJSON.name,
types,
...(publishConfig && { publishConfig }),
...x.packageJSON
},
null,
2
);
fs.writeFileSync(path.resolve(x.location, "package.json"), newJSON + "\n");
});
function getTypesFile({ sourceDir }) {
const tsx = path.join(sourceDir, "index.tsx");
if (fs.existsSync(tsx)) {
return tsx;
}
const ts = path.join(sourceDir, "index.ts");
if (fs.existsSync(ts)) {
return ts;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment