diff --git a/packages/editor/README.md b/packages/editor/README.md index f705b29ef..55e68cf54 100644 --- a/packages/editor/README.md +++ b/packages/editor/README.md @@ -25,6 +25,7 @@ const answer = await editor({ | Property | Type | Required | Description | | -------- | --------- | -------- | ------------------------------ | | message | `string` | yes | The question to ask | +| default | `string` | no | Default value which will automatically be present in the editor | | validate | `string => boolean \| string \| Promise` | no | On submit, validate the content. When returning a string, it'll be used as the error message displayed to the user. Note: returning a rejected promise, we'll assume a code error happened and crash. | | postfix | `string` | no (default to `.txt`) | The postfix of the file being edited. Adding this will add color highlighting to the file content in most editors. | diff --git a/packages/editor/demo.js b/packages/editor/demo.ts similarity index 89% rename from packages/editor/demo.js rename to packages/editor/demo.ts index ea7eddd7d..c8e802cf6 100644 --- a/packages/editor/demo.js +++ b/packages/editor/demo.ts @@ -1,4 +1,4 @@ -import editor from './index.js'; +import editor from './src/index.js'; (async () => { const answer = await editor({ diff --git a/packages/editor/package.json b/packages/editor/package.json index 10452aaf2..9d871b41c 100644 --- a/packages/editor/package.json +++ b/packages/editor/package.json @@ -3,7 +3,11 @@ "type": "module", "version": "0.0.14-alpha.0", "description": "Inquirer multiline editor prompt", - "main": "index.js", + "main": "dist/index.js", + "typings": "dist/index.d.ts", + "files": [ + "dist/" + ], "repository": "SBoudrias/Inquirer.js", "keywords": [ "cli", @@ -19,6 +23,9 @@ "chalk": "^5.0.1", "external-editor": "^3.0.3" }, + "scripts": { + "tsc": "tsc" + }, "publishConfig": { "access": "public" } diff --git a/packages/editor/index.js b/packages/editor/src/index.ts similarity index 77% rename from packages/editor/index.js rename to packages/editor/src/index.ts index da9ca126f..be5e4c7c9 100644 --- a/packages/editor/index.js +++ b/packages/editor/src/index.ts @@ -6,12 +6,18 @@ import { useKeypress, usePrefix, isEnterKey, + AsyncPromptConfig, } from '@inquirer/core'; -export default createPrompt((config, done) => { - const [status, setStatus] = useState('pending'); - const [value, setValue] = useState(config.default || ''); - const [errorMsg, setError] = useState(); +type EditorConfig = AsyncPromptConfig & { + default?: string; + postfix?: string; +}; + +export default createPrompt((config, done) => { + const [status, setStatus] = useState('pending'); + const [value, setValue] = useState(config.default || ''); + const [errorMsg, setError] = useState(undefined); useKeypress(async (key, rl) => { // Ignore keypress while our prompt is doing other processing. @@ -26,7 +32,7 @@ export default createPrompt((config, done) => { async (error, answer) => { rl.resume(); if (error) { - setError(error); + setError(error.toString()); } else { setStatus('loading'); const isValid = await config.validate(answer); diff --git a/packages/editor/tsconfig.json b/packages/editor/tsconfig.json new file mode 100644 index 000000000..6a62dbc48 --- /dev/null +++ b/packages/editor/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "./dist" + }, + "include": ["./src"] +}