Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: extractShebangCommand #6

Open
2 of 3 tasks
hugojosefson opened this issue Apr 5, 2024 · 1 comment
Open
2 of 3 tasks

feat: extractShebangCommand #6

hugojosefson opened this issue Apr 5, 2024 · 1 comment

Comments

@hugojosefson
Copy link
Owner

hugojosefson commented Apr 5, 2024

Add below function:

/**
 * Extracts the command to run a script, from its shebang line.
 * @param scriptContents the script source code
 * @returns array of command and parameters
 */
export function extractShebangCommand(scriptContents: string): string[] {
  return scriptContents.split("\n")[0].replace(/^#!/, "").split(" ");
}

...with the following edits:

TODO

  • Use .split("\n", 1) to not read more than necessary.
  • Use npm:[email protected] instead of .split(" ").
  • Return some more "Command":y type from this repo?
@hugojosefson
Copy link
Owner Author

import argvSplit from "argv-split";

/**
 * Extracts the command to run a script, from its shebang line.
 * @param scriptContents the script source code
 * @returns array of command and parameters
 */
export function extractShebangCommand(scriptContents: string): string[] {
  return argvSplit(scriptContents.split("\n", 1)[0].replace(/^#!/, ""));
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant