{"id":18446262,"url":"https://github.com/catdad/shellton","last_synced_at":"2025-04-15T09:10:27.725Z","repository":{"id":57358295,"uuid":"49383132","full_name":"catdad/shellton","owner":"catdad","description":":shell: execute other stuff from node","archived":false,"fork":false,"pushed_at":"2023-02-20T02:57:40.000Z","size":83,"stargazers_count":2,"open_issues_count":8,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-15T09:09:36.962Z","etag":null,"topics":["bash","linux","macos","npm","sh","shell","spawn","stream","windows"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/catdad.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-01-10T20:06:19.000Z","updated_at":"2023-02-20T02:14:23.000Z","dependencies_parsed_at":"2024-06-21T15:21:53.228Z","dependency_job_id":"7cd4c6a9-de7b-45df-aaa6-554536cf4907","html_url":"https://github.com/catdad/shellton","commit_stats":{"total_commits":141,"total_committers":1,"mean_commits":141.0,"dds":0.0,"last_synced_commit":"0d653d220318cebd0af465f696dadc6bd3ca11f1"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/catdad%2Fshellton","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/catdad%2Fshellton/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/catdad%2Fshellton/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/catdad%2Fshellton/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/catdad","download_url":"https://codeload.github.com/catdad/shellton/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249040072,"owners_count":21202816,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash","linux","macos","npm","sh","shell","spawn","stream","windows"],"created_at":"2024-11-06T07:08:50.520Z","updated_at":"2025-04-15T09:10:27.660Z","avatar_url":"https://github.com/catdad.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# shellton\n\n[![Build][1]][2]\n[![Test Coverage][3]][4]\n[![Code Climate][5]][6]\n[![Downloads][7]][8]\n[![Version][9]][8]\n\n[1]: https://img.shields.io/github/actions/workflow/status/catdad/shellton/ci.yml?branch=master\u0026logo=github\n[2]: https://github.com/catdad/shellton/actions/workflows/ci.yml?query=branch%3Amaster\n\n[3]: https://codeclimate.com/github/catdad/shellton/badges/coverage.svg\n[4]: https://codeclimate.com/github/catdad/shellton/coverage\n\n[5]: https://codeclimate.com/github/catdad/shellton/badges/gpa.svg\n[6]: https://codeclimate.com/github/catdad/shellton\n\n[7]: https://img.shields.io/npm/dm/shellton.svg\n[8]: https://www.npmjs.com/package/shellton\n[9]: https://img.shields.io/npm/v/shellton.svg\n\n## Install\n\n    npm install --save shellton\n    \n## Use\n\n### Basic example\n\n```javascript\nvar shellton = require('shellton');\n\nshellton('echo all the things', function(err, stdout, stderr) {\n    console.log(stdout); // all the things\n});\n```\n\n### Using IO streams\n\nYou can pipe the standard output streams from the child process, as such:\n\n```javascript\nvar output = fs.createWriteStream('script-output.txt');\n\nshellton({\n    task: 'node script.js',\n    stdout: output\n    // you can also do stderr here, if you need\n    // or just pipe it to the parent process io stream\n    stderr: process.stderr\n}, function(err, stdout, stderr) {\n    console.log('script.js has exited');\n});\n```\n\nYou can also provide input to the external process, as such:\n\n```javascript\nvar input = fs.createReadStream('my-script.js');\n\nshellton({\n    task: 'node',\n    stdin: input\n}, function(err, stdout, stderr) {\n    console.log('my-script.js has exited');\n});\n```\n\nUse your imagination here, and you can come up with some much more useful cases.\n\n```javascript\nvar shellton = require('shellton');\nvar through = require('through2');\nvar chalk = require('chalk');\n\nfunction colorStream(name, writeStream) {\n    writeStream = writeStream || process.stdout;\n    \n    var colorFunc = (chalk[name] || chalk.white).bind(chalk);\n    \n    var stream = through();\n    stream.on('data', function(chunk) {\n        writeStream.write(colorFunc(chunk));\n    });\n    \n    return stream;\n}\n\nvar input = through();\n// write to the parent's output stream in green\nvar output = colorStream('green', process.stdout);\n// write to the parent's error stream in red\nvar error = colorStream('red', process.stderr);\n\nshellton({\n    task: 'node',\n    stdin: input,\n    stdout: output,\n    stderr: error\n});\n\n// use any dynamically generated javascript\ninput.write('console.log(\"output is green\");');\ninput.write('console.error(\"errors are red\");');\ninput.end();\n```\n\n## API\n\n### `shellton(options, callback)`\n\n`options` {string | Object} : The options defining the external task to execute. This parameter is required.\n- When given a string, this is the command line command being executed. You can supply a full command, as you would normally type into bash or the Windows command prompt.\n- When given an object, the following properties are available:\n  - `task` {string} : the command to executed.\n  - `stdin` {Stream} : a stream to pipe into the command.\n  - `stdout` {Stream} : a stream to where the standard output of the command will be piped.\n  - `stderr` {Stream} : a stream to where the standard error of the command will be piped.\n  - `cwd` {string} : the directory from where the command will be executed. The default is the current directory of the parent process.\n  - `env` {Object} : the environment variables for the child process. Values here will be merged with an overwrite values in the current `process.env`.\n  - `encoding` {string} : the encoding to use to the data provided to the callback. The options are `utf8` and `buffer`, with `utf8` being the default.\n  \n`callback` {function} : The callback to call when the child process exists. This parameter is optional. It receives the following parameters, in order:\n- `error` {Error} : An error that occurred when executing the command. This generally means the command exited with a code other than 0. `error.code` specifies the exit code of the command.\n- `stdout` {string|Buffer} : A string representation of the standard output of the command. If the command outputs binary, you will likely want to read directly from `stdout` in the `options` object.\n- `stderr` {string|Buffer} : A string representation of the standard error of the command. If the command outputs binary, you will likely want to read directly from `stderr` in the `options` object.\n\n[![Analytics](https://ga-beacon.appspot.com/UA-17159207-7/shellton/readme?flat)](https://github.com/igrigorik/ga-beacon)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcatdad%2Fshellton","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcatdad%2Fshellton","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcatdad%2Fshellton/lists"}