@form8ion/project 21.1.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.
@@ -3,16 +3,14 @@ import any from '@travi/any';
3
3
  import {when} from 'vitest-when';
4
4
 
5
5
  import {questionNames} from '../../prompts/question-names.js';
6
- import terminalPromptFactory from '../../prompts/terminal-prompt.js';
7
6
  import promptForVcsHostDetails from './prompt.js';
8
7
  import scaffoldVcsHost from './scaffolder.js';
9
8
 
10
- vi.mock('../../prompts/terminal-prompt.js');
11
9
  vi.mock('./prompt');
12
10
 
13
11
  describe('vcs host scaffolder', () => {
14
12
  const options = any.simpleObject();
15
- const decisions = any.simpleObject();
13
+ const prompt = () => undefined;
16
14
 
17
15
  it('should scaffold the chosen vcs host', async () => {
18
16
  const chosenHost = `${any.word()}CAPITAL${any.word()}`;
@@ -20,22 +18,20 @@ describe('vcs host scaffolder', () => {
20
18
  const chosenHostScaffolder = vi.fn();
21
19
  const hostPlugins = {...any.simpleObject(), [chosenHost.toLowerCase()]: {scaffold: chosenHostScaffolder}};
22
20
  const owner = any.word;
23
- const terminalPrompt = () => undefined;
24
- when(terminalPromptFactory).calledWith(decisions).thenReturn(terminalPrompt);
25
21
  when(promptForVcsHostDetails)
26
- .calledWith(hostPlugins, decisions)
22
+ .calledWith(hostPlugins, {prompt})
27
23
  .thenResolve({[questionNames.REPO_HOST]: chosenHost, [questionNames.REPO_OWNER]: owner});
28
- when(chosenHostScaffolder).calledWith(options, {prompt: terminalPrompt}).thenResolve(results);
24
+ when(chosenHostScaffolder).calledWith(options).thenResolve(results);
29
25
 
30
- expect(await scaffoldVcsHost(hostPlugins, decisions, options)).toEqual(results);
26
+ expect(await scaffoldVcsHost(hostPlugins, options, {prompt})).toEqual(results);
31
27
  });
32
28
 
33
29
  it('should return empty `vcs` results when no matching host is available', async () => {
34
30
  const hostPlugins = any.simpleObject();
35
31
  when(promptForVcsHostDetails)
36
- .calledWith(hostPlugins, decisions)
32
+ .calledWith(hostPlugins, {prompt})
37
33
  .thenResolve({[questionNames.REPO_HOST]: any.word()});
38
34
 
39
- expect(await scaffoldVcsHost(hostPlugins, decisions, options)).toEqual({vcs: {}});
35
+ expect(await scaffoldVcsHost(hostPlugins, options, {prompt})).toEqual({vcs: {}});
40
36
  });
41
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,8 +5,8 @@ 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
 
@@ -14,11 +14,7 @@ export default async function scaffoldVcs({projectRoot, projectName, decisions,
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(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
- });
@@ -1,5 +0,0 @@
1
- import {prompt} from '@form8ion/overridable-prompts';
2
-
3
- export default function (decisions) {
4
- return ({questions}) => prompt(questions, decisions);
5
- }
@@ -1,20 +0,0 @@
1
- import {prompt as promptWithInquirer} from '@form8ion/overridable-prompts';
2
-
3
- import {when} from 'vitest-when';
4
- import {describe, it, vi, expect} from 'vitest';
5
- import any from '@travi/any';
6
-
7
- import prompt from './terminal-prompt.js';
8
-
9
- vi.mock('@form8ion/overridable-prompts');
10
-
11
- describe('terminal prompt', () => {
12
- it('should present the provided questions using inquirer', async () => {
13
- const questions = any.listOf(any.simpleObject);
14
- const decisions = any.simpleObject();
15
- const answers = any.simpleObject();
16
- when(promptWithInquirer).calledWith(questions, decisions).thenResolve(answers);
17
-
18
- expect(await prompt(decisions)({questions})).toEqual(answers);
19
- });
20
- });