Last active
November 9, 2020 10:29
-
-
Save remorses/d88ebc6213df8a23502595784a35a170 to your computer and use it in GitHub Desktop.
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
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