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
*/
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
*/
${code}
import { compiler } from 'flowgen';
const flowdef = compiler.compileDefinitionFile('../node_modules/flv.js/d.ts/flv.d.ts');
console.log(flowdef);
declare module 'toxic-decorators' {
declare module.exports: any;
}
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);
}
};
if (
e.message.includes(
'`declare module` cannot be used inside another `declare module`',
)
) {
flowgenOutput = prettier.format(code, {
parser: 'babel-flow',
singleQuote: true,
semi: true,
});
} else {
flowgenOutput = format(flowgenTemplate, packageName, code);
}
}
} else if (typescriptTypingsContent) {
const code = flowgen.compiler.compileDefinitionString(
typescriptTypingsContent,
);
try {
flowgenOutput = prettier.format(
format(flowgenTemplate, packageName, code),
{parser: 'babel-flow', singleQuote: true, semi: true},
);
} catch (e) {
if (
e.message.includes(
'`declare module` cannot be used inside another `declare module`',
)
) {
flowgenOutput = prettier.format(code, {
parser: 'babel-flow',
singleQuote: true,
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);
}
};