input-from-file 0.1.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +20 -0
- package/README.md +27 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +16 -0
- package/lib/index.js.map +1 -0
- package/lib/index.test.d.ts +1 -0
- package/lib/index.test.js +43 -0
- package/lib/index.test.js.map +1 -0
- package/package.json +38 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# MIT License
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
'Software'), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
17
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
18
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
19
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
20
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
<h1 align="center">input-from-file</h1>
|
|
2
|
+
|
|
3
|
+
<p align="center"><code>create</code> input that reads a file as JSON.</p>
|
|
4
|
+
|
|
5
|
+
<p align="center">
|
|
6
|
+
<a href="https://github.com/JoshuaKGoldberg/input-from-file/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>
|
|
7
|
+
<a href="https://codecov.io/gh/JoshuaKGoldberg/input-from-file" target="_blank"><img alt="๐งช Coverage" src="https://img.shields.io/codecov/c/github/JoshuaKGoldberg/input-from-file?label=%F0%9F%A7%AA%20coverage" /></a>
|
|
8
|
+
<a href="https://github.com/JoshuaKGoldberg/input-from-file/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>
|
|
9
|
+
<a href="http://npmjs.com/package/input-from-file"><img alt="๐ฆ npm version" src="https://img.shields.io/npm/v/input-from-file?color=21bb42&label=%F0%9F%93%A6%20npm" /></a>
|
|
10
|
+
<img alt="๐ช TypeScript: Strict" src="https://img.shields.io/badge/%F0%9F%92%AA_typescript-strict-21bb42.svg" />
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+
```shell
|
|
14
|
+
npm i input-from-file
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { inputFromFile } from "input-from-file";
|
|
19
|
+
|
|
20
|
+
await take(inputFromFile, { filePath: "data.txt" });
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Options
|
|
24
|
+
|
|
25
|
+
`inputFromFile` takes a single argument, `filePath`, of type `string`.
|
|
26
|
+
|
|
27
|
+
See **[create-josh.vercel.app > Engine > Runtime > Inputs](https://create-josh.vercel.app/engine/runtime/inputs)** for more documentation on Inputs.
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createInput } from "create";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
export const inputFromFile = createInput({
|
|
4
|
+
args: {
|
|
5
|
+
filePath: z.string(),
|
|
6
|
+
},
|
|
7
|
+
async produce({ args, fs }) {
|
|
8
|
+
try {
|
|
9
|
+
return await fs.readFile(args.filePath);
|
|
10
|
+
}
|
|
11
|
+
catch (error) {
|
|
12
|
+
return error instanceof Error ? error : new Error(error);
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,aAAa,GAAG,WAAW,CAAC;IACxC,IAAI,EAAE;QACL,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;KACpB;IACD,KAAK,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE;QACzB,IAAI,CAAC;YACJ,OAAO,MAAM,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACzC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,KAAe,CAAC,CAAC;QACpE,CAAC;IACF,CAAC;CACD,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { testInput } from "create-testers";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import { inputFromFile } from "./index.js";
|
|
4
|
+
describe("inputFromFile", () => {
|
|
5
|
+
it("returns the file's text when it exists", async () => {
|
|
6
|
+
const text = "abc123";
|
|
7
|
+
const actual = await testInput(inputFromFile, {
|
|
8
|
+
args: {
|
|
9
|
+
filePath: "file.txt",
|
|
10
|
+
},
|
|
11
|
+
fs: {
|
|
12
|
+
readFile: () => Promise.resolve(text),
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
expect(actual).toBe(text);
|
|
16
|
+
});
|
|
17
|
+
it("returns an error when reading the file rejects with an error", async () => {
|
|
18
|
+
const error = new Error("Oh no!");
|
|
19
|
+
const actual = await testInput(inputFromFile, {
|
|
20
|
+
args: {
|
|
21
|
+
filePath: "file.txt",
|
|
22
|
+
},
|
|
23
|
+
fs: {
|
|
24
|
+
readFile: () => Promise.reject(error),
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
expect(actual).toEqual(error);
|
|
28
|
+
});
|
|
29
|
+
it("returns an error when reading the file rejects with a string", async () => {
|
|
30
|
+
const error = new Error("Oh no!");
|
|
31
|
+
const actual = await testInput(inputFromFile, {
|
|
32
|
+
args: {
|
|
33
|
+
filePath: "file.txt",
|
|
34
|
+
},
|
|
35
|
+
fs: {
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
|
|
37
|
+
readFile: () => Promise.reject(error.message),
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
expect(actual).toEqual(error);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
//# sourceMappingURL=index.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.js","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC9B,EAAE,CAAC,wCAAw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AAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "input-from-file",
|
|
3
|
+
"version": "0.1.0-alpha.0",
|
|
4
|
+
"description": "Test utilities for composable, testable, type-safe templates. โ๏ธ",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/JoshuaKGoldberg/create",
|
|
8
|
+
"directory": "packages/input-from-file"
|
|
9
|
+
},
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"author": {
|
|
12
|
+
"name": "Josh Goldberg โจ",
|
|
13
|
+
"email": "npm@joshuakgoldberg.com"
|
|
14
|
+
},
|
|
15
|
+
"type": "module",
|
|
16
|
+
"main": "./lib/index.js",
|
|
17
|
+
"files": [
|
|
18
|
+
"lib/",
|
|
19
|
+
"package.json",
|
|
20
|
+
"LICENSE.md",
|
|
21
|
+
"README.md"
|
|
22
|
+
],
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"zod": "^3.23.8"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"create-testers": "0.1.0-alpha.0"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"create": "0.1.0-alpha.0"
|
|
31
|
+
},
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=18"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "tsc"
|
|
37
|
+
}
|
|
38
|
+
}
|