forked from aws-amplify/amplify-cli
-
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: create new amplify-prompts package to handle all terminal inter…
…actions (aws-amplify#7774) * feat: working on prompts package * feat: add list picker methods * feat: autocomplete for all pick types * feat: fancy types * test: restructure interface a bit and scaffold unit tests * test: adding a bunch of tests * chore: mark deprecated methods / functions * chore: adding some comments * Update packages/amplify-prompts/src/__tests__/prompter.test.ts Co-authored-by: John Hockett <[email protected]> * chore: rename multiselect => multiSelect * feat: better support for --yes and support input list * fix: use EOL as line ending Co-authored-by: John Hockett <[email protected]>
- Loading branch information
Showing
20 changed files
with
1,056 additions
and
1 deletion.
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
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
3 changes: 3 additions & 0 deletions
3
packages/amplify-cli/src/extensions/amplify-helpers/confirm-prompt.ts
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
1 change: 1 addition & 0 deletions
1
packages/amplify-cli/src/extensions/amplify-helpers/input-validation.ts
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,7 @@ | ||
module.exports = { | ||
roots: ['<rootDir>/src'], | ||
testMatch: ['**/__tests__/**/*.+(ts|tsx|js)', '**/?(*.)+(spec|test).+(ts|tsx|js)'], | ||
transform: { | ||
'^.+\\.(ts|tsx)$': 'ts-jest', | ||
}, | ||
}; |
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,35 @@ | ||
{ | ||
"name": "amplify-prompts", | ||
"version": "1.0.0", | ||
"description": "Utility functions for Amplify CLI terminal I/O", | ||
"main": "lib/index.js", | ||
"scripts": { | ||
"build": "tsc", | ||
"clean": "rimraf lib tsconfig.tsbuildinfo", | ||
"demo": "yarn build && node lib/demo/demo.js", | ||
"test": "jest", | ||
"watch": "tsc -w" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/aws-amplify/amplify-cli.git" | ||
}, | ||
"keywords": [ | ||
"amplify", | ||
"cli", | ||
"prompts" | ||
], | ||
"author": "Amazon Web Services", | ||
"license": "Apache-2.0", | ||
"bugs": { | ||
"url": "https://github.com/aws-amplify/amplify-cli/issues" | ||
}, | ||
"homepage": "https://github.com/aws-amplify/amplify-cli#readme", | ||
"dependencies": { | ||
"chalk": "^4.1.1", | ||
"enquirer": "^2.3.6" | ||
}, | ||
"devDependencies": { | ||
"rimraf": "^3.0.2" | ||
} | ||
} |
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,17 @@ | ||
import { printer } from '../printer'; | ||
import { formatter } from '../formatter'; | ||
|
||
jest.mock('../printer'); | ||
|
||
const printer_mock = printer as jest.Mocked<typeof printer>; | ||
|
||
describe('list', () => { | ||
beforeEach(jest.clearAllMocks); | ||
it('prints list items at info level', () => { | ||
const items = ['item1', 'item2']; | ||
formatter.list(items); | ||
expect(printer_mock.info.mock.calls.length).toBe(2); | ||
expect(printer_mock.info.mock.calls[0][0]).toMatchInlineSnapshot(`"- item1"`); | ||
expect(printer_mock.info.mock.calls[1][0]).toMatchInlineSnapshot(`"- item2"`); | ||
}); | ||
}); |
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,112 @@ | ||
import { AmplifyPrinter } from '../printer'; | ||
import os from 'os'; | ||
import * as flags from '../flags'; | ||
const writeStream_stub = ({ | ||
write: jest.fn(), | ||
} as unknown) as jest.Mocked<NodeJS.WritableStream>; | ||
|
||
jest.mock('../flags'); | ||
jest.mock('os'); | ||
|
||
type Writeable<T> = { -readonly [P in keyof T]: T[P] }; | ||
|
||
const flags_mock = flags as jest.Mocked<Writeable<typeof flags>>; | ||
|
||
const testInput = 'this is a test line'; | ||
|
||
const printer = new AmplifyPrinter(writeStream_stub); | ||
|
||
const os_mock = os as jest.Mocked<Writeable<typeof os>>; | ||
|
||
os_mock.EOL = '\n'; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
flags_mock.isDebug = false; | ||
flags_mock.isSilent = false; | ||
flags_mock.isYes = false; | ||
}); | ||
|
||
it('prints debug lines when debug flag is set', () => { | ||
flags_mock.isDebug = true; | ||
printer.debug(testInput); | ||
expect(writeStream_stub.write.mock.calls[0][0]).toMatchInlineSnapshot(` | ||
"this is a test line | ||
" | ||
`); | ||
}); | ||
|
||
it('does not print debug lines by default', () => { | ||
printer.debug(testInput); | ||
expect(writeStream_stub.write.mock.calls.length).toBe(0); | ||
}); | ||
|
||
it('prints info line by default', () => { | ||
printer.info(testInput); | ||
expect(writeStream_stub.write.mock.calls[0][0]).toMatchInlineSnapshot(` | ||
"[0mthis is a test line[0m | ||
" | ||
`); | ||
}); | ||
|
||
it('prints info line in specified color', () => { | ||
printer.info(testInput, 'blue'); | ||
expect(writeStream_stub.write.mock.calls[0][0]).toMatchInlineSnapshot(` | ||
"[34mthis is a test line[39m | ||
" | ||
`); | ||
}); | ||
|
||
it('does not print info line when silent flag is set', () => { | ||
flags_mock.isSilent = true; | ||
printer.info(testInput); | ||
expect(writeStream_stub.write.mock.calls.length).toBe(0); | ||
}); | ||
|
||
it('prints success line by default', () => { | ||
printer.success(testInput); | ||
expect(writeStream_stub.write.mock.calls[0][0]).toMatchInlineSnapshot(` | ||
"✅ [32mthis is a test line[39m | ||
" | ||
`); | ||
}); | ||
|
||
it('does not print success line when silent flag is set', () => { | ||
flags_mock.isSilent = true; | ||
printer.success(testInput); | ||
expect(writeStream_stub.write.mock.calls.length).toBe(0); | ||
}); | ||
|
||
it('prints warn line by default', () => { | ||
printer.warn(testInput); | ||
expect(writeStream_stub.write.mock.calls[0][0]).toMatchInlineSnapshot(` | ||
"⚠️ [33mthis is a test line[39m | ||
" | ||
`); | ||
}); | ||
|
||
it('prints warn line when silent flag is set', () => { | ||
flags_mock.isSilent = true; | ||
printer.warn(testInput); | ||
expect(writeStream_stub.write.mock.calls[0][0]).toMatchInlineSnapshot(` | ||
"⚠️ [33mthis is a test line[39m | ||
" | ||
`); | ||
}); | ||
|
||
it('prints error line by default', () => { | ||
printer.error(testInput); | ||
expect(writeStream_stub.write.mock.calls[0][0]).toMatchInlineSnapshot(` | ||
"🛑 [31mthis is a test line[39m | ||
" | ||
`); | ||
}); | ||
|
||
it('prints error line when silent flag is set', () => { | ||
flags_mock.isSilent = true; | ||
printer.error(testInput); | ||
expect(writeStream_stub.write.mock.calls[0][0]).toMatchInlineSnapshot(` | ||
"🛑 [31mthis is a test line[39m | ||
" | ||
`); | ||
}); |
Oops, something went wrong.