@pgsql/cli
Version:
Unified CLI for PostgreSQL AST parsing, deparsing, and code generation
38 lines (34 loc) • 1.48 kB
JavaScript
import { downloadProtoFile, generateProtoJS, replaceTextInProtoJS } from './helpers';
export const help = () => {
console.log(`
Usage:
pg-proto-parser protogen --protoUrl <URL to proto file>
--inFile <path to proto file>
--outFile <path to output JS file>
--originalPackageName <original package name>
--newPackageName <new package name>
Options:
--help, -h Show this help message.
--version, -v Show the version number.
--protoUrl Full URL to download the proto file (optional).
--inFile Path where the proto file will be saved or path to an existing proto file.
--outFile Path where the generated JavaScript file will be saved.
--originalPackageName Original package name to be replaced in the JS file.
--newPackageName New package name to replace in the JS file.
`);
};
export default async (argv) => {
try {
if (argv.protoUrl) {
await downloadProtoFile(argv.protoUrl, argv.inFile);
}
await generateProtoJS(argv.inFile, argv.outFile);
await replaceTextInProtoJS(argv.outFile, argv.originalPackageName, argv.newPackageName);
console.log('All operations completed successfully.');
}
catch (error) {
// @ts-ignore
console.error('An error occurred:', error.message);
}
return argv;
};