Skip to content

Commit 03e91ce

Browse files
feat: add ncc builder block (#2033)
## PR Checklist - [x] Addresses an existing open issue: fixes #2030 - [x] That issue was marked as [`status: accepting prs`](https://github.com/JoshuaKGoldberg/create-typescript-app/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22) - [x] Steps in [CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/create-typescript-app/blob/main/.github/CONTRIBUTING.md) were taken ## Overview 🎁
1 parent 59f5f19 commit 03e91ce

File tree

5 files changed

+191
-0
lines changed

5 files changed

+191
-0
lines changed

docs/Blocks.md

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ This table summarizes each block and which base levels they're included in:
3333
| Knip | `--exclude-knip` | | | 💯 |
3434
| Markdownlint | `--exclude-markdownlint` | | | 💯 |
3535
| MIT License | `--exclude-mit-license` | ✔️ || 💯 |
36+
| ncc | `--exclude-ncc` | | | |
3637
| nvmrc | `--exclude-nvmrc` | | | 💯 |
3738
| Package JSON | `--exclude-package-json` | ✔️ || 💯 |
3839
| pnpm Dedupe | `--exclude-pnpm-dedupe` | | | 💯 |

src/blocks/blockNcc.test.ts

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import { testBlock } from "bingo-stratum-testers";
2+
import { describe, expect, test } from "vitest";
3+
4+
import { blockNcc } from "./blockNcc.js";
5+
import { optionsBase } from "./options.fakes.js";
6+
7+
describe("blockNcc", () => {
8+
test("production", () => {
9+
const creation = testBlock(blockNcc, {
10+
options: optionsBase,
11+
});
12+
13+
expect(creation).toMatchInlineSnapshot(`
14+
{
15+
"addons": [
16+
{
17+
"addons": {
18+
"ignores": [
19+
"dist",
20+
],
21+
},
22+
"block": [Function],
23+
},
24+
{
25+
"addons": {
26+
"sections": {
27+
"Building": {
28+
"contents": "
29+
Run [TypeScript](https://typescriptlang.org) locally to type check and build source files from \`src/\` into output files in \`lib/\`:
30+
31+
\`\`\`shell
32+
pnpm build
33+
\`\`\`
34+
35+
Add \`--watch\` to run the builder in a watch mode that continuously cleans and recreates \`lib/\` as you save files:
36+
37+
\`\`\`shell
38+
pnpm build --watch
39+
\`\`\`
40+
",
41+
"innerSections": [
42+
{
43+
"contents": "
44+
Run [\`@vercel/ncc\`](https://github.com/vercel/ncc) to create an output \`dist/\` to be used in production.
45+
46+
\`\`\`shell
47+
pnpm build:release
48+
\`\`\`
49+
",
50+
"heading": "Building for Release",
51+
},
52+
],
53+
},
54+
},
55+
},
56+
"block": [Function],
57+
},
58+
{
59+
"addons": {
60+
"ignores": [
61+
"dist",
62+
],
63+
},
64+
"block": [Function],
65+
},
66+
{
67+
"addons": {
68+
"jobs": [
69+
{
70+
"name": "Build",
71+
"steps": [
72+
{
73+
"run": "pnpm build",
74+
},
75+
],
76+
},
77+
{
78+
"name": "Build (Release)",
79+
"steps": [
80+
{
81+
"run": "pnpm build:release",
82+
},
83+
],
84+
},
85+
],
86+
},
87+
"block": [Function],
88+
},
89+
{
90+
"addons": {
91+
"properties": {
92+
"devDependencies": {
93+
"@vercel/ncc": "^0.38.3",
94+
},
95+
"scripts": {
96+
"build": "tsc",
97+
"build:release": "ncc build src/index.ts -o dist",
98+
},
99+
},
100+
},
101+
"block": [Function],
102+
},
103+
],
104+
}
105+
`);
106+
});
107+
});

src/blocks/blockNcc.ts

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { base } from "../base.js";
2+
import { blockCSpell } from "./blockCSpell.js";
3+
import { blockDevelopmentDocs } from "./blockDevelopmentDocs.js";
4+
import { blockESLint } from "./blockESLint.js";
5+
import { blockGitHubActionsCI } from "./blockGitHubActionsCI.js";
6+
import { blockPackageJson } from "./blockPackageJson.js";
7+
8+
export const blockNcc = base.createBlock({
9+
about: {
10+
name: "ncc",
11+
},
12+
produce() {
13+
return {
14+
addons: [
15+
blockCSpell({
16+
ignores: ["dist"],
17+
}),
18+
blockDevelopmentDocs({
19+
sections: {
20+
Building: {
21+
contents: `
22+
Run [TypeScript](https://typescriptlang.org) locally to type check and build source files from \`src/\` into output files in \`lib/\`:
23+
24+
\`\`\`shell
25+
pnpm build
26+
\`\`\`
27+
28+
Add \`--watch\` to run the builder in a watch mode that continuously cleans and recreates \`lib/\` as you save files:
29+
30+
\`\`\`shell
31+
pnpm build --watch
32+
\`\`\`
33+
`,
34+
innerSections: [
35+
{
36+
contents: `
37+
Run [\`@vercel/ncc\`](https://github.com/vercel/ncc) to create an output \`dist/\` to be used in production.
38+
39+
\`\`\`shell
40+
pnpm build:release
41+
\`\`\`
42+
`,
43+
heading: "Building for Release",
44+
},
45+
],
46+
},
47+
},
48+
}),
49+
blockESLint({
50+
ignores: ["dist"],
51+
}),
52+
blockGitHubActionsCI({
53+
jobs: [
54+
{
55+
name: "Build",
56+
steps: [{ run: "pnpm build" }],
57+
},
58+
{
59+
name: "Build (Release)",
60+
steps: [{ run: "pnpm build:release" }],
61+
},
62+
],
63+
}),
64+
blockPackageJson({
65+
properties: {
66+
devDependencies: {
67+
"@vercel/ncc": "^0.38.3",
68+
},
69+
scripts: {
70+
build: "tsc",
71+
"build:release": "ncc build src/index.ts -o dist",
72+
},
73+
},
74+
}),
75+
],
76+
};
77+
},
78+
});

src/blocks/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { blockGitignore } from "./blockGitignore.js";
2424
import { blockKnip } from "./blockKnip.js";
2525
import { blockMarkdownlint } from "./blockMarkdownlint.js";
2626
import { blockMITLicense } from "./blockMITLicense.js";
27+
import { blockNcc } from "./blockNcc.js";
2728
import { blockNvmrc } from "./blockNvmrc.js";
2829
import { blockPackageJson } from "./blockPackageJson.js";
2930
import { blockPnpmDedupe } from "./blockPnpmDedupe.js";
@@ -69,6 +70,7 @@ export const blocks = {
6970
blockKnip,
7071
blockMarkdownlint,
7172
blockMITLicense,
73+
blockNcc,
7274
blockNvmrc,
7375
blockPackageJson,
7476
blockPnpmDedupe,
@@ -115,6 +117,7 @@ export { blockGitignore } from "./blockGitignore.js";
115117
export { blockKnip } from "./blockKnip.js";
116118
export { blockMarkdownlint } from "./blockMarkdownlint.js";
117119
export { blockMITLicense } from "./blockMITLicense.js";
120+
export { blockNcc } from "./blockNcc.js";
118121
export { blockNvmrc } from "./blockNvmrc.js";
119122
export { blockPackageJson } from "./blockPackageJson.js";
120123
export { blockPnpmDedupe } from "./blockPnpmDedupe.js";

src/template.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { base } from "./base.js";
22
import { blockAreTheTypesWrong } from "./blocks/blockAreTheTypesWrong.js";
33
import { blockCTATransitions } from "./blocks/blockCTATransitions.js";
4+
import { blockNcc } from "./blocks/blockNcc.js";
45
import { blockRemoveDependencies } from "./blocks/blockRemoveDependencies.js";
56
import { blockRemoveFiles } from "./blocks/blockRemoveFiles.js";
67
import { presetCommon } from "./presets/common.js";
@@ -18,6 +19,7 @@ export const template = base.createStratumTemplate({
1819
blocks: [
1920
blockAreTheTypesWrong,
2021
blockCTATransitions,
22+
blockNcc,
2123
blockRemoveDependencies,
2224
blockRemoveFiles,
2325
],

0 commit comments

Comments
 (0)