@treeseed/cli 0.1.1 → 0.4.2

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 (200) hide show
  1. package/README.md +27 -26
  2. package/dist/cli/handlers/auth-login.d.ts +2 -0
  3. package/dist/cli/handlers/auth-login.js +67 -0
  4. package/dist/cli/handlers/auth-logout.d.ts +2 -0
  5. package/dist/cli/handlers/auth-logout.js +20 -0
  6. package/dist/cli/handlers/auth-whoami.d.ts +2 -0
  7. package/dist/cli/handlers/auth-whoami.js +24 -0
  8. package/dist/cli/handlers/close.js +19 -53
  9. package/dist/cli/handlers/config.js +33 -53
  10. package/dist/cli/handlers/destroy.js +34 -79
  11. package/dist/{src/cli/handlers/ship.d.ts → cli/handlers/dev.d.ts} +1 -1
  12. package/dist/cli/handlers/dev.js +19 -0
  13. package/dist/cli/handlers/doctor.js +13 -6
  14. package/dist/cli/handlers/init.js +32 -8
  15. package/dist/cli/handlers/release.js +21 -53
  16. package/dist/cli/handlers/rollback.js +8 -8
  17. package/dist/cli/handlers/save.js +21 -79
  18. package/dist/cli/handlers/stage.d.ts +2 -0
  19. package/dist/cli/handlers/stage.js +28 -0
  20. package/dist/cli/handlers/status.js +35 -26
  21. package/dist/{src/cli/handlers/deploy.d.ts → cli/handlers/switch.d.ts} +1 -1
  22. package/dist/cli/handlers/switch.js +29 -0
  23. package/dist/{src/cli/handlers/next.d.ts → cli/handlers/sync.d.ts} +1 -1
  24. package/dist/cli/handlers/sync.js +26 -0
  25. package/dist/cli/handlers/tasks.d.ts +2 -0
  26. package/dist/cli/handlers/tasks.js +31 -0
  27. package/dist/cli/handlers/template.d.ts +2 -0
  28. package/dist/cli/handlers/template.js +27 -0
  29. package/dist/cli/handlers/workflow.d.ts +6 -0
  30. package/dist/cli/handlers/workflow.js +71 -0
  31. package/dist/{src/cli → cli}/help.d.ts +2 -2
  32. package/dist/cli/help.js +36 -24
  33. package/dist/cli/main.d.ts +6 -0
  34. package/dist/cli/main.js +14 -19
  35. package/dist/cli/operations-help.d.ts +1 -0
  36. package/dist/cli/operations-help.js +1 -0
  37. package/dist/cli/operations-parser.d.ts +1 -0
  38. package/dist/cli/operations-parser.js +1 -0
  39. package/dist/cli/operations-registry.d.ts +5 -0
  40. package/dist/cli/operations-registry.js +260 -0
  41. package/dist/cli/operations-types.d.ts +72 -0
  42. package/dist/cli/parser.d.ts +3 -0
  43. package/dist/cli/parser.js +1 -6
  44. package/dist/cli/registry.d.ts +25 -0
  45. package/dist/cli/registry.js +28 -416
  46. package/dist/cli/repair.js +6 -4
  47. package/dist/cli/runtime.d.ts +31 -0
  48. package/dist/cli/runtime.js +240 -111
  49. package/dist/cli/types.d.ts +1 -0
  50. package/dist/{src/cli → cli}/workflow-state.d.ts +9 -0
  51. package/dist/cli/workflow-state.js +45 -21
  52. package/package.json +13 -13
  53. package/dist/cli/handlers/continue.js +0 -23
  54. package/dist/cli/handlers/deploy.js +0 -139
  55. package/dist/cli/handlers/next.js +0 -27
  56. package/dist/cli/handlers/prepare.js +0 -8
  57. package/dist/cli/handlers/promote.js +0 -8
  58. package/dist/cli/handlers/publish.js +0 -8
  59. package/dist/cli/handlers/setup.js +0 -48
  60. package/dist/cli/handlers/ship.js +0 -49
  61. package/dist/cli/handlers/start.js +0 -97
  62. package/dist/cli/handlers/teardown.js +0 -50
  63. package/dist/cli/handlers/work.js +0 -85
  64. package/dist/scripts/aggregate-book.d.ts +0 -1
  65. package/dist/scripts/aggregate-book.js +0 -121
  66. package/dist/scripts/assert-release-tag-version.d.ts +0 -1
  67. package/dist/scripts/assert-release-tag-version.js +0 -21
  68. package/dist/scripts/build-dist.d.ts +0 -1
  69. package/dist/scripts/build-dist.js +0 -108
  70. package/dist/scripts/build-tenant-worker.d.ts +0 -1
  71. package/dist/scripts/build-tenant-worker.js +0 -36
  72. package/dist/scripts/cleanup-markdown.d.ts +0 -2
  73. package/dist/scripts/cleanup-markdown.js +0 -373
  74. package/dist/scripts/config-runtime-lib.d.ts +0 -122
  75. package/dist/scripts/config-runtime-lib.js +0 -505
  76. package/dist/scripts/config-treeseed.d.ts +0 -2
  77. package/dist/scripts/config-treeseed.js +0 -81
  78. package/dist/scripts/d1-migration-lib.d.ts +0 -6
  79. package/dist/scripts/d1-migration-lib.js +0 -90
  80. package/dist/scripts/deploy-lib.d.ts +0 -127
  81. package/dist/scripts/deploy-lib.js +0 -841
  82. package/dist/scripts/ensure-mailpit.d.ts +0 -1
  83. package/dist/scripts/ensure-mailpit.js +0 -29
  84. package/dist/scripts/git-workflow-lib.d.ts +0 -25
  85. package/dist/scripts/git-workflow-lib.js +0 -136
  86. package/dist/scripts/github-automation-lib.d.ts +0 -156
  87. package/dist/scripts/github-automation-lib.js +0 -242
  88. package/dist/scripts/local-dev-lib.d.ts +0 -9
  89. package/dist/scripts/local-dev-lib.js +0 -84
  90. package/dist/scripts/local-dev.d.ts +0 -1
  91. package/dist/scripts/local-dev.js +0 -129
  92. package/dist/scripts/logs-mailpit.d.ts +0 -1
  93. package/dist/scripts/logs-mailpit.js +0 -2
  94. package/dist/scripts/mailpit-runtime.d.ts +0 -4
  95. package/dist/scripts/mailpit-runtime.js +0 -57
  96. package/dist/scripts/package-tools.d.ts +0 -22
  97. package/dist/scripts/package-tools.js +0 -255
  98. package/dist/scripts/patch-starlight-content-path.d.ts +0 -1
  99. package/dist/scripts/patch-starlight-content-path.js +0 -172
  100. package/dist/scripts/paths.d.ts +0 -17
  101. package/dist/scripts/paths.js +0 -26
  102. package/dist/scripts/publish-package.d.ts +0 -1
  103. package/dist/scripts/publish-package.js +0 -19
  104. package/dist/scripts/release-verify.d.ts +0 -1
  105. package/dist/scripts/release-verify.js +0 -136
  106. package/dist/scripts/run-fixture-astro-command.d.ts +0 -1
  107. package/dist/scripts/run-fixture-astro-command.js +0 -18
  108. package/dist/scripts/save-deploy-preflight-lib.d.ts +0 -34
  109. package/dist/scripts/save-deploy-preflight-lib.js +0 -69
  110. package/dist/scripts/scaffold-site.d.ts +0 -2
  111. package/dist/scripts/scaffold-site.js +0 -92
  112. package/dist/scripts/stop-mailpit.d.ts +0 -1
  113. package/dist/scripts/stop-mailpit.js +0 -5
  114. package/dist/scripts/sync-dev-vars.d.ts +0 -1
  115. package/dist/scripts/sync-dev-vars.js +0 -6
  116. package/dist/scripts/template-registry-lib.d.ts +0 -47
  117. package/dist/scripts/template-registry-lib.js +0 -137
  118. package/dist/scripts/tenant-astro-command.d.ts +0 -1
  119. package/dist/scripts/tenant-astro-command.js +0 -3
  120. package/dist/scripts/tenant-build.d.ts +0 -1
  121. package/dist/scripts/tenant-build.js +0 -16
  122. package/dist/scripts/tenant-check.d.ts +0 -1
  123. package/dist/scripts/tenant-check.js +0 -7
  124. package/dist/scripts/tenant-d1-migrate-local.d.ts +0 -1
  125. package/dist/scripts/tenant-d1-migrate-local.js +0 -11
  126. package/dist/scripts/tenant-deploy.d.ts +0 -2
  127. package/dist/scripts/tenant-deploy.js +0 -180
  128. package/dist/scripts/tenant-destroy.d.ts +0 -2
  129. package/dist/scripts/tenant-destroy.js +0 -104
  130. package/dist/scripts/tenant-dev.d.ts +0 -1
  131. package/dist/scripts/tenant-dev.js +0 -171
  132. package/dist/scripts/tenant-lint.d.ts +0 -1
  133. package/dist/scripts/tenant-lint.js +0 -4
  134. package/dist/scripts/tenant-test.d.ts +0 -1
  135. package/dist/scripts/tenant-test.js +0 -4
  136. package/dist/scripts/test-cloudflare-local.d.ts +0 -1
  137. package/dist/scripts/test-cloudflare-local.js +0 -212
  138. package/dist/scripts/test-scaffold.d.ts +0 -2
  139. package/dist/scripts/test-scaffold.js +0 -297
  140. package/dist/scripts/treeseed.d.ts +0 -2
  141. package/dist/scripts/treeseed.js +0 -4
  142. package/dist/scripts/validate-templates.d.ts +0 -2
  143. package/dist/scripts/validate-templates.js +0 -4
  144. package/dist/scripts/watch-dev-lib.d.ts +0 -21
  145. package/dist/scripts/watch-dev-lib.js +0 -277
  146. package/dist/scripts/workspace-close.d.ts +0 -2
  147. package/dist/scripts/workspace-close.js +0 -24
  148. package/dist/scripts/workspace-command-e2e.d.ts +0 -2
  149. package/dist/scripts/workspace-command-e2e.js +0 -718
  150. package/dist/scripts/workspace-lint.d.ts +0 -1
  151. package/dist/scripts/workspace-lint.js +0 -9
  152. package/dist/scripts/workspace-preflight-lib.d.ts +0 -36
  153. package/dist/scripts/workspace-preflight-lib.js +0 -179
  154. package/dist/scripts/workspace-preflight.d.ts +0 -2
  155. package/dist/scripts/workspace-preflight.js +0 -22
  156. package/dist/scripts/workspace-publish-changed-packages.d.ts +0 -1
  157. package/dist/scripts/workspace-publish-changed-packages.js +0 -16
  158. package/dist/scripts/workspace-release-verify.d.ts +0 -1
  159. package/dist/scripts/workspace-release-verify.js +0 -81
  160. package/dist/scripts/workspace-release.d.ts +0 -2
  161. package/dist/scripts/workspace-release.js +0 -42
  162. package/dist/scripts/workspace-save-lib.d.ts +0 -42
  163. package/dist/scripts/workspace-save-lib.js +0 -220
  164. package/dist/scripts/workspace-save.d.ts +0 -2
  165. package/dist/scripts/workspace-save.js +0 -124
  166. package/dist/scripts/workspace-start-warning.js +0 -3
  167. package/dist/scripts/workspace-start.d.ts +0 -2
  168. package/dist/scripts/workspace-start.js +0 -71
  169. package/dist/scripts/workspace-test-unit.d.ts +0 -1
  170. package/dist/scripts/workspace-test-unit.js +0 -4
  171. package/dist/scripts/workspace-test.d.ts +0 -1
  172. package/dist/scripts/workspace-test.js +0 -11
  173. package/dist/scripts/workspace-tools.d.ts +0 -13
  174. package/dist/scripts/workspace-tools.js +0 -226
  175. package/dist/src/cli/handlers/continue.d.ts +0 -2
  176. package/dist/src/cli/handlers/prepare.d.ts +0 -2
  177. package/dist/src/cli/handlers/promote.d.ts +0 -2
  178. package/dist/src/cli/handlers/publish.d.ts +0 -2
  179. package/dist/src/cli/handlers/setup.d.ts +0 -2
  180. package/dist/src/cli/handlers/start.d.ts +0 -3
  181. package/dist/src/cli/handlers/teardown.d.ts +0 -2
  182. package/dist/src/cli/handlers/work.d.ts +0 -2
  183. package/dist/src/cli/main.d.ts +0 -6
  184. package/dist/src/cli/parser.d.ts +0 -3
  185. package/dist/src/cli/registry.d.ts +0 -27
  186. package/dist/src/cli/runtime.d.ts +0 -4
  187. package/dist/src/cli/types.d.ts +0 -71
  188. /package/dist/{src/cli → cli}/handlers/close.d.ts +0 -0
  189. /package/dist/{src/cli → cli}/handlers/config.d.ts +0 -0
  190. /package/dist/{src/cli → cli}/handlers/destroy.d.ts +0 -0
  191. /package/dist/{src/cli → cli}/handlers/doctor.d.ts +0 -0
  192. /package/dist/{src/cli → cli}/handlers/init.d.ts +0 -0
  193. /package/dist/{src/cli → cli}/handlers/release.d.ts +0 -0
  194. /package/dist/{src/cli → cli}/handlers/rollback.d.ts +0 -0
  195. /package/dist/{src/cli → cli}/handlers/save.d.ts +0 -0
  196. /package/dist/{src/cli → cli}/handlers/status.d.ts +0 -0
  197. /package/dist/{src/cli → cli}/handlers/utils.d.ts +0 -0
  198. /package/dist/{scripts/workspace-start-warning.d.ts → cli/operations-types.js} +0 -0
  199. /package/dist/{src/cli → cli}/repair.d.ts +0 -0
  200. /package/dist/{src/index.d.ts → index.d.ts} +0 -0
