Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
)
const name = fileName(packageName)
//console.log(packageName, name, path)
const file = await fs.readFile(path, 'utf8')
const hasHeader =
file.includes(`declare module '${name}'`) ||
file.includes(`declare module "${name}"`)
const template = hasHeader
? file
: `
declare module '${name}' {
${file}
};
`
try {
const code = flowgen.beautify(
flowgen.compiler.compileDefinitionString(template),
)
await fs.ensureFile(`flow-typed/flowgen/${name}_v${json.version}.js`)
await fs.writeFile(
`flow-typed/flowgen/${name}_v${json.version}.js`,
`/**
* This is an autogenerated libdef stub for:
*
* '${name}'
*
* Fill this stub out by fixing all the errors.
*
* Once filled out, we encourage you to share your work with the
* community by sending a pull request to:
* https://github.com/flowtype/flow-typed
*/
export default (req: NextApiRequest, res: NextApiResponse) => {
try {
const result = compiler.compileDefinitionString(req.body);
res.status(200).send(beautify(result));
} catch (e) {
res.status(500).send(e.message);
}
};