Skip to content

Commit

Permalink
chore: use cspell-populate-words in CSpell block (#1794)
Browse files Browse the repository at this point in the history
- [x] Addresses an existing open issue: fixes #381
- [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

Applies only to the new `create` engine Block system, because it'd be a
nontrivial change in the old system, and I want that old system to be
gone within the next few weeks. 🚀

Uses:

1.
[`object-strings-deep`](https://github.com/JoshuaKGoldberg/object-strings-deep)
to collect all strings from options
2.
[`cspell-populate-words`](https://github.com/JoshuaKGoldberg/cspell-populate-words)
in a new `script` to add any reported words to the `cspell.json` file

Scoping the PR as a `chore:` because the new system is not yet part of
the public API.

💖
  • Loading branch information
JoshuaKGoldberg authored Dec 21, 2024
1 parent 33e235b commit c7a0881
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 3 deletions.
2 changes: 1 addition & 1 deletion knip.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://unpkg.com/[email protected]/schema.json",
"entry": ["script/*e2e.js", "src/index.ts!", "src/**/*.test.*"],
"ignoreDependencies": ["all-contributors-cli"],
"ignoreDependencies": ["all-contributors-cli", "cspell-populate-words"],
"ignoreExportsUsedInFile": { "interface": true, "type": true },
"project": ["src/**/*.ts!", "script/**/*.js"]
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"@prettier/sync": "^0.5.2",
"chalk": "^5.3.0",
"create": "0.1.0-alpha.7",
"cspell-populate-words": "^0.2.2",
"execa": "^9.5.2",
"git-remote-origin-url": "^4.0.0",
"git-url-parse": "^16.0.0",
Expand All @@ -53,6 +54,7 @@
"js-yaml": "^4.1.0",
"lazy-value": "^3.0.0",
"npm-user": "^6.1.1",
"object-strings-deep": "^0.1.1",
"octokit": "^4.0.2",
"octokit-from-auth": "^0.3.0",
"parse-author": "^2.0.0",
Expand Down
21 changes: 21 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion src/next/blocks/blockCSpell.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { testBlock } from "create-testers";
import { describe, expect, test } from "vitest";
import { describe, expect, test, vi } from "vitest";

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

vi.mock("../utils/resolveBin.js", () => ({
resolveBin: (bin: string) => `path/to/${bin}`,
}));

describe("blockCSpell", () => {
test("without addons", () => {
const creation = testBlock(blockCSpell, {
Expand Down
19 changes: 19 additions & 0 deletions src/next/blocks/blockCSpell.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { getObjectStringsDeep } from "object-strings-deep";
import { z } from "zod";

import { base } from "../base.js";
import { resolveBin } from "../utils/resolveBin.js";
import { blockDevelopmentDocs } from "./blockDevelopmentDocs.js";
import { blockGitHubActionsCI } from "./blockGitHubActionsCI.js";
import { blockPackageJson } from "./blockPackageJson.js";
import { blockVSCode } from "./blockVSCode.js";
import { getPackageDependencies } from "./packageData.js";
import { CommandPhase } from "./phases.js";

const filesGlob = `"**" ".github/**/*"`;

Expand All @@ -17,6 +20,22 @@ export const blockCSpell = base.createBlock({
ignores: z.array(z.string()).default([]),
words: z.array(z.string()).default([]),
},
initialize({ options }) {
const wordArgs = getObjectStringsDeep(options)
.map((word) => `--words "${word.replaceAll(`"`, " ")}"`)
.join(" ");

return {
scripts: [
{
commands: [
`node ${resolveBin("cspell-populate-words/bin/index.mjs")} ${wordArgs}`,
],
phase: CommandPhase.Process,
},
],
};
},
produce({ addons }) {
const { ignores, words } = addons;

Expand Down
3 changes: 3 additions & 0 deletions src/next/utils/resolveBin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function resolveBin(bin: string) {
return import.meta.resolve(bin).replace(/^file:\/\//gu, "");
}
2 changes: 2 additions & 0 deletions src/steps/uninstallPackages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export async function uninstallPackages(offline: boolean | undefined) {
"all-contributors-cli",
"chalk",
"create",
"cspell-populate-words",
"execa",
"git-remote-origin-url",
"git-url-parse",
Expand All @@ -20,6 +21,7 @@ export async function uninstallPackages(offline: boolean | undefined) {
"js-yaml",
"lazy-value",
"npm-user",
"object-strings-deep",
"octokit",
"octokit-from-auth",
"parse-author",
Expand Down
8 changes: 7 additions & 1 deletion src/steps/writing/creation/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { describe, expect, it } from "vitest";
import { describe, expect, it, vi } from "vitest";

import { getPackageDependencies } from "../../../next/blocks/packageData.js";
import { Options } from "../../../shared/types.js";
import { createStructure } from "./index.js";

vi.mock("../../../next/utils/resolveBin.ts", () => ({
resolveBin: (bin: string) => `path/to/${bin}`,
}));

/* eslint-disable @typescript-eslint/no-dynamic-delete */

const documentation = `
Expand Down Expand Up @@ -204,6 +208,7 @@ describe("createStructure", () => {
"@prettier/sync",
"chalk",
"create",
"cspell-populate-words",
"execa",
"git-remote-origin-url",
"git-url-parse",
Expand All @@ -212,6 +217,7 @@ describe("createStructure", () => {
"js-yaml",
"lazy-value",
"npm-user",
"object-strings-deep",
"octokit",
"octokit-from-auth",
"parse-author",
Expand Down

0 comments on commit c7a0881

Please sign in to comment.