@form8ion/project 22.0.0-beta.1 → 22.0.0-beta.10

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.
@@ -1,14 +1,17 @@
1
- import {prompt} from '@form8ion/overridable-prompts';
2
-
3
1
  import {questionNames} from '../../prompts/question-names.js';
4
2
 
5
- export default async function (hosts, decisions) {
6
- const answers = await prompt([{
7
- name: questionNames.REPO_HOST,
8
- type: 'list',
9
- message: 'Where will the repository be hosted?',
10
- choices: Object.keys(hosts)
11
- }], decisions);
3
+ export const REPOSITORY_HOST_PROMPT_ID = 'REPOSITORY_HOST';
4
+
5
+ export default async function promptForVcsHostChoice(hosts, {prompt}) {
6
+ const answers = await prompt({
7
+ id: REPOSITORY_HOST_PROMPT_ID,
8
+ questions: [{
9
+ name: questionNames.REPO_HOST,
10
+ type: 'list',
11
+ message: 'Where will the repository be hosted?',
12
+ choices: Object.keys(hosts)
13
+ }]
14
+ });
12
15
  const host = hosts[answers[questionNames.REPO_HOST]];
13
16
 
14
17
  return {...answers, ...host};
@@ -1,21 +1,19 @@
1
- import * as prompts from '@form8ion/overridable-prompts';
2
-
3
- import {afterEach, describe, expect, it, vi} from 'vitest';
1
+ import {beforeEach, describe, expect, it, vi} from 'vitest';
4
2
  import any from '@travi/any';
5
3
  import {when} from 'vitest-when';
6
4
 
7
5
  import {questionNames} from '../../prompts/question-names.js';
8
- import promptForVcsHostDetails from './prompt.js';
6
+ import promptForVcsHostDetails, {REPOSITORY_HOST_PROMPT_ID} from './prompt.js';
9
7
 
10
8
  vi.mock('@form8ion/overridable-prompts');
11
9
  vi.mock('../../prompts/conditionals');
12
10
 
13
11
  describe('vcs host details prompt', () => {
12
+ let prompt;
14
13
  const answers = any.simpleObject();
15
- const decisions = any.simpleObject();
16
14
 
17
- afterEach(() => {
18
- vi.clearAllMocks();
15
+ beforeEach(() => {
16
+ prompt = vi.fn();
19
17
  });
20
18
 
21
19
  it('should prompt for the vcs hosting details', async () => {
@@ -23,25 +21,31 @@ describe('vcs host details prompt', () => {
23
21
  const hostNames = [...any.listOf(any.string), host];
24
22
  const hosts = any.objectWithKeys(hostNames, {factory: () => ({})});
25
23
  const answersWithHostChoice = {...answers, [questionNames.REPO_HOST]: host};
26
- when(prompts.prompt).calledWith([{
27
- name: questionNames.REPO_HOST,
28
- type: 'list',
29
- message: 'Where will the repository be hosted?',
30
- choices: hostNames
31
- }], decisions).thenResolve(answersWithHostChoice);
32
-
33
- expect(await promptForVcsHostDetails(hosts, decisions)).toEqual(answersWithHostChoice);
24
+ when(prompt).calledWith({
25
+ id: REPOSITORY_HOST_PROMPT_ID,
26
+ questions: [{
27
+ name: questionNames.REPO_HOST,
28
+ type: 'list',
29
+ message: 'Where will the repository be hosted?',
30
+ choices: hostNames
31
+ }]
32
+ }).thenResolve(answersWithHostChoice);
33
+
34
+ expect(await promptForVcsHostDetails(hosts, {prompt})).toEqual(answersWithHostChoice);
34
35
  });
35
36
 
36
37
  it('should not throw an error when `Other` is chosen as the host', async () => {
37
38
  const answersWithHostChoice = {...answers, [questionNames.REPO_HOST]: 'Other'};
38
- when(prompts.prompt).calledWith([{
39
- name: questionNames.REPO_HOST,
40
- type: 'list',
41
- message: 'Where will the repository be hosted?',
42
- choices: []
43
- }], decisions).thenResolve(answersWithHostChoice);
44
-
45
- expect(await promptForVcsHostDetails({}, decisions)).toEqual(answersWithHostChoice);
39
+ when(prompt).calledWith({
40
+ id: REPOSITORY_HOST_PROMPT_ID,
41
+ questions: [{
42
+ name: questionNames.REPO_HOST,
43
+ type: 'list',
44
+ message: 'Where will the repository be hosted?',
45
+ choices: []
46
+ }]
47
+ }).thenResolve(answersWithHostChoice);
48
+
49
+ expect(await promptForVcsHostDetails({}, {prompt})).toEqual(answersWithHostChoice);
46
50
  });
47
51
  });
@@ -1,8 +1,8 @@
1
1
  import {questionNames} from '../../prompts/question-names.js';
2
2
  import promptForVcsHostDetails from './prompt.js';
3
3
 
4
- export default async function scaffoldVcsHost(hosts, decisions, options) {
5
- const {[questionNames.REPO_HOST]: chosenHost} = await promptForVcsHostDetails(hosts, decisions);
4
+ export default async function scaffoldVcsHost(hosts, options, {prompt}) {
5
+ const {[questionNames.REPO_HOST]: chosenHost} = await promptForVcsHostDetails(hosts, {prompt});
6
6
 
7
7
  const lowercasedHosts = Object.fromEntries(
8
8
  Object.entries(hosts).map(([name, details]) => [name.toLowerCase(), details])
@@ -10,7 +10,7 @@ vi.mock('./prompt');
10
10
 
11
11
  describe('vcs host scaffolder', () => {
12
12
  const options = any.simpleObject();
13
- const decisions = any.simpleObject();
13
+ const prompt = () => undefined;
14
14
 
15
15
  it('should scaffold the chosen vcs host', async () => {
16
16
  const chosenHost = `${any.word()}CAPITAL${any.word()}`;
@@ -19,19 +19,19 @@ describe('vcs host scaffolder', () => {
19
19
  const hostPlugins = {...any.simpleObject(), [chosenHost.toLowerCase()]: {scaffold: chosenHostScaffolder}};
20
20
  const owner = any.word;
21
21
  when(promptForVcsHostDetails)
22
- .calledWith(hostPlugins, decisions)
22
+ .calledWith(hostPlugins, {prompt})
23
23
  .thenResolve({[questionNames.REPO_HOST]: chosenHost, [questionNames.REPO_OWNER]: owner});
24
24
  when(chosenHostScaffolder).calledWith(options).thenResolve(results);
25
25
 
26
- expect(await scaffoldVcsHost(hostPlugins, decisions, options)).toEqual(results);
26
+ expect(await scaffoldVcsHost(hostPlugins, options, {prompt})).toEqual(results);
27
27
  });
28
28
 
29
29
  it('should return empty `vcs` results when no matching host is available', async () => {
30
30
  const hostPlugins = any.simpleObject();
31
31
  when(promptForVcsHostDetails)
32
- .calledWith(hostPlugins, decisions)
32
+ .calledWith(hostPlugins, {prompt})
33
33
  .thenResolve({[questionNames.REPO_HOST]: any.word()});
34
34
 
35
- expect(await scaffoldVcsHost(hostPlugins, decisions, options)).toEqual({vcs: {}});
35
+ expect(await scaffoldVcsHost(hostPlugins, options, {prompt})).toEqual({vcs: {}});
36
36
  });
37
37
  });
package/src/vcs/prompt.js CHANGED
@@ -1,17 +1,17 @@
1
- import {prompt} from '@form8ion/overridable-prompts';
2
-
3
1
  import {questionNames} from '../prompts/question-names.js';
4
2
 
5
- export default async function promptForRepoCreation(decisions) {
6
- const {[questionNames.GIT_REPO]: gitRepoShouldBeCreated} = await prompt(
7
- [{
3
+ export const GIT_REPOSITORY_PROMPT_ID = 'GIT_REPOSITORY';
4
+
5
+ export default async function promptForRepoCreation({prompt}) {
6
+ const {[questionNames.GIT_REPO]: gitRepoShouldBeCreated} = await prompt({
7
+ id: GIT_REPOSITORY_PROMPT_ID,
8
+ questions: [{
8
9
  name: questionNames.GIT_REPO,
9
10
  type: 'confirm',
10
11
  default: true,
11
12
  message: 'Should a git repository be initialized?'
12
- }],
13
- decisions
14
- );
13
+ }]
14
+ });
15
15
 
16
16
  return gitRepoShouldBeCreated;
17
17
  }
@@ -1,27 +1,28 @@
1
- import {prompt} from '@form8ion/overridable-prompts';
2
-
3
1
  import {describe, vi, it, expect} from 'vitest';
4
2
  import {when} from 'vitest-when';
5
3
  import any from '@travi/any';
6
4
 
7
5
  import {questionNames} from '../prompts/question-names.js';
8
- import promptForRepoCreation from './prompt.js';
6
+ import promptForRepoCreation, {GIT_REPOSITORY_PROMPT_ID} from './prompt.js';
9
7
 
10
8
  vi.mock('@form8ion/overridable-prompts');
11
9
 
12
10
  describe('git prompt', () => {
13
11
  it('should ask whether a repository should be created', async () => {
14
- const decisions = any.simpleObject();
12
+ const prompt = vi.fn();
15
13
  const repoShouldBeCreated = any.boolean();
16
14
  when(prompt)
17
- .calledWith([{
18
- name: questionNames.GIT_REPO,
19
- type: 'confirm',
20
- default: true,
21
- message: 'Should a git repository be initialized?'
22
- }], decisions)
15
+ .calledWith({
16
+ id: GIT_REPOSITORY_PROMPT_ID,
17
+ questions: [{
18
+ name: questionNames.GIT_REPO,
19
+ type: 'confirm',
20
+ default: true,
21
+ message: 'Should a git repository be initialized?'
22
+ }]
23
+ })
23
24
  .thenResolve({[questionNames.GIT_REPO]: repoShouldBeCreated});
24
25
 
25
- expect(await promptForRepoCreation(decisions)).toBe(repoShouldBeCreated);
26
+ expect(await promptForRepoCreation({prompt})).toBe(repoShouldBeCreated);
26
27
  });
27
28
  });
@@ -5,20 +5,16 @@ import repositoryShouldBeCreated from './prompt.js';
5
5
  import {determineExistingVcsDetails, defineRemoteOrigin} from './git/index.js';
6
6
  import {scaffold as scaffoldVcsHost} from './host/index.js';
7
7
 
8
- export default async function scaffoldVcs({projectRoot, projectName, decisions, vcsHosts, visibility, description}) {
9
- if (await repositoryShouldBeCreated(decisions)) {
8
+ export default async function scaffoldVcs({projectRoot, projectName, vcsHosts, visibility, description}, {prompt}) {
9
+ if (await repositoryShouldBeCreated({prompt})) {
10
10
  if (await alreadyVersionedByGit({projectRoot})) {
11
11
  info('Git repository already exists');
12
12
 
13
- return {vcs: await determineExistingVcsDetails({projectRoot})};
13
+ return determineExistingVcsDetails({projectRoot});
14
14
  }
15
15
 
16
16
  const [{vcs: {host, owner, name, sshUrl}}] = await Promise.all([
17
- scaffoldVcsHost(
18
- vcsHosts,
19
- decisions,
20
- {projectName, projectRoot, description, visibility}
21
- ),
17
+ scaffoldVcsHost(vcsHosts, {projectName, projectRoot, description, visibility}, {prompt}),
22
18
  scaffoldGit({projectRoot})
23
19
  ]);
24
20
 
@@ -16,7 +16,7 @@ vi.mock('./prompt.js');
16
16
 
17
17
  describe('vcs scaffolder', () => {
18
18
  const projectRoot = any.string();
19
- const decisions = any.simpleObject();
19
+ const prompt = () => undefined;
20
20
 
21
21
  it('should scaffold the repository and vcs host details', async () => {
22
22
  const host = any.word();
@@ -29,14 +29,14 @@ describe('vcs scaffolder', () => {
29
29
  const vcsHostDetails = {host, owner, name};
30
30
  const sshUrl = any.url();
31
31
  const remoteOriginNextSteps = any.listOf(any.simpleObject);
32
- when(promptForRepoCreation).calledWith(decisions).thenResolve(true);
32
+ when(promptForRepoCreation).calledWith({prompt}).thenResolve(true);
33
33
  when(alreadyVersionedByGit).calledWith({projectRoot}).thenResolve(false);
34
34
  when(scaffoldVcsHost)
35
- .calledWith(vcsHosts, decisions, {projectName, projectRoot, description, visibility})
35
+ .calledWith(vcsHosts, {projectName, projectRoot, description, visibility}, {prompt})
36
36
  .thenResolve({vcs: {...vcsHostDetails, sshUrl, ...any.simpleObject()}});
37
37
  when(defineRemoteOrigin).calledWith(projectRoot, sshUrl).thenResolve({nextSteps: remoteOriginNextSteps});
38
38
 
39
- expect(await scaffoldVcs({projectRoot, projectName, decisions, vcsHosts, visibility, description})).toEqual({
39
+ expect(await scaffoldVcs({projectRoot, projectName, vcsHosts, visibility, description}, {prompt})).toEqual({
40
40
  vcs: vcsHostDetails,
41
41
  nextSteps: [{summary: 'Commit scaffolded files'}, ...remoteOriginNextSteps]
42
42
  });
@@ -45,16 +45,16 @@ describe('vcs scaffolder', () => {
45
45
 
46
46
  it('should not scaffold a repository or vcs host details when the project is already versioned by git', async () => {
47
47
  const existingVcsDetails = any.simpleObject();
48
- when(promptForRepoCreation).calledWith(decisions).thenResolve(true);
48
+ when(promptForRepoCreation).calledWith({prompt}).thenResolve(true);
49
49
  when(alreadyVersionedByGit).calledWith({projectRoot}).thenResolve(true);
50
50
  when(determineExistingVcsDetails).calledWith({projectRoot}).thenResolve(existingVcsDetails);
51
51
 
52
- expect(await scaffoldVcs({projectRoot, decisions})).toEqual({vcs: existingVcsDetails});
52
+ expect(await scaffoldVcs({projectRoot}, {prompt})).toEqual(existingVcsDetails);
53
53
  });
54
54
 
55
55
  it('should not scaffold a repository or vcs host details when a repository should not be created', async () => {
56
- when(promptForRepoCreation).calledWith(decisions).thenResolve(false);
56
+ when(promptForRepoCreation).calledWith({prompt}).thenResolve(false);
57
57
 
58
- expect(await scaffoldVcs({projectRoot, decisions})).toEqual({});
58
+ expect(await scaffoldVcs({projectRoot}, {prompt})).toEqual({});
59
59
  });
60
60
  });
@@ -1,3 +0,0 @@
1
- import joi from 'joi';
2
-
3
- export const decisionsSchema = joi.object();
@@ -1,20 +0,0 @@
1
- import {validateOptions} from '@form8ion/core';
2
-
3
- import {describe, expect, it} from 'vitest';
4
- import any from '@travi/any';
5
-
6
- import {decisionsSchema} from './options-schemas.js';
7
-
8
- describe('generic options schemas', () => {
9
- describe('decisions', () => {
10
- it('should return the validated options', () => {
11
- const options = any.simpleObject();
12
-
13
- expect(validateOptions(decisionsSchema, options)).toEqual(options);
14
- });
15
-
16
- it('should require the decisions to be defined as a map', () => {
17
- expect(() => validateOptions(decisionsSchema, any.word())).toThrowError('must be of type object');
18
- });
19
- });
20
- });