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: separate out blockMain #2050

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 @@ -31,6 +31,7 @@ This table summarizes each block and which base levels they're included in:
| GitHub PR Template | `--exclude-github-pr-template` | ✔️ | ✅ | 💯 |
| Gitignore | `--exclude-gitignore` | ✔️ | ✅ | 💯 |
| Knip | `--exclude-knip` | | | 💯 |
| Main | `--exclude-main` | ✔️ | ✅ | 💯 |
| Markdownlint | `--exclude-markdownlint` | | | 💯 |
| MIT License | `--exclude-mit-license` | ✔️ | ✅ | 💯 |
| ncc | `--exclude-ncc` | | | |
Expand Down
67 changes: 67 additions & 0 deletions src/blocks/blockMain.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { testBlock } from "bingo-stratum-testers";
import { describe, expect, it } from "vitest";

import { blockMain } from "./blockMain.js";
import { optionsBase } from "./options.fakes.js";

describe("blockMain", () => {
it("without addons", () => {
const creation = testBlock(blockMain, { options: optionsBase });

expect(creation).toMatchInlineSnapshot(`
{
"addons": [
{
"addons": {
"properties": {
"main": "lib/index.js",
},
},
"block": [Function],
},
{
"addons": {
"runInCI": [
"node lib/index.js",
],
},
"block": [Function],
},
],
}
`);
});

it("with addons", () => {
const creation = testBlock(blockMain, {
addons: {
filePath: "other.js",
runArgs: ["--version"],
},
options: optionsBase,
});

expect(creation).toMatchInlineSnapshot(`
{
"addons": [
{
"addons": {
"properties": {
"main": "other.js",
},
},
"block": [Function],
},
{
"addons": {
"runInCI": [
"node other.js --version",
],
},
"block": [Function],
},
],
}
`);
});
});
33 changes: 33 additions & 0 deletions src/blocks/blockMain.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { z } from "zod";

import { base } from "../base.js";
import { blockPackageJson } from "./blockPackageJson.js";
import { blockTSup } from "./blockTSup.js";

