@jaykingson/cdk-toolbox 0.0.2 → 0.0.3

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.
package/README.md CHANGED
@@ -13,7 +13,11 @@ vite-plus monorepo for shared CDK constructs and deployment apps. The published
13
13
 
14
14
  ## Scaffold
15
15
 
16
- `cdkToolbox()` writes a CDK app when the package name is `cdk-app`, and an account-setup app (GitHub OIDC provider plus a deploy role) when the package name is `cdk-account-setup`. vite-plus-base 0.0.17 places those two apps for `vp create @jaykingson:monorepo -- --plugins cdk-toolbox`. Any other package only receives the CDK devDependencies.
16
+ `@jaykingson/cdk-toolbox/vite-plus-base` is a vite-plus-base plugin. It owns `apps/cdk-app` and `apps/cdk-account-setup`. Setup creates those directories and names the packages `cdk-app` and `cdk-account-setup`. The preset then writes a CDK app, or an account-setup app (GitHub OIDC provider plus a deploy role). `--cdk-toolbox.owner` is the GitHub repository owner written into the account-setup files. The default is `owner`. Any other package that lists the preset only receives the CDK devDependencies.
17
+
18
+ ```bash
19
+ vp create @jaykingson:monorepo -- --plugins @jaykingson/cdk-toolbox --cdk-toolbox.owner octo
20
+ ```
17
21
 
18
22
  ## Quick start
19
23
 
@@ -0,0 +1,450 @@
1
+ import { base, blockPackageJson } from "@jaykingson/vite-plus-base/bingo";
2
+ //#region src/bingo-blocks/blockCdkApps/blockCdkApps.ts
3
+ /**
4
+ * Versions already used by this repo's CDK apps. Package-scoped bingo writes a
5
+ * missing name as a devDependency range. An existing specifier, including
6
+ * `catalog:`, is left alone. Package scope cannot add catalog pins.
7
+ */
8
+ const CDK_DEV_DEPENDENCIES = {
9
+ "aws-cdk": "2.1144.0",
10
+ "aws-cdk-lib": "2.272.0",
11
+ constructs: "^10.8.1"
12
+ };
13
+ const CDK_APP_PACKAGE = "cdk-app";
14
+ const ACCOUNT_SETUP_PACKAGE = "cdk-account-setup";
15
+ /** Fallback already written into the account-setup scaffold. Create passes a replacement. */
16
+ const DEFAULT_CDK_OWNER = "owner";
17
+ /**
18
+ * Directories setup creates. The package name is the directory basename, which
19
+ * is what selects the scaffold. This repo's own apps use different names, so a
20
+ * bingo run here still only adds the CDK devDependencies.
21
+ */
22
+ const CDK_APP_DIRECTORY = "apps/cdk-app";
23
+ const ACCOUNT_SETUP_DIRECTORY = "apps/cdk-account-setup";
24
+ function createBlockCdkApps(owner = DEFAULT_CDK_OWNER) {
25
+ const accountOwner = owner.trim() || "owner";
26
+ return base.createBlock({
27
+ about: { name: "CDK Apps" },
28
+ produce({ options }) {
29
+ const extensions = [blockPackageJson({ properties: { devDependencies: { ...CDK_DEV_DEPENDENCIES } } })];
30
+ const scaffold = scaffoldPackage("name" in options && typeof options.name === "string" ? options.name : void 0);
31
+ if (!scaffold) return { extensions };
32
+ return {
33
+ extensions,
34
+ files: scaffold === CDK_APP_PACKAGE ? cdkAppFiles(accountOwner) : accountSetupFiles(accountOwner)
35
+ };
36
+ }
37
+ });
38
+ }
39
+ const blockCdkApps = createBlockCdkApps();
40
+ function scaffoldPackage(name) {
41
+ if (name === CDK_APP_PACKAGE || name === ACCOUNT_SETUP_PACKAGE) return name;
42
+ }
43
+ function cdkAppFiles(owner) {
44
+ return {
45
+ ".gitignore": "cdk.out\n",
46
+ "cdk.json": cdkJson(),
47
+ "vite.config.ts": applicationConfig(owner, true),
48
+ bin: { "app.ts": CDK_APP_BIN },
49
+ lib: {
50
+ "cdk-app-stack.ts": CDK_APP_STACK,
51
+ "cdk-app-stack.test.ts": CDK_APP_STACK_TEST
52
+ }
53
+ };
54
+ }
55
+ function accountSetupFiles(owner) {
56
+ return {
57
+ ".gitignore": "cdk.out\n",
58
+ "cdk.json": cdkJson(),
59
+ "vite.config.ts": applicationConfig(owner, true),
60
+ bin: { "app.ts": ACCOUNT_SETUP_BIN },
61
+ lib: {
62
+ "account-setup-stack.ts": accountSetupStack(owner),
63
+ "account-setup-stack.test.ts": ACCOUNT_SETUP_STACK_TEST,
64
+ "github-repository.ts": githubRepository(owner),
65
+ "github-repository.test.ts": githubRepositoryTest(owner)
66
+ }
67
+ };
68
+ }
69
+ function cdkJson() {
70
+ return `${JSON.stringify({
71
+ app: "node bin/app.ts",
72
+ requireApproval: "never",
73
+ context: { "@aws-cdk/core:target-partitions": ["aws", "aws-cn"] }
74
+ }, null, 2)}\n`;
75
+ }
76
+ function applicationConfig(owner, synthCheck) {
77
+ const checkTasks = synthCheck ? ` "check-synth": {
78
+ command: "cdk synth",
79
+ cache: false,
80
+ },
81
+ "check-all": {
82
+ command: "vp run check-synth",
83
+ cache: false,
84
+ },` : ` "check-all": {
85
+ command: "echo \\"no checks yet\\"",
86
+ cache: false,
87
+ },`;
88
+ return `import cdkToolbox from "@jaykingson/cdk-toolbox/vite-plus-base";
89
+ import { defineApplicationConfig } from "@jaykingson/vite-plus-base";
90
+
91
+ export default defineApplicationConfig({
92
+ bingo: {
93
+ plugins: [cdkToolbox.preset({ owner: ${JSON.stringify(owner)} })],
94
+ },
95
+ run: {
96
+ tasks: {
97
+ synth: {
98
+ command: "cdk synth",
99
+ cache: false,
100
+ },
101
+ diff: {
102
+ command: "cdk diff",
103
+ cache: false,
104
+ },
105
+ deploy: {
106
+ command: "cdk deploy --all",
107
+ cache: false,
108
+ },
109
+ ${checkTasks}
110
+ },
111
+ },
112
+ test: {
113
+ environment: "node",
114
+ include: ["lib/**/*.test.ts"],
115
+ exclude: ["**/node_modules/**", "**/.git/**", "cdk.out/**"],
116
+ passWithNoTests: true,
117
+ },
118
+ });
119
+ `;
120
+ }
121
+ const CDK_APP_BIN = `#!/usr/bin/env node
122
+ import { App } from "aws-cdk-lib";
123
+
124
+ import { CdkAppStack } from "../lib/cdk-app-stack.ts";
125
+
126
+ const app = new App();
127
+ new CdkAppStack(app, "CdkAppStack");
128
+ `;
129
+ const CDK_APP_STACK = `import { CfnOutput, Stack, type StackProps } from "aws-cdk-lib";
130
+ import { Construct } from "constructs";
131
+
132
+ export class CdkAppStack extends Stack {
133
+ constructor(scope: Construct, id: string, props?: StackProps) {
134
+ super(scope, id, props);
135
+
136
+ new CfnOutput(this, "StackName", {
137
+ value: this.stackName,
138
+ description: "Name of the scaffolded CDK stack.",
139
+ });
140
+ }
141
+ }
142
+ `;
143
+ const CDK_APP_STACK_TEST = `import { App } from "aws-cdk-lib";
144
+ import { Template } from "aws-cdk-lib/assertions";
145
+ import { describe, it } from "vite-plus/test";
146
+
147
+ import { CdkAppStack } from "./cdk-app-stack.ts";
148
+
149
+ describe("CdkAppStack", () => {
150
+ it("synthesizes without AWS credentials", () => {
151
+ const app = new App();
152
+ const stack = new CdkAppStack(app, "CdkAppStack");
153
+ const template = Template.fromStack(stack);
154
+
155
+ template.hasOutput("StackName", {});
156
+ });
157
+ });
158
+ `;
159
+ const ACCOUNT_SETUP_BIN = `#!/usr/bin/env node
160
+ import { readFileSync } from "node:fs";
161
+ import { dirname, join } from "node:path";
162
+ import { fileURLToPath } from "node:url";
163
+ import { App } from "aws-cdk-lib";
164
+
165
+ import { AccountSetupStack } from "../lib/account-setup-stack.ts";
166
+ import { resolveGitHubRepository } from "../lib/github-repository.ts";
167
+
168
+ const app = new App();
169
+ const rootManifest = readRootManifest();
170
+ const repository = resolveGitHubRepository({
171
+ contextOwner: app.node.tryGetContext("githubOwner"),
172
+ contextName: app.node.tryGetContext("githubRepo"),
173
+ env: process.env,
174
+ repositoryUrl: rootManifest.repositoryUrl,
175
+ packageName: rootManifest.name,
176
+ });
177
+
178
+ new AccountSetupStack(app, "AccountSetupStack", {
179
+ repositoryOwner: repository.owner,
180
+ repositoryName: repository.name,
181
+ });
182
+
183
+ function readRootManifest(): { name?: string; repositoryUrl?: string } {
184
+ try {
185
+ const root = join(dirname(fileURLToPath(import.meta.url)), "../../..");
186
+ const manifest = JSON.parse(readFileSync(join(root, "package.json"), "utf8")) as {
187
+ name?: unknown;
188
+ repository?: unknown;
189
+ };
190
+ return {
191
+ name: typeof manifest.name === "string" ? manifest.name : undefined,
192
+ repositoryUrl: repositoryUrl(manifest.repository),
193
+ };
194
+ } catch {
195
+ return {};
196
+ }
197
+ }
198
+
199
+ function repositoryUrl(repository: unknown): string | undefined {
200
+ if (typeof repository === "string") {
201
+ return repository;
202
+ }
203
+ if (repository && typeof repository === "object" && "url" in repository) {
204
+ const url = (repository as { url?: unknown }).url;
205
+ return typeof url === "string" ? url : undefined;
206
+ }
207
+ return undefined;
208
+ }
209
+ `;
210
+ function accountSetupStack(owner) {
211
+ return `import { Aws, CfnOutput, Stack, type StackProps } from "aws-cdk-lib";
212
+ import {
213
+ OidcProviderNative,
214
+ PolicyStatement,
215
+ Role,
216
+ WebIdentityPrincipal,
217
+ } from "aws-cdk-lib/aws-iam";
218
+ import { Construct } from "constructs";
219
+
220
+ const BOOTSTRAP_QUALIFIER = "hnb659fds";
221
+ const BOOTSTRAP_REGION = "us-east-1";
222
+ const BOOTSTRAP_ROLE_NAMES = [
223
+ "deploy-role",
224
+ "file-publishing-role",
225
+ "image-publishing-role",
226
+ "lookup-role",
227
+ "cfn-exec-role",
228
+ ] as const;
229
+
230
+ const GITHUB_OIDC_URL = "https://token.actions.githubusercontent.com";
231
+ const GITHUB_OIDC_AUDIENCE = "sts.amazonaws.com";
232
+
233
+ export type AccountSetupStackProps = StackProps & {
234
+ repositoryOwner?: string;
235
+ repositoryName?: string;
236
+ };
237
+
238
+ export class AccountSetupStack extends Stack {
239
+ constructor(scope: Construct, id: string, props: AccountSetupStackProps = {}) {
240
+ super(scope, id, props);
241
+
242
+ const owner = props.repositoryOwner ?? ${JSON.stringify(owner)};
243
+ const name = props.repositoryName ?? "repo";
244
+ const repository = \`\${owner}/\${name}\`;
245
+
246
+ const provider = new OidcProviderNative(this, "GitHubProvider", {
247
+ url: GITHUB_OIDC_URL,
248
+ clientIds: [GITHUB_OIDC_AUDIENCE],
249
+ });
250
+
251
+ const deployRole = new Role(this, "DeployRole", {
252
+ roleName: "GitHubActionsCdkDeployRole",
253
+ description: \`Allows GitHub Actions from \${repository} to deploy CDK stacks.\`,
254
+ assumedBy: new WebIdentityPrincipal(provider.openIdConnectProviderArn, {
255
+ StringEquals: {
256
+ "token.actions.githubusercontent.com:aud": GITHUB_OIDC_AUDIENCE,
257
+ },
258
+ StringLike: {
259
+ // owner/name subjects. Immutable numeric subjects are a later polish.
260
+ "token.actions.githubusercontent.com:sub": \`repo:\${repository}:*\`,
261
+ },
262
+ }),
263
+ });
264
+
265
+ deployRole.addToPolicy(
266
+ new PolicyStatement({
267
+ actions: ["sts:AssumeRole"],
268
+ resources: BOOTSTRAP_ROLE_NAMES.map(
269
+ (roleName) =>
270
+ \`arn:\${Aws.PARTITION}:iam::\${Aws.ACCOUNT_ID}:role/cdk-\${BOOTSTRAP_QUALIFIER}-\${roleName}-\${Aws.ACCOUNT_ID}-\${BOOTSTRAP_REGION}\`,
271
+ ),
272
+ }),
273
+ );
274
+
275
+ new CfnOutput(this, "GitHubActionsDeployRoleArn", {
276
+ value: deployRole.roleArn,
277
+ description: "Assume this role from GitHub Actions via OIDC.",
278
+ });
279
+ new CfnOutput(this, "GitHubActionsOidcProviderArn", {
280
+ value: provider.openIdConnectProviderArn,
281
+ description: "GitHub Actions OIDC provider ARN.",
282
+ });
283
+ }
284
+ }
285
+ `;
286
+ }
287
+ const ACCOUNT_SETUP_STACK_TEST = `import { App } from "aws-cdk-lib";
288
+ import { Template } from "aws-cdk-lib/assertions";
289
+ import { describe, expect, it } from "vite-plus/test";
290
+
291
+ import { AccountSetupStack } from "./account-setup-stack.ts";
292
+
293
+ describe("AccountSetupStack", () => {
294
+ it("synthesizes a GitHub OIDC provider and deploy role without AWS credentials", () => {
295
+ const app = new App();
296
+ const stack = new AccountSetupStack(app, "AccountSetupStack", {
297
+ repositoryOwner: "octo",
298
+ repositoryName: "aws-ops",
299
+ });
300
+ const template = Template.fromStack(stack);
301
+
302
+ template.resourceCountIs("AWS::IAM::OIDCProvider", 1);
303
+ template.hasResourceProperties("AWS::IAM::Role", {
304
+ RoleName: "GitHubActionsCdkDeployRole",
305
+ });
306
+ expect(JSON.stringify(template.toJSON())).toContain("repo:octo/aws-ops:*");
307
+ });
308
+ });
309
+ `;
310
+ function githubRepository(owner) {
311
+ return `const GITHUB_SLUG = /^[A-Za-z0-9_.-]+\\/[A-Za-z0-9_.-]+$/;
312
+ const GITHUB_URL = /github\\.com[:/]([^/]+)\\/([^/#?\\s]+?)(?:\\.git)?$/;
313
+
314
+ export type GitHubRepository = {
315
+ owner: string;
316
+ name: string;
317
+ };
318
+
319
+ export function resolveGitHubRepository(input: {
320
+ contextOwner?: unknown;
321
+ contextName?: unknown;
322
+ env?: Record<string, string | undefined>;
323
+ repositoryUrl?: string;
324
+ packageName?: string;
325
+ }): GitHubRepository {
326
+ const context = pair(input.contextOwner, input.contextName);
327
+ if (context) {
328
+ return context;
329
+ }
330
+
331
+ const fromEnv = parseSlug(input.env?.GITHUB_REPOSITORY);
332
+ if (fromEnv) {
333
+ return fromEnv;
334
+ }
335
+
336
+ const fromUrl = parseRepositoryUrl(input.repositoryUrl);
337
+ if (fromUrl) {
338
+ return fromUrl;
339
+ }
340
+
341
+ return { owner: ${JSON.stringify(owner)}, name: input.packageName || "repo" };
342
+ }
343
+
344
+ function pair(owner: unknown, name: unknown): GitHubRepository | undefined {
345
+ if (typeof owner !== "string" || typeof name !== "string") {
346
+ return undefined;
347
+ }
348
+ const trimmedOwner = owner.trim();
349
+ const trimmedName = name.trim();
350
+ if (!trimmedOwner || !trimmedName) {
351
+ return undefined;
352
+ }
353
+ return { owner: trimmedOwner, name: trimmedName };
354
+ }
355
+
356
+ function parseSlug(value: string | undefined): GitHubRepository | undefined {
357
+ const trimmed = value?.trim();
358
+ if (!trimmed || !GITHUB_SLUG.test(trimmed)) {
359
+ return undefined;
360
+ }
361
+ const [owner, name] = trimmed.split("/");
362
+ if (!owner || !name) {
363
+ return undefined;
364
+ }
365
+ return { owner, name };
366
+ }
367
+
368
+ function parseRepositoryUrl(value: string | undefined): GitHubRepository | undefined {
369
+ const trimmed = value?.trim();
370
+ if (!trimmed) {
371
+ return undefined;
372
+ }
373
+ const slug = parseSlug(trimmed);
374
+ if (slug) {
375
+ return slug;
376
+ }
377
+ const match = GITHUB_URL.exec(trimmed);
378
+ const owner = match?.[1];
379
+ const name = match?.[2];
380
+ if (!owner || !name) {
381
+ return undefined;
382
+ }
383
+ return { owner, name };
384
+ }
385
+ `;
386
+ }
387
+ function githubRepositoryTest(owner) {
388
+ return `import { describe, expect, it } from "vite-plus/test";
389
+
390
+ import { resolveGitHubRepository } from "./github-repository.ts";
391
+
392
+ describe("resolveGitHubRepository", () => {
393
+ it("prefers CDK context, then GitHub env, then the repository URL", () => {
394
+ expect(
395
+ resolveGitHubRepository({
396
+ contextOwner: "from-context",
397
+ contextName: "repo",
398
+ env: { GITHUB_REPOSITORY: "from-env/repo" },
399
+ repositoryUrl: "https://github.com/from-url/repo",
400
+ }),
401
+ ).toEqual({ owner: "from-context", name: "repo" });
402
+
403
+ expect(
404
+ resolveGitHubRepository({
405
+ env: { GITHUB_REPOSITORY: "from-env/repo" },
406
+ repositoryUrl: "git+https://github.com/from-url/repo.git",
407
+ }),
408
+ ).toEqual({ owner: "from-env", name: "repo" });
409
+
410
+ expect(
411
+ resolveGitHubRepository({
412
+ repositoryUrl: "https://github.com/from-url/repo.git",
413
+ packageName: "aws-ops",
414
+ }),
415
+ ).toEqual({ owner: "from-url", name: "repo" });
416
+ });
417
+
418
+ it("falls back to the package name so synth still has a subject", () => {
419
+ expect(resolveGitHubRepository({ packageName: "aws-ops" })).toEqual({
420
+ owner: ${JSON.stringify(owner)},
421
+ name: "aws-ops",
422
+ });
423
+ });
424
+ });
425
+ `;
426
+ }
427
+ //#endregion
428
+ //#region src/bingo-blocks/blockCdkPreflight/blockCdkPreflight.ts
429
+ const cdkPreflightRange = "^1.20.19";
430
+ const blockCdkPreflight = base.createBlock({
431
+ about: { name: "CDK Preflight" },
432
+ produce() {
433
+ return { extensions: [blockPackageJson({ properties: { devDependencies: { "cdk-preflight": cdkPreflightRange } } })] };
434
+ }
435
+ });
436
+ //#endregion
437
+ //#region src/bingo-blocks/index.ts
438
+ function cdkToolbox(options) {
439
+ const owner = options?.owner?.trim() || "owner";
440
+ return base.createPreset({
441
+ about: { name: "cdk-toolbox" },
442
+ blocks: [
443
+ blockPackageJson,
444
+ blockCdkPreflight,
445
+ owner === "owner" ? blockCdkApps : createBlockCdkApps(owner)
446
+ ]
447
+ });
448
+ }
449
+ //#endregion
450
+ export { DEFAULT_CDK_OWNER as a, CDK_APP_DIRECTORY as i, blockCdkPreflight as n, blockCdkApps as o, ACCOUNT_SETUP_DIRECTORY as r, createBlockCdkApps as s, cdkToolbox as t };
@@ -1,418 +1,2 @@
1
- import { base, blockPackageJson } from "@jaykingson/vite-plus-base/bingo";
2
- //#region src/bingo-blocks/blockCdkApps/blockCdkApps.ts
3
- /**
4
- * Versions already used by this repo's CDK apps. Package-scoped bingo writes a
5
- * missing name as a devDependency range. An existing specifier, including
6
- * `catalog:`, is left alone. Package scope cannot add catalog pins.
7
- */
8
- const CDK_DEV_DEPENDENCIES = {
9
- "aws-cdk": "2.1144.0",
10
- "aws-cdk-lib": "2.272.0",
11
- constructs: "^10.8.1"
12
- };
13
- const CDK_APP_PACKAGE = "cdk-app";
14
- const ACCOUNT_SETUP_PACKAGE = "cdk-account-setup";
15
- const blockCdkApps = base.createBlock({
16
- about: { name: "CDK Apps" },
17
- produce({ options }) {
18
- const extensions = [blockPackageJson({ properties: { devDependencies: { ...CDK_DEV_DEPENDENCIES } } })];
19
- const scaffold = scaffoldPackage("name" in options && typeof options.name === "string" ? options.name : void 0);
20
- if (!scaffold) return { extensions };
21
- return {
22
- extensions,
23
- files: scaffold === CDK_APP_PACKAGE ? cdkAppFiles() : accountSetupFiles()
24
- };
25
- }
26
- });
27
- function scaffoldPackage(name) {
28
- if (name === CDK_APP_PACKAGE || name === ACCOUNT_SETUP_PACKAGE) return name;
29
- }
30
- function cdkAppFiles() {
31
- return {
32
- ".gitignore": "cdk.out\n",
33
- "cdk.json": cdkJson(),
34
- "vite.config.ts": applicationConfig(),
35
- bin: { "app.ts": CDK_APP_BIN },
36
- lib: {
37
- "cdk-app-stack.ts": CDK_APP_STACK,
38
- "cdk-app-stack.test.ts": CDK_APP_STACK_TEST
39
- }
40
- };
41
- }
42
- function accountSetupFiles() {
43
- return {
44
- ".gitignore": "cdk.out\n",
45
- "cdk.json": cdkJson(),
46
- "vite.config.ts": applicationConfig(),
47
- bin: { "app.ts": ACCOUNT_SETUP_BIN },
48
- lib: {
49
- "account-setup-stack.ts": ACCOUNT_SETUP_STACK,
50
- "account-setup-stack.test.ts": ACCOUNT_SETUP_STACK_TEST,
51
- "github-repository.ts": GITHUB_REPOSITORY,
52
- "github-repository.test.ts": GITHUB_REPOSITORY_TEST
53
- }
54
- };
55
- }
56
- function cdkJson() {
57
- return `${JSON.stringify({
58
- app: "node bin/app.ts",
59
- requireApproval: "never",
60
- context: { "@aws-cdk/core:target-partitions": ["aws", "aws-cn"] }
61
- }, null, 2)}\n`;
62
- }
63
- function applicationConfig() {
64
- return `import { cdkToolbox } from "@jaykingson/cdk-toolbox/bingo-blocks";
65
- import { defineApplicationConfig } from "@jaykingson/vite-plus-base";
66
-
67
- export default defineApplicationConfig({
68
- bingo: {
69
- plugins: [cdkToolbox()],
70
- },
71
- run: {
72
- tasks: {
73
- synth: {
74
- command: "cdk synth",
75
- cache: false,
76
- },
77
- diff: {
78
- command: "cdk diff",
79
- cache: false,
80
- },
81
- deploy: {
82
- command: "cdk deploy --all",
83
- cache: false,
84
- },
85
- },
86
- },
87
- test: {
88
- environment: "node",
89
- include: ["lib/**/*.test.ts"],
90
- exclude: ["**/node_modules/**", "**/.git/**", "cdk.out/**"],
91
- passWithNoTests: true,
92
- },
93
- });
94
- `;
95
- }
96
- const CDK_APP_BIN = `#!/usr/bin/env node
97
- import { App } from "aws-cdk-lib";
98
-
99
- import { CdkAppStack } from "../lib/cdk-app-stack.ts";
100
-
101
- const app = new App();
102
- new CdkAppStack(app, "CdkAppStack");
103
- `;
104
- const CDK_APP_STACK = `import { CfnOutput, Stack, type StackProps } from "aws-cdk-lib";
105
- import { Construct } from "constructs";
106
-
107
- export class CdkAppStack extends Stack {
108
- constructor(scope: Construct, id: string, props?: StackProps) {
109
- super(scope, id, props);
110
-
111
- new CfnOutput(this, "StackName", {
112
- value: this.stackName,
113
- description: "Name of the scaffolded CDK stack.",
114
- });
115
- }
116
- }
117
- `;
118
- const CDK_APP_STACK_TEST = `import { App } from "aws-cdk-lib";
119
- import { Template } from "aws-cdk-lib/assertions";
120
- import { describe, it } from "vite-plus/test";
121
-
122
- import { CdkAppStack } from "./cdk-app-stack.ts";
123
-
124
- describe("CdkAppStack", () => {
125
- it("synthesizes without AWS credentials", () => {
126
- const app = new App();
127
- const stack = new CdkAppStack(app, "CdkAppStack");
128
- const template = Template.fromStack(stack);
129
-
130
- template.hasOutput("StackName", {});
131
- });
132
- });
133
- `;
134
- const ACCOUNT_SETUP_BIN = `#!/usr/bin/env node
135
- import { readFileSync } from "node:fs";
136
- import { dirname, join } from "node:path";
137
- import { fileURLToPath } from "node:url";
138
- import { App } from "aws-cdk-lib";
139
-
140
- import { AccountSetupStack } from "../lib/account-setup-stack.ts";
141
- import { resolveGitHubRepository } from "../lib/github-repository.ts";
142
-
143
- const app = new App();
144
- const rootManifest = readRootManifest();
145
- const repository = resolveGitHubRepository({
146
- contextOwner: app.node.tryGetContext("githubOwner"),
147
- contextName: app.node.tryGetContext("githubRepo"),
148
- env: process.env,
149
- repositoryUrl: rootManifest.repositoryUrl,
150
- packageName: rootManifest.name,
151
- });
152
-
153
- new AccountSetupStack(app, "AccountSetupStack", {
154
- repositoryOwner: repository.owner,
155
- repositoryName: repository.name,
156
- });
157
-
158
- function readRootManifest(): { name?: string; repositoryUrl?: string } {
159
- try {
160
- const root = join(dirname(fileURLToPath(import.meta.url)), "../../..");
161
- const manifest = JSON.parse(readFileSync(join(root, "package.json"), "utf8")) as {
162
- name?: unknown;
163
- repository?: unknown;
164
- };
165
- return {
166
- name: typeof manifest.name === "string" ? manifest.name : undefined,
167
- repositoryUrl: repositoryUrl(manifest.repository),
168
- };
169
- } catch {
170
- return {};
171
- }
172
- }
173
-
174
- function repositoryUrl(repository: unknown): string | undefined {
175
- if (typeof repository === "string") {
176
- return repository;
177
- }
178
- if (repository && typeof repository === "object" && "url" in repository) {
179
- const url = (repository as { url?: unknown }).url;
180
- return typeof url === "string" ? url : undefined;
181
- }
182
- return undefined;
183
- }
184
- `;
185
- const ACCOUNT_SETUP_STACK = `import { Aws, CfnOutput, Stack, type StackProps } from "aws-cdk-lib";
186
- import {
187
- OidcProviderNative,
188
- PolicyStatement,
189
- Role,
190
- WebIdentityPrincipal,
191
- } from "aws-cdk-lib/aws-iam";
192
- import { Construct } from "constructs";
193
-
194
- const BOOTSTRAP_QUALIFIER = "hnb659fds";
195
- const BOOTSTRAP_REGION = "us-east-1";
196
- const BOOTSTRAP_ROLE_NAMES = [
197
- "deploy-role",
198
- "file-publishing-role",
199
- "image-publishing-role",
200
- "lookup-role",
201
- "cfn-exec-role",
202
- ] as const;
203
-
204
- const GITHUB_OIDC_URL = "https://token.actions.githubusercontent.com";
205
- const GITHUB_OIDC_AUDIENCE = "sts.amazonaws.com";
206
-
207
- export type AccountSetupStackProps = StackProps & {
208
- repositoryOwner?: string;
209
- repositoryName?: string;
210
- };
211
-
212
- export class AccountSetupStack extends Stack {
213
- constructor(scope: Construct, id: string, props: AccountSetupStackProps = {}) {
214
- super(scope, id, props);
215
-
216
- const owner = props.repositoryOwner ?? "owner";
217
- const name = props.repositoryName ?? "repo";
218
- const repository = \`\${owner}/\${name}\`;
219
-
220
- const provider = new OidcProviderNative(this, "GitHubProvider", {
221
- url: GITHUB_OIDC_URL,
222
- clientIds: [GITHUB_OIDC_AUDIENCE],
223
- });
224
-
225
- const deployRole = new Role(this, "DeployRole", {
226
- roleName: "GitHubActionsCdkDeployRole",
227
- description: \`Allows GitHub Actions from \${repository} to deploy CDK stacks.\`,
228
- assumedBy: new WebIdentityPrincipal(provider.openIdConnectProviderArn, {
229
- StringEquals: {
230
- "token.actions.githubusercontent.com:aud": GITHUB_OIDC_AUDIENCE,
231
- },
232
- StringLike: {
233
- // owner/name subjects. Immutable numeric subjects are a later polish.
234
- "token.actions.githubusercontent.com:sub": \`repo:\${repository}:*\`,
235
- },
236
- }),
237
- });
238
-
239
- deployRole.addToPolicy(
240
- new PolicyStatement({
241
- actions: ["sts:AssumeRole"],
242
- resources: BOOTSTRAP_ROLE_NAMES.map(
243
- (roleName) =>
244
- \`arn:\${Aws.PARTITION}:iam::\${Aws.ACCOUNT_ID}:role/cdk-\${BOOTSTRAP_QUALIFIER}-\${roleName}-\${Aws.ACCOUNT_ID}-\${BOOTSTRAP_REGION}\`,
245
- ),
246
- }),
247
- );
248
-
249
- new CfnOutput(this, "GitHubActionsDeployRoleArn", {
250
- value: deployRole.roleArn,
251
- description: "Assume this role from GitHub Actions via OIDC.",
252
- });
253
- new CfnOutput(this, "GitHubActionsOidcProviderArn", {
254
- value: provider.openIdConnectProviderArn,
255
- description: "GitHub Actions OIDC provider ARN.",
256
- });
257
- }
258
- }
259
- `;
260
- const ACCOUNT_SETUP_STACK_TEST = `import { App } from "aws-cdk-lib";
261
- import { Template } from "aws-cdk-lib/assertions";
262
- import { describe, expect, it } from "vite-plus/test";
263
-
264
- import { AccountSetupStack } from "./account-setup-stack.ts";
265
-
266
- describe("AccountSetupStack", () => {
267
- it("synthesizes a GitHub OIDC provider and deploy role without AWS credentials", () => {
268
- const app = new App();
269
- const stack = new AccountSetupStack(app, "AccountSetupStack", {
270
- repositoryOwner: "octo",
271
- repositoryName: "aws-ops",
272
- });
273
- const template = Template.fromStack(stack);
274
-
275
- template.resourceCountIs("AWS::IAM::OIDCProvider", 1);
276
- template.hasResourceProperties("AWS::IAM::Role", {
277
- RoleName: "GitHubActionsCdkDeployRole",
278
- });
279
- expect(JSON.stringify(template.toJSON())).toContain("repo:octo/aws-ops:*");
280
- });
281
- });
282
- `;
283
- const GITHUB_REPOSITORY = `const GITHUB_SLUG = /^[A-Za-z0-9_.-]+\\/[A-Za-z0-9_.-]+$/;
284
- const GITHUB_URL = /github\\.com[:/]([^/]+)\\/([^/#?\\s]+?)(?:\\.git)?$/;
285
-
286
- export type GitHubRepository = {
287
- owner: string;
288
- name: string;
289
- };
290
-
291
- export function resolveGitHubRepository(input: {
292
- contextOwner?: unknown;
293
- contextName?: unknown;
294
- env?: Record<string, string | undefined>;
295
- repositoryUrl?: string;
296
- packageName?: string;
297
- }): GitHubRepository {
298
- const context = pair(input.contextOwner, input.contextName);
299
- if (context) {
300
- return context;
301
- }
302
-
303
- const fromEnv = parseSlug(input.env?.GITHUB_REPOSITORY);
304
- if (fromEnv) {
305
- return fromEnv;
306
- }
307
-
308
- const fromUrl = parseRepositoryUrl(input.repositoryUrl);
309
- if (fromUrl) {
310
- return fromUrl;
311
- }
312
-
313
- return { owner: "owner", name: input.packageName || "repo" };
314
- }
315
-
316
- function pair(owner: unknown, name: unknown): GitHubRepository | undefined {
317
- if (typeof owner !== "string" || typeof name !== "string") {
318
- return undefined;
319
- }
320
- const trimmedOwner = owner.trim();
321
- const trimmedName = name.trim();
322
- if (!trimmedOwner || !trimmedName) {
323
- return undefined;
324
- }
325
- return { owner: trimmedOwner, name: trimmedName };
326
- }
327
-
328
- function parseSlug(value: string | undefined): GitHubRepository | undefined {
329
- const trimmed = value?.trim();
330
- if (!trimmed || !GITHUB_SLUG.test(trimmed)) {
331
- return undefined;
332
- }
333
- const [owner, name] = trimmed.split("/");
334
- if (!owner || !name) {
335
- return undefined;
336
- }
337
- return { owner, name };
338
- }
339
-
340
- function parseRepositoryUrl(value: string | undefined): GitHubRepository | undefined {
341
- const trimmed = value?.trim();
342
- if (!trimmed) {
343
- return undefined;
344
- }
345
- const slug = parseSlug(trimmed);
346
- if (slug) {
347
- return slug;
348
- }
349
- const match = GITHUB_URL.exec(trimmed);
350
- const owner = match?.[1];
351
- const name = match?.[2];
352
- if (!owner || !name) {
353
- return undefined;
354
- }
355
- return { owner, name };
356
- }
357
- `;
358
- const GITHUB_REPOSITORY_TEST = `import { describe, expect, it } from "vite-plus/test";
359
-
360
- import { resolveGitHubRepository } from "./github-repository.ts";
361
-
362
- describe("resolveGitHubRepository", () => {
363
- it("prefers CDK context, then GitHub env, then the repository URL", () => {
364
- expect(
365
- resolveGitHubRepository({
366
- contextOwner: "from-context",
367
- contextName: "repo",
368
- env: { GITHUB_REPOSITORY: "from-env/repo" },
369
- repositoryUrl: "https://github.com/from-url/repo",
370
- }),
371
- ).toEqual({ owner: "from-context", name: "repo" });
372
-
373
- expect(
374
- resolveGitHubRepository({
375
- env: { GITHUB_REPOSITORY: "from-env/repo" },
376
- repositoryUrl: "git+https://github.com/from-url/repo.git",
377
- }),
378
- ).toEqual({ owner: "from-env", name: "repo" });
379
-
380
- expect(
381
- resolveGitHubRepository({
382
- repositoryUrl: "https://github.com/from-url/repo.git",
383
- packageName: "aws-ops",
384
- }),
385
- ).toEqual({ owner: "from-url", name: "repo" });
386
- });
387
-
388
- it("falls back to the package name so synth still has a subject", () => {
389
- expect(resolveGitHubRepository({ packageName: "aws-ops" })).toEqual({
390
- owner: "owner",
391
- name: "aws-ops",
392
- });
393
- });
394
- });
395
- `;
396
- //#endregion
397
- //#region src/bingo-blocks/blockCdkPreflight/blockCdkPreflight.ts
398
- const cdkPreflightRange = "^1.20.19";
399
- const blockCdkPreflight = base.createBlock({
400
- about: { name: "CDK Preflight" },
401
- produce() {
402
- return { extensions: [blockPackageJson({ properties: { devDependencies: { "cdk-preflight": cdkPreflightRange } } })] };
403
- }
404
- });
405
- //#endregion
406
- //#region src/bingo-blocks/index.ts
407
- function cdkToolbox() {
408
- return base.createPreset({
409
- about: { name: "cdk-toolbox" },
410
- blocks: [
411
- blockPackageJson,
412
- blockCdkPreflight,
413
- blockCdkApps
414
- ]
415
- });
416
- }
417
- //#endregion
418
- export { blockCdkApps, blockCdkPreflight, cdkToolbox };
1
+ import { a as DEFAULT_CDK_OWNER, i as CDK_APP_DIRECTORY, n as blockCdkPreflight, o as blockCdkApps, r as ACCOUNT_SETUP_DIRECTORY, s as createBlockCdkApps, t as cdkToolbox } from "./bingo-blocks-CZonM9Rp.mjs";
2
+ export { ACCOUNT_SETUP_DIRECTORY, CDK_APP_DIRECTORY, DEFAULT_CDK_OWNER, blockCdkApps, blockCdkPreflight, cdkToolbox, createBlockCdkApps };
@@ -0,0 +1,20 @@
1
+ import { a as DEFAULT_CDK_OWNER, i as CDK_APP_DIRECTORY, n as blockCdkPreflight, o as blockCdkApps, r as ACCOUNT_SETUP_DIRECTORY, t as cdkToolbox } from "./bingo-blocks-CZonM9Rp.mjs";
2
+ import { definePlugin } from "@jaykingson/vite-plus-base";
3
+ //#region src/vite-plus-base.ts
4
+ const cdkToolboxPlugin = definePlugin({
5
+ apiVersion: 1,
6
+ id: "cdk-toolbox",
7
+ description: "CDK app and account-setup packages for a vite-plus-base repository.",
8
+ directories: [CDK_APP_DIRECTORY, ACCOUNT_SETUP_DIRECTORY],
9
+ options: { owner: {
10
+ type: "string",
11
+ message: "GitHub repository owner for the account setup app",
12
+ default: DEFAULT_CDK_OWNER
13
+ } },
14
+ blocks: [blockCdkPreflight, blockCdkApps],
15
+ preset(options) {
16
+ return cdkToolbox({ owner: options.owner });
17
+ }
18
+ });
19
+ //#endregion
20
+ export { cdkToolboxPlugin as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jaykingson/cdk-toolbox",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "CDK apps and bingo blocks for vite-plus-base.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -9,6 +9,7 @@
9
9
  },
10
10
  "files": [
11
11
  "dist",
12
+ "src/vite-plus-base.ts",
12
13
  "src/bingo-blocks/index.ts",
13
14
  "src/bingo-blocks/blockCdkPreflight/blockCdkPreflight.ts",
14
15
  "src/bingo-blocks/blockCdkApps/blockCdkApps.ts"
@@ -19,10 +20,14 @@
19
20
  "types": "./src/bingo-blocks/index.ts",
20
21
  "default": "./dist/bingo-blocks.mjs"
21
22
  },
23
+ "./vite-plus-base": {
24
+ "types": "./src/vite-plus-base.ts",
25
+ "default": "./dist/vite-plus-base.mjs"
26
+ },
22
27
  "./package.json": "./package.json"
23
28
  },
24
29
  "devDependencies": {
25
- "@jaykingson/vite-plus-base": "0.0.13",
30
+ "@jaykingson/vite-plus-base": "0.0.19",
26
31
  "@types/node": "^24",
27
32
  "bingo-stratum": "0.11.1",
28
33
  "dependency-cruiser": "^18.5.0",
@@ -33,7 +38,7 @@
33
38
  "vitest": "5.0.3"
34
39
  },
35
40
  "peerDependencies": {
36
- "@jaykingson/vite-plus-base": ">=0.0.13"
41
+ "@jaykingson/vite-plus-base": ">=0.0.19"
37
42
  },
38
43
  "devEngines": {
39
44
  "packageManager": {
@@ -14,32 +14,51 @@ const CDK_DEV_DEPENDENCIES = {
14
14
  const CDK_APP_PACKAGE = "cdk-app";
15
15
  const ACCOUNT_SETUP_PACKAGE = "cdk-account-setup";
16
16
 
17
+ /** Fallback already written into the account-setup scaffold. Create passes a replacement. */
18
+ export const DEFAULT_CDK_OWNER = "owner";
19
+
20
+ /**
21
+ * Directories setup creates. The package name is the directory basename, which
22
+ * is what selects the scaffold. This repo's own apps use different names, so a
23
+ * bingo run here still only adds the CDK devDependencies.
24
+ */
25
+ export const CDK_APP_DIRECTORY = "apps/cdk-app";
26
+ export const ACCOUNT_SETUP_DIRECTORY = "apps/cdk-account-setup";
27
+
17
28
  type ScaffoldPackage = typeof CDK_APP_PACKAGE | typeof ACCOUNT_SETUP_PACKAGE;
18
29
 
19
- export const blockCdkApps = base.createBlock({
20
- about: {
21
- name: "CDK Apps",
22
- },
23
- produce({ options }) {
24
- const extensions = [
25
- blockPackageJson({
26
- properties: {
27
- devDependencies: { ...CDK_DEV_DEPENDENCIES },
28
- },
29
- }),
30
- ];
31
- const name = "name" in options && typeof options.name === "string" ? options.name : undefined;
32
- const scaffold = scaffoldPackage(name);
33
- if (!scaffold) {
34
- return { extensions };
35
- }
30
+ export function createBlockCdkApps(owner: string = DEFAULT_CDK_OWNER) {
31
+ const accountOwner = owner.trim() || DEFAULT_CDK_OWNER;
32
+ return base.createBlock({
33
+ about: {
34
+ name: "CDK Apps",
35
+ },
36
+ produce({ options }) {
37
+ const extensions = [
38
+ blockPackageJson({
39
+ properties: {
40
+ devDependencies: { ...CDK_DEV_DEPENDENCIES },
41
+ },
42
+ }),
43
+ ];
44
+ const name = "name" in options && typeof options.name === "string" ? options.name : undefined;
45
+ const scaffold = scaffoldPackage(name);
46
+ if (!scaffold) {
47
+ return { extensions };
48
+ }
49
+
50
+ return {
51
+ extensions,
52
+ files:
53
+ scaffold === CDK_APP_PACKAGE
54
+ ? cdkAppFiles(accountOwner)
55
+ : accountSetupFiles(accountOwner),
56
+ };
57
+ },
58
+ });
59
+ }
36
60
 
37
- return {
38
- extensions,
39
- files: scaffold === CDK_APP_PACKAGE ? cdkAppFiles() : accountSetupFiles(),
40
- };
41
- },
42
- });
61
+ export const blockCdkApps = createBlockCdkApps();
43
62
 
44
63
  function scaffoldPackage(name: string | undefined): ScaffoldPackage | undefined {
45
64
  if (name === CDK_APP_PACKAGE || name === ACCOUNT_SETUP_PACKAGE) {
@@ -48,11 +67,11 @@ function scaffoldPackage(name: string | undefined): ScaffoldPackage | undefined
48
67
  return undefined;
49
68
  }
50
69
 
51
- function cdkAppFiles() {
70
+ function cdkAppFiles(owner: string) {
52
71
  return {
53
72
  ".gitignore": "cdk.out\n",
54
73
  "cdk.json": cdkJson(),
55
- "vite.config.ts": applicationConfig(),
74
+ "vite.config.ts": applicationConfig(owner, true),
56
75
  bin: {
57
76
  "app.ts": CDK_APP_BIN,
58
77
  },
@@ -63,19 +82,19 @@ function cdkAppFiles() {
63
82
  };
64
83
  }
65
84
 
66
- function accountSetupFiles() {
85
+ function accountSetupFiles(owner: string) {
67
86
  return {
68
87
  ".gitignore": "cdk.out\n",
69
88
  "cdk.json": cdkJson(),
70
- "vite.config.ts": applicationConfig(),
89
+ "vite.config.ts": applicationConfig(owner, true),
71
90
  bin: {
72
91
  "app.ts": ACCOUNT_SETUP_BIN,
73
92
  },
74
93
  lib: {
75
- "account-setup-stack.ts": ACCOUNT_SETUP_STACK,
94
+ "account-setup-stack.ts": accountSetupStack(owner),
76
95
  "account-setup-stack.test.ts": ACCOUNT_SETUP_STACK_TEST,
77
- "github-repository.ts": GITHUB_REPOSITORY,
78
- "github-repository.test.ts": GITHUB_REPOSITORY_TEST,
96
+ "github-repository.ts": githubRepository(owner),
97
+ "github-repository.test.ts": githubRepositoryTest(owner),
79
98
  },
80
99
  };
81
100
  }
@@ -94,13 +113,27 @@ function cdkJson() {
94
113
  )}\n`;
95
114
  }
96
115
 
97
- function applicationConfig() {
98
- return `import { cdkToolbox } from "@jaykingson/cdk-toolbox/bingo-blocks";
116
+ function applicationConfig(owner: string, synthCheck: boolean) {
117
+ const checkTasks = synthCheck
118
+ ? ` "check-synth": {
119
+ command: "cdk synth",
120
+ cache: false,
121
+ },
122
+ "check-all": {
123
+ command: "vp run check-synth",
124
+ cache: false,
125
+ },`
126
+ : ` "check-all": {
127
+ command: "echo \\"no checks yet\\"",
128
+ cache: false,
129
+ },`;
130
+
131
+ return `import cdkToolbox from "@jaykingson/cdk-toolbox/vite-plus-base";
99
132
  import { defineApplicationConfig } from "@jaykingson/vite-plus-base";
100
133
 
101
134
  export default defineApplicationConfig({
102
135
  bingo: {
103
- plugins: [cdkToolbox()],
136
+ plugins: [cdkToolbox.preset({ owner: ${JSON.stringify(owner)} })],
104
137
  },
105
138
  run: {
106
139
  tasks: {
@@ -116,6 +149,7 @@ export default defineApplicationConfig({
116
149
  command: "cdk deploy --all",
117
150
  cache: false,
118
151
  },
152
+ ${checkTasks}
119
153
  },
120
154
  },
121
155
  test: {
@@ -221,7 +255,8 @@ function repositoryUrl(repository: unknown): string | undefined {
221
255
  }
222
256
  `;
223
257
 
224
- const ACCOUNT_SETUP_STACK = `import { Aws, CfnOutput, Stack, type StackProps } from "aws-cdk-lib";
258
+ function accountSetupStack(owner: string) {
259
+ return `import { Aws, CfnOutput, Stack, type StackProps } from "aws-cdk-lib";
225
260
  import {
226
261
  OidcProviderNative,
227
262
  PolicyStatement,
@@ -252,7 +287,7 @@ export class AccountSetupStack extends Stack {
252
287
  constructor(scope: Construct, id: string, props: AccountSetupStackProps = {}) {
253
288
  super(scope, id, props);
254
289
 
255
- const owner = props.repositoryOwner ?? "owner";
290
+ const owner = props.repositoryOwner ?? ${JSON.stringify(owner)};
256
291
  const name = props.repositoryName ?? "repo";
257
292
  const repository = \`\${owner}/\${name}\`;
258
293
 
@@ -296,6 +331,7 @@ export class AccountSetupStack extends Stack {
296
331
  }
297
332
  }
298
333
  `;
334
+ }
299
335
 
300
336
  const ACCOUNT_SETUP_STACK_TEST = `import { App } from "aws-cdk-lib";
301
337
  import { Template } from "aws-cdk-lib/assertions";
@@ -321,7 +357,8 @@ describe("AccountSetupStack", () => {
321
357
  });
322
358
  `;
323
359
 
324
- const GITHUB_REPOSITORY = `const GITHUB_SLUG = /^[A-Za-z0-9_.-]+\\/[A-Za-z0-9_.-]+$/;
360
+ function githubRepository(owner: string) {
361
+ return `const GITHUB_SLUG = /^[A-Za-z0-9_.-]+\\/[A-Za-z0-9_.-]+$/;
325
362
  const GITHUB_URL = /github\\.com[:/]([^/]+)\\/([^/#?\\s]+?)(?:\\.git)?$/;
326
363
 
327
364
  export type GitHubRepository = {
@@ -351,7 +388,7 @@ export function resolveGitHubRepository(input: {
351
388
  return fromUrl;
352
389
  }
353
390
 
354
- return { owner: "owner", name: input.packageName || "repo" };
391
+ return { owner: ${JSON.stringify(owner)}, name: input.packageName || "repo" };
355
392
  }
356
393
 
357
394
  function pair(owner: unknown, name: unknown): GitHubRepository | undefined {
@@ -396,8 +433,10 @@ function parseRepositoryUrl(value: string | undefined): GitHubRepository | undef
396
433
  return { owner, name };
397
434
  }
398
435
  `;
436
+ }
399
437
 
400
- const GITHUB_REPOSITORY_TEST = `import { describe, expect, it } from "vite-plus/test";
438
+ function githubRepositoryTest(owner: string) {
439
+ return `import { describe, expect, it } from "vite-plus/test";
401
440
 
402
441
  import { resolveGitHubRepository } from "./github-repository.ts";
403
442
 
@@ -429,9 +468,10 @@ describe("resolveGitHubRepository", () => {
429
468
 
430
469
  it("falls back to the package name so synth still has a subject", () => {
431
470
  expect(resolveGitHubRepository({ packageName: "aws-ops" })).toEqual({
432
- owner: "owner",
471
+ owner: ${JSON.stringify(owner)},
433
472
  name: "aws-ops",
434
473
  });
435
474
  });
436
475
  });
437
476
  `;
477
+ }
@@ -1,17 +1,33 @@
1
1
  import { base, blockPackageJson } from "@jaykingson/vite-plus-base/bingo";
2
2
 
3
- import { blockCdkApps } from "./blockCdkApps/blockCdkApps.ts";
3
+ import {
4
+ blockCdkApps,
5
+ createBlockCdkApps,
6
+ DEFAULT_CDK_OWNER,
7
+ } from "./blockCdkApps/blockCdkApps.ts";
4
8
  import { blockCdkPreflight } from "./blockCdkPreflight/blockCdkPreflight.ts";
5
9
 
6
- export { blockCdkApps, blockCdkPreflight };
10
+ export {
11
+ ACCOUNT_SETUP_DIRECTORY,
12
+ blockCdkApps,
13
+ CDK_APP_DIRECTORY,
14
+ createBlockCdkApps,
15
+ DEFAULT_CDK_OWNER,
16
+ } from "./blockCdkApps/blockCdkApps.ts";
17
+ export { blockCdkPreflight };
7
18
 
8
- export function cdkToolbox() {
19
+ export function cdkToolbox(options?: { owner?: string }) {
20
+ const owner = options?.owner?.trim() || DEFAULT_CDK_OWNER;
9
21
  return base.createPreset({
10
22
  about: {
11
23
  name: "cdk-toolbox",
12
24
  },
13
25
  // Package scope does not include the base preset, and extensions only apply
14
26
  // to blocks already in the preset. Package JSON has to travel with the block.
15
- blocks: [blockPackageJson, blockCdkPreflight, blockCdkApps],
27
+ blocks: [
28
+ blockPackageJson,
29
+ blockCdkPreflight,
30
+ owner === DEFAULT_CDK_OWNER ? blockCdkApps : createBlockCdkApps(owner),
31
+ ],
16
32
  });
17
33
  }
@@ -0,0 +1,30 @@
1
+ import { definePlugin } from "@jaykingson/vite-plus-base";
2
+
3
+ import {
4
+ ACCOUNT_SETUP_DIRECTORY,
5
+ blockCdkApps,
6
+ blockCdkPreflight,
7
+ CDK_APP_DIRECTORY,
8
+ cdkToolbox,
9
+ DEFAULT_CDK_OWNER,
10
+ } from "./bingo-blocks/index.ts";
11
+
12
+ const cdkToolboxPlugin = definePlugin({
13
+ apiVersion: 1,
14
+ id: "cdk-toolbox",
15
+ description: "CDK app and account-setup packages for a vite-plus-base repository.",
16
+ directories: [CDK_APP_DIRECTORY, ACCOUNT_SETUP_DIRECTORY],
17
+ options: {
18
+ owner: {
19
+ type: "string",
20
+ message: "GitHub repository owner for the account setup app",
21
+ default: DEFAULT_CDK_OWNER,
22
+ },
23
+ },
24
+ blocks: [blockCdkPreflight, blockCdkApps],
25
+ preset(options) {
26
+ return cdkToolbox({ owner: options.owner });
27
+ },
28
+ });
29
+
30
+ export default cdkToolboxPlugin;