Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ncc builder block #2033

Merged
merged 2 commits into from
Mar 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/Blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` | | | 💯 |
Expand Down
107 changes: 107 additions & 0 deletions src/blocks/blockNcc.test.ts
Original file line number Diff line number Diff line change
@@ -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],
},
],
}
`);
});
});
78 changes: 78 additions & 0 deletions src/blocks/blockNcc.ts
Original file line number Diff line number Diff line change
@@ -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",
},
},
}),
],
};
},
});
3 changes: 3 additions & 0 deletions src/blocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -69,6 +70,7 @@ export const blocks = {
blockKnip,
blockMarkdownlint,
blockMITLicense,
blockNcc,
blockNvmrc,
blockPackageJson,
blockPnpmDedupe,
Expand Down Expand Up @@ -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";
Expand Down
2 changes: 2 additions & 0 deletions src/template.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -18,6 +19,7 @@ export const template = base.createStratumTemplate({
blocks: [
blockAreTheTypesWrong,
blockCTATransitions,
blockNcc,
blockRemoveDependencies,
blockRemoveFiles,
],
Expand Down