用于构建 Web 应用程序和库的工具包。
Foundry should be installed as a dev-dependency. Run the following command in your terminal:
npm install --save-dev @sumup-oss/foundryFoundry 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:
npx foundry initFoundry will launch an interactive prompt to ask you questions about your project, such as whether you are planning to open source it. Once you have answered all questions, Foundry will write the config files (don't worry, it asks before overwriting existing files) and will add scripts to your package.json file to conveniently run the tools.
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):
--configDir The directory to write configs to [string] [default: "."]
--overwrite Whether to overwrite existing configs [boolean] [default: false]
--version Show version number [boolean]
--help Show this help menu [boolean]Foundry adds the following scripts to your package.json file:
lint: format JavaScript & TypeScript files and check them for problematic patternslint:fix: same as lint, but also try to fix the issueslint:ci: same as lint, but optimized for continuous integration workflowslint:css: check CSS files for problematic patternsBiome formats your code to look the same after every save and identifies & fixes problematic patterns in your code so you can spot mistakes early. It works on JavaScript, TypeScript, JSON, CSS, and GraphQL files.
Foundry exposes a default config for Biome to extend. Refer to Biome's documentation to learn how to customize the config to your needs.
// biome.jsonc
{
"$schema": "https://biomejs.dev/schemas/2.2.4/schema.json",
"extends": ["@sumup-oss/foundry/biome"]
}Foundry also generates an .editorconfig file that is used by Biome, IDEs, and other tools to apply consistent formatting to a variety of supported filetypes.
ESLint identifies and fixes problematic patterns in your code so you can spot mistakes early. It is slower than Biome, but can detect a larger number of issue types and has an established plugin ecosystem. It works on JavaScript and TypeScript files.
Foundry exposes a number ESLint configs to be composed together based on the language, environment, and frameworks used. Refer to ESLint's documentation to familiarize yourself with the configuration format.
// eslint.config.js
import { defineConfig, configs } from "@sumup-oss/foundry/eslint";
export default defineConfig([
configs.ignores,
configs.javascript,
configs.browser,
configs.tests,
]);Foundry exports the following configuration objects:
ignoresjavascript, typescriptbrowser, nodenext, react, storybook, testsopen-sourceTypeScript
Note that the typescript config includes the javascript config, so it doesn't need to be added separately.
…Node
// eslint.config.js
import { defineConfig, configs } from "@sumup-oss/foundry/eslint";
export default defineConfig([
configs.ignores,
{
extends: [configs.node],
// Specify which files are executed in Node
files: ["src/app/**/*", "src/pages/api/**/*", "**/server/**/*"],
// Optionally, customize the lint rules
rules: {
"no-console": "off",
},
},
]);Next.js
Note that the next config includes the react config, so it doesn't need to be added separately.
// eslint.config.js
import { defineConfig, configs } from "@sumup-oss/foundry/eslint";
import next from "@next/eslint-plugin-next";
export default defineConfig([
configs.ignores,
{
extends: [next.flatConfig.recommended, configs.next],
},
]);React
// eslint.config.js
import { defineConfig, configs } from "@sumup-oss/foundry/eslint";
import react from "eslint-plugin-react";
export default defineConfig([
configs.ignores,
configs.browser,
{
extends: [react.configs.flat.recommended, configs.react],
},
]);Circuit UI
// eslint.config.js
import { defineConfig, configs, files } from "@sumup-oss/foundry/eslint";
import circuitUI from "@sumup-oss/eslint-plugin-circuit-ui";
export default defineConfig([
configs.ignores,
configs.browser,
{
extends: [circuitUI.configs.recommended],
files: [...files.javascript, ...files.typescript],
},
]);Storybook
// eslint.config.js
import { defineConfig, configs } from "@sumup-oss/foundry/eslint";
import storybook from "eslint-plugin-storybook";
export default defineConfig([
configs.ignores,
{
extends: [storybook.configs["flat/recommended"], configs.stories],
},
]);Jest
// eslint.config.js
import { defineConfig, configs } from "@sumup-oss/foundry/eslint";
import jest from "eslint-plugin-jest";
export default defineConfig([
configs.ignores,
{
extends: [jest.configs["flat/recommended"], configs.tests],
},
]);Vitest
// eslint.config.js
import { defineConfig, configs } from "@sumup-oss/foundry/eslint";
import vitest from "@vitest/eslint-plugin";
export default defineConfig([
configs.ignores,
{
extends: [vitest.configs.recommended, configs.tests],
},
]);Testing Library
// eslint.config.js
import { defineConfig, configs } from "@sumup-oss/foundry/eslint";
import testingLibrary from "eslint-plugin-testing-library";
export default defineConfig([
configs.ignores,
{
extends: [testingLibrary.configs["flat/react"], configs.tests],
// Optionally, configure a custom test utils file
settings: {
"testing-library/utils-module": "test-utils",
},
},
]);Stylelint identifies and fixes problematic patterns in your styles so you can spot mistakes early. It is slower than Biome, but can detect a larger number of issue types. It works on CSS files.
Foundry exposes a default Stylelint config that can be extended and overridden. Refer to Stylelint's documentation to familiarize yourself with the configuration format.
// stylelint.config.js
import { defineConfig } from "@sumup-oss/foundry/stylelint";
export default defineConfig();CSS Modules
// stylelint.config.js
import { defineConfig } from "@sumup-oss/foundry/stylelint";
export default defineConfig({
extends: ["stylelint-config-css-modules"],
});lint-staged is a tool for running linters on files staged for your next commit in git. Together with Husky (see below) it prevents problematic code from being committed.
Foundry exposes a default lint-staged config that can be extended and overridden. Refer to lint-staged's documentation to familiarize yourself with the configuration format.
// lint-staged.config.js
import { defineConfig } from "@sumup-oss/foundry/lint-staged";
export default defineConfig();Optimize SVGs
import { defineConfig } from "@sumup-oss/foundry/lint-staged";
export default defineConfig({
"*.svg": ["svgo --config svgo.config.js --pretty"],
});Husky makes setting up git hooks easy. Whenever someone installs your project, Husky will automatically set up git hooks as part of its postinstall script.
Note that Foundry uses Husky v4, the last version to support a JavaScript configuration file.
// husky.config.cjs
const { defineConfig } = require("@sumup-oss/foundry/husky");
module.exports = defineConfig();TL;DR
Creating and maintaining a JavaScript project can be very tedious. There are tools, configurations, dependency management, and boilerplate. With Foundry, you can fix all of that with a single dependency. It lints, creates files, and keeps the tools up to date. And the best part? You can still get down and dirty with your configurations. But only if you want.
Setting up and maintaining a complex JavaScript project can be very tedious. There are many different dependencies to install (linters, testing frameworks, bundlers) and configurations to set up. Once you have a running project, you end up writing a lot of boilerplate code when creating commonly used files. For example, a React component might come with a spec file (test), a Storybook file (isolated component development), and a service for handling business logic.
It gets much, much worse when you have several (many?) projects. What happens when there is a breaking change in a tooling dependency? What if a team decides you need to add a new linting rule? Nobody wants to go through every project and update those files all the time. And who knows, if they are even the same? Syncing configurations is terrible. Or think about that new engineer you are onboarding. How are they supposed to know how you structure your project, how your components are supposed to look, which files they need to create?
You might think you could solve these issues with a boilerplate repository and some snippets or templates. But you cannot. At least the maintenance problem will not go away.
Toolkits are a way to mitigate these kinds of problems. They encapsulate as much as possible of the toolchain into a single dependency and expose it through a CLI. Doing so gets you the following, probably more!
package.json shorter. :spider_web:We were inspired by many toolkit projects, such as create-react-app and kcd-scripts. These projects are opinionated, and so is Foundry. But Foundry is different, in our opinion, because:
So please, go ahead and try it.
We want to foster an inclusive and friendly community around our Open Sou
暂无开放 Issues,或尚未同步最近议题。