generated from JoshuaKGoldberg/create-typescript-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add inputFromScript, and make SystemRunner use execa's reject: …
…false (#74) * feat: add inputFromScript, and make SystemRunner use execa's reject: false * pnpm dedupe
- Loading branch information
1 parent
62b2a1d
commit 9405d14
Showing
15 changed files
with
143 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import { execa, parseCommandString } from "execa"; | ||
|
||
export function createSystemRunner(directory: string) { | ||
const executor = execa({ cwd: directory }); | ||
import { SystemRunner } from "../types/system.js"; | ||
|
||
export function createSystemRunner(directory: string): SystemRunner { | ||
const executor = execa({ cwd: directory, reject: false }); | ||
|
||
return (command: string) => executor`${parseCommandString(command)}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<h1 align="center">input-from-script</h1> | ||
|
||
<p align="center"><code>create</code> input that runs a script.</p> | ||
|
||
<p align="center"> | ||
<a href="https://github.com/JoshuaKGoldberg/create/blob/main/.github/CODE_OF_CONDUCT.md" target="_blank"><img alt="🤝 Code of Conduct: Kept" src="https://img.shields.io/badge/%F0%9F%A4%9D_code_of_conduct-kept-21bb42" /></a> | ||
<a href="https://github.com/JoshuaKGoldberg/create/blob/main/LICENSE.md" target="_blank"><img alt="📝 License: MIT" src="https://img.shields.io/badge/%F0%9F%93%9D_license-MIT-21bb42.svg"></a> | ||
<a href="http://npmjs.com/package/input-from-script"><img alt="📦 npm version" src="https://img.shields.io/npm/v/input-from-script?color=21bb42&label=%F0%9F%93%A6%20npm" /></a> | ||
<img alt="💪 TypeScript: Strict" src="https://img.shields.io/badge/%F0%9F%92%AA_typescript-strict-21bb42.svg" /> | ||
</p> | ||
|
||
```shell | ||
npm i input-from-script | ||
``` | ||
|
||
```ts | ||
import { inputFromScript } from "input-from-script"; | ||
|
||
await take(inputFromScript, { command: "npm whoami" }); | ||
``` | ||
|
||
## Options | ||
|
||
`inputFromScript` takes a single argument, `command`, of type `string`. | ||
|
||
It runs the `command` with [`execa`](https://www.npmjs.com/package/execa) and returns either: | ||
|
||
- `Error`: If an error was caught running the script | ||
- `Result`: The type from `execa`, including the `stdout` property | ||
|
||
See **[create-josh.vercel.app > Engine > Runtime > Inputs](https://create-josh.vercel.app/engine/runtime/inputs)** for more documentation on Inputs. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"name": "input-from-script", | ||
"version": "0.1.0-alpha.2", | ||
"description": "create input that runs a script.", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/JoshuaKGoldberg/create", | ||
"directory": "packages/input-from-script" | ||
}, | ||
"license": "MIT", | ||
"author": { | ||
"name": "Josh Goldberg ✨", | ||
"email": "npm@joshuakgoldberg.com" | ||
}, | ||
"type": "module", | ||
"main": "./lib/index.js", | ||
"files": [ | ||
"lib/", | ||
"package.json", | ||
"LICENSE.md", | ||
"README.md" | ||
], | ||
"scripts": { | ||
"build": "tsc" | ||
}, | ||
"dependencies": { | ||
"zod": "^3.24.1" | ||
}, | ||
"devDependencies": { | ||
"create-testers": "workspace:*" | ||
}, | ||
"peerDependencies": { | ||
"create": "workspace:*" | ||
}, | ||
"engines": { | ||
"node": ">=18" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { testInput } from "create-testers"; | ||
import { describe, expect, it, vi } from "vitest"; | ||
|
||
import { inputFromScript } from "./index.js"; | ||
|
||
describe("inputFromScript", () => { | ||
it("returns the result from running the command", async () => { | ||
const command = "echo 123"; | ||
const expected = { stdout: "123" }; | ||
const runner = vi.fn().mockResolvedValue(expected); | ||
|
||
const actual = await testInput(inputFromScript, { | ||
args: { command }, | ||
runner, | ||
}); | ||
|
||
expect(actual).toBe(expected); | ||
expect(runner).toHaveBeenCalledWith(command); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { createInput } from "create"; | ||
import { z } from "zod"; | ||
|
||
export const inputFromScript = createInput({ | ||
args: { | ||
command: z.string(), | ||
}, | ||
async produce({ args, runner }) { | ||
return await runner(args.command); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"compilerOptions": { | ||
"outDir": "lib", | ||
"rootDir": "src" | ||
}, | ||
"extends": "../../tsconfig.base.json", | ||
"include": ["src"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { defineProject } from "vitest/config"; | ||
|
||
export default defineProject({ | ||
test: { | ||
clearMocks: true, | ||
exclude: ["lib", "node_modules"], | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters