diff --git a/docs/Blocks.md b/docs/Blocks.md index 350a0aab4..544da1d46 100644 --- a/docs/Blocks.md +++ b/docs/Blocks.md @@ -33,6 +33,7 @@ This table summarizes each block and which base levels they're included in: | Knip | `--exclude-knip` | | | 💯 | | Markdownlint | `--exclude-markdownlint` | | | 💯 | | MIT License | `--exclude-mit-license` | ✔️ | ✅ | 💯 | +| ncc | `--exclude-ncc` | | | | | nvmrc | `--exclude-nvmrc` | | | 💯 | | Package JSON | `--exclude-package-json` | ✔️ | ✅ | 💯 | | pnpm Dedupe | `--exclude-pnpm-dedupe` | | | 💯 | diff --git a/src/blocks/blockNcc.test.ts b/src/blocks/blockNcc.test.ts new file mode 100644 index 000000000..7bda2b193 --- /dev/null +++ b/src/blocks/blockNcc.test.ts @@ -0,0 +1,107 @@ +import { testBlock } from "bingo-stratum-testers"; +import { describe, expect, test } from "vitest"; + +import { blockNcc } from "./blockNcc.js"; +import { optionsBase } from "./options.fakes.js"; + +describe("blockNcc", () => { + test("production", () => { + const creation = testBlock(blockNcc, { + options: optionsBase, + }); + + expect(creation).toMatchInlineSnapshot(` + { + "addons": [ + { + "addons": { + "ignores": [ + "dist", + ], + }, + "block": [Function], + }, + { + "addons": { + "sections": { + "Building": { + "contents": " + Run [TypeScript](https://typescriptlang.org) locally to type check and build source files from \`src/\` into output files in \`lib/\`: + + \`\`\`shell + pnpm build + \`\`\` + + Add \`--watch\` to run the builder in a watch mode that continuously cleans and recreates \`lib/\` as you save files: + + \`\`\`shell + pnpm build --watch + \`\`\` + ", + "innerSections": [ + { + "contents": " + Run [\`@vercel/ncc\`](https://github.com/vercel/ncc) to create an output \`dist/\` to be used in production. + + \`\`\`shell + pnpm build:release + \`\`\` + ", + "heading": "Building for Release", + }, + ], + }, + }, + }, + "block": [Function], + }, + { + "addons": { + "ignores": [ + "dist", + ], + }, + "block": [Function], + }, + { + "addons": { + "jobs": [ + { + "name": "Build", + "steps": [ + { + "run": "pnpm build", + }, + ], + }, + { + "name": "Build (Release)", + "steps": [ + { + "run": "pnpm build:release", + }, + ], + }, + ], + }, + "block": [Function], + }, + { + "addons": { + "properties": { + "devDependencies": { + "@vercel/ncc": "^0.38.3", + }, + "scripts": { + "build": "tsc", + "build:release": "ncc build src/index.ts -o dist", + }, + }, + }, + "block": [Function], + }, + ], + } + `); + }); +}); diff --git a/src/blocks/blockNcc.ts b/src/blocks/blockNcc.ts new file mode 100644 index 000000000..40f683839 --- /dev/null +++ b/src/blocks/blockNcc.ts @@ -0,0 +1,78 @@ +import { base } from "../base.js"; +import { blockCSpell } from "./blockCSpell.js"; +import { blockDevelopmentDocs } from "./blockDevelopmentDocs.js"; +import { blockESLint } from "./blockESLint.js"; +import { blockGitHubActionsCI } from "./blockGitHubActionsCI.js"; +import { blockPackageJson } from "./blockPackageJson.js"; + +export const blockNcc = base.createBlock({ + about: { + name: "ncc", + }, + produce() { + return { + addons: [ + blockCSpell({ + ignores: ["dist"], + }), + blockDevelopmentDocs({ + sections: { + Building: { + contents: ` +Run [TypeScript](https://typescriptlang.org) locally to type check and build source files from \`src/\` into output files in \`lib/\`: + +\`\`\`shell +pnpm build +\`\`\` + +Add \`--watch\` to run the builder in a watch mode that continuously cleans and recreates \`lib/\` as you save files: + +\`\`\`shell +pnpm build --watch +\`\`\` +`, + innerSections: [ + { + contents: ` +Run [\`@vercel/ncc\`](https://github.com/vercel/ncc) to create an output \`dist/\` to be used in production. + +\`\`\`shell +pnpm build:release +\`\`\` + `, + heading: "Building for Release", + }, + ], + }, + }, + }), + blockESLint({ + ignores: ["dist"], + }), + blockGitHubActionsCI({ + jobs: [ + { + name: "Build", + steps: [{ run: "pnpm build" }], + }, + { + name: "Build (Release)", + steps: [{ run: "pnpm build:release" }], + }, + ], + }), + blockPackageJson({ + properties: { + devDependencies: { + "@vercel/ncc": "^0.38.3", + }, + scripts: { + build: "tsc", + "build:release": "ncc build src/index.ts -o dist", + }, + }, + }), + ], + }; + }, +}); diff --git a/src/blocks/index.ts b/src/blocks/index.ts index 2c6d4d76c..e06253783 100644 --- a/src/blocks/index.ts +++ b/src/blocks/index.ts @@ -24,6 +24,7 @@ import { blockGitignore } from "./blockGitignore.js"; import { blockKnip } from "./blockKnip.js"; import { blockMarkdownlint } from "./blockMarkdownlint.js"; import { blockMITLicense } from "./blockMITLicense.js"; +import { blockNcc } from "./blockNcc.js"; import { blockNvmrc } from "./blockNvmrc.js"; import { blockPackageJson } from "./blockPackageJson.js"; import { blockPnpmDedupe } from "./blockPnpmDedupe.js"; @@ -69,6 +70,7 @@ export const blocks = { blockKnip, blockMarkdownlint, blockMITLicense, + blockNcc, blockNvmrc, blockPackageJson, blockPnpmDedupe, @@ -115,6 +117,7 @@ export { blockGitignore } from "./blockGitignore.js"; export { blockKnip } from "./blockKnip.js"; export { blockMarkdownlint } from "./blockMarkdownlint.js"; export { blockMITLicense } from "./blockMITLicense.js"; +export { blockNcc } from "./blockNcc.js"; export { blockNvmrc } from "./blockNvmrc.js"; export { blockPackageJson } from "./blockPackageJson.js"; export { blockPnpmDedupe } from "./blockPnpmDedupe.js"; diff --git a/src/template.ts b/src/template.ts index 738f7f28c..26c3e1f80 100644 --- a/src/template.ts +++ b/src/template.ts @@ -1,6 +1,7 @@ import { base } from "./base.js"; import { blockAreTheTypesWrong } from "./blocks/blockAreTheTypesWrong.js"; import { blockCTATransitions } from "./blocks/blockCTATransitions.js"; +import { blockNcc } from "./blocks/blockNcc.js"; import { blockRemoveDependencies } from "./blocks/blockRemoveDependencies.js"; import { blockRemoveFiles } from "./blocks/blockRemoveFiles.js"; import { presetCommon } from "./presets/common.js"; @@ -18,6 +19,7 @@ export const template = base.createStratumTemplate({ blocks: [ blockAreTheTypesWrong, blockCTATransitions, + blockNcc, blockRemoveDependencies, blockRemoveFiles, ],