Skip to content

Commit 0e7fdb1

Browse files
fix: moved hydrate to bin (#553)
## PR Checklist - [x] Addresses an existing open issue: fixes #552 - [x] That issue was marked as [`status: accepting prs`](https://github.com/JoshuaKGoldberg/template-typescript-node-package/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22) - [x] Steps in [CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/template-typescript-node-package/blob/main/.github/CONTRIBUTING.md) were taken ## Overview Uses a proper `bin/` file with a `#!` hashbang comment.
1 parent 27b4983 commit 0e7fdb1

File tree

7 files changed

+85
-79
lines changed

7 files changed

+85
-79
lines changed

.github/workflows/lint-knip.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ jobs:
44
steps:
55
- uses: actions/checkout@v3
66
- uses: ./.github/actions/prepare
7+
- run: pnpm build || true
78
- run: pnpm lint:knip
89

910
name: Lint Knip

.github/workflows/lint.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ jobs:
44
steps:
55
- uses: actions/checkout@v3
66
- uses: ./.github/actions/prepare
7+
- run: pnpm build || true
78
- run: pnpm lint
89

910
name: Lint

bin/hydrate.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env node
2+
import { hydrate } from "../lib/hydrate/index.js";
3+
4+
process.exitCode = await hydrate(process.argv.slice(2));

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
},
1414
"type": "module",
1515
"main": "./lib/index.js",
16-
"bin": "./lib/hydrate/index.js",
16+
"bin": "./bin/hydrate.js",
1717
"files": [
18+
"bin/",
1819
"lib/",
1920
"package.json",
2021
"LICENSE.md",

script/hydrate-test-e2e.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const title = "Template TypeScript Node Package";
99

1010
await $({
1111
stdio: "inherit",
12-
})`c8 -o ./coverage-hydrate -r html -r lcov node ./lib/hydrate/index.js --description ${description} --owner ${owner} --title ${title} --repository ${repository} --skip-api --skip-install --skip-setup`;
12+
})`c8 -o ./coverage-hydrate -r html -r lcov node ./bin/hydrate.js --description ${description} --owner ${owner} --title ${title} --repository ${repository} --skip-api --skip-install --skip-setup`;
1313

1414
const { stdout: gitStatus } = await $`git status`;
1515
console.log(`Stdout from running \`git status\`:\n${gitStatus}`);
@@ -33,6 +33,8 @@ const filesExpectedToBeChanged = new Set([
3333
".eslintrc.cjs",
3434
".github/DEVELOPMENT.md",
3535
".github/workflows/release.yml",
36+
".github/workflows/lint.yml",
37+
".github/workflows/lint-knip.yml",
3638
".github/workflows/test.yml",
3739
".gitignore",
3840
".prettierignore",

src/hydrate/hydrate.ts

Lines changed: 0 additions & 75 deletions
This file was deleted.

src/hydrate/index.ts

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,75 @@
1-
import { hydrate } from "./hydrate.js";
1+
import { parseArgs } from "node:util";
22

3-
process.exitCode = await hydrate(process.argv.slice(2));
3+
import { setupWithInformation } from "../setup/setupWithInformation.js";
4+
import {
5+
skipSpinnerBlock,
6+
successSpinnerBlock,
7+
withSpinner,
8+
} from "../shared/cli/spinners.js";
9+
import { runOrRestore } from "../shared/runOrRestore.js";
10+
import { clearUnnecessaryFiles } from "./steps/clearUnnecessaryFiles.js";
11+
import { finalizeDependencies as finalizeDependencies } from "./steps/finalizeDependencies.js";
12+
import { runCommand } from "./steps/runCommand.js";
13+
import { writeReadme } from "./steps/writeReadme.js";
14+
import { writeStructure } from "./steps/writing/writeStructure.js";
15+
import { getHydrationDefaults } from "./values/getHydrationDefaults.js";
16+
import { augmentWithHydrationValues } from "./values/hydrationInputValues.js";
17+
18+
export async function hydrate(args: string[]) {
19+
const { values: hydrationSkips } = parseArgs({
20+
args,
21+
options: {
22+
"skip-install": { type: "boolean" },
23+
"skip-setup": { type: "boolean" },
24+
},
25+
strict: false,
26+
tokens: true,
27+
});
28+
29+
return await runOrRestore({
30+
args,
31+
defaults: await getHydrationDefaults(),
32+
label: "hydration",
33+
run: async ({ octokit, values }) => {
34+
const hydrationValues = await augmentWithHydrationValues(values);
35+
36+
await withSpinner(clearUnnecessaryFiles, "clearing unnecessary files");
37+
38+
await withSpinner(
39+
() => writeStructure(hydrationValues),
40+
"writing new repository structure"
41+
);
42+
43+
await withSpinner(
44+
() => writeReadme(hydrationValues),
45+
"writing README.md"
46+
);
47+
48+
if (hydrationSkips["skip-install"]) {
49+
skipSpinnerBlock(`Skipping package installations.`);
50+
} else {
51+
await withSpinner(
52+
() => finalizeDependencies(hydrationValues),
53+
"finalizing dependencies"
54+
);
55+
}
56+
57+
await runCommand("pnpm lint --fix", "auto-fixing lint rules");
58+
await runCommand("pnpm format --write", "formatting files");
59+
60+
if (hydrationSkips["skip-setup"]) {
61+
skipSpinnerBlock(`Done hydrating, and skipping setup command.`);
62+
} else {
63+
successSpinnerBlock("Done hydrating. Starting setup command...");
64+
65+
await setupWithInformation({
66+
octokit,
67+
values: {
68+
...hydrationValues,
69+
skipUninstalls: true,
70+
},
71+
});
72+
}
73+
},
74+
});
75+
}

0 commit comments

Comments
 (0)