-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add usage option for create engine (#1822)
## PR Checklist - [x] Addresses an existing open issue: fixes #1821 - [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 Marking as `chore:` because this is only for the new `create` Blocks engine. 💖
- Loading branch information
1 parent
f109519
commit c8c7591
Showing
8 changed files
with
138 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/shared/options/createOptionDefaults/getUsageFromReadme.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { describe, expect, it } from "vitest"; | ||
|
||
import { getUsageFromReadme } from "./getUsageFromReadme.js"; | ||
|
||
describe("getUsageFromReadme", () => { | ||
it("returns undefined when ## Usage is not found", () => { | ||
const usage = getUsageFromReadme("## Other"); | ||
|
||
expect(usage).toBeUndefined(); | ||
}); | ||
|
||
it("returns undefined when ## Usage found and ## Development is not found", () => { | ||
const usage = getUsageFromReadme("## Usage\n\nContents."); | ||
|
||
expect(usage).toBeUndefined(); | ||
}); | ||
|
||
it("returns undefined when there is no content between ## Usage and ## Development", () => { | ||
const usage = getUsageFromReadme("## Usage\n\n \n## Development"); | ||
|
||
expect(usage).toBeUndefined(); | ||
}); | ||
|
||
it("returns the content when content exists between ## Usage and ## Development", () => { | ||
const usage = getUsageFromReadme("## Usage\n\n Content.\n## Development"); | ||
|
||
expect(usage).toBe("Content."); | ||
}); | ||
}); |
23 changes: 23 additions & 0 deletions
23
src/shared/options/createOptionDefaults/getUsageFromReadme.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const startDevelopment = "## Development"; | ||
const startUsage = "## Usage"; | ||
|
||
export function getUsageFromReadme(readme: string) { | ||
const indexOfUsage = readme.indexOf(startUsage); | ||
if (indexOfUsage === -1) { | ||
return undefined; | ||
} | ||
|
||
const indexOfDevelopment = readme.indexOf( | ||
startDevelopment, | ||
indexOfUsage + startUsage.length, | ||
); | ||
if (indexOfDevelopment === -1) { | ||
return undefined; | ||
} | ||
|
||
const usage = readme | ||
.slice(indexOfUsage + startUsage.length, indexOfDevelopment) | ||
.trim(); | ||
|
||
return usage ? usage : undefined; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.