NickHeiner / jscodemod

Codemod runner
MIT License
41 stars 4 forks source link

Js-to-Ts prompt #50

Open sachin-sumasoft opened 1 year ago

sachin-sumasoft commented 1 year ago

Hi, I am trying to js-to-ts prompt but I am facing this error: yarn run v1.22.19 $ yarn build && yarn jscodemod --prompt jscodemod --prompt "// Convert the code above to TypeScript. Be sure to retain any variables imported via require. Use ESM instead of CommonJS for imports and exports. Remove the \"use strict\" directive. You can import the following global types from my-global-types and use them as you see fit: GameState, Player, MovePart, Row, Col, Space." ../camelot-engine/lib/*/.js $ rm -rf build && tsc && chmod a+x ./build/bin.js $ ./build/bin.js --prompt 'The Javascript code above is written in ES5. Transform it to ES6. Include only the transformed code; do not include any other comments, context, or metadata. Do not create new comments. Make sure to apply the following transformations: 1. Use optional chaining. 2. Use the object property shorthand.' fixtures/ai/source/es5.js --resetDirtyInputFiles bin.js [inputFilesPatterns...]

Run the codemod. Any arguments after "--" will be passed through to the codemod.

Positionals: inputFilesPatterns [string]

Primary -c, --codemod Path to the codemod to run [string] -d, --dry Print a list of files to modify, then stop. [boolean] -r, --resetDirtyInputFiles Use git to restore dirty files to a clean state before running the codemod. This assumes that all input files have the same .git root. If you use submodules, this may not work. [boolean] [default: false] -l, --inputFileList A file containing a newline-delimited set of file paths to run on [string]

AI (Completion). Only applicable if you're using AI for your codemod. See /Users/tuxiuluofromhome/Documents/code/openai/jscodemod/docs/ai.md. --prompt --promptFile --openAICompletionRequestConfig API params to pass to OpenAI's createCompletionRequest API. See https://beta.openai.com/docs/api-referenc e/completions/create. The argument you pass to this flag will be interpreted as JSON. [string] --openAICompletionRequestFile A path to a JSON file containing request params for OpenAI's createCompletionRequest API. See https://beta.openai.com/docs/api-referenc e/completions/create. [string]

AI (chatGPT). Only applicable if you're using AI for your codemod. See /Users/tuxiuluofromhome/Documents/code/openai/jscodemod/docs/ai.md. --chatMessage A prompt for an AI-powered codemod. The AI will be sent the code file to transform as a message, and then whatever you pass for this flag. If that format doesn't work for you, implement an AICodemod instead and pass the --codemod flag. [string] --chatMessageFile A prompt for an AI-powered codemod. The AI will be sent the code file to transform as a message, and then the contents of the filepath you pass for this flag. If that format doesn't work for you, implement an AICodemod instead and pass the --codemod flag. [string] --openAIChatRequestConfig API params to pass to OpenAI's chat API. See https://beta.openai.com/docs/api-reference/chat /create. The argument you pass to this flag will be interpreted as JSON. [string] --openAIChatRequestFile A path to a JSON file containing request params for OpenAI's chat API. See https://beta.openai. com/docs/api-reference/chat/create. [string]

TypeScript (only applicable if your codemod is written in TypeScript) --tsconfig path to the tsconfig.json [string] --tsOutDir directory in which to compile your codemod to. Defaults to a temporary directory. [string] --tsc path to a "tsc" executable to compile your codemod. Defaults to looking for a "tsc" bin accessible from the current working directory. [string]

Rarely Useful --jsonOutput Output logs as JSON, instead of human-readable formatting. Useful if you want to consume the output of this tool from another tool, or process the logs using your own Bunyan log processor/formatter. The precise set of logs emitted is not considered to be part of the public API. [boolean] [default: false] -p, --porcelain Produce machine-readable output. [boolean] [default: false]

Options: --version Show version number [boolean] --builtInCodemod The built-in codemod to run [string] [choices: "js-to-ts"] -b, --piscinaLowerBoundInclusive Only use piscina if there are at least this many files. At smaller file sizes, the fixed cost of spinning up piscina outweighs the benefits. [number] [default: 20] --completionPrompt A prompt for an AI-powered codemod. The AI will be asked to complete an input. The input will be form: ${input file source code} //${the value you pass for this flag}. If that format doesn't work for you, implement an AICodemod instead and pass the --codemod flag. [string] --completionPromptFile A prompt for an AI-powered codemod. The AI will be asked to complete an input. The input will be form: ${input file source code} //${the contents of the file pointed to by this flag}. If that format doesn't work for you, implement an AICodemod instead and pass the --codemod flag. [string] --help Show help [boolean]

Examples: bin.js --codemod codemod.js Run codemod.js against JS files in "source/*/.js" source bin.js --codemod codemod.js Run the codemod against a set of --inputFileList files-to-modify.txt files listed in the text file. bin.js --prompt "Translate the file Run an AI-powered codemod against above from ES5 to modern JS" the files matching the passed glob. "source/*/.js"

Unknown argument: prompt error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

NickHeiner commented 1 year ago

Hmm. Well to start it looks like your yarn command repeats jscodemod —prompt twice?

On Wed, Aug 16, 2023 at 13:36 sachin-sumasoft @.***> wrote:

Hi, I am trying to js-to-ts prompt but I am facing this error: yarn run v1.22.19 $ yarn build && yarn jscodemod --prompt jscodemod --prompt "// Convert the code above to TypeScript. Be sure to retain any variables imported via require. Use ESM instead of CommonJS for imports and exports. Remove the "use strict" directive. You can import the following global types from my-global-types and use them as you see fit: GameState, Player, MovePart, Row, Col, Space." ../camelot-engine/lib/*/.js $ rm -rf build && tsc && chmod a+x ./build/bin.js $ ./build/bin.js --prompt 'The Javascript code above is written in ES5. Transform it to ES6. Include only the transformed code; do not include any other comments, context, or metadata. Do not create new comments. Make sure to apply the following transformations: 1. Use optional chaining. 2. Use the object property shorthand.' fixtures/ai/source/es5.js --resetDirtyInputFiles bin.js [inputFilesPatterns...]

