Skip to content

Commit

Permalink
Remove the concept of "presets" (#862)
Browse files Browse the repository at this point in the history
* Remove preset concept

* Add changesets
  • Loading branch information
connor-baer authored Apr 20, 2023
1 parent 3018a51 commit ab39701
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 109 deletions.
5 changes: 5 additions & 0 deletions .changeset/cold-dancers-approve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sumup/foundry': minor
---

Remove the `presets` CLI option. The only remaining preset is "lint" which is now selected by default.
18 changes: 5 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[![NPM version](https://img.shields.io/npm/v/@sumup/foundry)](https://www.npmjs.com/package/@sumup/foundry) [![Code coverage](https://img.shields.io/codecov/c/github/sumup-oss/foundry)](https://codecov.io/gh/sumup-oss/foundry) [![License](https://img.shields.io/github/license/sumup-oss/foundry)](https://github.com/sumup-oss/foundry/blob/main/LICENSE) [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-v2.1%20adopted-ff69b4.svg)](CODE_OF_CONDUCT.md)

A toolkit that makes it a breeze to set up and maintain JavaScript + TypeScript applications. Foundry has presets for [🔍 linting](#-lint) and currently supports [Next.js](https://nextjs.org), [React](https://reactjs.org), [Emotion](https://emotion.sh/), [Jest](https://jestjs.io/), [Testing Library](https://testing-library.com/), [Cypress](https://www.cypress.io/), [Playwright](https://playwright.dev/) and [Node](https://nodejs.org/en/).
A toolkit that makes it a breeze to set up and maintain JavaScript + TypeScript applications. Foundry has tools for [🔍 linting](#lint-preset) and currently supports [Next.js](https://nextjs.org), [React](https://reactjs.org), [Emotion](https://emotion.sh/), [Jest](https://jestjs.io/), [Testing Library](https://testing-library.com/), [Cypress](https://www.cypress.io/), [Playwright](https://playwright.dev/) and [Node](https://nodejs.org/en/).

</div>

Expand All @@ -14,8 +14,7 @@ A toolkit that makes it a breeze to set up and maintain JavaScript + TypeScript
- [Installation](#installation)
- [Initialization](#initialization)
- [Configuration](#configuration)
- [Presets](#presets)
- [🔍 Lint](#-lint)
- [Lint preset](#lint-preset)
- [Running a tool](#running-a-tool)
- [Why?](#why)
- [Code of conduct (CoC)](#code-of-conduct-coc)
Expand All @@ -39,7 +38,7 @@ $ yarn add --dev @sumup/foundry

### Initialization

Foundry exposes customizable configuration presets for the CLI tools it supports. To make use of these presets, you need to initialize a configuration file for each tool you would like to use. This is done with the `init` command.
Foundry exposes customizable configurations for the CLI tools it supports. Use the `init` command to initialize a configuration file for the tools you would like to use:

```sh
# With npm
Expand All @@ -54,8 +53,6 @@ Foundry will launch an interactive prompt to ask you questions about your projec
Alternatively, you can pass your answers to the `init` command directly as flags. This is useful for environments such as CI where interactive prompts cannot be used. Here is an overview of all available options (you can view this help menu by running `npx foundry init --help`):

```sh
-p, --presets A preset configures a group of tools that solve a common
problem [array] [choices: "lint", "ci"]
-o, --openSource Whether the project is open-source [boolean]
--publish Whether to publish to NPM [boolean]
-c, --configDir The directory to write configs to [string] [default: "."]
Expand Down Expand Up @@ -88,7 +85,7 @@ Foundry analyzes your project's `package.json` file to tailor the configurations
// package.json
{
"foundry": {
"publish": true
"environments": ["Browser"]
}
}
```
Expand All @@ -101,13 +98,8 @@ The supported options are:
| environments | array | 'Browser', 'Node' | _autodetected_ |
| frameworks | array | 'React', 'Next.js', 'Emotion', 'Jest', 'Testing Library', 'Cypress', 'Playwright' | _autodetected_ |
| openSource | boolean | true, false | _autodetected_ |
| publish | boolean | true, false | false |

## Presets

A preset includes the configurations and scripts that are needed for a certain task.

### 🔍 Lint
## Lint preset

Check code for syntax errors and format it automatically. The preset adds the following scripts to your `package.json`:

Expand Down
3 changes: 1 addition & 2 deletions src/cli/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
* limitations under the License.
*/

import { InitOptions, Preset } from '../types/shared';
import { InitOptions } from '../types/shared';

export const DEFAULT_OPTIONS: InitOptions = {
presets: [Preset.LINT],
configDir: '.',
openSource: false,
publish: false,
Expand Down
9 changes: 0 additions & 9 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@

import yargs from 'yargs';

import { Preset } from '../types/shared';
import { enumToChoices } from '../lib/choices';

import { run, RunParams } from './run';
import { init, InitParams } from './init';
import { DEFAULT_OPTIONS } from './defaults';
Expand All @@ -30,12 +27,6 @@ void yargs
'init',
"Initialize Foundry's tools in your project",
{
presets: {
alias: 'p',
desc: 'A preset configures a group of tools that solve a common problem',
choices: enumToChoices(Preset),
type: 'array',
},
openSource: {
alias: 'o',
desc: 'Whether the project is open-source',
Expand Down
18 changes: 1 addition & 17 deletions src/cli/init.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,9 @@
* limitations under the License.
*/

import { Preset } from '../types/shared';

import { validatePresets, validatePath } from './init';
import { validatePath } from './init';

describe('init command', () => {
describe('validatePresets', () => {
it('should return an error message when no presets were selected', () => {
const presets: Preset[] = [];
const actual = validatePresets(presets);
expect(typeof actual).toBe('string');
});

it('should return true otherwise', () => {
const presets = [Preset.LINT];
const actual = validatePresets(presets);
expect(actual).toBeTruthy();
});
});

describe('validatePath', () => {
it('should return false if no path was passed', () => {
const actual = validatePath();
Expand Down
36 changes: 7 additions & 29 deletions src/cli/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { resolve } from 'path';
import inquirer, { Question } from 'inquirer';
import Listr, { ListrTaskWrapper } from 'listr';
import listrInquirer from 'listr-inquirer';
import { isEmpty, flow, map, flatten, uniq } from 'lodash/fp';
import { flow, map, flatten, uniq } from 'lodash/fp';
import chalk from 'chalk';
import isCI from 'is-ci';
import readPkgUp from 'read-pkg-up';
Expand All @@ -36,14 +36,13 @@ import {
} from '../types/shared';
import * as logger from '../lib/logger';
import { writeFile, addPackageScript, savePackageJson } from '../lib/files';
import { presets, presetChoices } from '../presets';
import { presets } from '../presets';
import { tools } from '../configs';

import { DEFAULT_OPTIONS } from './defaults';

export interface InitParams {
configDir: string;
presets?: Preset[];
openSource?: boolean;
publish?: boolean;
overwrite?: boolean;
Expand All @@ -54,19 +53,9 @@ export interface InitParams {
export async function init({ $0, _, ...args }: InitParams): Promise<void> {
let options: InitOptions;

if (!isCI) {
const initialAnswers = (await inquirer.prompt([
{
type: 'checkbox',
name: 'presets',
message: 'Which presets do you want to use?',
choices: presetChoices,
default: args.presets,
validate: validatePresets,
when: (): boolean => validatePresets(args.presets as Preset[]) !== true,
},
])) as { presets: Preset[] };
const selectedPresets = [Preset.LINT];

if (!isCI) {
const prompts = {
[Prompt.OPEN_SOURCE]: {
type: 'confirm',
Expand All @@ -77,21 +66,18 @@ export async function init({ $0, _, ...args }: InitParams): Promise<void> {
},
};

const additionalPrompts = getPromptsForPresets(
initialAnswers.presets,
prompts,
);
const additionalPrompts = getPromptsForPresets(selectedPresets, prompts);
const additionalAnswers = await inquirer.prompt(additionalPrompts);

options = { ...args, ...initialAnswers, ...additionalAnswers };
options = { ...args, ...additionalAnswers };
} else {
logger.empty();
logger.info('Detected CI environment, falling back to default options.');

options = { ...DEFAULT_OPTIONS, ...args };
}

const selectedTools = getToolsForPresets(options.presets);
const selectedTools = getToolsForPresets(selectedPresets);
const files = getFilesForTools(options, selectedTools);
const scripts = getScriptsForTools(options, selectedTools);

Expand Down Expand Up @@ -294,14 +280,6 @@ function getScriptsForTools(
}, []);
}

export function validatePresets(selectedPresets: Preset[]): string | boolean {
if (isEmpty(selectedPresets)) {
return 'You must choose at least one preset.';
}

return true;
}

export function validatePath(path?: string): string | boolean {
if (!path) {
return false;
Expand Down
31 changes: 0 additions & 31 deletions src/lib/choices.spec.ts

This file was deleted.

6 changes: 0 additions & 6 deletions src/lib/choices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@

import { isArray } from 'lodash/fp';

export function enumToChoices<Enum = string>(enums: {
[key: string]: Enum;
}): Enum[] {
return Object.values(enums);
}

type Enum = { [key: string]: string };
type Choices = { [key: string]: Enum | Enum[] };
type Combination = { [key: string]: string | string[] };
Expand Down
1 change: 0 additions & 1 deletion src/presets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,3 @@ function formatName(name: string, description: string): string {
}

export const presets = { lint };
export const presetChoices = [lint];
1 change: 0 additions & 1 deletion src/types/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ export interface Options {
}

export interface InitOptions extends Options {
presets: Preset[];
configDir: string;
overwrite?: boolean;
}
Expand Down

0 comments on commit ab39701

Please sign in to comment.