create-typescript-app 2.3.0 → 2.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,33 +1,28 @@
1
1
  import { z } from "zod";
2
2
  import { base } from "../base.js";
3
- const zApp = z.object({
4
- name: z.string(),
5
- url: z.string()
6
- });
3
+ import { getInstallationSuggestions } from "./getInstallationSuggestions.js";
7
4
  const blockGitHubApps = base.createBlock({
8
5
  about: {
9
6
  name: "GitHub Apps"
10
7
  },
11
8
  addons: {
12
- apps: z.array(zApp).default([])
9
+ apps: z.array(
10
+ z.object({
11
+ name: z.string(),
12
+ url: z.string()
13
+ })
14
+ ).default([])
13
15
  },
14
- produce({ addons }) {
16
+ produce({ addons, options }) {
15
17
  return {
16
- suggestions: addons.apps.length ? [
17
- [
18
- `- enable the GitHub app`,
19
- addons.apps.length === 1 ? "" : "s",
20
- `:
21
- `,
22
- addons.apps.map(printApp).join("\n")
23
- ].join("")
24
- ] : void 0
18
+ suggestions: getInstallationSuggestions(
19
+ "enable the GitHub app",
20
+ addons.apps.map((app) => `${app.name} (${app.url})`),
21
+ `https://github.com/${options.owner}/${options.repository}/settings/installations`
22
+ )
25
23
  };
26
24
  }
27
25
  });
28
- function printApp(app) {
29
- return ` - ${app.name} (${app.url})`;
30
- }
31
26
  export {
32
27
  blockGitHubApps
33
28
  };
@@ -8,22 +8,45 @@ const blockRepositoryBranchRuleset = base.createBlock({
8
8
  requiredStatusChecks: z.array(z.string()).default([])
9
9
  },
10
10
  setup({ addons, options }) {
11
- return createRequestSend(
12
- addons.requiredStatusChecks,
13
- "POST /repos/{owner}/{repo}/rulesets",
14
- options,
15
- "branch-ruleset-create",
16
- void 0
17
- );
11
+ return {
12
+ requests: [
13
+ {
14
+ id: "branch-ruleset-create",
15
+ async send({ octokit }) {
16
+ await octokit.request(
17
+ "POST /repos/{owner}/{repo}/rulesets",
18
+ createInnerSend(addons.requiredStatusChecks, options)
19
+ );
20
+ }
21
+ }
22
+ ]
23
+ };
18
24
  },
19
25
  transition({ addons, options }) {
20
- return createRequestSend(
21
- addons.requiredStatusChecks,
22
- `PUT /repos/{owner}/{repo}/rulesets/{ruleset_id}`,
23
- options,
24
- "branch-ruleset-update",
25
- options.rulesetId
26
- );
26
+ return {
27
+ requests: [
28
+ {
29
+ id: "branch-ruleset-update",
30
+ async send({ octokit }) {
31
+ if (options.rulesetId) {
32
+ await octokit.request(
33
+ `PUT /repos/{owner}/{repo}/rulesets/{ruleset_id}`,
34
+ createInnerSend(
35
+ addons.requiredStatusChecks,
36
+ options,
37
+ options.rulesetId
38
+ )
39
+ );
40
+ } else {
41
+ await octokit.request(
42
+ `POST /repos/{owner}/{repo}/rulesets/{ruleset_id}`,
43
+ createInnerSend(addons.requiredStatusChecks, options)
44
+ );
45
+ }
46
+ }
47
+ }
48
+ ]
49
+ };
27
50
  },
28
51
  // TODO: Make produce() optional
29
52
  // This needs createBlock to be generic to know if block.produce({}) is ok
@@ -31,61 +54,54 @@ const blockRepositoryBranchRuleset = base.createBlock({
31
54
  return {};
32
55
  }
33
56
  });
34
- function createRequestSend(contexts, endpoint, options, requestId, rulesetId) {
57
+ function createInnerSend(contexts, options, rulesetId) {
35
58
  return {
36
- requests: [
59
+ bypass_actors: [
37
60
  {
38
- id: requestId,
39
- async send({ octokit }) {
40
- await octokit.request(endpoint, {
41
- bypass_actors: [
42
- {
43
- // This *seems* to be the Repository Admin role always?
44
- // https://github.com/github/rest-api-description/issues/4406
45
- actor_id: 5,
46
- actor_type: "RepositoryRole",
47
- bypass_mode: "always"
48
- }
49
- ],
50
- conditions: {
51
- ref_name: {
52
- exclude: [],
53
- include: ["refs/heads/main"]
54
- }
55
- },
56
- enforcement: "active",
57
- name: "Branch protection for main",
58
- owner: options.owner,
59
- repo: options.repository,
60
- rules: [
61
- { type: "deletion" },
62
- {
63
- parameters: {
64
- allowed_merge_methods: ["squash"],
65
- dismiss_stale_reviews_on_push: false,
66
- require_code_owner_review: false,
67
- require_last_push_approval: false,
68
- required_approving_review_count: 0,
69
- required_review_thread_resolution: false
70
- },
71
- type: "pull_request"
72
- },
73
- {
74
- parameters: {
75
- required_status_checks: contexts.map((context) => ({
76
- context
77
- })),
78
- strict_required_status_checks_policy: false
79
- },
80
- type: "required_status_checks"
81
- }
82
- ],
83
- ruleset_id: rulesetId,
84
- target: "branch"
85
- });
86
- }
61
+ // This *seems* to be the Repository Admin role always?
62
+ // https://github.com/github/rest-api-description/issues/4406
63
+ actor_id: 5,
64
+ actor_type: "RepositoryRole",
65
+ bypass_mode: "always"
66
+ }
67
+ ],
68
+ conditions: {
69
+ ref_name: {
70
+ exclude: [],
71
+ include: ["refs/heads/main"]
72
+ }
73
+ },
74
+ enforcement: "active",
75
+ name: "Branch protection for main",
76
+ owner: options.owner,
77
+ repo: options.repository,
78
+ rules: [
79
+ { type: "deletion" },
80
+ {
81
+ parameters: {
82
+ allowed_merge_methods: ["squash"],
83
+ dismiss_stale_reviews_on_push: false,
84
+ require_code_owner_review: false,
85
+ require_last_push_approval: false,
86
+ required_approving_review_count: 0,
87
+ required_review_thread_resolution: false
88
+ },
89
+ type: "pull_request"
90
+ },
91
+ {
92
+ parameters: {
93
+ required_status_checks: contexts.map((context) => ({
94
+ context
95
+ })),
96
+ strict_required_status_checks_policy: false
97
+ },
98
+ type: "required_status_checks"
87
99
  }
88
- ]
100
+ ],
101
+ // Type fun because the GitHub Octokit APIs don't provide named types...
102
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
103
+ ruleset_id: rulesetId === void 0 ? rulesetId : Number(rulesetId),
104
+ target: "branch"
89
105
  };
90
106
  }
91
107
  export {
@@ -1,33 +1,30 @@
1
1
  import { z } from "zod";
2
2
  import { base } from "../base.js";
3
- const zSecret = z.object({
4
- description: z.string(),
5
- name: z.string()
6
- });
3
+ import { getInstallationSuggestions } from "./getInstallationSuggestions.js";
7
4
  const blockRepositorySecrets = base.createBlock({
8
5
  about: {
9
6
  name: "Repository Secrets"
10
7
  },
11
8
  addons: {
12
- secrets: z.array(zSecret).default([])
9
+ secrets: z.array(
10
+ z.object({
11
+ description: z.string(),
12
+ name: z.string()
13
+ })
14
+ ).default([])
13
15
  },
14
- produce({ addons }) {
16
+ produce({ addons, options }) {
15
17
  return {
16
- suggestions: addons.secrets.length ? [
17
- [
18
- `- populate the secret`,
19
- addons.secrets.length === 1 ? "" : "s",
20
- `:
21
- `,
22
- addons.secrets.map(printSecret).join("\n")
23
- ].join("")
24
- ] : void 0
18
+ suggestions: getInstallationSuggestions(
19
+ "populate the secret",
20
+ addons.secrets.map(
21
+ (secret) => `${secret.name} (${secret.description})`
22
+ ),
23
+ `https://github.com/${options.owner}/${options.repository}/settings/secrets/actions`
24
+ )
25
25
  };
26
26
  }
27
27
  });
28
- function printSecret(app) {
29
- return ` - ${app.name} (${app.description})`;
30
- }
31
28
  export {
32
29
  blockRepositorySecrets
33
30
  };
@@ -0,0 +1,3 @@
1
+ declare function getInstallationSuggestions(description: string, entries: string[], url: string): string[] | undefined;
2
+
3
+ export { getInstallationSuggestions };
@@ -0,0 +1,14 @@
1
+ function getInstallationSuggestions(description, entries, url) {
2
+ return entries.length ? [
3
+ [
4
+ `- ${description}`,
5
+ entries.length === 1 ? "" : "s",
6
+ ` on ${url}:
7
+ `,
8
+ entries.map((entry) => ` - ${entry}`).join("\n")
9
+ ].join("")
10
+ ] : void 0;
11
+ }
12
+ export {
13
+ getInstallationSuggestions
14
+ };
@@ -1,5 +1,5 @@
1
1
  var name = "create-typescript-app";
2
- var version = "2.2.0";
2
+ var version = "2.4.0";
3
3
  var description = "Quickstart-friendly TypeScript template with comprehensive, configurable, opinionated tooling. 🎁";
4
4
  var repository = {
5
5
  type: "git",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-typescript-app",
3
- "version": "2.3.0",
3
+ "version": "2.4.1",
4
4
  "description": "Quickstart-friendly TypeScript template with comprehensive, configurable, opinionated tooling. 🎁",
5
5
  "repository": {
6
6
  "type": "git",