python2ts 1.1.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/cli/index.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { parseArgs } from \"node:util\"\nimport { readFile, writeFile } from \"node:fs/promises\"\nimport { createInterface } from \"node:readline\"\nimport { transpileAsync, type GeneratorOptions } from \"../generator/index.js\"\n\nconst VERSION = \"0.1.0\"\n\nconst HELP = `\npython2ts - Transpile Python code to TypeScript\n\nUsage:\n python2ts [options] [file]\n\nArguments:\n file Input Python file (reads from stdin if omitted)\n\nOptions:\n -o, --output <file> Write output to file (prints to stdout if omitted)\n --no-runtime Don't include runtime import statement\n --runtime-path <path> Custom runtime import path (default: pythonlib)\n -h, --help Show this help message\n -v, --version Show version number\n\nExamples:\n python2ts input.py Transpile and print to stdout\n python2ts input.py -o output.ts Transpile to file\n cat input.py | python2ts Read from stdin\n python2ts input.py --no-runtime Transpile without runtime import\n`.trim()\n\nasync function readStdin(): Promise<string> {\n const lines: string[] = []\n const rl = createInterface({\n input: process.stdin,\n crlfDelay: Infinity\n })\n\n for await (const line of rl) {\n lines.push(line)\n }\n\n return lines.join(\"\\n\")\n}\n\nasync function main(): Promise<void> {\n const { values, positionals } = parseArgs({\n options: {\n output: { type: \"string\", short: \"o\" },\n \"no-runtime\": { type: \"boolean\", default: false },\n \"runtime-path\": { type: \"string\" },\n help: { type: \"boolean\", short: \"h\", default: false },\n version: { type: \"boolean\", short: \"v\", default: false }\n },\n allowPositionals: true\n })\n\n if (values.help) {\n console.log(HELP)\n process.exit(0)\n }\n\n if (values.version) {\n console.log(VERSION)\n process.exit(0)\n }\n\n // Read input\n let pythonCode: string\n const inputFile = positionals[0]\n\n if (inputFile) {\n try {\n pythonCode = await readFile(inputFile, \"utf-8\")\n } catch (error) {\n const err = error as NodeJS.ErrnoException\n if (err.code === \"ENOENT\") {\n console.error(`Error: File not found: ${inputFile}`)\n } else {\n console.error(`Error reading file: ${err.message}`)\n }\n process.exit(1)\n }\n } else {\n // Read from stdin\n if (process.stdin.isTTY) {\n console.error(\"Error: No input file specified and stdin is a terminal.\")\n console.error(\"Usage: python2ts <file> or cat file.py | python2ts\")\n process.exit(1)\n }\n pythonCode = await readStdin()\n }\n\n // Transpile (with Prettier formatting)\n let tsCode: string\n try {\n const options: GeneratorOptions = {\n includeRuntime: !values[\"no-runtime\"]\n }\n if (values[\"runtime-path\"]) {\n options.runtimeImportPath = values[\"runtime-path\"]\n }\n tsCode = await transpileAsync(pythonCode, options)\n } catch (error) {\n const err = error as Error\n console.error(`Transpilation error: ${err.message}`)\n process.exit(1)\n }\n\n // Write output\n const outputFile = values.output\n if (outputFile) {\n try {\n await writeFile(outputFile, tsCode, \"utf-8\")\n } catch (error) {\n const err = error as Error\n console.error(`Error writing file: ${err.message}`)\n process.exit(1)\n }\n } else {\n console.log(tsCode)\n }\n}\n\nmain().catch((error: unknown) => {\n console.error(`Unexpected error: ${String(error)}`)\n process.exit(1)\n})\n"],"mappings":";;;;;;AACA,SAAS,iBAAiB;AAC1B,SAAS,UAAU,iBAAiB;AACpC,SAAS,uBAAuB;AAGhC,IAAM,UAAU;AAEhB,IAAM,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAqBX,KAAK;AAEP,eAAe,YAA6B;AAC1C,QAAM,QAAkB,CAAC;AACzB,QAAM,KAAK,gBAAgB;AAAA,IACzB,OAAO,QAAQ;AAAA,IACf,WAAW;AAAA,EACb,CAAC;AAED,mBAAiB,QAAQ,IAAI;AAC3B,UAAM,KAAK,IAAI;AAAA,EACjB;AAEA,SAAO,MAAM,KAAK,IAAI;AACxB;AAEA,eAAe,OAAsB;AACnC,QAAM,EAAE,QAAQ,YAAY,IAAI,UAAU;AAAA,I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