@contember/cli 2.2.0-alpha.17 → 2.2.0-alpha.19
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/dist/development/src/commands/tenant/policy/TenantAuthLogCommand.cjs +1 -2
- package/dist/development/src/commands/tenant/policy/TenantAuthLogCommand.cjs.map +1 -1
- package/dist/development/src/commands/tenant/policy/TenantAuthLogCommand.js +2 -3
- package/dist/development/src/commands/tenant/policy/TenantAuthLogCommand.js.map +1 -1
- package/dist/development/src/commands/transfer/ExportCommand.cjs +2 -2
- package/dist/development/src/commands/transfer/ExportCommand.cjs.map +1 -1
- package/dist/development/src/commands/transfer/ImportCommand.cjs +2 -2
- package/dist/development/src/commands/transfer/ImportCommand.cjs.map +1 -1
- package/dist/development/src/lib/VersionChecker.cjs +2 -19
- package/dist/development/src/lib/VersionChecker.cjs.map +1 -1
- package/dist/development/src/lib/VersionChecker.js +2 -2
- package/dist/development/src/lib/VersionChecker.js.map +1 -1
- package/dist/development/src/lib/fs/FileSystem.cjs +36 -4
- package/dist/development/src/lib/fs/FileSystem.cjs.map +1 -1
- package/dist/development/src/lib/fs/FileSystem.js +35 -3
- package/dist/development/src/lib/fs/FileSystem.js.map +1 -1
- package/dist/development/src/lib/migrations/MigrationPrinter.cjs +9 -12
- package/dist/development/src/lib/migrations/MigrationPrinter.cjs.map +1 -1
- package/dist/development/src/lib/migrations/MigrationPrinter.js +10 -13
- package/dist/development/src/lib/migrations/MigrationPrinter.js.map +1 -1
- package/dist/development/src/lib/migrations/MigrationSnapshotFacade.cjs +1 -1
- package/dist/development/src/lib/migrations/MigrationSnapshotFacade.cjs.map +1 -1
- package/dist/development/src/lib/migrations/MigrationSnapshotFacade.js +1 -1
- package/dist/development/src/lib/migrations/MigrationSnapshotFacade.js.map +1 -1
- package/dist/development/src/lib/prompt/prompt.cjs +41 -7
- package/dist/development/src/lib/prompt/prompt.cjs.map +1 -1
- package/dist/development/src/lib/prompt/prompt.js +41 -7
- package/dist/development/src/lib/prompt/prompt.js.map +1 -1
- package/dist/development/src/lib/transfer/DataTransferClient.cjs +2 -2
- package/dist/development/src/lib/transfer/DataTransferClient.cjs.map +1 -1
- package/dist/development/src/lib/versionRange.cjs +276 -0
- package/dist/development/src/lib/versionRange.cjs.map +1 -0
- package/dist/development/src/lib/versionRange.js +276 -0
- package/dist/development/src/lib/versionRange.js.map +1 -0
- package/dist/production/src/commands/tenant/policy/TenantAuthLogCommand.cjs +1 -2
- package/dist/production/src/commands/tenant/policy/TenantAuthLogCommand.cjs.map +1 -1
- package/dist/production/src/commands/tenant/policy/TenantAuthLogCommand.js +2 -3
- package/dist/production/src/commands/tenant/policy/TenantAuthLogCommand.js.map +1 -1
- package/dist/production/src/commands/transfer/ExportCommand.cjs +2 -2
- package/dist/production/src/commands/transfer/ExportCommand.cjs.map +1 -1
- package/dist/production/src/commands/transfer/ImportCommand.cjs +2 -2
- package/dist/production/src/commands/transfer/ImportCommand.cjs.map +1 -1
- package/dist/production/src/lib/VersionChecker.cjs +2 -19
- package/dist/production/src/lib/VersionChecker.cjs.map +1 -1
- package/dist/production/src/lib/VersionChecker.js +2 -2
- package/dist/production/src/lib/VersionChecker.js.map +1 -1
- package/dist/production/src/lib/fs/FileSystem.cjs +36 -4
- package/dist/production/src/lib/fs/FileSystem.cjs.map +1 -1
- package/dist/production/src/lib/fs/FileSystem.js +35 -3
- package/dist/production/src/lib/fs/FileSystem.js.map +1 -1
- package/dist/production/src/lib/migrations/MigrationPrinter.cjs +9 -12
- package/dist/production/src/lib/migrations/MigrationPrinter.cjs.map +1 -1
- package/dist/production/src/lib/migrations/MigrationPrinter.js +10 -13
- package/dist/production/src/lib/migrations/MigrationPrinter.js.map +1 -1
- package/dist/production/src/lib/migrations/MigrationSnapshotFacade.cjs +1 -1
- package/dist/production/src/lib/migrations/MigrationSnapshotFacade.cjs.map +1 -1
- package/dist/production/src/lib/migrations/MigrationSnapshotFacade.js +1 -1
- package/dist/production/src/lib/migrations/MigrationSnapshotFacade.js.map +1 -1
- package/dist/production/src/lib/prompt/prompt.cjs +41 -7
- package/dist/production/src/lib/prompt/prompt.cjs.map +1 -1
- package/dist/production/src/lib/prompt/prompt.js +41 -7
- package/dist/production/src/lib/prompt/prompt.js.map +1 -1
- package/dist/production/src/lib/transfer/DataTransferClient.cjs +2 -2
- package/dist/production/src/lib/transfer/DataTransferClient.cjs.map +1 -1
- package/dist/production/src/lib/versionRange.cjs +276 -0
- package/dist/production/src/lib/versionRange.cjs.map +1 -0
- package/dist/production/src/lib/versionRange.js +276 -0
- package/dist/production/src/lib/versionRange.js.map +1 -0
- package/dist/types/commands/tenant/policy/TenantAuthLogCommand.d.ts.map +1 -1
- package/dist/types/lib/VersionChecker.d.ts.map +1 -1
- package/dist/types/lib/fs/FileSystem.d.ts +5 -0
- package/dist/types/lib/fs/FileSystem.d.ts.map +1 -1
- package/dist/types/lib/migrations/MigrationPrinter.d.ts.map +1 -1
- package/dist/types/lib/prompt/prompt.d.ts +17 -4
- package/dist/types/lib/prompt/prompt.d.ts.map +1 -1
- package/dist/types/lib/versionRange.d.ts +9 -0
- package/dist/types/lib/versionRange.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +17 -21
- package/src/commands/tenant/policy/TenantAuthLogCommand.ts +2 -5
- package/src/lib/VersionChecker.ts +3 -2
- package/src/lib/fs/FileSystem.ts +46 -3
- package/src/lib/migrations/MigrationPrinter.ts +10 -15
- package/src/lib/migrations/MigrationSnapshotFacade.ts +1 -1
- package/src/lib/prompt/prompt.ts +55 -18
- package/src/lib/versionRange.ts +347 -0
- package/tests/cases/unit/MigrationDiffCommand.test.ts +3 -7
- package/tests/cases/unit/MigrationExecutionFacade.test.ts +20 -25
- package/tests/cases/unit/MigrationRebaseCommand.test.ts +1 -3
- package/tests/cases/unit/MigrationSnapshotFacade.test.ts +1 -3
- package/tests/cases/unit/MigrationsValidator.test.ts +2 -2
- package/tests/cases/unit/actions.test.ts +2 -2
- package/tests/cases/unit/deploy.test.ts +4 -28
- package/tests/cases/unit/fileSystem.test.ts +63 -0
- package/tests/cases/unit/fixtures/semverCorpus.json +1157 -0
- package/tests/cases/unit/project.test.ts +2 -2
- package/tests/cases/unit/prompt.test.ts +64 -0
- package/tests/cases/unit/transfer.test.ts +1 -3
- package/tests/cases/unit/versionRange.test.ts +57 -0
- package/dist/development/src/lib/prompt/prompt.internal.cjs +0 -21
- package/dist/development/src/lib/prompt/prompt.internal.cjs.map +0 -1
- package/dist/development/src/lib/prompt/prompt.internal.js +0 -21
- package/dist/development/src/lib/prompt/prompt.internal.js.map +0 -1
- package/dist/production/src/lib/prompt/prompt.internal.cjs +0 -21
- package/dist/production/src/lib/prompt/prompt.internal.cjs.map +0 -1
- package/dist/production/src/lib/prompt/prompt.internal.js +0 -21
- package/dist/production/src/lib/prompt/prompt.internal.js.map +0 -1
- package/dist/types/lib/prompt/prompt.internal.d.ts +0 -37
- package/dist/types/lib/prompt/prompt.internal.d.ts.map +0 -1
- package/dist/types/lib/prompt/prompt.test.d.ts +0 -2
- package/dist/types/lib/prompt/prompt.test.d.ts.map +0 -1
- package/src/lib/prompt/prompt.internal.ts +0 -69
- package/src/lib/prompt/prompt.test.ts +0 -100
- package/types/chalk-table/index.d.ts +0 -9
|
@@ -2,7 +2,7 @@ import { afterEach, beforeAll, describe, expect, test } from 'bun:test'
|
|
|
2
2
|
import * as fs from 'node:fs/promises'
|
|
3
3
|
import * as os from 'node:os'
|
|
4
4
|
import * as path from 'node:path'
|
|
5
|
-
import
|
|
5
|
+
import { setColorsEnabled } from '@contember/cli-common'
|
|
6
6
|
import { Model, Schema } from '@contember/schema'
|
|
7
7
|
import { emptySchema } from '@contember/schema-utils'
|
|
8
8
|
import {
|
|
@@ -25,7 +25,7 @@ import { ProjectValidateCommand } from '../../../src/commands/project/ProjectVal
|
|
|
25
25
|
|
|
26
26
|
beforeAll(() => {
|
|
27
27
|
// deterministic assertions regardless of the terminal the suite runs in
|
|
28
|
-
|
|
28
|
+
setColorsEnabled(false)
|
|
29
29
|
})
|
|
30
30
|
|
|
31
31
|
class CapturingStream implements OutputStream {
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test'
|
|
2
|
+
import { Output, setColorsEnabled } from '@contember/cli-common'
|
|
3
|
+
import { createTestOutput } from '../../../../cli-common/tests/lib/testOutput.js'
|
|
4
|
+
import { promptConfirm, promptSelect } from '../../../src/lib/prompt/index.js'
|
|
5
|
+
|
|
6
|
+
setColorsEnabled(false)
|
|
7
|
+
|
|
8
|
+
const prompt = (answers: readonly string[]) => createTestOutput({ stdinTty: true, stderrTty: true, answers })
|
|
9
|
+
|
|
10
|
+
describe('promptConfirm', () => {
|
|
11
|
+
test('accepts y, yes, n and no in any case', async () => {
|
|
12
|
+
const confirm = (answer: string) => promptConfirm(prompt([answer]).output, { message: 'Continue?' })
|
|
13
|
+
expect(await confirm('y')).toBe(true)
|
|
14
|
+
expect(await confirm('YES')).toBe(true)
|
|
15
|
+
expect(await confirm(' n ')).toBe(false)
|
|
16
|
+
expect(await confirm('No')).toBe(false)
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
test('an empty line takes the initial value, which defaults to no', async () => {
|
|
20
|
+
expect(await promptConfirm(prompt(['']).output, { message: 'Continue?' })).toBe(false)
|
|
21
|
+
expect(await promptConfirm(prompt(['']).output, { message: 'Continue?', initial: true })).toBe(true)
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
test('asks again after an unknown answer', async () => {
|
|
25
|
+
const { output, stderr } = prompt(['maybe', 'y'])
|
|
26
|
+
expect(await promptConfirm(output, { message: 'Continue?' })).toBe(true)
|
|
27
|
+
expect(stderr.text).toBe('Continue? (y/N) Continue? (y/N) ')
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
test('shows the default and answers no when the input is closed', async () => {
|
|
31
|
+
const { output, stderr } = prompt([])
|
|
32
|
+
expect(await promptConfirm(output, { message: 'Continue?', initial: true })).toBe(false)
|
|
33
|
+
expect(stderr.text).toBe('Continue? (Y/n) ')
|
|
34
|
+
})
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
describe('promptSelect', () => {
|
|
38
|
+
const choose = (output: Output) =>
|
|
39
|
+
promptSelect(output, {
|
|
40
|
+
message: 'Choose an action',
|
|
41
|
+
choices: [
|
|
42
|
+
{ value: 'remove', title: 'Remove migration' },
|
|
43
|
+
{ value: 'keep', title: 'Keep migration' },
|
|
44
|
+
],
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
test('lists numbered choices and returns the picked value with its literal type', async () => {
|
|
48
|
+
const { output, stderr } = prompt(['2'])
|
|
49
|
+
const selected: 'remove' | 'keep' | undefined = await choose(output)
|
|
50
|
+
expect(selected).toBe('keep')
|
|
51
|
+
expect(stderr.text).toBe('Choose an action\n 1) Remove migration\n 2) Keep migration\nChoose 1-2: ')
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
test('asks again after an empty, out-of-range or non-numeric answer', async () => {
|
|
55
|
+
const { output, stderr } = prompt(['', '0', '3', '1.0', 'keep', ' 1 '])
|
|
56
|
+
expect(await choose(output)).toBe('remove')
|
|
57
|
+
expect(stderr.text.split('Choose 1-2: ').length - 1).toBe(1)
|
|
58
|
+
expect(stderr.text.split('Enter a number from 1 to 2: ').length - 1).toBe(5)
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
test('returns undefined when the input is closed', async () => {
|
|
62
|
+
expect(await choose(prompt([]).output)).toBeUndefined()
|
|
63
|
+
})
|
|
64
|
+
})
|
|
@@ -14,7 +14,6 @@ import { RemoteProject } from '../../../src/lib/project/RemoteProject.js'
|
|
|
14
14
|
import { join } from 'node:path'
|
|
15
15
|
import { tmpdir } from 'node:os'
|
|
16
16
|
import { mkdtemp, rm } from 'node:fs/promises'
|
|
17
|
-
import prompts from 'prompts'
|
|
18
17
|
import { confirmImport } from '../../../src/commands/transfer/utils.js'
|
|
19
18
|
|
|
20
19
|
const cliEnv = (overrides: Partial<CliEnv> = {}): CliEnv => ({
|
|
@@ -687,9 +686,8 @@ describe('data export output', () => {
|
|
|
687
686
|
|
|
688
687
|
describe('data transfer confirmation guard', () => {
|
|
689
688
|
test('maps interactive confirmation through the diagnostic prompt stream', async () => {
|
|
690
|
-
const { output } = createTestOutput({ stdinTty: true, stderrTty: true })
|
|
689
|
+
const { output } = createTestOutput({ stdinTty: true, stderrTty: true, answers: ['y', 'n'] })
|
|
691
690
|
const input = new Input({}, { yes: false })
|
|
692
|
-
prompts.inject([true, false])
|
|
693
691
|
|
|
694
692
|
expect(await confirmImport(input, output)).toBe(true)
|
|
695
693
|
expect(await confirmImport(input, output)).toBe(false)
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test'
|
|
2
|
+
import { readFileSync } from 'node:fs'
|
|
3
|
+
import { satisfiesVersionRange } from '../../../src/lib/versionRange.js'
|
|
4
|
+
|
|
5
|
+
interface Corpus {
|
|
6
|
+
readonly versions: readonly string[]
|
|
7
|
+
readonly supported: readonly string[]
|
|
8
|
+
readonly unsupported: readonly string[]
|
|
9
|
+
readonly ranges: readonly string[]
|
|
10
|
+
/** One string per range, one character per version: semver's answer, `1` or `0`. */
|
|
11
|
+
readonly expected: readonly string[]
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Recorded from node-semver `satisfies` (default options), see `generatedWith` in the fixture.
|
|
15
|
+
const corpus: Corpus = JSON.parse(readFileSync(new URL('./fixtures/semverCorpus.json', import.meta.url), 'utf8'))
|
|
16
|
+
|
|
17
|
+
describe('satisfiesVersionRange', () => {
|
|
18
|
+
test('agrees with semver wherever it gives an answer', () => {
|
|
19
|
+
const mismatches: string[] = []
|
|
20
|
+
corpus.ranges.forEach((range, rangeIndex) => {
|
|
21
|
+
corpus.versions.forEach((version, versionIndex) => {
|
|
22
|
+
const ours = satisfiesVersionRange(version, range)
|
|
23
|
+
const theirs = corpus.expected[rangeIndex][versionIndex] === '1'
|
|
24
|
+
if (ours !== undefined && ours !== theirs) {
|
|
25
|
+
mismatches.push(`${JSON.stringify(range)} on ${version}: ours ${ours}, semver ${theirs}`)
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
})
|
|
29
|
+
expect(mismatches).toEqual([])
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
test('answers every supported range form for every valid version', () => {
|
|
33
|
+
// The installed version comes from a package.json, so a `v` prefix or a partial version is not interpreted.
|
|
34
|
+
const validVersions = corpus.versions.filter(version => !['v2.1.0', '2.1', 'latest', '01.2.3'].includes(version))
|
|
35
|
+
const unanswered = corpus.supported.flatMap(range =>
|
|
36
|
+
validVersions.filter(version => satisfiesVersionRange(version, range) === undefined).map(version => `${range} on ${version}`)
|
|
37
|
+
)
|
|
38
|
+
expect(unanswered).toEqual([])
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
test('does not interpret tags, protocols, aliases or malformed ranges', () => {
|
|
42
|
+
const answered = corpus.unsupported.filter(range => satisfiesVersionRange('2.1.0', range) !== undefined)
|
|
43
|
+
expect(answered).toEqual([])
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
test('does not interpret an invalid installed version', () => {
|
|
47
|
+
expect(satisfiesVersionRange('2.1', '^2.1.0')).toBeUndefined()
|
|
48
|
+
expect(satisfiesVersionRange('latest', '*')).toBeUndefined()
|
|
49
|
+
expect(satisfiesVersionRange('2.1.0-' + 'a'.repeat(260), '>=2.1.0-a')).toBeUndefined()
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
test('excludes prereleases unless the range names one with the same version', () => {
|
|
53
|
+
expect(satisfiesVersionRange('2.2.0-alpha.1', '^2.1.0')).toBe(false)
|
|
54
|
+
expect(satisfiesVersionRange('2.1.0-alpha.16', '^2.1.0-alpha.15')).toBe(true)
|
|
55
|
+
expect(satisfiesVersionRange('2.1.0-alpha.16', '*')).toBe(false)
|
|
56
|
+
})
|
|
57
|
+
})
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const answerName = "value";
|
|
4
|
-
const promptConfirmWithRunner = async (output, options, runner) => {
|
|
5
|
-
const question = options.initial === void 0 ? { type: "confirm", name: answerName, message: options.message, stdout: output.promptOutput } : { type: "confirm", name: answerName, message: options.message, initial: options.initial, stdout: output.promptOutput };
|
|
6
|
-
const answer = await runner(question);
|
|
7
|
-
return answer.value === true;
|
|
8
|
-
};
|
|
9
|
-
const promptSelectWithRunner = async (output, options, runner) => {
|
|
10
|
-
const answer = await runner({
|
|
11
|
-
type: "select",
|
|
12
|
-
name: answerName,
|
|
13
|
-
message: options.message,
|
|
14
|
-
choices: options.choices.map((choice) => ({ title: choice.title, value: choice.value })),
|
|
15
|
-
stdout: output.promptOutput
|
|
16
|
-
});
|
|
17
|
-
return options.choices.find((choice) => choice.value === answer.value)?.value;
|
|
18
|
-
};
|
|
19
|
-
exports.promptConfirmWithRunner = promptConfirmWithRunner;
|
|
20
|
-
exports.promptSelectWithRunner = promptSelectWithRunner;
|
|
21
|
-
//# sourceMappingURL=prompt.internal.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prompt.internal.cjs","sources":["../../../../../../packages/cli/src/lib/prompt/prompt.internal.ts"],"sourcesContent":["import { Output, type PromptOutputStream } from '@contember/cli-common'\n\nconst answerName = 'value'\n\nexport interface ConfirmPromptOptions {\n\treadonly message: string\n\treadonly initial?: boolean\n}\n\nexport interface SelectPromptChoice<T extends string> {\n\treadonly title: string\n\treadonly value: T\n}\n\nexport interface SelectPromptOptions<T extends string> {\n\treadonly message: string\n\treadonly choices: readonly SelectPromptChoice<T>[]\n}\n\nexport interface PromptAnswer {\n\treadonly value?: unknown\n}\n\nexport interface ConfirmQuestion {\n\treadonly type: 'confirm'\n\treadonly name: typeof answerName\n\treadonly message: string\n\treadonly initial?: boolean\n\treadonly stdout: PromptOutputStream\n}\n\nexport interface SelectQuestion<T extends string> {\n\treadonly type: 'select'\n\treadonly name: typeof answerName\n\treadonly message: string\n\treadonly choices: SelectPromptChoice<T>[]\n\treadonly stdout: PromptOutputStream\n}\n\nexport type PromptQuestion = ConfirmQuestion | SelectQuestion<string>\n\ntype PromptRunner<Q> = (question: Q) => Promise<PromptAnswer>\n\nexport const promptConfirmWithRunner = async (\n\toutput: Output,\n\toptions: ConfirmPromptOptions,\n\trunner: PromptRunner<ConfirmQuestion>,\n): Promise<boolean> => {\n\tconst question: ConfirmQuestion = options.initial === undefined\n\t\t? { type: 'confirm', name: answerName, message: options.message, stdout: output.promptOutput }\n\t\t: { type: 'confirm', name: answerName, message: options.message, initial: options.initial, stdout: output.promptOutput }\n\tconst answer = await runner(question)\n\treturn answer.value === true\n}\n\nexport const promptSelectWithRunner = async <const T extends string>(\n\toutput: Output,\n\toptions: SelectPromptOptions<T>,\n\trunner: PromptRunner<SelectQuestion<T>>,\n): Promise<T | undefined> => {\n\tconst answer = await runner({\n\t\ttype: 'select',\n\t\tname: answerName,\n\t\tmessage: options.message,\n\t\tchoices: options.choices.map(choice => ({ title: choice.title, value: choice.value })),\n\t\tstdout: output.promptOutput,\n\t})\n\treturn options.choices.find(choice => choice.value === answer.value)?.value\n}\n"],"names":[],"mappings":";;AAEA,MAAM,aAAa;AAyCZ,MAAM,0BAA0B,OACtC,QACA,SACA,WACsB;AACtB,QAAM,WAA4B,QAAQ,YAAY,SACnD,EAAE,MAAM,WAAW,MAAM,YAAY,SAAS,QAAQ,SAAS,QAAQ,OAAO,aAAA,IAC9E,EAAE,MAAM,WAAW,MAAM,YAAY,SAAS,QAAQ,SAAS,SAAS,QAAQ,SAAS,QAAQ,OAAO,aAAA;AAC3G,QAAM,SAAS,MAAM,OAAO,QAAQ;AACpC,SAAO,OAAO,UAAU;AACzB;AAEO,MAAM,yBAAyB,OACrC,QACA,SACA,WAC4B;AAC5B,QAAM,SAAS,MAAM,OAAO;AAAA,IAC3B,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SAAS,QAAQ;AAAA,IACjB,SAAS,QAAQ,QAAQ,IAAI,CAAA,YAAW,EAAE,OAAO,OAAO,OAAO,OAAO,OAAO,MAAA,EAAQ;AAAA,IACrF,QAAQ,OAAO;AAAA,EAAA,CACf;AACD,SAAO,QAAQ,QAAQ,KAAK,CAAA,WAAU,OAAO,UAAU,OAAO,KAAK,GAAG;AACvE;;;"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
const answerName = "value";
|
|
2
|
-
const promptConfirmWithRunner = async (output, options, runner) => {
|
|
3
|
-
const question = options.initial === void 0 ? { type: "confirm", name: answerName, message: options.message, stdout: output.promptOutput } : { type: "confirm", name: answerName, message: options.message, initial: options.initial, stdout: output.promptOutput };
|
|
4
|
-
const answer = await runner(question);
|
|
5
|
-
return answer.value === true;
|
|
6
|
-
};
|
|
7
|
-
const promptSelectWithRunner = async (output, options, runner) => {
|
|
8
|
-
const answer = await runner({
|
|
9
|
-
type: "select",
|
|
10
|
-
name: answerName,
|
|
11
|
-
message: options.message,
|
|
12
|
-
choices: options.choices.map((choice) => ({ title: choice.title, value: choice.value })),
|
|
13
|
-
stdout: output.promptOutput
|
|
14
|
-
});
|
|
15
|
-
return options.choices.find((choice) => choice.value === answer.value)?.value;
|
|
16
|
-
};
|
|
17
|
-
export {
|
|
18
|
-
promptConfirmWithRunner,
|
|
19
|
-
promptSelectWithRunner
|
|
20
|
-
};
|
|
21
|
-
//# sourceMappingURL=prompt.internal.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prompt.internal.js","sources":["../../../../../../packages/cli/src/lib/prompt/prompt.internal.ts"],"sourcesContent":["import { Output, type PromptOutputStream } from '@contember/cli-common'\n\nconst answerName = 'value'\n\nexport interface ConfirmPromptOptions {\n\treadonly message: string\n\treadonly initial?: boolean\n}\n\nexport interface SelectPromptChoice<T extends string> {\n\treadonly title: string\n\treadonly value: T\n}\n\nexport interface SelectPromptOptions<T extends string> {\n\treadonly message: string\n\treadonly choices: readonly SelectPromptChoice<T>[]\n}\n\nexport interface PromptAnswer {\n\treadonly value?: unknown\n}\n\nexport interface ConfirmQuestion {\n\treadonly type: 'confirm'\n\treadonly name: typeof answerName\n\treadonly message: string\n\treadonly initial?: boolean\n\treadonly stdout: PromptOutputStream\n}\n\nexport interface SelectQuestion<T extends string> {\n\treadonly type: 'select'\n\treadonly name: typeof answerName\n\treadonly message: string\n\treadonly choices: SelectPromptChoice<T>[]\n\treadonly stdout: PromptOutputStream\n}\n\nexport type PromptQuestion = ConfirmQuestion | SelectQuestion<string>\n\ntype PromptRunner<Q> = (question: Q) => Promise<PromptAnswer>\n\nexport const promptConfirmWithRunner = async (\n\toutput: Output,\n\toptions: ConfirmPromptOptions,\n\trunner: PromptRunner<ConfirmQuestion>,\n): Promise<boolean> => {\n\tconst question: ConfirmQuestion = options.initial === undefined\n\t\t? { type: 'confirm', name: answerName, message: options.message, stdout: output.promptOutput }\n\t\t: { type: 'confirm', name: answerName, message: options.message, initial: options.initial, stdout: output.promptOutput }\n\tconst answer = await runner(question)\n\treturn answer.value === true\n}\n\nexport const promptSelectWithRunner = async <const T extends string>(\n\toutput: Output,\n\toptions: SelectPromptOptions<T>,\n\trunner: PromptRunner<SelectQuestion<T>>,\n): Promise<T | undefined> => {\n\tconst answer = await runner({\n\t\ttype: 'select',\n\t\tname: answerName,\n\t\tmessage: options.message,\n\t\tchoices: options.choices.map(choice => ({ title: choice.title, value: choice.value })),\n\t\tstdout: output.promptOutput,\n\t})\n\treturn options.choices.find(choice => choice.value === answer.value)?.value\n}\n"],"names":[],"mappings":"AAEA,MAAM,aAAa;AAyCZ,MAAM,0BAA0B,OACtC,QACA,SACA,WACsB;AACtB,QAAM,WAA4B,QAAQ,YAAY,SACnD,EAAE,MAAM,WAAW,MAAM,YAAY,SAAS,QAAQ,SAAS,QAAQ,OAAO,aAAA,IAC9E,EAAE,MAAM,WAAW,MAAM,YAAY,SAAS,QAAQ,SAAS,SAAS,QAAQ,SAAS,QAAQ,OAAO,aAAA;AAC3G,QAAM,SAAS,MAAM,OAAO,QAAQ;AACpC,SAAO,OAAO,UAAU;AACzB;AAEO,MAAM,yBAAyB,OACrC,QACA,SACA,WAC4B;AAC5B,QAAM,SAAS,MAAM,OAAO;AAAA,IAC3B,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SAAS,QAAQ;AAAA,IACjB,SAAS,QAAQ,QAAQ,IAAI,CAAA,YAAW,EAAE,OAAO,OAAO,OAAO,OAAO,OAAO,MAAA,EAAQ;AAAA,IACrF,QAAQ,OAAO;AAAA,EAAA,CACf;AACD,SAAO,QAAQ,QAAQ,KAAK,CAAA,WAAU,OAAO,UAAU,OAAO,KAAK,GAAG;AACvE;"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const answerName = "value";
|
|
4
|
-
const promptConfirmWithRunner = async (output, options, runner) => {
|
|
5
|
-
const question = options.initial === void 0 ? { type: "confirm", name: answerName, message: options.message, stdout: output.promptOutput } : { type: "confirm", name: answerName, message: options.message, initial: options.initial, stdout: output.promptOutput };
|
|
6
|
-
const answer = await runner(question);
|
|
7
|
-
return answer.value === true;
|
|
8
|
-
};
|
|
9
|
-
const promptSelectWithRunner = async (output, options, runner) => {
|
|
10
|
-
const answer = await runner({
|
|
11
|
-
type: "select",
|
|
12
|
-
name: answerName,
|
|
13
|
-
message: options.message,
|
|
14
|
-
choices: options.choices.map((choice) => ({ title: choice.title, value: choice.value })),
|
|
15
|
-
stdout: output.promptOutput
|
|
16
|
-
});
|
|
17
|
-
return options.choices.find((choice) => choice.value === answer.value)?.value;
|
|
18
|
-
};
|
|
19
|
-
exports.promptConfirmWithRunner = promptConfirmWithRunner;
|
|
20
|
-
exports.promptSelectWithRunner = promptSelectWithRunner;
|
|
21
|
-
//# sourceMappingURL=prompt.internal.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prompt.internal.cjs","sources":["../../../../../../packages/cli/src/lib/prompt/prompt.internal.ts"],"sourcesContent":["import { Output, type PromptOutputStream } from '@contember/cli-common'\n\nconst answerName = 'value'\n\nexport interface ConfirmPromptOptions {\n\treadonly message: string\n\treadonly initial?: boolean\n}\n\nexport interface SelectPromptChoice<T extends string> {\n\treadonly title: string\n\treadonly value: T\n}\n\nexport interface SelectPromptOptions<T extends string> {\n\treadonly message: string\n\treadonly choices: readonly SelectPromptChoice<T>[]\n}\n\nexport interface PromptAnswer {\n\treadonly value?: unknown\n}\n\nexport interface ConfirmQuestion {\n\treadonly type: 'confirm'\n\treadonly name: typeof answerName\n\treadonly message: string\n\treadonly initial?: boolean\n\treadonly stdout: PromptOutputStream\n}\n\nexport interface SelectQuestion<T extends string> {\n\treadonly type: 'select'\n\treadonly name: typeof answerName\n\treadonly message: string\n\treadonly choices: SelectPromptChoice<T>[]\n\treadonly stdout: PromptOutputStream\n}\n\nexport type PromptQuestion = ConfirmQuestion | SelectQuestion<string>\n\ntype PromptRunner<Q> = (question: Q) => Promise<PromptAnswer>\n\nexport const promptConfirmWithRunner = async (\n\toutput: Output,\n\toptions: ConfirmPromptOptions,\n\trunner: PromptRunner<ConfirmQuestion>,\n): Promise<boolean> => {\n\tconst question: ConfirmQuestion = options.initial === undefined\n\t\t? { type: 'confirm', name: answerName, message: options.message, stdout: output.promptOutput }\n\t\t: { type: 'confirm', name: answerName, message: options.message, initial: options.initial, stdout: output.promptOutput }\n\tconst answer = await runner(question)\n\treturn answer.value === true\n}\n\nexport const promptSelectWithRunner = async <const T extends string>(\n\toutput: Output,\n\toptions: SelectPromptOptions<T>,\n\trunner: PromptRunner<SelectQuestion<T>>,\n): Promise<T | undefined> => {\n\tconst answer = await runner({\n\t\ttype: 'select',\n\t\tname: answerName,\n\t\tmessage: options.message,\n\t\tchoices: options.choices.map(choice => ({ title: choice.title, value: choice.value })),\n\t\tstdout: output.promptOutput,\n\t})\n\treturn options.choices.find(choice => choice.value === answer.value)?.value\n}\n"],"names":[],"mappings":";;AAEA,MAAM,aAAa;AAyCZ,MAAM,0BAA0B,OACtC,QACA,SACA,WACsB;AACtB,QAAM,WAA4B,QAAQ,YAAY,SACnD,EAAE,MAAM,WAAW,MAAM,YAAY,SAAS,QAAQ,SAAS,QAAQ,OAAO,aAAA,IAC9E,EAAE,MAAM,WAAW,MAAM,YAAY,SAAS,QAAQ,SAAS,SAAS,QAAQ,SAAS,QAAQ,OAAO,aAAA;AAC3G,QAAM,SAAS,MAAM,OAAO,QAAQ;AACpC,SAAO,OAAO,UAAU;AACzB;AAEO,MAAM,yBAAyB,OACrC,QACA,SACA,WAC4B;AAC5B,QAAM,SAAS,MAAM,OAAO;AAAA,IAC3B,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SAAS,QAAQ;AAAA,IACjB,SAAS,QAAQ,QAAQ,IAAI,CAAA,YAAW,EAAE,OAAO,OAAO,OAAO,OAAO,OAAO,MAAA,EAAQ;AAAA,IACrF,QAAQ,OAAO;AAAA,EAAA,CACf;AACD,SAAO,QAAQ,QAAQ,KAAK,CAAA,WAAU,OAAO,UAAU,OAAO,KAAK,GAAG;AACvE;;;"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
const answerName = "value";
|
|
2
|
-
const promptConfirmWithRunner = async (output, options, runner) => {
|
|
3
|
-
const question = options.initial === void 0 ? { type: "confirm", name: answerName, message: options.message, stdout: output.promptOutput } : { type: "confirm", name: answerName, message: options.message, initial: options.initial, stdout: output.promptOutput };
|
|
4
|
-
const answer = await runner(question);
|
|
5
|
-
return answer.value === true;
|
|
6
|
-
};
|
|
7
|
-
const promptSelectWithRunner = async (output, options, runner) => {
|
|
8
|
-
const answer = await runner({
|
|
9
|
-
type: "select",
|
|
10
|
-
name: answerName,
|
|
11
|
-
message: options.message,
|
|
12
|
-
choices: options.choices.map((choice) => ({ title: choice.title, value: choice.value })),
|
|
13
|
-
stdout: output.promptOutput
|
|
14
|
-
});
|
|
15
|
-
return options.choices.find((choice) => choice.value === answer.value)?.value;
|
|
16
|
-
};
|
|
17
|
-
export {
|
|
18
|
-
promptConfirmWithRunner,
|
|
19
|
-
promptSelectWithRunner
|
|
20
|
-
};
|
|
21
|
-
//# sourceMappingURL=prompt.internal.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prompt.internal.js","sources":["../../../../../../packages/cli/src/lib/prompt/prompt.internal.ts"],"sourcesContent":["import { Output, type PromptOutputStream } from '@contember/cli-common'\n\nconst answerName = 'value'\n\nexport interface ConfirmPromptOptions {\n\treadonly message: string\n\treadonly initial?: boolean\n}\n\nexport interface SelectPromptChoice<T extends string> {\n\treadonly title: string\n\treadonly value: T\n}\n\nexport interface SelectPromptOptions<T extends string> {\n\treadonly message: string\n\treadonly choices: readonly SelectPromptChoice<T>[]\n}\n\nexport interface PromptAnswer {\n\treadonly value?: unknown\n}\n\nexport interface ConfirmQuestion {\n\treadonly type: 'confirm'\n\treadonly name: typeof answerName\n\treadonly message: string\n\treadonly initial?: boolean\n\treadonly stdout: PromptOutputStream\n}\n\nexport interface SelectQuestion<T extends string> {\n\treadonly type: 'select'\n\treadonly name: typeof answerName\n\treadonly message: string\n\treadonly choices: SelectPromptChoice<T>[]\n\treadonly stdout: PromptOutputStream\n}\n\nexport type PromptQuestion = ConfirmQuestion | SelectQuestion<string>\n\ntype PromptRunner<Q> = (question: Q) => Promise<PromptAnswer>\n\nexport const promptConfirmWithRunner = async (\n\toutput: Output,\n\toptions: ConfirmPromptOptions,\n\trunner: PromptRunner<ConfirmQuestion>,\n): Promise<boolean> => {\n\tconst question: ConfirmQuestion = options.initial === undefined\n\t\t? { type: 'confirm', name: answerName, message: options.message, stdout: output.promptOutput }\n\t\t: { type: 'confirm', name: answerName, message: options.message, initial: options.initial, stdout: output.promptOutput }\n\tconst answer = await runner(question)\n\treturn answer.value === true\n}\n\nexport const promptSelectWithRunner = async <const T extends string>(\n\toutput: Output,\n\toptions: SelectPromptOptions<T>,\n\trunner: PromptRunner<SelectQuestion<T>>,\n): Promise<T | undefined> => {\n\tconst answer = await runner({\n\t\ttype: 'select',\n\t\tname: answerName,\n\t\tmessage: options.message,\n\t\tchoices: options.choices.map(choice => ({ title: choice.title, value: choice.value })),\n\t\tstdout: output.promptOutput,\n\t})\n\treturn options.choices.find(choice => choice.value === answer.value)?.value\n}\n"],"names":[],"mappings":"AAEA,MAAM,aAAa;AAyCZ,MAAM,0BAA0B,OACtC,QACA,SACA,WACsB;AACtB,QAAM,WAA4B,QAAQ,YAAY,SACnD,EAAE,MAAM,WAAW,MAAM,YAAY,SAAS,QAAQ,SAAS,QAAQ,OAAO,aAAA,IAC9E,EAAE,MAAM,WAAW,MAAM,YAAY,SAAS,QAAQ,SAAS,SAAS,QAAQ,SAAS,QAAQ,OAAO,aAAA;AAC3G,QAAM,SAAS,MAAM,OAAO,QAAQ;AACpC,SAAO,OAAO,UAAU;AACzB;AAEO,MAAM,yBAAyB,OACrC,QACA,SACA,WAC4B;AAC5B,QAAM,SAAS,MAAM,OAAO;AAAA,IAC3B,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SAAS,QAAQ;AAAA,IACjB,SAAS,QAAQ,QAAQ,IAAI,CAAA,YAAW,EAAE,OAAO,OAAO,OAAO,OAAO,OAAO,MAAA,EAAQ;AAAA,IACrF,QAAQ,OAAO;AAAA,EAAA,CACf;AACD,SAAO,QAAQ,QAAQ,KAAK,CAAA,WAAU,OAAO,UAAU,OAAO,KAAK,GAAG;AACvE;"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { Output, type PromptOutputStream } from '@contember/cli-common';
|
|
2
|
-
declare const answerName = "value";
|
|
3
|
-
export interface ConfirmPromptOptions {
|
|
4
|
-
readonly message: string;
|
|
5
|
-
readonly initial?: boolean;
|
|
6
|
-
}
|
|
7
|
-
export interface SelectPromptChoice<T extends string> {
|
|
8
|
-
readonly title: string;
|
|
9
|
-
readonly value: T;
|
|
10
|
-
}
|
|
11
|
-
export interface SelectPromptOptions<T extends string> {
|
|
12
|
-
readonly message: string;
|
|
13
|
-
readonly choices: readonly SelectPromptChoice<T>[];
|
|
14
|
-
}
|
|
15
|
-
export interface PromptAnswer {
|
|
16
|
-
readonly value?: unknown;
|
|
17
|
-
}
|
|
18
|
-
export interface ConfirmQuestion {
|
|
19
|
-
readonly type: 'confirm';
|
|
20
|
-
readonly name: typeof answerName;
|
|
21
|
-
readonly message: string;
|
|
22
|
-
readonly initial?: boolean;
|
|
23
|
-
readonly stdout: PromptOutputStream;
|
|
24
|
-
}
|
|
25
|
-
export interface SelectQuestion<T extends string> {
|
|
26
|
-
readonly type: 'select';
|
|
27
|
-
readonly name: typeof answerName;
|
|
28
|
-
readonly message: string;
|
|
29
|
-
readonly choices: SelectPromptChoice<T>[];
|
|
30
|
-
readonly stdout: PromptOutputStream;
|
|
31
|
-
}
|
|
32
|
-
export type PromptQuestion = ConfirmQuestion | SelectQuestion<string>;
|
|
33
|
-
type PromptRunner<Q> = (question: Q) => Promise<PromptAnswer>;
|
|
34
|
-
export declare const promptConfirmWithRunner: (output: Output, options: ConfirmPromptOptions, runner: PromptRunner<ConfirmQuestion>) => Promise<boolean>;
|
|
35
|
-
export declare const promptSelectWithRunner: <const T extends string>(output: Output, options: SelectPromptOptions<T>, runner: PromptRunner<SelectQuestion<T>>) => Promise<T | undefined>;
|
|
36
|
-
export {};
|
|
37
|
-
//# sourceMappingURL=prompt.internal.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prompt.internal.d.ts","sourceRoot":"","sources":["../../../../src/lib/prompt/prompt.internal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAEvE,QAAA,MAAM,UAAU,UAAU,CAAA;AAE1B,MAAM,WAAW,oBAAoB;IACpC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAC1B;AAED,MAAM,WAAW,kBAAkB,CAAC,CAAC,SAAS,MAAM;IACnD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAA;CACjB;AAED,MAAM,WAAW,mBAAmB,CAAC,CAAC,SAAS,MAAM;IACpD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,OAAO,EAAE,SAAS,kBAAkB,CAAC,CAAC,CAAC,EAAE,CAAA;CAClD;AAED,MAAM,WAAW,YAAY;IAC5B,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CACxB;AAED,MAAM,WAAW,eAAe;IAC/B,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;IACxB,QAAQ,CAAC,IAAI,EAAE,OAAO,UAAU,CAAA;IAChC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAA;IAC1B,QAAQ,CAAC,MAAM,EAAE,kBAAkB,CAAA;CACnC;AAED,MAAM,WAAW,cAAc,CAAC,CAAC,SAAS,MAAM;IAC/C,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;IACvB,QAAQ,CAAC,IAAI,EAAE,OAAO,UAAU,CAAA;IAChC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAC,CAAC,CAAC,EAAE,CAAA;IACzC,QAAQ,CAAC,MAAM,EAAE,kBAAkB,CAAA;CACnC;AAED,MAAM,MAAM,cAAc,GAAG,eAAe,GAAG,cAAc,CAAC,MAAM,CAAC,CAAA;AAErE,KAAK,YAAY,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,KAAK,OAAO,CAAC,YAAY,CAAC,CAAA;AAE7D,eAAO,MAAM,uBAAuB,WAC3B,MAAM,WACL,oBAAoB,UACrB,YAAY,CAAC,eAAe,CAAC,KACnC,OAAO,CAAC,OAAO,CAMjB,CAAA;AAED,eAAO,MAAM,sBAAsB,GAAU,KAAK,CAAC,CAAC,SAAS,MAAM,UAC1D,MAAM,WACL,mBAAmB,CAAC,CAAC,CAAC,UACvB,YAAY,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,KACrC,OAAO,CAAC,CAAC,GAAG,SAAS,CASvB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prompt.test.d.ts","sourceRoot":"","sources":["../../../../src/lib/prompt/prompt.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { Output, type PromptOutputStream } from '@contember/cli-common'
|
|
2
|
-
|
|
3
|
-
const answerName = 'value'
|
|
4
|
-
|
|
5
|
-
export interface ConfirmPromptOptions {
|
|
6
|
-
readonly message: string
|
|
7
|
-
readonly initial?: boolean
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export interface SelectPromptChoice<T extends string> {
|
|
11
|
-
readonly title: string
|
|
12
|
-
readonly value: T
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface SelectPromptOptions<T extends string> {
|
|
16
|
-
readonly message: string
|
|
17
|
-
readonly choices: readonly SelectPromptChoice<T>[]
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface PromptAnswer {
|
|
21
|
-
readonly value?: unknown
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface ConfirmQuestion {
|
|
25
|
-
readonly type: 'confirm'
|
|
26
|
-
readonly name: typeof answerName
|
|
27
|
-
readonly message: string
|
|
28
|
-
readonly initial?: boolean
|
|
29
|
-
readonly stdout: PromptOutputStream
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export interface SelectQuestion<T extends string> {
|
|
33
|
-
readonly type: 'select'
|
|
34
|
-
readonly name: typeof answerName
|
|
35
|
-
readonly message: string
|
|
36
|
-
readonly choices: SelectPromptChoice<T>[]
|
|
37
|
-
readonly stdout: PromptOutputStream
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export type PromptQuestion = ConfirmQuestion | SelectQuestion<string>
|
|
41
|
-
|
|
42
|
-
type PromptRunner<Q> = (question: Q) => Promise<PromptAnswer>
|
|
43
|
-
|
|
44
|
-
export const promptConfirmWithRunner = async (
|
|
45
|
-
output: Output,
|
|
46
|
-
options: ConfirmPromptOptions,
|
|
47
|
-
runner: PromptRunner<ConfirmQuestion>,
|
|
48
|
-
): Promise<boolean> => {
|
|
49
|
-
const question: ConfirmQuestion = options.initial === undefined
|
|
50
|
-
? { type: 'confirm', name: answerName, message: options.message, stdout: output.promptOutput }
|
|
51
|
-
: { type: 'confirm', name: answerName, message: options.message, initial: options.initial, stdout: output.promptOutput }
|
|
52
|
-
const answer = await runner(question)
|
|
53
|
-
return answer.value === true
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export const promptSelectWithRunner = async <const T extends string>(
|
|
57
|
-
output: Output,
|
|
58
|
-
options: SelectPromptOptions<T>,
|
|
59
|
-
runner: PromptRunner<SelectQuestion<T>>,
|
|
60
|
-
): Promise<T | undefined> => {
|
|
61
|
-
const answer = await runner({
|
|
62
|
-
type: 'select',
|
|
63
|
-
name: answerName,
|
|
64
|
-
message: options.message,
|
|
65
|
-
choices: options.choices.map(choice => ({ title: choice.title, value: choice.value })),
|
|
66
|
-
stdout: output.promptOutput,
|
|
67
|
-
})
|
|
68
|
-
return options.choices.find(choice => choice.value === answer.value)?.value
|
|
69
|
-
}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'bun:test'
|
|
2
|
-
import { Output, type OutputStream } from '@contember/cli-common'
|
|
3
|
-
import { promptConfirmWithRunner, promptSelectWithRunner } from './prompt.internal.js'
|
|
4
|
-
|
|
5
|
-
class CapturingStream implements OutputStream {
|
|
6
|
-
public readonly isTty = true
|
|
7
|
-
public readonly columns = 120
|
|
8
|
-
|
|
9
|
-
public write(): void {
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const createOutput = (): Output =>
|
|
14
|
-
new Output({
|
|
15
|
-
stdout: new CapturingStream(),
|
|
16
|
-
stderr: new CapturingStream(),
|
|
17
|
-
isStdinTty: () => true,
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
describe('promptConfirm', () => {
|
|
21
|
-
test('binds diagnostic output and maps a confirmed answer', async () => {
|
|
22
|
-
const output = createOutput()
|
|
23
|
-
const result = await promptConfirmWithRunner(output, { message: 'Continue?', initial: false }, async question => {
|
|
24
|
-
expect(question).toStrictEqual({
|
|
25
|
-
type: 'confirm',
|
|
26
|
-
name: 'value',
|
|
27
|
-
message: 'Continue?',
|
|
28
|
-
initial: false,
|
|
29
|
-
stdout: output.promptOutput,
|
|
30
|
-
})
|
|
31
|
-
return { value: true }
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
expect(result).toBe(true)
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
test('maps rejection and cancellation to false', async () => {
|
|
38
|
-
const output = createOutput()
|
|
39
|
-
expect(
|
|
40
|
-
await promptConfirmWithRunner(output, { message: 'Continue?' }, async question => {
|
|
41
|
-
expect(question).toStrictEqual({
|
|
42
|
-
type: 'confirm',
|
|
43
|
-
name: 'value',
|
|
44
|
-
message: 'Continue?',
|
|
45
|
-
stdout: output.promptOutput,
|
|
46
|
-
})
|
|
47
|
-
expect('initial' in question).toBe(false)
|
|
48
|
-
return { value: false }
|
|
49
|
-
}),
|
|
50
|
-
).toBe(false)
|
|
51
|
-
expect(await promptConfirmWithRunner(output, { message: 'Continue?' }, async () => ({}))).toBe(false)
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
test('propagates runner rejection unchanged', async () => {
|
|
55
|
-
const output = createOutput()
|
|
56
|
-
const rejection = new Error('prompt failed')
|
|
57
|
-
const promise = promptConfirmWithRunner(output, { message: 'Continue?' }, async () => {
|
|
58
|
-
throw rejection
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
await expect(promise).rejects.toBe(rejection)
|
|
62
|
-
})
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
describe('promptSelect', () => {
|
|
66
|
-
test('preserves literal values, binds diagnostic output, and maps the answer', async () => {
|
|
67
|
-
const output = createOutput()
|
|
68
|
-
const selected = await promptSelectWithRunner(output, {
|
|
69
|
-
message: 'Choose an action',
|
|
70
|
-
choices: [
|
|
71
|
-
{ value: 'remove', title: 'Remove migration' },
|
|
72
|
-
{ value: 'keep', title: 'Keep migration' },
|
|
73
|
-
],
|
|
74
|
-
}, async question => {
|
|
75
|
-
expect(question.type).toBe('select')
|
|
76
|
-
expect(question.name).toBe('value')
|
|
77
|
-
expect(question.message).toBe('Choose an action')
|
|
78
|
-
expect(question.choices).toStrictEqual([
|
|
79
|
-
{ value: 'remove', title: 'Remove migration' },
|
|
80
|
-
{ value: 'keep', title: 'Keep migration' },
|
|
81
|
-
])
|
|
82
|
-
expect(question.stdout).toBe(output.promptOutput)
|
|
83
|
-
return { value: 'remove' }
|
|
84
|
-
})
|
|
85
|
-
const typedSelection: 'remove' | 'keep' | undefined = selected
|
|
86
|
-
|
|
87
|
-
expect(typedSelection).toBe('remove')
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
test('returns undefined for cancellation and unknown answers', async () => {
|
|
91
|
-
const output = createOutput()
|
|
92
|
-
const options = {
|
|
93
|
-
message: 'Choose an action',
|
|
94
|
-
choices: [{ value: 'keep', title: 'Keep migration' }],
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
expect(await promptSelectWithRunner(output, options, async () => ({}))).toBeUndefined()
|
|
98
|
-
expect(await promptSelectWithRunner(output, options, async () => ({ value: 'unexpected' }))).toBeUndefined()
|
|
99
|
-
})
|
|
100
|
-
})
|