@codedrifters/configulator 0.0.196 → 0.0.198

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/lib/index.mjs CHANGED
@@ -2990,6 +2990,15 @@ var VERSION = {
2990
2990
  * Version of Projen to use.
2991
2991
  */
2992
2992
  PROJEN_VERSION: "0.99.48",
2993
+ /**
2994
+ * Version of sharp to pin for StarlightProject (required peer for
2995
+ * Starlight's image optimization pipeline).
2996
+ */
2997
+ SHARP_VERSION: "0.34.5",
2998
+ /**
2999
+ * Version of @astrojs/starlight to pin for StarlightProject scaffolding.
3000
+ */
3001
+ STARLIGHT_VERSION: "0.38.3",
2993
3002
  /**
2994
3003
  * What version of the turborepo library should we use?
2995
3004
  */
@@ -4751,6 +4760,8 @@ var VERSION_NPM_PACKAGES = [
4751
4760
  { key: "AWS_CONSTRUCTS_VERSION", npmPackage: "constructs" },
4752
4761
  { key: "PNPM_VERSION", npmPackage: "pnpm" },
4753
4762
  { key: "PROJEN_VERSION", npmPackage: "projen" },
4763
+ { key: "SHARP_VERSION", npmPackage: "sharp" },
4764
+ { key: "STARLIGHT_VERSION", npmPackage: "@astrojs/starlight" },
4754
4765
  { key: "TURBO_VERSION", npmPackage: "turbo" },
4755
4766
  { key: "TYPES_NODE_VERSION", npmPackage: "@types/node" },
4756
4767
  { key: "VITEST_VERSION", npmPackage: "vitest" }
@@ -6140,6 +6151,210 @@ var AwsDeployWorkflow = class _AwsDeployWorkflow extends Component16 {
6140
6151
  }
6141
6152
  };
6142
6153
 
6154
+ // src/workflows/aws-teardown-workflow.ts
6155
+ import { Component as Component17 } from "projen";
6156
+ import { GitHub as GitHub3, GithubWorkflow } from "projen/lib/github";
6157
+ import { JobPermission as JobPermission6 } from "projen/lib/github/workflows-model";
6158
+ var DEFAULT_TEARDOWN_BRANCH_PATTERNS = [
6159
+ "feat/*",
6160
+ "fix/*",
6161
+ "feature/*"
6162
+ ];
6163
+ var resolveBranchPatterns = (explicit, targets) => {
6164
+ if (explicit && explicit.length > 0) {
6165
+ return [...explicit];
6166
+ }
6167
+ const derived = Array.from(
6168
+ new Set(
6169
+ targets.flatMap((target) => target.branches.map((b) => b.branch)).filter((branch) => typeof branch === "string").filter((branch) => branch.includes("*"))
6170
+ )
6171
+ );
6172
+ if (derived.length > 0) {
6173
+ return derived;
6174
+ }
6175
+ return [...DEFAULT_TEARDOWN_BRANCH_PATTERNS];
6176
+ };
6177
+ var AwsTeardownWorkflow = class extends Component17 {
6178
+ constructor(rootProject, options) {
6179
+ super(rootProject);
6180
+ this.rootProject = rootProject;
6181
+ const {
6182
+ awsDestructionTargets,
6183
+ repoTagName,
6184
+ stageTypeTagName,
6185
+ environmentTypeTagName,
6186
+ branchNameTagName,
6187
+ deleteBranchPatterns
6188
+ } = options;
6189
+ if (!repoTagName) {
6190
+ throw new Error("AwsTeardownWorkflow requires `repoTagName`");
6191
+ }
6192
+ if (!stageTypeTagName) {
6193
+ throw new Error("AwsTeardownWorkflow requires `stageTypeTagName`");
6194
+ }
6195
+ if (!environmentTypeTagName) {
6196
+ throw new Error("AwsTeardownWorkflow requires `environmentTypeTagName`");
6197
+ }
6198
+ if (!branchNameTagName) {
6199
+ throw new Error("AwsTeardownWorkflow requires `branchNameTagName`");
6200
+ }
6201
+ if (!(rootProject instanceof MonorepoProject)) {
6202
+ throw new Error(
6203
+ "AwsTeardownWorkflow requires the root project to be a MonorepoProject"
6204
+ );
6205
+ }
6206
+ const github = GitHub3.of(this.rootProject);
6207
+ if (!github) {
6208
+ throw new Error(
6209
+ "AwsTeardownWorkflow requires a GitHub component in the root project"
6210
+ );
6211
+ }
6212
+ const branchPatterns = resolveBranchPatterns(
6213
+ deleteBranchPatterns,
6214
+ awsDestructionTargets
6215
+ );
6216
+ const workflow = new GithubWorkflow(github, "teardown-dev");
6217
+ workflow.on({
6218
+ workflowDispatch: {},
6219
+ schedule: [
6220
+ {
6221
+ cron: "32 6 * * *"
6222
+ }
6223
+ ],
6224
+ delete: {
6225
+ branches: branchPatterns
6226
+ }
6227
+ });
6228
+ awsDestructionTargets.forEach((target) => {
6229
+ const {
6230
+ awsStageType,
6231
+ deploymentTargetRole,
6232
+ account,
6233
+ region,
6234
+ ciDeploymentConfig
6235
+ } = target;
6236
+ const { roleArn } = ciDeploymentConfig ?? {};
6237
+ workflow.addJob(
6238
+ `teardown-${awsStageType}-${deploymentTargetRole}-${account}-${region}`.toLowerCase(),
6239
+ {
6240
+ name: `Teardown Stacks in ${awsStageType}/${deploymentTargetRole}/${account}/${region}`,
6241
+ runsOn: ["ubuntu-latest"],
6242
+ permissions: {
6243
+ contents: JobPermission6.READ,
6244
+ idToken: JobPermission6.WRITE
6245
+ },
6246
+ env: {
6247
+ REPO: "${{ github.repository }}",
6248
+ REGIONS: [region].join(" ")
6249
+ },
6250
+ steps: [
6251
+ {
6252
+ name: `AWS Creds ${account}/${region}`,
6253
+ uses: "aws-actions/configure-aws-credentials@v6",
6254
+ with: {
6255
+ "role-to-assume": roleArn,
6256
+ "aws-region": region,
6257
+ "role-duration-seconds": 900
6258
+ }
6259
+ },
6260
+ {
6261
+ name: "Fetch All Branches",
6262
+ id: "fetch_branches",
6263
+ uses: "actions/github-script@v9",
6264
+ with: {
6265
+ script: [
6266
+ "const all = await github.paginate(github.rest.repos.listBranches, {",
6267
+ " owner: context.repo.owner,",
6268
+ " repo: context.repo.repo,",
6269
+ " per_page: 100",
6270
+ "});",
6271
+ "const names = all.map(b => b.name);",
6272
+ "console.log(`Found branches: ${names}`);",
6273
+ 'core.setOutput("json", JSON.stringify(names));'
6274
+ ].join("\n")
6275
+ }
6276
+ },
6277
+ {
6278
+ name: "Save Branches to File",
6279
+ run: [
6280
+ 'echo "Saving branches to file"',
6281
+ "echo '${{ steps.fetch_branches.outputs.json }}' | jq -r '.[]' | sort -u > branches.txt",
6282
+ 'echo "Branches:"',
6283
+ "cat branches.txt"
6284
+ ].join("\n")
6285
+ },
6286
+ {
6287
+ name: "Find Stacks by Tag",
6288
+ id: "find_stacks",
6289
+ run: [
6290
+ "set -euo pipefail",
6291
+ ": > candidates.txt # columns: arn region branchTag",
6292
+ "# Build tag filters",
6293
+ `TAG_FILTERS=( "Key=${repoTagName},Values=$REPO" )`,
6294
+ `TAG_FILTERS+=( "Key=${stageTypeTagName},Values=${awsStageType}" )`,
6295
+ `TAG_FILTERS+=( "Key=${environmentTypeTagName},Values=${deploymentTargetRole}" )`,
6296
+ "for r in $REGIONS; do",
6297
+ ` echo "Scanning region: $r"`,
6298
+ " aws resourcegroupstaggingapi get-resources \\",
6299
+ ' --region "$r" \\',
6300
+ ' --resource-type-filters "cloudformation:stack" \\',
6301
+ ' --tag-filters "${TAG_FILTERS[@]}" \\',
6302
+ ` | jq -r --arg r "$r" '`,
6303
+ " .ResourceTagMappingList[]",
6304
+ " | . as $res",
6305
+ ` | ($res.Tags[] | select(.Key=="${branchNameTagName}") | .Value) as $branch`,
6306
+ ' | [$res.ResourceARN, $r, ($branch // "")]',
6307
+ " | @tsv",
6308
+ " ' >> candidates.txt",
6309
+ "done",
6310
+ "echo 'Tagged stacks:'",
6311
+ `(echo -e "ARN\\tREGION\\tBRANCH"; cat candidates.txt) | column -t -s $'\\t'`
6312
+ ].join("\n")
6313
+ },
6314
+ {
6315
+ name: "Determine Orphan Stacks (No Matching Branch)",
6316
+ run: [
6317
+ "set -euo pipefail",
6318
+ ": > orphans.txt # arn region branch",
6319
+ "while IFS=$'\\t' read -r arn region branch; do",
6320
+ ' [ -z "$arn" ] && continue',
6321
+ ' if [ -z "$branch" ]; then',
6322
+ " # If no Branch tag, treat as not-a-preview; skip",
6323
+ " continue",
6324
+ " fi",
6325
+ ' if ! grep -Fxq "$branch" branches.txt; then',
6326
+ ' echo -e "$arn\\t$region\\t$branch" >> orphans.txt',
6327
+ " fi",
6328
+ "done < candidates.txt",
6329
+ "",
6330
+ "if [ -s orphans.txt ]; then",
6331
+ ' echo "Orphan stacks (no matching branch):"',
6332
+ ` (echo -e "ARN\\tREGION\\tBRANCH"; cat orphans.txt) | column -t -s $'\\t'`,
6333
+ "else",
6334
+ ' echo "No orphan stacks found."',
6335
+ "fi"
6336
+ ].join("\n")
6337
+ },
6338
+ {
6339
+ name: "Delete Orphan Stacks",
6340
+ if: "hashFiles('orphans.txt') != ''",
6341
+ run: [
6342
+ "set -euo pipefail",
6343
+ "while IFS=$'\\t' read -r arn region branch; do",
6344
+ ' [ -z "$arn" ] && continue',
6345
+ ` stack_name=$(cut -d'/' -f2 <<<"$arn")`,
6346
+ ' echo "Deleting $stack_name (branch=$branch) in $region"',
6347
+ ' aws cloudformation delete-stack --region "$region" --stack-name "$stack_name" || true',
6348
+ "done < orphans.txt"
6349
+ ].join("\n")
6350
+ }
6351
+ ]
6352
+ }
6353
+ );
6354
+ });
6355
+ }
6356
+ };
6357
+
6143
6358
  // src/projects/aws-cdk-project.ts
6144
6359
  var AwsCdkProject = class extends awscdk.AwsCdkTypeScriptApp {
6145
6360
  constructor(userOptions) {
@@ -6272,6 +6487,9 @@ var AwsCdkProject = class extends awscdk.AwsCdkTypeScriptApp {
6272
6487
  deployWorkflows.forEach(
6273
6488
  (workflowOptions) => new AwsDeployWorkflow(this, workflowOptions)
6274
6489
  );
6490
+ if (options.teardownWorkflow) {
6491
+ new AwsTeardownWorkflow(parent, options.teardownWorkflow);
6492
+ }
6275
6493
  const turboActive = TurboRepo.of(parent) !== void 0;
6276
6494
  if (turboActive) {
6277
6495
  const turbo = new TurboRepo(this);
@@ -6330,11 +6548,96 @@ var AwsCdkProject = class extends awscdk.AwsCdkTypeScriptApp {
6330
6548
  }
6331
6549
  };
6332
6550
 
6551
+ // src/projects/starlight-project.ts
6552
+ import { SampleFile as SampleFile2 } from "projen";
6553
+ var StarlightProject = class extends AstroProject {
6554
+ constructor(userOptions) {
6555
+ const starlightConfig = buildStarlightConfig(userOptions);
6556
+ const starlightSpec = {
6557
+ name: "starlight",
6558
+ importPath: "@astrojs/starlight",
6559
+ defaultImport: true,
6560
+ args: JSON.stringify(starlightConfig, null, 2)
6561
+ };
6562
+ const mergedOptions = {
6563
+ ...userOptions,
6564
+ integrations: [starlightSpec, ...userOptions.integrations ?? []],
6565
+ depsUpgradeOptions: {
6566
+ ...userOptions.depsUpgradeOptions,
6567
+ exclude: [
6568
+ ...userOptions.depsUpgradeOptions?.exclude ?? [],
6569
+ "@astrojs/starlight",
6570
+ "sharp"
6571
+ ]
6572
+ }
6573
+ };
6574
+ super(mergedOptions);
6575
+ const starlightVersion = userOptions.starlightVersion ?? VERSION.STARLIGHT_VERSION;
6576
+ const sharpVersion = userOptions.sharpVersion ?? VERSION.SHARP_VERSION;
6577
+ this.addDeps(
6578
+ `@astrojs/starlight@${starlightVersion}`,
6579
+ `sharp@${sharpVersion}`
6580
+ );
6581
+ const turbo = TurboRepo.of(this);
6582
+ if (turbo?.compileTask) {
6583
+ turbo.compileTask.inputs.push("src/content/**");
6584
+ }
6585
+ if (userOptions.sampleContent === true) {
6586
+ new SampleFile2(this, "src/content/docs/index.mdx", {
6587
+ contents: DEFAULT_INDEX_MDX
6588
+ });
6589
+ new SampleFile2(this, "src/content/config.ts", {
6590
+ contents: DEFAULT_CONTENT_CONFIG_TS
6591
+ });
6592
+ }
6593
+ }
6594
+ };
6595
+ function buildStarlightConfig(options) {
6596
+ const config = {
6597
+ title: options.starlightTitle
6598
+ };
6599
+ if (options.starlightDescription !== void 0) {
6600
+ config.description = options.starlightDescription;
6601
+ }
6602
+ if (options.social !== void 0) {
6603
+ config.social = options.social;
6604
+ }
6605
+ if (options.sidebar !== void 0) {
6606
+ config.sidebar = options.sidebar;
6607
+ }
6608
+ if (options.customCss !== void 0) {
6609
+ config.customCss = options.customCss;
6610
+ }
6611
+ if (options.logo !== void 0) {
6612
+ config.logo = options.logo;
6613
+ }
6614
+ if (options.editLink !== void 0) {
6615
+ config.editLink = options.editLink;
6616
+ }
6617
+ return config;
6618
+ }
6619
+ var DEFAULT_INDEX_MDX = `---
6620
+ title: Welcome
6621
+ description: Starlight-powered documentation site.
6622
+ ---
6623
+
6624
+ # Hello, Starlight!
6625
+
6626
+ Edit \`src/content/docs/index.mdx\` to replace this page.
6627
+ `;
6628
+ var DEFAULT_CONTENT_CONFIG_TS = `import { defineCollection } from "astro:content";
6629
+ import { docsSchema } from "@astrojs/starlight/schema";
6630
+
6631
+ export const collections = {
6632
+ docs: defineCollection({ schema: docsSchema() }),
6633
+ };
6634
+ `;
6635
+
6333
6636
  // src/typescript/typescript-config.ts
6334
6637
  import { relative as relative4 } from "path";
6335
- import { Component as Component17 } from "projen";
6638
+ import { Component as Component18 } from "projen";
6336
6639
  import { ensureRelativePathStartsWithDot } from "projen/lib/util/path";
6337
- var TypeScriptConfig = class extends Component17 {
6640
+ var TypeScriptConfig = class extends Component18 {
6338
6641
  constructor(project) {
6339
6642
  super(project);
6340
6643
  let tsPaths = {};
@@ -6371,11 +6674,13 @@ export {
6371
6674
  AwsDeployWorkflow,
6372
6675
  AwsDeploymentConfig,
6373
6676
  AwsDeploymentTarget,
6677
+ AwsTeardownWorkflow,
6374
6678
  BUILT_IN_BUNDLES,
6375
6679
  CLAUDE_RULE_TARGET,
6376
6680
  COMPLETE_JOB_ID,
6377
6681
  DEFAULT_PRIORITY_LABELS,
6378
6682
  DEFAULT_STATUS_LABELS,
6683
+ DEFAULT_TEARDOWN_BRANCH_PATTERNS,
6379
6684
  DEFAULT_TYPE_LABELS,
6380
6685
  JsiiFaker,
6381
6686
  MCP_TRANSPORT,
@@ -6389,6 +6694,7 @@ export {
6389
6694
  ROOT_CI_TASK_NAME,
6390
6695
  ROOT_TURBO_TASK_NAME,
6391
6696
  ResetTask,
6697
+ StarlightProject,
6392
6698
  TestRunner,
6393
6699
  TurboRepo,
6394
6700
  TurboRepoTask,