Run the codemod. Any arguments after "--" will be passed through to the codemod.

Positionals: inputFilesPatterns [string]

Primary -c, --codemod Path to the codemod to run [string] -d, --dry Print a list of files to modify, then stop. [boolean] -r, --resetDirtyInputFiles Use git to restore dirty files to a clean state before running the codemod. This assumes that all input files have the same .git root. If you use submodules, this may not work. [boolean] [default: false] -l, --inputFileList A file containing a newline-delimited set of file paths to run on [string]

AI (Completion). Only applicable if you're using AI for your codemod. See /Users/tuxiuluofromhome/Documents/code/openai/jscodemod/docs/ai.md. --prompt --promptFile --openAICompletionRequestConfig API params to pass to OpenAI's createCompletionRequest API. See https://beta.openai.com/docs/api-referenc e/completions/create. The argument you pass to this flag will be interpreted as JSON. [string] --openAICompletionRequestFile A path to a JSON file containing request params for OpenAI's createCompletionRequest API. See https://beta.openai.com/docs/api-referenc e/completions/create. [string]

AI (chatGPT). Only applicable if you're using AI for your codemod. See /Users/tuxiuluofromhome/Documents/code/openai/jscodemod/docs/ai.md. --chatMessage A prompt for an AI-powered codemod. The AI will be sent the code file to transform as a message, and then whatever you pass for this flag. If that format doesn't work for you, implement an AICodemod instead and pass the --codemod flag. [string] --chatMessageFile A prompt for an AI-powered codemod. The AI will be sent the code file to transform as a message, and then the contents of the filepath you pass for this flag. If that format doesn't work for you, implement an AICodemod instead and pass the --codemod flag. [string] --openAIChatRequestConfig API params to pass to OpenAI's chat API. See https://beta.openai.com/docs/api-reference/chat /create. The argument you pass to this flag will be interpreted as JSON. [string] --openAIChatRequestFile A path to a JSON file containing request params for OpenAI's chat API. See https://beta.openai. com/docs/api-reference/chat/create. [string]

TypeScript (only applicable if your codemod is written in TypeScript) --tsconfig path to the tsconfig.json [string] --tsOutDir directory in which to compile your codemod to. Defaults to a temporary directory. [string] --tsc path to a "tsc" executable to compile your codemod. Defaults to looking for a "tsc" bin accessible from the current working directory. [string]

