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: populate existing cspell.json words during migration #1208

Merged
merged 16 commits into from
Jan 9, 2024
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
14 changes: 3 additions & 11 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,31 @@
"dictionaries": ["typescript"],
"ignorePaths": [
"./coverage*",
"./script/__snapshots__",
".github",
"CHANGELOG.md",
"lib",
"node_modules",
"pnpm-lock.yaml",
"./script/__snapshots__"
"pnpm-lock.yaml"
],
"words": [
"allcontributors",
"apexskier",
"arethetypeswrong",
"Codecov",
"codespace",
"commitlint",
"contributorsrc",
"conventionalcommits",
"execa",
"infile",
"joshuakgoldberg",
"knip",
"lcov",
"markdownlintignore",
"mtfoley",
"npmignore",
"npmjs",
"npmpackagejsonlintrc",
"outro",
"packagejson",
"quickstart",
"tada",
"tsup",
"Unstaged",
"vitest",
"wontfix"
"vitest"
]
}
40 changes: 14 additions & 26 deletions script/__snapshots__/migrate-test-e2e.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -156,42 +156,30 @@ exports[`expected file changes > cspell.json 1`] = `
"dictionaries": ["typescript"],
"ignorePaths": [
- "./coverage*",
- "./script/__snapshots__",
".github",
"CHANGELOG.md",
+ "coverage",
"lib",
"node_modules",
- "pnpm-lock.yaml",
- "./script/__snapshots__"
+ "pnpm-lock.yaml"
],
"words": [
- "allcontributors",
- "apexskier",
- "arethetypeswrong",
"Codecov",
"codespace",
"commitlint",
"pnpm-lock.yaml"
@@ ... @@
"contributorsrc",
"conventionalcommits",
- "execa",
- "infile",
- "joshuakgoldberg",
"execa",
"infile",
+ "joshuakgoldberg",
"knip",
"lcov",
+ "markdownlint",
"markdownlintignore",
- "mtfoley",
- "npmignore",
- "npmjs",
"npmpackagejsonlintrc",
"outro",
"packagejson",
"mtfoley",
"npmignore",
@@ ... @@
"quickstart",
- "tada",
"tada",
"tsup",
- "Unstaged",
- "vitest",
"wontfix"
- "vitest"
+ "vitest",
+ "wontfix"
]
}"
`;
Expand Down
2 changes: 1 addition & 1 deletion script/initialize-test-e2e.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { $ } from "execa";
import { globby } from "globby";
import { strict as assert } from "node:assert";
import fs from "node:fs/promises";
import * as fs from "node:fs/promises";

const description = "New Description Test";
const owner = "RNR1";
Expand Down
2 changes: 1 addition & 1 deletion script/migrate-test-e2e.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import chalk from "chalk";
import { $, execaCommand } from "execa";
import fs from "node:fs/promises";
import * as fs from "node:fs/promises";
import { assert, describe, expect, test } from "vitest";

import packageData from "../package.json" assert { type: "json" };
Expand Down
9 changes: 7 additions & 2 deletions src/create/createWithOptions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Options } from "../shared/types.js";
import { addToolAllContributors } from "../steps/addToolAllContributors.js";
import { finalizeDependencies } from "../steps/finalizeDependencies.js";
import { initializeGitHubRepository } from "../steps/initializeGitHubRepository/index.js";
import { populateCSpellDictionary } from "../steps/populateCSpellDictionary.js";
import { runCommands } from "../steps/runCommands.js";
import { createWithOptions } from "./createWithOptions.js";

Expand Down Expand Up @@ -60,6 +61,8 @@ vi.mock("../steps/writeReadme/index.js");

vi.mock("../steps/finalizeDependencies.js");

vi.mock("../steps/populateCSpellDictionary.js");

vi.mock("../steps/runCommands.js");

vi.mock("../shared/doesRepositoryExist.js", () => ({
Expand Down Expand Up @@ -111,18 +114,19 @@ describe("createWithOptions", () => {
expect(addToolAllContributors).not.toHaveBeenCalled();
});

it("does not call finalizeDependencies or runCommands when skipInstall is true", async () => {
it("does not call finalizeDependencies, populateCSpellDictionary, or runCommands when skipInstall is true", async () => {
const options = {
...optionsBase,
skipInstall: true,
};

await createWithOptions({ github, options });
expect(finalizeDependencies).not.toHaveBeenCalled();
expect(populateCSpellDictionary).not.toHaveBeenCalled();
expect(runCommands).not.toHaveBeenCalled();
});

it("calls finalizeDependencies and runCommands when skipInstall is false", async () => {
it("calls finalizeDependencies, populateCSpellDictionary, and runCommands when skipInstall is false", async () => {
const options = {
...optionsBase,
skipInstall: false,
Expand All @@ -131,6 +135,7 @@ describe("createWithOptions", () => {
await createWithOptions({ github, options });

expect(finalizeDependencies).toHaveBeenCalledWith(options);
expect(populateCSpellDictionary).toHaveBeenCalled();
expect(runCommands).toHaveBeenCalled();
});

Expand Down
8 changes: 8 additions & 0 deletions src/create/createWithOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { GitHubAndOptions } from "../shared/options/readOptions.js";
import { addToolAllContributors } from "../steps/addToolAllContributors.js";
import { finalizeDependencies } from "../steps/finalizeDependencies.js";
import { initializeGitHubRepository } from "../steps/initializeGitHubRepository/index.js";
import { populateCSpellDictionary } from "../steps/populateCSpellDictionary.js";
import { runCommands } from "../steps/runCommands.js";
import { writeReadme } from "../steps/writeReadme/index.js";
import { writeStructure } from "../steps/writing/writeStructure.js";
Expand Down Expand Up @@ -38,6 +39,13 @@ export async function createWithOptions({ github, options }: GitHubAndOptions) {
finalizeDependencies(options),
);

if (!options.excludeLintSpelling) {
await withSpinner(
"Populating CSpell dictionary",
populateCSpellDictionary,
);
}

await runCommands(
"Cleaning up files",
createCleanUpFilesCommands({
Expand Down
5 changes: 5 additions & 0 deletions src/migrate/migrateWithOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { clearUnnecessaryFiles } from "../steps/clearUnnecessaryFiles.js";
import { detectExistingContributors } from "../steps/detectExistingContributors.js";
import { finalizeDependencies } from "../steps/finalizeDependencies.js";
import { initializeGitHubRepository } from "../steps/initializeGitHubRepository/index.js";
import { populateCSpellDictionary } from "../steps/populateCSpellDictionary.js";
import { runCommands } from "../steps/runCommands.js";
import { updateAllContributorsTable } from "../steps/updateAllContributorsTable.js";
import { updateLocalFiles } from "../steps/updateLocalFiles.js";
Expand Down Expand Up @@ -61,6 +62,10 @@ export async function migrateWithOptions({
);
}

if (!options.excludeLintSpelling) {
await withSpinner("Populating CSpell dictionary", populateCSpellDictionary);
}

await runCommands(
"Cleaning up files",
createCleanUpFilesCommands({
Expand Down
2 changes: 1 addition & 1 deletion src/shared/options/createOptionDefaults/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { $ } from "execa";
import gitRemoteOriginUrl from "git-remote-origin-url";
import gitUrlParse from "git-url-parse";
import lazyValue from "lazy-value";
import fs from "node:fs/promises";
import * as fs from "node:fs/promises";
import npmUser from "npm-user";

import { readPackageData } from "../../packages.js";
Expand Down
8 changes: 2 additions & 6 deletions src/shared/readFileSafe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@ import { readFileSafe } from "./readFileSafe.js";
const mockReadFile = vi.fn();

vi.mock("node:fs/promises", () => ({
get default() {
return {
get readFile() {
return mockReadFile;
},
};
get readFile() {
return mockReadFile;
},
}));

Expand Down
2 changes: 1 addition & 1 deletion src/shared/readFileSafe.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fs from "node:fs/promises";
import * as fs from "node:fs/promises";

export async function readFileSafe(filePath: URL | string, fallback: string) {
try {
Expand Down
34 changes: 12 additions & 22 deletions src/steps/addOwnerAsAllContributor.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import prettier from "prettier";
import { describe, expect, it, vi } from "vitest";

import { addOwnerAsAllContributor } from "./addOwnerAsAllContributor.js";
import { formatJson } from "./writing/creation/formatters/formatJson.js";

const mock$ = vi.fn();

Expand All @@ -14,12 +14,8 @@ vi.mock("execa", () => ({
const mockWriteFile = vi.fn();

vi.mock("node:fs/promises", () => ({
get default() {
return {
get writeFile() {
return mockWriteFile;
},
};
get writeFile() {
return mockWriteFile;
},
}));

Expand Down Expand Up @@ -76,12 +72,9 @@ describe("addOwnerAsAllContributor", () => {

expect(mockWriteFile).toHaveBeenCalledWith(
"./.all-contributorsrc",
await prettier.format(
JSON.stringify({
contributors: [{ contributions: ["tool"], login: mockOwner }],
}),
{ parser: "json" },
),
await formatJson({
contributors: [{ contributions: ["tool"], login: mockOwner }],
}),
);
});

Expand All @@ -100,15 +93,12 @@ describe("addOwnerAsAllContributor", () => {

expect(mockWriteFile).toHaveBeenCalledWith(
"./.all-contributorsrc",
await prettier.format(
JSON.stringify({
contributors: [
{ contributions: ["bug", "fix", "tool"], login: mockOwner },
{ contributions: ["tool"], login: "JoshuaKGoldberg" },
],
}),
{ parser: "json" },
),
await formatJson({
contributors: [
{ contributions: ["bug", "fix", "tool"], login: mockOwner },
{ contributions: ["tool"], login: "JoshuaKGoldberg" },
],
}),
);
});
});
15 changes: 6 additions & 9 deletions src/steps/addOwnerAsAllContributor.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import fs from "node:fs/promises";
import prettier from "prettier";
import * as fs from "node:fs/promises";

import { getGitHubUserAsAllContributor } from "../shared/getGitHubUserAsAllContributor.js";
import { readFileAsJson } from "../shared/readFileAsJson.js";
import { AllContributorsData, Options } from "../shared/types.js";
import { formatJson } from "./writing/creation/formatters/formatJson.js";

export async function addOwnerAsAllContributor(
options: Pick<Options, "offline" | "owner">,
Expand Down Expand Up @@ -41,13 +41,10 @@ export async function addOwnerAsAllContributor(

await fs.writeFile(
"./.all-contributorsrc",
await prettier.format(
JSON.stringify({
...existingContributors,
contributors,
}),
{ parser: "json" },
),
await formatJson({
...existingContributors,
contributors,
}),
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/steps/clearChangelog.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fs from "node:fs/promises";
import * as fs from "node:fs/promises";
import prettier from "prettier";

export async function clearChangelog() {
Expand Down
2 changes: 1 addition & 1 deletion src/steps/clearUnnecessaryFiles.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fs from "node:fs/promises";
import * as fs from "node:fs/promises";

const globPaths = [
...extensions(".babelrc", "cjs", "cts", "js", "json", "mjs"),
Expand Down
Loading