Skip to content

Commit

Permalink
feat(options): removed overrides from the potential options to provide
Browse files Browse the repository at this point in the history
since `decisions` is the more appropriate approach to this anyway

BREAKING CHANGE: `overrides` is no longer a support option. use `decisions` instead
  • Loading branch information
travi committed Jul 9, 2023
1 parent 5cbd216 commit 1d40beb
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 58 deletions.
11 changes: 0 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ opinionated scaffolder for new projects
* [`languages` (_optional_)](#languages-optional)
* [`vcsHosts` (_optional_)](#vcshosts-optional)
* [`dependencyUpdaters` (_optional_)](#dependencyupdaters-optional)
* [`overrides` (_optional_) (_deprecated_)](#overrides-optional-deprecated)
* [`copyrightHolder`](#copyrightholder)
* [Contributing](#contributing)
* [Dependencies](#dependencies)
* [Verification](#verification)
Expand Down Expand Up @@ -195,15 +193,6 @@ __object__:
* `owner`: __string__ account name on the host service for the repository
owner. defaults to `$ git config github.user`

#### `overrides` (_optional_) (_deprecated_)

use `decisions` instead of `overrides`

##### `copyrightHolder`

__string__ enables setting the value of the prompt default for the copyright
holder. if not provided, the default will be empty.

## Contributing

<!--contribution-badges start -->
Expand Down
2 changes: 0 additions & 2 deletions src/options-schemas.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import joi from 'joi';

export const overridesSchema = joi.object({copyrightHolder: joi.string()});

export const decisionsSchema = joi.object();
19 changes: 1 addition & 18 deletions src/options-schemas.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,9 @@ import {validateOptions} from '@form8ion/core';
import {describe, expect, it} from 'vitest';
import any from '@travi/any';

import {overridesSchema, decisionsSchema} from './options-schemas';
import {decisionsSchema} from './options-schemas';

describe('generic options schemas', () => {
describe('overrides', () => {
it('should return the validated options', () => {
const options = {copyrightHolder: any.string()};

expect(validateOptions(overridesSchema, options)).toEqual(options);
});

it('should require the overrides to be defined as a map', () => {
expect(() => validateOptions(overridesSchema, any.word())).toThrowError('must be of type object');
});

it('should require `copyrightHolder` to be a string', () => {
expect(() => validateOptions(overridesSchema, {copyrightHolder: any.simpleObject()}))
.toThrowError('must be a string');
});
});

describe('decisions', () => {
it('should return the validated options', () => {
const options = any.simpleObject();
Expand Down
12 changes: 4 additions & 8 deletions src/options-validator.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import {validateOptions} from '@form8ion/core';
import joi from 'joi';

import languagePluginsSchema from './language/schema';
import vcsHostPluginsSchema from './vcs/host/schema';
import dependencyUpdaterPluginsSchema from './dependency-updater/schema';
import {decisionsSchema, overridesSchema} from './options-schemas';
import languagePluginsSchema from './language/schema.js';
import vcsHostPluginsSchema from './vcs/host/schema.js';
import dependencyUpdaterPluginsSchema from './dependency-updater/schema.js';
import {decisionsSchema} from './options-schemas.js';

export function validate(options) {
return validateOptions(joi.object({
languages: languagePluginsSchema,
/**
* @deprecated overrides should no longer be necessary. use decisions instead
*/
overrides: overridesSchema,
vcsHosts: vcsHostPluginsSchema,
decisions: decisionsSchema,
dependencyUpdaters: dependencyUpdaterPluginsSchema
Expand Down
11 changes: 5 additions & 6 deletions src/options-validator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import {describe, expect, it, beforeEach, afterEach, vi} from 'vitest';
import any from '@travi/any';
import {when} from 'jest-when';

import languagePluginsSchema from './language/schema';
import {decisionsSchema, overridesSchema} from './options-schemas';
import vcsHostPluginsSchema from './vcs/host/schema';
import dependencyUpdaterPluginsSchema from './dependency-updater/schema';
import {validate} from './options-validator';
import languagePluginsSchema from './language/schema.js';
import {decisionsSchema} from './options-schemas.js';
import vcsHostPluginsSchema from './vcs/host/schema.js';
import dependencyUpdaterPluginsSchema from './dependency-updater/schema.js';
import {validate} from './options-validator.js';

vi.mock('@form8ion/core');

Expand All @@ -28,7 +28,6 @@ describe('options validator', () => {
const validatedOptions = any.simpleObject();
when(joi.object).calledWith({
languages: languagePluginsSchema,
overrides: overridesSchema,
vcsHosts: vcsHostPluginsSchema,
decisions: decisionsSchema,
dependencyUpdaters: dependencyUpdaterPluginsSchema
Expand Down
4 changes: 2 additions & 2 deletions src/prompts/questions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import {prompt} from '@form8ion/overridable-prompts';

import {questionNames} from './question-names';

export function promptForBaseDetails(projectRoot, copyrightHolder, decisions) {
export function promptForBaseDetails(projectRoot, decisions) {
return prompt([
...questionsForBaseDetails(decisions, projectRoot, copyrightHolder),
...questionsForBaseDetails(decisions, projectRoot),
{name: questionNames.GIT_REPO, type: 'confirm', default: true, message: 'Should a git repository be initialized?'}
], decisions);
}
5 changes: 2 additions & 3 deletions src/prompts/questions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ describe('base details prompt', () => {
});

it('should prompt for the necessary details', async () => {
const copyrightHolder = any.string();
when(core.questionsForBaseDetails).calledWith(decisions, projectPath, copyrightHolder).mockReturnValue(questions);
when(core.questionsForBaseDetails).calledWith(decisions, projectPath).mockReturnValue(questions);
when(prompts.prompt).calledWith([
...questions,
{
Expand All @@ -34,6 +33,6 @@ describe('base details prompt', () => {
}
], decisions).mockResolvedValue(answers);

expect(await promptForBaseDetails(projectPath, copyrightHolder, decisions)).toEqual(answers);
expect(await promptForBaseDetails(projectPath, decisions)).toEqual(answers);
});
});
5 changes: 2 additions & 3 deletions src/scaffolder.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import {scaffold as scaffoldContributing} from './contributing';

export async function scaffold(options) {
const projectRoot = process.cwd();
const {languages = {}, overrides = {}, vcsHosts = {}, decisions, dependencyUpdaters} = validate(options);
const {copyrightHolder} = overrides;
const {languages = {}, vcsHosts = {}, decisions, dependencyUpdaters} = validate(options);

const {
[coreQuestionNames.PROJECT_NAME]: projectName,
Expand All @@ -29,7 +28,7 @@ export async function scaffold(options) {
[questionNames.GIT_REPO]: gitRepo,
[coreQuestionNames.COPYRIGHT_YEAR]: copyrightYear,
[coreQuestionNames.COPYRIGHT_HOLDER]: copyHolder
} = await promptForBaseDetails(projectRoot, copyrightHolder, decisions);
} = await promptForBaseDetails(projectRoot, decisions);
const copyright = {year: copyrightYear, holder: copyHolder};

const vcs = await initializeGit(gitRepo, projectRoot, projectName, vcsHosts, visibility, decisions);
Expand Down
7 changes: 3 additions & 4 deletions src/scaffolder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,16 @@ describe('project scaffolder', () => {
const year = any.word();
const holder = any.sentence();
const copyright = {year, holder};
const overrides = {...any.simpleObject(), copyrightHolder: any.string()};
const gitRepoShouldBeInitialized = true;
const dependencyUpdaters = any.simpleObject();
const gitNextSteps = any.listOf(any.simpleObject);
const dependencyUpdaterNextSteps = any.listOf(any.simpleObject);
const dependencyUpdaterContributionBadges = any.simpleObject();
when(optionsValidator.validate)
.calledWith(options)
.mockReturnValue({languages: languageScaffolders, overrides, vcsHosts, decisions, dependencyUpdaters});
.mockReturnValue({languages: languageScaffolders, vcsHosts, decisions, dependencyUpdaters});
when(prompts.promptForBaseDetails)
.calledWith(projectPath, overrides.copyrightHolder, decisions)
.calledWith(projectPath, decisions)
.mockResolvedValue({
[coreQuestionNames.PROJECT_NAME]: projectName,
[questionNames.GIT_REPO]: gitRepoShouldBeInitialized,
Expand Down Expand Up @@ -162,7 +161,7 @@ describe('project scaffolder', () => {
const gitRepoShouldBeInitialized = any.boolean();
optionsValidator.validate.mockReturnValue({});
when(prompts.promptForBaseDetails)
.calledWith(projectPath, undefined, undefined)
.calledWith(projectPath, undefined)
.mockResolvedValue({
[coreQuestionNames.PROJECT_NAME]: projectName,
[questionNames.GIT_REPO]: gitRepoShouldBeInitialized
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ When(/^the project is scaffolded$/, async function () {
}
}
},
overrides: {},
...this.updaterScaffolderDetails && {dependencyUpdaters: {[chosenUpdater]: this.updaterScaffolderDetails}},
...vcsHost && {
vcsHosts: {
Expand Down

0 comments on commit 1d40beb

Please sign in to comment.