Rarely Useful --jsonOutput Output logs as JSON, instead of human-readable formatting. Useful if you want to consume the output of this tool from another tool, or process the logs using your own Bunyan log processor/formatter. The precise set of logs emitted is not considered to be part of the public API. [boolean] [default: false] -p, --porcelain Produce machine-readable output. [boolean] [default: false]

Options: --version Show version number [boolean] --builtInCodemod The built-in codemod to run [string] [choices: "js-to-ts"] -b, --piscinaLowerBoundInclusive Only use piscina if there are at least this many files. At smaller file sizes, the fixed cost of spinning up piscina outweighs the benefits. [number] [default: 20] --completionPrompt A prompt for an AI-powered codemod. The AI will be asked to complete an input. The input will be form: ${input file source code} //${the value you pass for this flag}. If that format doesn't work for you, implement an AICodemod instead and pass the --codemod flag. [string] --completionPromptFile A prompt for an AI-powered codemod. The AI will be asked to complete an input. The input will be form: ${input file source code} //${the contents of the file pointed to by this flag}. If that format doesn't work for you, implement an AICodemod instead and pass the --codemod flag. [string] --help Show help [boolean]

Examples: bin.js --codemod codemod.js Run codemod.js against JS files in "source/

/.js" source bin.js --codemod codemod.js Run the codemod against a set of --inputFileList files-to-modify.txt files listed in the text file. bin.js --prompt "Translate the file Run an AI-powered codemod against above from ES5 to modern JS" the files matching the passed glob. "source//.js"

Unknown argument: prompt error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

— Reply to this email directly, view it on GitHub https://github.com/NickHeiner/jscodemod/issues/50, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGKTAYIEDRLYWDVDIHCLPTXVUAKXANCNFSM6AAAAAA3S33XZ4 . You are receiving this because you are subscribed to this thread.Message ID: @.***>

sachin-sumasoft commented 1 year ago

I have tried this one jscodemod --prompt "// Convert the code above to TypeScript. Be sure to retain any variables imported via require. Use ESM instead of CommonJS for imports and exports. Remove the \"use strict\" directive. " ../camelot-engine/lib//*.js** but facing same error. Can you share the js to ts migration steps with me? How to use this jscodemod? If, I had tried to run the command used jscodemod that time I have faced this error: jscodemod is not recognized at your internal and external command.

NickHeiner commented 1 year ago

That error makes it sound like you don’t have this module installed globally.

On Thu, Aug 17, 2023 at 01:51 sachin-sumasoft @.***> wrote:

I have tried this one jscodemod --prompt "// Convert the code above to TypeScript. Be sure to retain any variables imported via require. Use ESM instead of CommonJS for imports and exports. Remove the "use strict" directive. You can import the following global types from my-global-types and use them as you see fit: GameState, Player, MovePart, Row, Col, Space." ../camelot-engine/lib//*.js** but facing same error. Can you share the js to ts migration steps with me? How to use this jscodemod? If, I had tried to run the command used jscodemod that time I have faced this error: jscodemod is not recognized at your internal and external command.

— Reply to this email directly, view it on GitHub https://github.com/NickHeiner/jscodemod/issues/50#issuecomment-1681654144, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGKTA4MBHUWO6WNWVZRY63XVWWMPANCNFSM6AAAAAA3S33XZ4 . You are receiving this because you commented.Message ID: @.***>

kachurun commented 2 months ago

I have the same problem with commands: npx @nick.heiner/jscodemod --prompt "Test" or

npm i @nick.heiner/jscodemod -g
jscodemod --prompt

MacOS

NickHeiner commented 2 months ago

Yeah, I’m sure this is a real bug. I just don’t have time to fix it. :(

On Mon, Jul 29, 2024 at 19:06 Maksim Kachurin @.***> wrote:

I have the same problem with commands: npx @nick.heiner/jscodemod --prompt "Test" or

npm i @nick.heiner/jscodemod -g jscodemod --prompt

MacOS

— Reply to this email directly, view it on GitHub https://github.com/NickHeiner/jscodemod/issues/50#issuecomment-2257157463, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGKTA6TLMB4NHSVXSH52N3ZO3DH3AVCNFSM6AAAAABLVGAO2WVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENJXGE2TONBWGM . You are receiving this because you commented.Message ID: @.***>