Skip to content

Commit 0122770

Browse files
authored
add package readme (#14)
1 parent 9ce4a10 commit 0122770

1 file changed

Lines changed: 104 additions & 0 deletions

File tree

packages/clifty/README.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<div align="center">
2+
<img width="300" height="300" src="./doc/clifty-logo.png" />
3+
</div>
4+
5+
> Your CLI's nifty new best friend. Declarative CLI orchestration made easy.
6+
7+
**WARNING**: API design still work in progress, expect breaking changes!
8+
9+
## About
10+
11+
**Clifty** lets you script flows through CLI apps using a clean, readable, and high-level API.
12+
Whether you're writing end-to-end tests or embedding CLI behavior into your app, Clifty makes interacting with child processes a breeze.
13+
14+
## ✨ Features
15+
16+
- 🧠 **Declarative**: Define expected outputs and matching inputs in a readable chain.
17+
- 🧪 **Test-Friendly**: Use with Jest, Vitest, or any test runner.
18+
- 🔧 **The Last Resort**: Interact with tools that don't offer a programmatic API
19+
20+
## Install
21+
22+
```bash
23+
npm install clifty
24+
#or
25+
yarn add clifty
26+
#or
27+
pnpm add clifty
28+
```
29+
30+
## Usage
31+
32+
```js
33+
import { TestEnv } from "clifty";
34+
35+
const cliEnv = new TestEnv({
36+
cwd: "./bin",
37+
env: {
38+
FOO: "bar",
39+
},
40+
});
41+
42+
const exitCode = await cliEnv
43+
.buildScenario()
44+
.whenAsked("what's your name?")
45+
.respondWith("hacktor", KEYS.ENTER)
46+
.expectOutput("Hello hacktor")
47+
.run("./hello-world");
48+
49+
console.log(exitCode);
50+
```
51+
52+
### Testing example (with `vitest`)
53+
54+
```ts
55+
describe("NPM init with steps", async () => {
56+
const tmpDir = tmpdir();
57+
58+
const testbed = new TestEnv({
59+
cwd: tmpDir,
60+
});
61+
62+
const exitCode = await testbed
63+
.buildScenario()
64+
.step("Give package a name", (whenAsked) => {
65+
whenAsked("package name:").respondWith("testproject123", KEYS.ENTER);
66+
})
67+
.step("Additional information", (whenAsked) => {
68+
whenAsked("version:").respondWith("1.1.1", KEYS.ENTER);
69+
whenAsked("description:").respondWith(KEYS.ENTER);
70+
})
71+
.step("NPM registry metadata", (whenAsked) => {
72+
whenAsked("git repository:").respondWith(KEYS.ENTER);
73+
whenAsked("keywords:").respondWith(KEYS.ENTER);
74+
whenAsked("author:").respondWith(KEYS.ENTER);
75+
whenAsked("license:").respondWith("MIT", KEYS.ENTER);
76+
})
77+
.step("Confirmation", (whenAsked) => {
78+
whenAsked("Is this OK?").respondWith("yes", KEYS.ENTER);
79+
})
80+
.run("npm init");
81+
82+
it("terminates successfully", () => {
83+
expect(exitCode).toBe(0);
84+
});
85+
86+
it("writes the correct `package.json` entries", () => {
87+
expect(readFileSync(join(tmpDir, "package.json")).toString())
88+
.toMatchInlineSnapshot(`
89+
"{
90+
"name": "testproject123",
91+
"version": "1.1.1",
92+
"main": "index.js",
93+
"scripts": {
94+
"test": "echo \\"Error: no test specified\\" && exit 1"
95+
},
96+
"author": "",
97+
"license": "MIT",
98+
"description": ""
99+
}
100+
"
101+
`);
102+
});
103+
});
104+
```

0 commit comments

Comments
 (0)