export const blockMain = base.createBlock({
about: {
name: "Main",
},
addons: {
filePath: z.string().optional(),
runArgs: z.array(z.string()).default([]),
},
produce({ addons }) {
const { filePath = "lib/index.js", runArgs } = addons;

return {
addons: [
blockPackageJson({
properties: {
main: filePath,
},
}),
blockTSup({
runInCI: [
`node ${filePath}${runArgs.map((arg) => ` ${arg}`).join("")}`,
],
}),
],
};
},
});
18 changes: 9 additions & 9 deletions src/blocks/blockPackageJson.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe("blockPackageJson", () => {
expect(creation).toMatchInlineSnapshot(`
{
"files": {
"package.json": "{"name":"test-repository","version":"0.0.0","description":"A very very very very very very very very very very very very very very very very long HTML-ish description ending with an emoji. 🧵","repository":{"type":"git","url":"git+https://github.com/test-owner/test-repository.git"},"license":"MIT","author":{"email":"[email protected]"},"type":"module","main":"lib/index.js","files":["README.md","package.json"]}",
"package.json": "{"name":"test-repository","version":"0.0.0","description":"A very very very very very very very very very very very very very very very very long HTML-ish description ending with an emoji. 🧵","repository":{"type":"git","url":"git+https://github.com/test-owner/test-repository.git"},"license":"MIT","author":{"email":"[email protected]"},"type":"module","files":["README.md","package.json"]}",
},
"scripts": [
{
Expand Down Expand Up @@ -50,7 +50,7 @@ describe("blockPackageJson", () => {
},
],
"files": {
"package.json": "{"name":"test-repository","version":"0.0.0","description":"A very very very very very very very very very very very very very very very very long HTML-ish description ending with an emoji. 🧵","repository":{"type":"git","url":"git+https://github.com/test-owner/test-repository.git"},"license":"MIT","author":{"email":"[email protected]"},"type":"module","main":"lib/index.js","files":["README.md","package.json"]}",
"package.json": "{"name":"test-repository","version":"0.0.0","description":"A very very very very very very very very very very very very very very very very long HTML-ish description ending with an emoji. 🧵","repository":{"type":"git","url":"git+https://github.com/test-owner/test-repository.git"},"license":"MIT","author":{"email":"[email protected]"},"type":"module","files":["README.md","package.json"]}",
},
"scripts": [
{
Expand Down Expand Up @@ -81,7 +81,7 @@ describe("blockPackageJson", () => {
expect(creation).toMatchInlineSnapshot(`
{
"files": {
"package.json": "{"name":"test-repository","version":"0.0.0","description":"A very very very very very very very very very very very very very very very very long HTML-ish description ending with an emoji. 🧵","repository":{"type":"git","url":"git+https://github.com/test-owner/test-repository.git"},"license":"MIT","author":{"email":"[email protected]"},"type":"module","main":"lib/index.js","files":["README.md","package.json"],"dependencies":{"is-odd":"1.2.3"},"other":true}",
"package.json": "{"name":"test-repository","version":"0.0.0","description":"A very very very very very very very very very very very very very very very very long HTML-ish description ending with an emoji. 🧵","repository":{"type":"git","url":"git+https://github.com/test-owner/test-repository.git"},"license":"MIT","author":{"email":"[email protected]"},"type":"module","files":["README.md","package.json"],"dependencies":{"is-odd":"1.2.3"},"other":true}",
},
"scripts": [
{
Expand Down Expand Up @@ -116,7 +116,7 @@ describe("blockPackageJson", () => {
expect(creation).toMatchInlineSnapshot(`
{
"files": {
"package.json": "{"name":"test-repository","version":"0.0.0","description":"A very very very very very very very very very very very very very very very very long HTML-ish description ending with an emoji. 🧵","repository":{"type":"git","url":"git+https://github.com/test-owner/test-repository.git"},"license":"MIT","author":{"email":"[email protected]"},"type":"module","main":"lib/index.js","files":["README.md","package.json"],"dependencies":{"is-odd":"1.2.3"},"devDependencies":{"is-even":"4.5.6"},"other":true}",
"package.json": "{"name":"test-repository","version":"0.0.0","description":"A very very very very very very very very very very very very very very very very long HTML-ish description ending with an emoji. 🧵","repository":{"type":"git","url":"git+https://github.com/test-owner/test-repository.git"},"license":"MIT","author":{"email":"[email protected]"},"type":"module","files":["README.md","package.json"],"dependencies":{"is-odd":"1.2.3"},"devDependencies":{"is-even":"4.5.6"},"other":true}",
},
"scripts": [
{
Expand All @@ -142,7 +142,7 @@ describe("blockPackageJson", () => {
expect(creation).toMatchInlineSnapshot(`
{
"files": {
"package.json": "{"name":"test-repository","version":"0.0.0","description":"A very very very very very very very very very very very very very very very very long HTML-ish description ending with an emoji. 🧵","keywords":["abc","def","ghi"],"repository":{"type":"git","url":"git+https://github.com/test-owner/test-repository.git"},"license":"MIT","author":{"email":"[email protected]"},"type":"module","main":"lib/index.js","files":["README.md","package.json"]}",
"package.json": "{"name":"test-repository","version":"0.0.0","description":"A very very very very very very very very very very very very very very very very long HTML-ish description ending with an emoji. 🧵","keywords":["abc","def","ghi"],"repository":{"type":"git","url":"git+https://github.com/test-owner/test-repository.git"},"license":"MIT","author":{"email":"[email protected]"},"type":"module","files":["README.md","package.json"]}",
},
"scripts": [
{
Expand Down Expand Up @@ -170,7 +170,7 @@ describe("blockPackageJson", () => {
expect(creation).toMatchInlineSnapshot(`
{
"files": {
"package.json": "{"name":"test-repository","version":"0.0.0","description":"A very very very very very very very very very very very very very very very very long HTML-ish description ending with an emoji. 🧵","repository":{"type":"git","url":"git+https://github.com/test-owner/test-repository.git"},"license":"MIT","author":{"email":"[email protected]"},"type":"module","main":"lib/index.js","files":["README.md","package.json"],"packageManager":"[email protected]","engines":{"node":">=22.0.0"}}",
"package.json": "{"name":"test-repository","version":"0.0.0","description":"A very very very very very very very very very very very very very very very very long HTML-ish description ending with an emoji. 🧵","repository":{"type":"git","url":"git+https://github.com/test-owner/test-repository.git"},"license":"MIT","author":{"email":"[email protected]"},"type":"module","files":["README.md","package.json"],"packageManager":"[email protected]","engines":{"node":">=22.0.0"}}",
},
"scripts": [
{
Expand All @@ -195,7 +195,7 @@ describe("blockPackageJson", () => {
expect(creation).toMatchInlineSnapshot(`
{
"files": {
"package.json": "{"name":"test-repository","version":"0.0.0","description":"A very very very very very very very very very very very very very very very very long HTML-ish description ending with an emoji. 🧵","repository":{"type":"git","url":"git+https://github.com/test-owner/test-repository.git"},"license":"MIT","author":{"email":"[email protected]"},"type":"module","main":"lib/index.js","bin":"bin/index.js","files":["README.md","bin/index.js","package.json"]}",
"package.json": "{"name":"test-repository","version":"0.0.0","description":"A very very very very very very very very very very very very very very very very long HTML-ish description ending with an emoji. 🧵","repository":{"type":"git","url":"git+https://github.com/test-owner/test-repository.git"},"license":"MIT","author":{"email":"[email protected]"},"type":"module","bin":"bin/index.js","files":["README.md","bin/index.js","package.json"]}",
},
"scripts": [
{
Expand Down Expand Up @@ -223,7 +223,7 @@ describe("blockPackageJson", () => {
expect(creation).toMatchInlineSnapshot(`
{
"files": {
"package.json": "{"name":"test-repository","version":"0.0.0","description":"A very very very very very very very very very very very very very very very very long HTML-ish description ending with an emoji. 🧵","repository":{"type":"git","url":"git+https://github.com/test-owner/test-repository.git"},"license":"MIT","author":{"email":"[email protected]"},"type":"module","main":"lib/index.js","bin":{"absolute":"bin/absolute.js","relative":"./bin/relative.js"},"files":["README.md","bin/absolute.js","bin/relative.js","package.json"]}",
"package.json": "{"name":"test-repository","version":"0.0.0","description":"A very very very very very very very very very very very very very very very very long HTML-ish description ending with an emoji. 🧵","repository":{"type":"git","url":"git+https://github.com/test-owner/test-repository.git"},"license":"MIT","author":{"email":"[email protected]"},"type":"module","bin":{"absolute":"bin/absolute.js","relative":"./bin/relative.js"},"files":["README.md","bin/absolute.js","bin/relative.js","package.json"]}",
},
"scripts": [
{
Expand All @@ -246,7 +246,7 @@ describe("blockPackageJson", () => {
expect(creation).toMatchInlineSnapshot(`
{
"files": {
"package.json": "{"name":"test-repository","version":"0.0.0","description":"A very very very very very very very very very very very very very very very very long HTML-ish description ending with an emoji. 🧵","repository":{"type":"git","url":"git+https://github.com/test-owner/test-repository.git"},"license":"MIT","author":{"email":"[email protected]"},"type":"module","main":"lib/index.js","files":["README.md","package.json"]}",
"package.json": "{"name":"test-repository","version":"0.0.0","description":"A very very very very very very very very very very very very very very very very long HTML-ish description ending with an emoji. 🧵","repository":{"type":"git","url":"git+https://github.com/test-owner/test-repository.git"},"license":"MIT","author":{"email":"[email protected]"},"type":"module","files":["README.md","package.json"]}",
},
"scripts": [
{
Expand Down
1 change: 0 additions & 1 deletion src/blocks/blockPackageJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ export const blockPackageJson = base.createBlock({
keyword.split(/ /),
),
license: "MIT",
main: "lib/index.js",
name: options.repository,
repository: {
type: "git",
Expand Down
9 changes: 0 additions & 9 deletions src/blocks/blockTSup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ describe("blockTSup", () => {
{
"run": "pnpm build",
},
{
"run": "node lib/index.js",
},
],
},
],
Expand Down Expand Up @@ -141,9 +138,6 @@ describe("blockTSup", () => {
{
"run": "pnpm build",
},
{
"run": "node lib/index.js",
},
],
},
],
Expand Down Expand Up @@ -260,9 +254,6 @@ describe("blockTSup", () => {
{
"run": "pnpm build",
},
{
"run": "node lib/index.js",
},
],
},
],
Expand Down
6 changes: 2 additions & 4 deletions src/blocks/blockTSup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const blockTSup = base.createBlock({
},
addons: {
entry: z.array(z.string()).default([]),
runArgs: z.array(z.string()).default([]),
runInCI: z.array(z.string()).default([]),
},
produce({ addons, options }) {
const { entry } = addons;
Expand Down Expand Up @@ -52,9 +52,7 @@ pnpm build --watch
name: "Build",
steps: [
{ run: "pnpm build" },
{
run: `node lib/index.js${addons.runArgs.map((arg) => ` ${arg}`).join("")}`,
},
...addons.runInCI.map((run) => ({ run })),
],
},
],
Expand Down
3 changes: 0 additions & 3 deletions src/blocks/blockTypeScript.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ describe("blockTypeScript", () => {
"files": [
"lib/",
],
"main": "lib/index.js",
"scripts": {
"tsc": "tsc",
},
Expand Down Expand Up @@ -258,7 +257,6 @@ describe("blockTypeScript", () => {
"files": [
"lib/",
],
"main": "lib/index.js",
"scripts": {
"tsc": "tsc",
},
Expand Down Expand Up @@ -418,7 +416,6 @@ describe("blockTypeScript", () => {
"files": [
"lib/",
],
"main": "lib/index.js",
"scripts": {
"tsc": "tsc",
},
Expand Down
1 change: 0 additions & 1 deletion src/blocks/blockTypeScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ export * from "./types.js";
properties: {
devDependencies: getPackageDependencies("typescript"),
files: ["lib/"],
main: "lib/index.js",
scripts: {
tsc: "tsc",
},
Expand Down
3 changes: 3 additions & 0 deletions src/blocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { blockGitHubIssueTemplates } from "./blockGitHubIssueTemplates.js";
import { blockGitHubPRTemplate } from "./blockGitHubPRTemplate.js";
import { blockGitignore } from "./blockGitignore.js";
import { blockKnip } from "./blockKnip.js";
import { blockMain } from "./blockMain.js";
import { blockMarkdownlint } from "./blockMarkdownlint.js";
import { blockMITLicense } from "./blockMITLicense.js";
import { blockNcc } from "./blockNcc.js";
Expand Down Expand Up @@ -68,6 +69,7 @@ export const blocks = {
blockGitHubPRTemplate,
blockGitignore,
blockKnip,
blockMain,
blockMarkdownlint,
blockMITLicense,
blockNcc,
Expand Down Expand Up @@ -115,6 +117,7 @@ export { blockGitHubIssueTemplates } from "./blockGitHubIssueTemplates.js";
export { blockGitHubPRTemplate } from "./blockGitHubPRTemplate.js";
export { blockGitignore } from "./blockGitignore.js";
export { blockKnip } from "./blockKnip.js";
export { blockMain } from "./blockMain.js";
export { blockMarkdownlint } from "./blockMarkdownlint.js";
export { blockMITLicense } from "./blockMITLicense.js";
export { blockNcc } from "./blockNcc.js";
Expand Down
4 changes: 2 additions & 2 deletions src/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import {
blockCSpell,
blockESLint,
blockKnip,
blockMain,
blockTemplatedWith,
blockTSup,
presets,
} from "./index.js";

Expand Down Expand Up @@ -103,7 +103,7 @@ If you're interested in learning more, see the 'getting started' docs on:
"trash-cli",
],
}),
blockTSup({
blockMain({
runArgs: ["--version"],
}),
],
Expand Down
2 changes: 2 additions & 0 deletions src/presets/minimal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { blockGitHubApps } from "../blocks/blockGitHubApps.js";
import { blockGitHubIssueTemplates } from "../blocks/blockGitHubIssueTemplates.js";
import { blockGitHubPRTemplate } from "../blocks/blockGitHubPRTemplate.js";
import { blockGitignore } from "../blocks/blockGitignore.js";
import { blockMain } from "../blocks/blockMain.js";
import { blockMITLicense } from "../blocks/blockMITLicense.js";
import { blockPackageJson } from "../blocks/blockPackageJson.js";
import { blockPrettier } from "../blocks/blockPrettier.js";
Expand Down Expand Up @@ -42,6 +43,7 @@ export const presetMinimal = base.createPreset({
blockGitHubIssueTemplates,
blockGitHubPRTemplate,
blockGitignore,
blockMain,
blockMITLicense,
blockPackageJson,
blockPrettier,
Expand Down