@@ -1,124 +0,0 @@
1
- #!/usr/bin/env node
2
- import { writeFileSync, mkdirSync } from 'node:fs';
3
- import { dirname, resolve } from 'node:path';
4
- import { applyTreeseedEnvironmentToProcess } from './config-runtime-lib.js';
5
- import { collectMergeConflictReport, currentBranch, formatMergeConflictReport, hasMeaningfulChanges, originRemoteUrl, repoRoot, } from './workspace-save-lib.js';
6
- import { remoteBranchExists, STAGING_BRANCH, PRODUCTION_BRANCH } from './git-workflow-lib.js';
7
- import { run, workspaceRoot } from './workspace-tools.js';
8
- import { runWorkspaceSavePreflight } from './save-deploy-preflight-lib.js';
9
- function writeSaveReport(payload) {
10
- const target = process.env.TREESEED_SAVE_REPORT_PATH;
11
- if (!target) {
12
- return;
13
- }
14
- const filePath = resolve(target);
15
- mkdirSync(dirname(filePath), { recursive: true });
16
- writeFileSync(filePath, `${JSON.stringify(payload, null, 2)}\n`, 'utf8');
17
- }
18
- function parseArgs(argv) {
19
- const parsed = {
20
- hotfix: false,
21
- messageParts: [],
22
- };
23
- for (const current of argv) {
24
- if (current === '--hotfix') {
25
- parsed.hotfix = true;
26
- continue;
27
- }
28
- parsed.messageParts.push(current);
29
- }
30
- return {
31
- hotfix: parsed.hotfix,
32
- message: parsed.messageParts.join(' ').trim(),
33
- };
34
- }
35
- const options = parseArgs(process.argv.slice(2));
36
- const message = options.message;
37
- const root = workspaceRoot();
38
- const gitRoot = repoRoot(root);
39
- const branch = currentBranch(gitRoot);
40
- const scope = branch === STAGING_BRANCH ? 'staging' : branch === PRODUCTION_BRANCH ? 'prod' : 'local';
41
- applyTreeseedEnvironmentToProcess({ tenantRoot: root, scope });
42
- if (!message) {
43
- writeSaveReport({ ok: false, kind: 'usage', message: 'Treeseed save requires a commit message.' });
44
- console.error('Treeseed save requires a commit message. Usage: treeseed save <message>');
45
- process.exit(1);
46
- }
47
- if (!branch) {
48
- writeSaveReport({ ok: false, kind: 'missing_branch', message: 'Treeseed save requires an active git branch.' });
49
- console.error('Treeseed save requires an active git branch.');
50
- process.exit(1);
51
- }
52
- if (branch === PRODUCTION_BRANCH && !options.hotfix) {
53
- writeSaveReport({
54
- ok: false,
55
- kind: 'protected_branch',
56
- branch,
57
- message: 'Treeseed save is blocked on main. Use `treeseed release` for normal production promotion or `treeseed save --hotfix` for an explicit hotfix.',
58
- });
59
- console.error('Treeseed save is blocked on main. Use `treeseed release` for normal production promotion or `treeseed save --hotfix` for an explicit hotfix.');
60
- process.exit(1);
61
- }
62
- try {
63
- originRemoteUrl(gitRoot);
64
- }
65
- catch {
66
- writeSaveReport({ ok: false, kind: 'missing_origin', message: 'Treeseed save requires an origin remote.' });
67
- console.error('Treeseed save requires an origin remote.');
68
- process.exit(1);
69
- }
70
- try {
71
- runWorkspaceSavePreflight({ cwd: root });
72
- }
73
- catch (error) {
74
- const kind = error?.kind ?? 'preflight_failed';
75
- writeSaveReport({
76
- ok: false,
77
- kind,
78
- message: error instanceof Error ? error.message : String(error),
79
- });
80
- console.error(error instanceof Error ? error.message : String(error));
81
- process.exit(error?.exitCode ?? 1);
82
- }
83
- if (!hasMeaningfulChanges(gitRoot)) {
84
- writeSaveReport({ ok: false, kind: 'no_changes', message: 'Treeseed save found no meaningful repository changes to commit.' });
85
- console.error('Treeseed save found no meaningful repository changes to commit.');
86
- process.exit(1);
87
- }
88
- run('git', ['add', '-A'], { cwd: gitRoot });
89
- run('git', ['commit', '-m', message], { cwd: gitRoot });
90
- try {
91
- if (remoteBranchExists(gitRoot, branch)) {
92
- run('git', ['pull', '--rebase', 'origin', branch], { cwd: gitRoot });
93
- run('git', ['push', 'origin', branch], { cwd: gitRoot });
94
- }
95
- else {
96
- run('git', ['push', '-u', 'origin', branch], { cwd: gitRoot });
97
- }
98
- }
99
- catch (error) {
100
- const report = collectMergeConflictReport(gitRoot);
101
- writeSaveReport({
102
- ok: false,
103
- kind: 'merge_conflict',
104
- branch,
105
- report,
106
- formatted: formatMergeConflictReport(report, gitRoot, branch),
107
- });
108
- console.error(formatMergeConflictReport(report, gitRoot, branch));
109
- process.exit(12);
110
- }
111
- const summary = {
112
- ok: true,
113
- kind: 'success',
114
- message,
115
- branch,
116
- scope,
117
- hotfix: options.hotfix,
118
- root,
119
- repositoryRoot: gitRoot,
120
- };
121
- writeSaveReport(summary);
122
- console.log('Treeseed save completed successfully.');
123
- console.log(`Branch: ${branch}`);
124
- console.log(`Environment scope: ${scope}`);
@@ -1,3 +0,0 @@
1
- console.error('`npm run start` is deprecated because `treeseed start` creates feature branches.');
2
- console.error('Use `treeseed dev` for local development or `treeseed start <branch-name>` for branch creation.');
3
- process.exit(1);
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
@@ -1,71 +0,0 @@
1
- #!/usr/bin/env node
2
- import { spawnSync } from 'node:child_process';
3
- import { applyTreeseedEnvironmentToProcess, assertTreeseedCommandEnvironment } from './config-runtime-lib.js';
4
- import { createBranchPreviewDeployTarget, deployTargetLabel, ensureGeneratedWranglerConfig, finalizeDeploymentState, printDeploySummary, provisionCloudflareResources, runRemoteD1Migrations, syncCloudflareSecrets, validateDeployPrerequisites, } from './deploy-lib.js';
5
- import { createFeatureBranchFromStaging, pushBranch } from './git-workflow-lib.js';
6
- import { packageScriptPath, resolveWranglerBin } from './package-tools.js';
7
- function parseArgs(argv) {
8
- const parsed = {
9
- branchName: null,
10
- preview: false,
11
- };
12
- for (const current of argv) {
13
- if (current === '--preview') {
14
- parsed.preview = true;
15
- continue;
16
- }
17
- if (!parsed.branchName) {
18
- parsed.branchName = current;
19
- continue;
20
- }
21
- throw new Error(`Unknown start argument: ${current}`);
22
- }
23
- if (!parsed.branchName) {
24
- throw new Error('Usage: treeseed start <branch-name> [--preview]');
25
- }
26
- return parsed;
27
- }
28
- function runNodeScript(scriptPath, scriptArgs = [], cwd) {
29
- const result = spawnSync(process.execPath, [scriptPath, ...scriptArgs], {
30
- stdio: 'inherit',
31
- cwd,
32
- env: { ...process.env },
33
- });
34
- if (result.status !== 0) {
35
- process.exit(result.status ?? 1);
36
- }
37
- }
38
- function runWranglerDeploy(configPath, cwd) {
39
- const result = spawnSync(process.execPath, [resolveWranglerBin(), 'deploy', '--config', configPath], {
40
- stdio: 'inherit',
41
- cwd,
42
- env: { ...process.env },
43
- });
44
- if (result.status !== 0) {
45
- process.exit(result.status ?? 1);
46
- }
47
- }
48
- const options = parseArgs(process.argv.slice(2));
49
- const tenantRoot = process.cwd();
50
- const result = createFeatureBranchFromStaging(tenantRoot, options.branchName);
51
- pushBranch(result.repoDir, options.branchName, { setUpstream: true });
52
- if (!options.preview) {
53
- console.log(`Created feature branch ${options.branchName} from staging.`);
54
- console.log('Preview mode is disabled. Use local development for this branch.');
55
- process.exit(0);
56
- }
57
- applyTreeseedEnvironmentToProcess({ tenantRoot, scope: 'staging' });
58
- assertTreeseedCommandEnvironment({ tenantRoot, scope: 'staging', purpose: 'deploy' });
59
- validateDeployPrerequisites(tenantRoot, { requireRemote: true });
60
- const target = createBranchPreviewDeployTarget(options.branchName);
61
- const summary = provisionCloudflareResources(tenantRoot, { target });
62
- printDeploySummary(summary);
63
- const { wranglerPath } = ensureGeneratedWranglerConfig(tenantRoot, { target });
64
- syncCloudflareSecrets(tenantRoot, { target });
65
- runRemoteD1Migrations(tenantRoot, { target });
66
- runNodeScript(packageScriptPath('tenant-build'), [], tenantRoot);
67
- runWranglerDeploy(wranglerPath, tenantRoot);
68
- const state = finalizeDeploymentState(tenantRoot, { target });
69
- console.log(`Treeseed start preview completed for ${options.branchName}.`);
70
- console.log(`Target: ${deployTargetLabel(target)}`);
71
- console.log(`Preview URL: ${state.lastDeployedUrl}`);
@@ -1 +0,0 @@
1
- export {};
@@ -1,4 +0,0 @@
1
- import { packagesWithScript, run } from './workspace-tools.js';
2
- for (const pkg of packagesWithScript('test:unit')) {
3
- run('npm', ['run', 'test:unit'], { cwd: pkg.dir });
4
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,11 +0,0 @@
1
- import { sortWorkspacePackages, workspacePackages, run } from './workspace-tools.js';
2
- const packages = sortWorkspacePackages(workspacePackages());
3
- for (const pkg of packages) {
4
- if (typeof pkg.packageJson.scripts?.['test:unit'] === 'string') {
5
- run('npm', ['run', 'test:unit'], { cwd: pkg.dir });
6
- continue;
7
- }
8
- if (typeof pkg.packageJson.scripts?.test === 'string') {
9
- run('npm', ['run', 'test'], { cwd: pkg.dir });
10
- }
11
- }
@@ -1,13 +0,0 @@
1
- export declare function workspaceRoot(): string;
2
- export declare function readJson(filePath: any): any;
3
- export declare function workspacePackageJson(root?: string): any;
4
- export declare function workspacePatterns(root?: string): any;
5
- export declare function isWorkspaceRoot(root?: string): boolean;
6
- export declare function workspacePackages(root?: string): any[];
7
- export declare function sortWorkspacePackages(packages: any): any[];
8
- export declare function packagesWithScript(scriptName: any, root?: string): any[];
9
- export declare function run(command: any, args: any, options?: {}): string;
10
- export declare function changedWorkspacePackages(options?: {}): any[];
11
- export declare function publishableWorkspacePackages(root?: string): any[];
12
- export declare function createTempDir(prefix: any): string;
13
- export declare function cleanupDir(dirPath: any): void;
@@ -1,226 +0,0 @@
1
- import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync } from 'node:fs';
2
- import { spawnSync } from 'node:child_process';
3
- import { join, relative, resolve } from 'node:path';
4
- function escapeRegex(source) {
5
- return source.replace(/[|\\{}()[\]^$+?.]/g, '\\$&');
6
- }
7
- function segmentPatternToRegex(pattern) {
8
- return new RegExp(`^${escapeRegex(pattern).replaceAll('*', '.*')}$`);
9
- }
10
- function expandWorkspacePattern(root, pattern) {
11
- const segments = pattern.split(/[\\/]+/).filter(Boolean);
12
- const results = [];
13
- function visit(baseDir, index) {
14
- if (index >= segments.length) {
15
- results.push(baseDir);
16
- return;
17
- }
18
- const segment = segments[index];
19
- if (!segment.includes('*')) {
20
- const nextDir = resolve(baseDir, segment);
21
- if (existsSync(nextDir)) {
22
- visit(nextDir, index + 1);
23
- }
24
- return;
25
- }
26
- if (!existsSync(baseDir)) {
27
- return;
28
- }
29
- const matcher = segmentPatternToRegex(segment);
30
- for (const entry of readdirSync(baseDir, { withFileTypes: true })) {
31
- if (!entry.isDirectory() || !matcher.test(entry.name)) {
32
- continue;
33
- }
34
- visit(resolve(baseDir, entry.name), index + 1);
35
- }
36
- }
37
- visit(root, 0);
38
- return results;
39
- }
40
- export function workspaceRoot() {
41
- return process.cwd();
42
- }
43
- export function readJson(filePath) {
44
- return JSON.parse(readFileSync(filePath, 'utf8'));
45
- }
46
- export function workspacePackageJson(root = workspaceRoot()) {
47
- return readJson(resolve(root, 'package.json'));
48
- }
49
- export function workspacePatterns(root = workspaceRoot()) {
50
- const packageJson = workspacePackageJson(root);
51
- const workspaces = Array.isArray(packageJson.workspaces)
52
- ? packageJson.workspaces
53
- : Array.isArray(packageJson.workspaces?.packages)
54
- ? packageJson.workspaces.packages
55
- : [];
56
- return workspaces.filter((value) => typeof value === 'string' && value.trim().length > 0);
57
- }
58
- export function isWorkspaceRoot(root = workspaceRoot()) {
59
- return workspacePatterns(root).length > 0;
60
- }
61
- export function workspacePackages(root = workspaceRoot()) {
62
- const discovered = new Map();
63
- for (const pattern of workspacePatterns(root)) {
64
- for (const dir of expandWorkspacePattern(root, pattern)) {
65
- const packageJsonPath = resolve(dir, 'package.json');
66
- if (!existsSync(packageJsonPath)) {
67
- continue;
68
- }
69
- const packageJson = readJson(packageJsonPath);
70
- discovered.set(dir, {
71
- dir,
72
- name: packageJson.name,
73
- packageJson,
74
- relativeDir: relative(root, dir).replaceAll('\\', '/'),
75
- });
76
- }
77
- }
78
- return [...discovered.values()].sort((left, right) => left.name.localeCompare(right.name));
79
- }
80
- function internalDependenciesFor(pkg, packageNames) {
81
- const internalDeps = new Set();
82
- for (const field of ['dependencies', 'optionalDependencies', 'peerDependencies', 'devDependencies']) {
83
- for (const name of Object.keys(pkg.packageJson[field] ?? {})) {
84
- if (packageNames.has(name)) {
85
- internalDeps.add(name);
86
- }
87
- }
88
- }
89
- return internalDeps;
90
- }
91
- export function sortWorkspacePackages(packages) {
92
- const packageMap = new Map(packages.map((pkg) => [pkg.name, pkg]));
93
- const packageNames = new Set(packageMap.keys());
94
- const dependents = new Map(packages.map((pkg) => [pkg.name, new Set()]));
95
- const indegree = new Map(packages.map((pkg) => [pkg.name, 0]));
96
- for (const pkg of packages) {
97
- for (const dep of internalDependenciesFor(pkg, packageNames)) {
98
- dependents.get(dep)?.add(pkg.name);
99
- indegree.set(pkg.name, (indegree.get(pkg.name) ?? 0) + 1);
100
- }
101
- }
102
- const ready = [...packages]
103
- .filter((pkg) => (indegree.get(pkg.name) ?? 0) === 0)
104
- .sort((left, right) => left.name.localeCompare(right.name));
105
- const ordered = [];
106
- while (ready.length > 0) {
107
- const next = ready.shift();
108
- if (!next) {
109
- break;
110
- }
111
- ordered.push(next);
112
- for (const dependentName of [...(dependents.get(next.name) ?? [])].sort()) {
113
- const nextDegree = (indegree.get(dependentName) ?? 0) - 1;
114
- indegree.set(dependentName, nextDegree);
115
- if (nextDegree === 0) {
116
- const dependent = packageMap.get(dependentName);
117
- if (dependent) {
118
- ready.push(dependent);
119
- ready.sort((left, right) => left.name.localeCompare(right.name));
120
- }
121
- }
122
- }
123
- }
124
- if (ordered.length !== packages.length) {
125
- return [...packages].sort((left, right) => left.name.localeCompare(right.name));
126
- }
127
- return ordered;
128
- }
129
- export function packagesWithScript(scriptName, root = workspaceRoot()) {
130
- return sortWorkspacePackages(workspacePackages(root).filter((pkg) => typeof pkg.packageJson.scripts?.[scriptName] === 'string'));
131
- }
132
- export function run(command, args, options = {}) {
133
- const result = spawnSync(command, args, {
134
- cwd: options.cwd ?? workspaceRoot(),
135
- env: { ...process.env, ...(options.env ?? {}) },
136
- stdio: options.capture ? 'pipe' : 'inherit',
137
- encoding: 'utf8',
138
- timeout: options.timeoutMs,
139
- });
140
- if (result.status !== 0) {
141
- const message = (result.error?.message ? `${result.error.message}\n` : '')
142
- + (result.stderr?.trim()
143
- || result.stdout?.trim()
144
- || `${command} ${args.join(' ')} failed`);
145
- throw new Error(message);
146
- }
147
- return (result.stdout ?? '').trim();
148
- }
149
- function canResolveGitRef(baseRef, cwd = workspaceRoot()) {
150
- const result = spawnSync('git', ['rev-parse', '--verify', baseRef], {
151
- cwd,
152
- stdio: 'pipe',
153
- encoding: 'utf8',
154
- });
155
- return result.status === 0;
156
- }
157
- function resolveChangedFilesBaseRef(baseRef, cwd = workspaceRoot()) {
158
- if (canResolveGitRef(baseRef, cwd)) {
159
- return baseRef;
160
- }
161
- return null;
162
- }
163
- function changedWorkspaceFiles(baseRef, cwd = workspaceRoot()) {
164
- const changedFiles = new Set();
165
- const resolvedBaseRef = resolveChangedFilesBaseRef(baseRef, cwd);
166
- const diffCommands = [
167
- ['diff', '--name-only'],
168
- ['diff', '--name-only', '--cached'],
169
- ['ls-files', '--others', '--exclude-standard'],
170
- ];
171
- if (resolvedBaseRef) {
172
- diffCommands.unshift(['diff', '--name-only', resolvedBaseRef, 'HEAD']);
173
- }
174
- for (const args of diffCommands) {
175
- const output = run('git', args, { cwd, capture: true });
176
- for (const line of output.split('\n').map((entry) => entry.trim()).filter(Boolean)) {
177
- changedFiles.add(line);
178
- }
179
- }
180
- return changedFiles;
181
- }
182
- export function changedWorkspacePackages(options = {}) {
183
- const root = options.root ?? workspaceRoot();
184
- const baseRef = options.baseRef ?? process.env.TREESEED_RELEASE_BASE_REF ?? 'HEAD^';
185
- const includeDependents = options.includeDependents ?? false;
186
- const packages = options.packages ?? workspacePackages(root);
187
- const changedFiles = changedWorkspaceFiles(baseRef, root);
188
- const changed = new Set(packages
189
- .filter((pkg) => [...changedFiles].some((file) => file === pkg.relativeDir || file.startsWith(`${pkg.relativeDir}/`)))
190
- .map((pkg) => pkg.name));
191
- if (includeDependents && changed.size > 0) {
192
- const packageMap = new Map(packages.map((pkg) => [pkg.name, pkg]));
193
- const packageNames = new Set(packageMap.keys());
194
- const reverseDeps = new Map(packages.map((pkg) => [pkg.name, new Set()]));
195
- for (const pkg of packages) {
196
- for (const dep of internalDependenciesFor(pkg, packageNames)) {
197
- reverseDeps.get(dep)?.add(pkg.name);
198
- }
199
- }
200
- const queue = [...changed];
201
- while (queue.length > 0) {
202
- const next = queue.shift();
203
- for (const dependent of reverseDeps.get(next) ?? []) {
204
- if (changed.has(dependent)) {
205
- continue;
206
- }
207
- changed.add(dependent);
208
- queue.push(dependent);
209
- }
210
- }
211
- }
212
- return sortWorkspacePackages(packages.filter((pkg) => changed.has(pkg.name)));
213
- }
214
- export function publishableWorkspacePackages(root = workspaceRoot()) {
215
- return packagesWithScript('release:publish', root);
216
- }
217
- export function createTempDir(prefix) {
218
- const baseRoot = resolve(process.env.TREESEED_TEMP_ROOT ?? resolve(workspaceRoot(), '.local', 'tmp'));
219
- mkdirSync(baseRoot, { recursive: true });
220
- return mkdtempSync(join(baseRoot, prefix));
221
- }
222
- export function cleanupDir(dirPath) {
223
- if (dirPath && existsSync(dirPath)) {
224
- rmSync(dirPath, { recursive: true, force: true });
225
- }
226
- }
@@ -1,2 +0,0 @@
1
- import type { TreeseedCommandHandler } from '../types.js';
2
- export declare const handleContinue: TreeseedCommandHandler;
@@ -1,2 +0,0 @@
1
- import type { TreeseedCommandHandler } from '../types.js';
2
- export declare const handlePrepare: TreeseedCommandHandler;
@@ -1,2 +0,0 @@
1
- import type { TreeseedCommandHandler } from '../types.js';
2
- export declare const handlePromote: TreeseedCommandHandler;
@@ -1,2 +0,0 @@
1
- import type { TreeseedCommandHandler } from '../types.js';
2
- export declare const handlePublish: TreeseedCommandHandler;
@@ -1,2 +0,0 @@
1
- import type { TreeseedCommandHandler } from '../types.js';
2
- export declare const handleSetup: TreeseedCommandHandler;
@@ -1,3 +0,0 @@
1
- import type { TreeseedCommandHandler } from '../types.js';
2
- export declare function provisionBranchPreview(branchName: string, context: Parameters<TreeseedCommandHandler>[1], commandName?: string): import("../types.js").TreeseedCommandResult;
3
- export declare const handleStart: TreeseedCommandHandler;
@@ -1,2 +0,0 @@
1
- import type { TreeseedCommandHandler } from '../types.js';
2
- export declare const handleTeardown: TreeseedCommandHandler;
@@ -1,2 +0,0 @@
1
- import type { TreeseedCommandHandler } from '../types.js';
2
- export declare const handleWork: TreeseedCommandHandler;
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env node
2
- export { runTreeseedCli, executeTreeseedCommand, createTreeseedCommandContext } from './runtime.js';
3
- export { renderTreeseedHelp, renderUsage, suggestTreeseedCommands } from './help.js';
4
- export { findCommandSpec, listCommandNames, TRESEED_COMMAND_SPECS } from './registry.js';
5
- export { parseTreeseedInvocation, validateTreeseedInvocation } from './parser.js';
6
- export type { TreeseedCommandContext, TreeseedCommandResult, TreeseedCommandSpec, TreeseedParsedInvocation, } from './types.js';
@@ -1,3 +0,0 @@
1
- import type { TreeseedCommandSpec, TreeseedParsedInvocation } from './types.js';
2
- export declare function parseTreeseedInvocation(command: TreeseedCommandSpec, argv: string[]): TreeseedParsedInvocation;
3
- export declare function validateTreeseedInvocation(command: TreeseedCommandSpec, invocation: TreeseedParsedInvocation): string[];
@@ -1,27 +0,0 @@
1
- import type { TreeseedCommandSpec } from './types.js';
2
- export declare const COMMAND_HANDLERS: {
3
- readonly init: import("./types.js").TreeseedCommandHandler;
4
- readonly config: import("./types.js").TreeseedCommandHandler;
5
- readonly start: import("./types.js").TreeseedCommandHandler;
6
- readonly close: import("./types.js").TreeseedCommandHandler;
7
- readonly deploy: import("./types.js").TreeseedCommandHandler;
8
- readonly save: import("./types.js").TreeseedCommandHandler;
9
- readonly release: import("./types.js").TreeseedCommandHandler;
10
- readonly destroy: import("./types.js").TreeseedCommandHandler;
11
- readonly status: import("./types.js").TreeseedCommandHandler;
12
- readonly next: import("./types.js").TreeseedCommandHandler;
13
- readonly doctor: import("./types.js").TreeseedCommandHandler;
14
- readonly setup: import("./types.js").TreeseedCommandHandler;
15
- readonly work: import("./types.js").TreeseedCommandHandler;
16
- readonly ship: import("./types.js").TreeseedCommandHandler;
17
- readonly prepare: import("./types.js").TreeseedCommandHandler;
18
- readonly publish: import("./types.js").TreeseedCommandHandler;
19
- readonly promote: import("./types.js").TreeseedCommandHandler;
20
- readonly teardown: import("./types.js").TreeseedCommandHandler;
21
- readonly continue: import("./types.js").TreeseedCommandHandler;
22
- readonly rollback: import("./types.js").TreeseedCommandHandler;
23
- };
24
- export declare const TRESEED_COMMAND_SPECS: TreeseedCommandSpec[];
25
- export declare const TRESEED_COMMAND_INDEX: Map<string, TreeseedCommandSpec>;
26
- export declare function findCommandSpec(name: string | null | undefined): TreeseedCommandSpec | null;
27
- export declare function listCommandNames(): string[];
@@ -1,4 +0,0 @@
1
- import type { TreeseedCommandContext } from './types.js';
2
- export declare function createTreeseedCommandContext(overrides?: Partial<TreeseedCommandContext>): TreeseedCommandContext;
3
- export declare function executeTreeseedCommand(commandName: string, argv: string[], context: TreeseedCommandContext): Promise<number>;
4
- export declare function runTreeseedCli(argv: string[], overrides?: Partial<TreeseedCommandContext>): Promise<number>;
@@ -1,71 +0,0 @@
1
- export type TreeseedCommandGroup = 'Workflow' | 'Local Development' | 'Validation' | 'Release Utilities' | 'Utilities' | 'Passthrough';
2
- export type TreeseedExecutionMode = 'handler' | 'adapter';
3
- export type TreeseedArgumentKind = 'positional' | 'message_tail';
4
- export type TreeseedOptionKind = 'boolean' | 'string' | 'enum';
5
- export type TreeseedCommandArgumentSpec = {
6
- name: string;
7
- description: string;
8
- required?: boolean;
9
- kind?: TreeseedArgumentKind;
10
- };
11
- export type TreeseedCommandOptionSpec = {
12
- name: string;
13
- flags: string;
14
- description: string;
15
- kind: TreeseedOptionKind;
16
- repeatable?: boolean;
17
- values?: string[];
18
- };
19
- export type TreeseedCommandExample = string;
20
- export type TreeseedParsedInvocation = {
21
- commandName: string;
22
- args: Record<string, string | string[] | boolean | undefined>;
23
- positionals: string[];
24
- rawArgs: string[];
25
- };
26
- export type TreeseedCommandResult = {
27
- exitCode?: number;
28
- stdout?: string[];
29
- stderr?: string[];
30
- report?: Record<string, unknown> | null;
31
- };
32
- export type TreeseedWriter = (output: string, stream?: 'stdout' | 'stderr') => void;
33
- export type TreeseedSpawner = (command: string, args: string[], options: {
34
- cwd: string;
35
- env: NodeJS.ProcessEnv;
36
- stdio?: 'inherit';
37
- }) => {
38
- status?: number | null;
39
- };
40
- export type TreeseedCommandContext = {
41
- cwd: string;
42
- env: NodeJS.ProcessEnv;
43
- write: TreeseedWriter;
44
- spawn: TreeseedSpawner;
45
- outputFormat?: 'human' | 'json';
46
- };
47
- export type TreeseedCommandHandler = (invocation: TreeseedParsedInvocation, context: TreeseedCommandContext) => Promise<TreeseedCommandResult> | TreeseedCommandResult;
48
- export type TreeseedCommandSpec = {
49
- name: string;
50
- aliases: string[];
51
- group: TreeseedCommandGroup;
52
- summary: string;
53
- description: string;
54
- usage?: string;
55
- arguments?: TreeseedCommandArgumentSpec[];
56
- options?: TreeseedCommandOptionSpec[];
57
- examples?: TreeseedCommandExample[];
58
- notes?: string[];
59
- related?: string[];
60
- executionMode: TreeseedExecutionMode;
61
- handlerName?: string;
62
- adapter?: {
63
- script: string;
64
- workspaceScript?: string;
65
- directScript?: string;
66
- extraArgs?: string[];
67
- rewriteArgs?: (args: string[]) => string[];
68
- passthroughArgs?: boolean;
69
- requireWorkspaceRoot?: boolean;
70
- };
71
- };
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes