@warpgogol/repo-extract 1.1.0

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.
Files changed (48) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +155 -0
  3. package/dist/changelog.d.ts +9 -0
  4. package/dist/changelog.d.ts.map +1 -0
  5. package/dist/changelog.js +41 -0
  6. package/dist/cli.d.ts +3 -0
  7. package/dist/cli.d.ts.map +1 -0
  8. package/dist/cli.js +61 -0
  9. package/dist/config.d.ts +69 -0
  10. package/dist/config.d.ts.map +1 -0
  11. package/dist/config.js +90 -0
  12. package/dist/errors.d.ts +16 -0
  13. package/dist/errors.d.ts.map +1 -0
  14. package/dist/errors.js +39 -0
  15. package/dist/extract.d.ts +3 -0
  16. package/dist/extract.d.ts.map +1 -0
  17. package/dist/extract.js +407 -0
  18. package/dist/fs/copy.d.ts +16 -0
  19. package/dist/fs/copy.d.ts.map +1 -0
  20. package/dist/fs/copy.js +224 -0
  21. package/dist/fs/discover.d.ts +2 -0
  22. package/dist/fs/discover.d.ts.map +1 -0
  23. package/dist/fs/discover.js +126 -0
  24. package/dist/fs/git.d.ts +10 -0
  25. package/dist/fs/git.d.ts.map +1 -0
  26. package/dist/fs/git.js +252 -0
  27. package/dist/fs/transform.d.ts +16 -0
  28. package/dist/fs/transform.d.ts.map +1 -0
  29. package/dist/fs/transform.js +539 -0
  30. package/dist/index.d.ts +10 -0
  31. package/dist/index.d.ts.map +1 -0
  32. package/dist/index.js +21 -0
  33. package/dist/log.d.ts +6 -0
  34. package/dist/log.d.ts.map +1 -0
  35. package/dist/log.js +23 -0
  36. package/dist/package-manager.d.ts +4 -0
  37. package/dist/package-manager.d.ts.map +1 -0
  38. package/dist/package-manager.js +30 -0
  39. package/dist/postprocess/index.d.ts +4 -0
  40. package/dist/postprocess/index.d.ts.map +1 -0
  41. package/dist/postprocess/index.js +70 -0
  42. package/dist/scan.d.ts +4 -0
  43. package/dist/scan.d.ts.map +1 -0
  44. package/dist/scan.js +78 -0
  45. package/dist/types.d.ts +124 -0
  46. package/dist/types.d.ts.map +1 -0
  47. package/dist/types.js +17 -0
  48. package/package.json +82 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent to
55
+ the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and gross
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing the
166
+ Work or Derivative Works thereof, You may choose to offer, and
167
+ charge a fee for, acceptance of support, warranty, indemnity, or
168
+ other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced by your own identifying information. (Don't include the
183
+ brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Andrii Syrokomskyi
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,155 @@
1
+ # @warpgogol/repo-extract
2
+
3
+ [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE) [![CI](https://img.shields.io/github/actions/workflow/status/syrokomskyi/repo-extract/ci.yml?logo=github-actions&logoColor=white)](https://github.com/syrokomskyi/repo-extract/actions) [![npm](https://img.shields.io/npm/v/@warpgogol/repo-extract?logo=npm&logoColor=white)](https://www.npmjs.com/package/@warpgogol/repo-extract)
4
+
5
+ Extract apps and packages from a TurboRepo monorepo into standalone public repositories.
6
+
7
+ ## Features
8
+
9
+ - Extracts one or more workspace projects from a Turborepo monorepo
10
+ - **Standalone mode** for single-package export (flattens to repo root)
11
+ - **Monorepo mode** for multi-app export (preserves workspace structure)
12
+ - Declarative post-process rules: copy, patch, delete
13
+ - Optional `@warpgogol/changelog-live` integration for changelog generation
14
+ - Secret scanning with configurable skip
15
+ - Git history transfer by path prefix
16
+ - Auto-generated CI workflow with npm publish
17
+ - Zod-validated `extract.config.yaml` configuration
18
+ - CLI + programmatic API
19
+
20
+ ## Quick start
21
+
22
+ ```bash
23
+ # Install
24
+ npm install -g @warpgogol/repo-extract
25
+
26
+ # Extract a project (dry-run first)
27
+ repo-extract --config extract.config.yaml --dry-run
28
+
29
+ # Extract for real
30
+ repo-extract --config extract.config.yaml --dest /path/to/dest --verbose
31
+ ```
32
+
33
+ Or use without global install:
34
+
35
+ ```bash
36
+ npx @warpgogol/repo-extract --config extract.config.yaml --dry-run
37
+ ```
38
+
39
+ ## CLI flags
40
+
41
+ | Flag | Description |
42
+ | ----------------- | ------------------------------------------------ |
43
+ | `--config <path>` | Path to `extract.config.yaml` (required) |
44
+ | `--dest <path>` | Destination directory (overrides config default) |
45
+ | `--dry-run` | Print plan without writing files |
46
+ | `--verbose` | Verbose output |
47
+
48
+ ## Configuration
49
+
50
+ Create an `extract.config.yaml` in your project:
51
+
52
+ ### Standalone single-package export
53
+
54
+ ```yaml
55
+ projectDir: packages/my-package
56
+ destName: my-package
57
+ standalone: true
58
+
59
+ git:
60
+ remote: git@github.com:user/my-package.git
61
+ autoPush: true
62
+ ```
63
+
64
+ Standalone mode flattens the package to the repo root — `src/`, `tests/`, `package.json`, etc. become top-level. Workspace dependencies (`workspace:*`) are replaced with `*`, and `@warpgogol/*` devDependencies are stripped (except the package itself).
65
+
66
+ ### Multi-app monorepo export
67
+
68
+ ```yaml
69
+ projectDir: apps/my-app
70
+ destName: my-app
71
+
72
+ appDirs:
73
+ - apps/my-app/frontend
74
+ - apps/my-app/backend
75
+
76
+ projectRootFiles:
77
+ - README.md
78
+ - LICENSE
79
+ - CONTRIBUTING.md
80
+
81
+ git:
82
+ remote: git@github.com:user/my-app.git
83
+ autoPush: true
84
+ ```
85
+
86
+ Monorepo mode preserves the workspace structure, copies monorepo config files (`turbo.json`, `pnpm-workspace.yaml`, etc.), auto-discovers package dependencies, and generates `tsconfig.base.json`.
87
+
88
+ ### Post-process rules
89
+
90
+ ```yaml
91
+ postProcess:
92
+ - action: copy
93
+ from: src/config.yaml
94
+ to: dist/config.yaml
95
+ - action: patch
96
+ file: package.json
97
+ find: "workspace:*"
98
+ replace: "^1.0.0"
99
+ - action: patch
100
+ file: tsconfig.json
101
+ removeLinesMatching: "customConditions"
102
+ - action: delete
103
+ path: AGENTS.md
104
+ ```
105
+
106
+ ### Secret scanning
107
+
108
+ By default, the export scans for common secret patterns (AWS keys, private keys, GitHub tokens, generic API keys) before committing. If secrets are found, the export aborts.
109
+
110
+ ```yaml
111
+ skipSecretScan: true # disable scanning (not recommended)
112
+ ignoreDirs:
113
+ - .input
114
+ - spec
115
+ excludePathSegments:
116
+ - .input/signing-key
117
+ - secrets
118
+ excludeExtensions:
119
+ - .db
120
+ - .sqlite
121
+ ```
122
+
123
+ ### Optional changelog integration
124
+
125
+ If `changelog.config.yaml` exists in the project directory and `@warpgogol/changelog-live` is installed, the export automatically generates a changelog before committing. The generated commit message includes the AI-generated changelog summary.
126
+
127
+ ## Programmatic API
128
+
129
+ ```ts
130
+ import { extractProject, loadConfig } from "@warpgogol/repo-extract";
131
+
132
+ const config = await loadConfig("extract.config.yaml");
133
+ await extractProject(config, { dest: "../my-package" });
134
+ ```
135
+
136
+ ### Exports
137
+
138
+ | Export | Description |
139
+ | ------------------------------------------ | -------------------------------------------- |
140
+ | `extractProject(config, options)` | Run the full extraction pipeline |
141
+ | `loadConfig(path)` | Load and validate an `extract.config.yaml` |
142
+ | `scanForSecrets(dir)` | Scan a directory for secret patterns |
143
+ | `transferGitHistory(root, dest, prefixes)` | Transfer filtered git history |
144
+ | `commitExport(dest, message, gitConfig)` | Commit and optionally push |
145
+ | `generateCiWorkflow()` | Generate a GitHub Actions CI workflow string |
146
+ | `fixStandalonePackageJson(dest)` | Fix package.json for standalone export |
147
+ | `fixStandaloneVitestConfig(dest)` | Fix vitest.config.ts for standalone export |
148
+
149
+ ## Changelog
150
+
151
+ [CHANGELOG.md](CHANGELOG.md)
152
+
153
+ ## License
154
+
155
+ Apache-2.0
@@ -0,0 +1,9 @@
1
+ import type { Logger } from "./log.js";
2
+ export interface ChangelogResult {
3
+ skipped: boolean;
4
+ commitMessage?: string;
5
+ sectionsGenerated: number;
6
+ filesWritten: string[];
7
+ }
8
+ export declare function tryGenerateChangelog(projectDir: string, logger?: Logger): Promise<ChangelogResult>;
9
+ //# sourceMappingURL=changelog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"changelog.d.ts","sourceRoot":"","sources":["../src/changelog.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEvC,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB;AAED,wBAAsB,oBAAoB,CACxC,UAAU,EAAE,MAAM,EAClB,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,eAAe,CAAC,CAyB1B"}
@@ -0,0 +1,41 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>Optional changelog-live integration via dynamic import.</purpose>
4
+ <non-goals>
5
+ <item>Does not hard-depend on @warpgogol/changelog-live — it is an optional peer dependency.</item>
6
+ </non-goals>
7
+ </MODULE_CONTRACT>
8
+ <CHANGE_SUMMARY>
9
+ <item>Initial changelog integration for RFC-0070. Uses dynamic import to gracefully handle missing peer dep.</item>
10
+ <item>RFC-0073: consolidated getLastExportDate — removed local duplicate, imports from fs/git.js.</item>
11
+ <item>RFC-0075: removed dead tryAiCommitMessage() function and unused getLastExportDate import.</item>
12
+ </CHANGE_SUMMARY>
13
+ */
14
+ import { existsSync } from "node:fs";
15
+ import * as path from "node:path";
16
+ export async function tryGenerateChangelog(projectDir, logger) {
17
+ const log = logger?.log ?? console.log;
18
+ const changelogConfigPath = path.join(projectDir, "changelog.config.yaml");
19
+ if (!existsSync(changelogConfigPath)) {
20
+ return { skipped: true, sectionsGenerated: 0, filesWritten: [] };
21
+ }
22
+ try {
23
+ const mod = await import("@warpgogol/changelog-live");
24
+ const { loadConfig, generateChangelog } = mod;
25
+ const config = await loadConfig(changelogConfigPath);
26
+ config.git.repoRoot = path.resolve(projectDir, config.git.repoRoot);
27
+ config.output.dir = path.resolve(projectDir, config.output.dir);
28
+ const result = await generateChangelog(config);
29
+ return {
30
+ skipped: result.skipped,
31
+ commitMessage: result.commitMessage,
32
+ sectionsGenerated: result.sectionsGenerated,
33
+ filesWritten: result.filesWritten,
34
+ };
35
+ }
36
+ catch (err) {
37
+ log(" changelog generation skipped (peer dep not installed or error)");
38
+ log(` ${(err instanceof Error ? err.message : String(err)).slice(0, 200)}`);
39
+ return { skipped: true, sectionsGenerated: 0, filesWritten: [] };
40
+ }
41
+ }
package/dist/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
package/dist/cli.js ADDED
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env node
2
+ /*
3
+ <MODULE_CONTRACT>
4
+ <purpose>CLI entrypoint for @warpgogol/repo-extract.</purpose>
5
+ <non-goals>
6
+ <item>Does not implement extraction logic (see extract.ts).</item>
7
+ </non-goals>
8
+ </MODULE_CONTRACT>
9
+ <CHANGE_SUMMARY>
10
+ <item>Initial CLI for RFC-0070. Supports --config, --dest, --dry-run, --verbose flags.</item>
11
+ <item>RFC-0074: Catch SecretScanError, GitOperationError, PackageManagerError and exit with code 1. Pass verbose: true.</item>
12
+ </CHANGE_SUMMARY>
13
+ */
14
+ import { Command } from "commander";
15
+ import { loadConfig } from "./config.js";
16
+ import { extractProject } from "./extract.js";
17
+ import { SecretScanError, GitOperationError, PackageManagerError } from "./errors.js";
18
+ const program = new Command();
19
+ program
20
+ .name("repo-extract")
21
+ .description("Extract apps and packages from a TurboRepo monorepo into standalone public repositories")
22
+ .option("--config <path>", "Path to extract.config.yaml")
23
+ .option("--dest <path>", "Destination directory (overrides config default)")
24
+ .option("--dry-run", "Print plan without writing files")
25
+ .option("--verbose", "Verbose output")
26
+ .action(async (opts) => {
27
+ if (!opts.config) {
28
+ console.error("Error: --config is required");
29
+ program.outputHelp();
30
+ process.exit(1);
31
+ }
32
+ const config = await loadConfig(opts.config);
33
+ try {
34
+ await extractProject(config, {
35
+ dest: opts.dest,
36
+ dryRun: opts.dryRun,
37
+ verbose: true,
38
+ });
39
+ }
40
+ catch (err) {
41
+ if (err instanceof SecretScanError) {
42
+ console.error(`\n!!! ABORTED: ${err.findings.length} secret(s) detected !!!`);
43
+ for (const f of err.findings) {
44
+ console.error(` ${f.file}:${f.line} — ${f.name}`);
45
+ console.error(` ${f.preview}`);
46
+ }
47
+ console.error("\nExport aborted. Fix the source files or add directories to ignoreDirs in config.");
48
+ process.exit(1);
49
+ }
50
+ if (err instanceof GitOperationError) {
51
+ console.error(`\nGit error: ${err.message}`);
52
+ process.exit(1);
53
+ }
54
+ if (err instanceof PackageManagerError) {
55
+ console.error(`\nPackage manager error: ${err.message}`);
56
+ process.exit(1);
57
+ }
58
+ throw err;
59
+ }
60
+ });
61
+ program.parse();
@@ -0,0 +1,69 @@
1
+ import { z } from "zod";
2
+ import type { ExtractConfig } from "./types.js";
3
+ declare const ExtractConfigSchema: z.ZodObject<{
4
+ projectDir: z.ZodString;
5
+ destName: z.ZodString;
6
+ appDirs: z.ZodDefault<z.ZodArray<z.ZodString>>;
7
+ packageDirs: z.ZodOptional<z.ZodArray<z.ZodString>>;
8
+ projectRootFiles: z.ZodOptional<z.ZodArray<z.ZodString>>;
9
+ extraGitignore: z.ZodOptional<z.ZodArray<z.ZodString>>;
10
+ batchDataDir: z.ZodOptional<z.ZodString>;
11
+ postProcess: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
12
+ action: z.ZodLiteral<"copy">;
13
+ from: z.ZodString;
14
+ to: z.ZodString;
15
+ }, z.core.$strip>, z.ZodObject<{
16
+ action: z.ZodLiteral<"patch">;
17
+ file: z.ZodString;
18
+ find: z.ZodOptional<z.ZodString>;
19
+ replace: z.ZodOptional<z.ZodString>;
20
+ removeLinesMatching: z.ZodOptional<z.ZodString>;
21
+ }, z.core.$strip>, z.ZodObject<{
22
+ action: z.ZodLiteral<"delete">;
23
+ path: z.ZodString;
24
+ }, z.core.$strip>], "action">>>;
25
+ workspacePrefixes: z.ZodDefault<z.ZodArray<z.ZodString>>;
26
+ stripScopes: z.ZodOptional<z.ZodArray<z.ZodString>>;
27
+ preservePackages: z.ZodDefault<z.ZodArray<z.ZodString>>;
28
+ rootPackageName: z.ZodOptional<z.ZodString>;
29
+ customConditions: z.ZodDefault<z.ZodArray<z.ZodString>>;
30
+ aiEcosystemFiles: z.ZodDefault<z.ZodArray<z.ZodString>>;
31
+ monorepoConfigFiles: z.ZodOptional<z.ZodArray<z.ZodString>>;
32
+ onlyBuiltDependencies: z.ZodDefault<z.ZodArray<z.ZodString>>;
33
+ destBase: z.ZodOptional<z.ZodString>;
34
+ packageManager: z.ZodOptional<z.ZodEnum<{
35
+ pnpm: "pnpm";
36
+ npm: "npm";
37
+ yarn: "yarn";
38
+ }>>;
39
+ ci: z.ZodOptional<z.ZodObject<{
40
+ provider: z.ZodDefault<z.ZodEnum<{
41
+ "github-actions": "github-actions";
42
+ none: "none";
43
+ }>>;
44
+ packageManager: z.ZodOptional<z.ZodEnum<{
45
+ pnpm: "pnpm";
46
+ npm: "npm";
47
+ yarn: "yarn";
48
+ }>>;
49
+ publish: z.ZodDefault<z.ZodBoolean>;
50
+ nodeVersion: z.ZodDefault<z.ZodNumber>;
51
+ }, z.core.$strip>>;
52
+ gitignoreMode: z.ZodDefault<z.ZodEnum<{
53
+ minimal: "minimal";
54
+ extended: "extended";
55
+ }>>;
56
+ git: z.ZodOptional<z.ZodObject<{
57
+ remote: z.ZodOptional<z.ZodString>;
58
+ autoPush: z.ZodOptional<z.ZodBoolean>;
59
+ }, z.core.$strip>>;
60
+ copyDirs: z.ZodDefault<z.ZodArray<z.ZodString>>;
61
+ standalone: z.ZodDefault<z.ZodBoolean>;
62
+ ignoreDirs: z.ZodOptional<z.ZodArray<z.ZodString>>;
63
+ excludePathSegments: z.ZodOptional<z.ZodArray<z.ZodString>>;
64
+ excludeExtensions: z.ZodOptional<z.ZodArray<z.ZodString>>;
65
+ skipSecretScan: z.ZodOptional<z.ZodBoolean>;
66
+ }, z.core.$strip>;
67
+ export declare function loadConfig(configPath: string): Promise<ExtractConfig>;
68
+ export { ExtractConfigSchema };
69
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AA4ChD,QAAA,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA4BvB,CAAC;AAEH,wBAAsB,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAQ3E;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
package/dist/config.js ADDED
@@ -0,0 +1,90 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>Zod schema and loader for extract.config.yaml files.</purpose>
4
+ <non-goals>
5
+ <item>Does not implement extraction logic (see extract.ts).</item>
6
+ </non-goals>
7
+ </MODULE_CONTRACT>
8
+ <CHANGE_SUMMARY>
9
+ <item>Initial config schema and loader for RFC-0070.</item>
10
+ <item>RFC-0071: Added stripScopes, preservePackages, rootPackageName, customConditions, aiEcosystemFiles, monorepoConfigFiles, onlyBuiltDependencies, destBase, packageManager, gitignoreMode. Changed workspacePrefixes default to [] and copyDirs default to [].</item>
11
+ <item>RFC-0072: Changed packageManager from string to enum. Added CiConfigSchema and ci field.</item>
12
+ <item>RFC-0075: Added excludePathSegments and excludeExtensions fields.</item>
13
+ <item>ADR-0016: Config schema is the single source of truth — all org-specific values are config fields with org-neutral defaults, no behavioral assumptions baked into source code.</item>
14
+ </CHANGE_SUMMARY>
15
+ */
16
+ import { readFile } from "node:fs/promises";
17
+ import { parse as parseYaml } from "yaml";
18
+ import { z } from "zod";
19
+ const GitConfigSchema = z.object({
20
+ remote: z.string().optional(),
21
+ autoPush: z.boolean().optional(),
22
+ });
23
+ const CopyRuleSchema = z.object({
24
+ action: z.literal("copy"),
25
+ from: z.string(),
26
+ to: z.string(),
27
+ });
28
+ const PatchRuleSchema = z
29
+ .object({
30
+ action: z.literal("patch"),
31
+ file: z.string(),
32
+ find: z.string().optional(),
33
+ replace: z.string().optional(),
34
+ removeLinesMatching: z.string().optional(),
35
+ })
36
+ .refine((v) => v.removeLinesMatching !== undefined || (v.find !== undefined && v.replace !== undefined), { message: "patch rule must have either (find + replace) or removeLinesMatching" });
37
+ const DeleteRuleSchema = z.object({
38
+ action: z.literal("delete"),
39
+ path: z.string(),
40
+ });
41
+ const PostProcessRuleSchema = z.discriminatedUnion("action", [
42
+ CopyRuleSchema,
43
+ PatchRuleSchema,
44
+ DeleteRuleSchema,
45
+ ]);
46
+ const CiConfigSchema = z.object({
47
+ provider: z.enum(["github-actions", "none"]).default("github-actions"),
48
+ packageManager: z.enum(["pnpm", "npm", "yarn"]).optional(),
49
+ publish: z.boolean().default(true),
50
+ nodeVersion: z.number().default(22),
51
+ });
52
+ const ExtractConfigSchema = z.object({
53
+ projectDir: z.string().min(1),
54
+ destName: z.string().min(1),
55
+ appDirs: z.array(z.string()).default([]),
56
+ packageDirs: z.array(z.string()).optional(),
57
+ projectRootFiles: z.array(z.string()).optional(),
58
+ extraGitignore: z.array(z.string()).optional(),
59
+ batchDataDir: z.string().optional(),
60
+ postProcess: z.array(PostProcessRuleSchema).optional(),
61
+ workspacePrefixes: z.array(z.string()).default([]),
62
+ stripScopes: z.array(z.string()).optional(),
63
+ preservePackages: z.array(z.string()).default([]),
64
+ rootPackageName: z.string().optional(),
65
+ customConditions: z.array(z.string()).default([]),
66
+ aiEcosystemFiles: z.array(z.string()).default([]),
67
+ monorepoConfigFiles: z.array(z.string()).optional(),
68
+ onlyBuiltDependencies: z.array(z.string()).default([]),
69
+ destBase: z.string().optional(),
70
+ packageManager: z.enum(["pnpm", "npm", "yarn"]).optional(),
71
+ ci: CiConfigSchema.optional(),
72
+ gitignoreMode: z.enum(["minimal", "extended"]).default("extended"),
73
+ git: GitConfigSchema.optional(),
74
+ copyDirs: z.array(z.string()).default([]),
75
+ standalone: z.boolean().default(false),
76
+ ignoreDirs: z.array(z.string()).optional(),
77
+ excludePathSegments: z.array(z.string()).optional(),
78
+ excludeExtensions: z.array(z.string()).optional(),
79
+ skipSecretScan: z.boolean().optional(),
80
+ });
81
+ export async function loadConfig(configPath) {
82
+ const raw = await readFile(configPath, "utf-8");
83
+ const parsed = parseYaml(raw);
84
+ const config = ExtractConfigSchema.parse(parsed);
85
+ if (config.stripScopes === undefined) {
86
+ config.stripScopes = config.workspacePrefixes;
87
+ }
88
+ return config;
89
+ }
90
+ export { ExtractConfigSchema };
@@ -0,0 +1,16 @@
1
+ import type { SecretFinding } from "./types.js";
2
+ export declare class SecretScanError extends Error {
3
+ readonly findings: SecretFinding[];
4
+ constructor(findings: SecretFinding[]);
5
+ }
6
+ export declare class GitOperationError extends Error {
7
+ readonly operation: string;
8
+ readonly cause?: Error;
9
+ constructor(operation: string, message: string, cause?: Error);
10
+ }
11
+ export declare class PackageManagerError extends Error {
12
+ readonly command: string;
13
+ readonly cause?: Error;
14
+ constructor(command: string, message: string, cause?: Error);
15
+ }
16
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,qBAAa,eAAgB,SAAQ,KAAK;IACxC,QAAQ,CAAC,QAAQ,EAAE,aAAa,EAAE,CAAC;gBACvB,QAAQ,EAAE,aAAa,EAAE;CAKtC;AAED,qBAAa,iBAAkB,SAAQ,KAAK;IAC1C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,SAAkB,KAAK,CAAC,EAAE,KAAK,CAAC;gBACpB,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK;CAM9D;AAED,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,SAAkB,KAAK,CAAC,EAAE,KAAK,CAAC;gBACpB,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK;CAM5D"}