@creact-labs/creact 0.1.8 → 0.2.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 (146) hide show
  1. package/README.md +73 -22
  2. package/dist/cli.d.ts +11 -0
  3. package/dist/cli.js +88 -0
  4. package/dist/index.d.ts +19 -44
  5. package/dist/index.js +20 -68
  6. package/dist/jsx/index.d.ts +2 -0
  7. package/dist/jsx/index.js +1 -0
  8. package/dist/jsx/jsx-dev-runtime.d.ts +4 -0
  9. package/dist/jsx/jsx-dev-runtime.js +4 -0
  10. package/dist/jsx/jsx-runtime.d.ts +38 -0
  11. package/dist/jsx/jsx-runtime.js +38 -0
  12. package/dist/jsx/types.d.ts +12 -0
  13. package/dist/jsx/types.js +4 -0
  14. package/dist/primitives/context.d.ts +34 -0
  15. package/dist/primitives/context.js +63 -0
  16. package/dist/primitives/index.d.ts +3 -0
  17. package/dist/primitives/index.js +3 -0
  18. package/dist/primitives/instance.d.ts +72 -0
  19. package/dist/primitives/instance.js +235 -0
  20. package/dist/primitives/store.d.ts +22 -0
  21. package/dist/primitives/store.js +97 -0
  22. package/dist/provider/backend.d.ts +110 -0
  23. package/dist/provider/backend.js +37 -0
  24. package/dist/provider/interface.d.ts +48 -0
  25. package/dist/provider/interface.js +39 -0
  26. package/dist/reactive/effect.d.ts +11 -0
  27. package/dist/reactive/effect.js +42 -0
  28. package/dist/reactive/index.d.ts +3 -0
  29. package/dist/reactive/index.js +3 -0
  30. package/dist/reactive/signal.d.ts +32 -0
  31. package/dist/reactive/signal.js +60 -0
  32. package/dist/reactive/tracking.d.ts +41 -0
  33. package/dist/reactive/tracking.js +161 -0
  34. package/dist/runtime/fiber.d.ts +21 -0
  35. package/dist/runtime/fiber.js +16 -0
  36. package/dist/runtime/index.d.ts +4 -0
  37. package/dist/runtime/index.js +4 -0
  38. package/dist/runtime/reconcile.d.ts +66 -0
  39. package/dist/runtime/reconcile.js +210 -0
  40. package/dist/runtime/render.d.ts +42 -0
  41. package/dist/runtime/render.js +231 -0
  42. package/dist/runtime/run.d.ts +119 -0
  43. package/dist/runtime/run.js +334 -0
  44. package/dist/runtime/state-machine.d.ts +95 -0
  45. package/dist/runtime/state-machine.js +209 -0
  46. package/dist/types.d.ts +13 -0
  47. package/dist/types.js +4 -0
  48. package/package.json +11 -24
  49. package/dist/cli/commands/BuildCommand.d.ts +0 -40
  50. package/dist/cli/commands/BuildCommand.js +0 -151
  51. package/dist/cli/commands/DeployCommand.d.ts +0 -38
  52. package/dist/cli/commands/DeployCommand.js +0 -194
  53. package/dist/cli/commands/DevCommand.d.ts +0 -52
  54. package/dist/cli/commands/DevCommand.js +0 -394
  55. package/dist/cli/commands/PlanCommand.d.ts +0 -39
  56. package/dist/cli/commands/PlanCommand.js +0 -164
  57. package/dist/cli/commands/index.d.ts +0 -36
  58. package/dist/cli/commands/index.js +0 -43
  59. package/dist/cli/core/ArgumentParser.d.ts +0 -46
  60. package/dist/cli/core/ArgumentParser.js +0 -127
  61. package/dist/cli/core/BaseCommand.d.ts +0 -75
  62. package/dist/cli/core/BaseCommand.js +0 -95
  63. package/dist/cli/core/CLIContext.d.ts +0 -68
  64. package/dist/cli/core/CLIContext.js +0 -183
  65. package/dist/cli/core/CommandRegistry.d.ts +0 -64
  66. package/dist/cli/core/CommandRegistry.js +0 -89
  67. package/dist/cli/core/index.d.ts +0 -36
  68. package/dist/cli/core/index.js +0 -43
  69. package/dist/cli/index.d.ts +0 -35
  70. package/dist/cli/index.js +0 -100
  71. package/dist/cli/output.d.ts +0 -204
  72. package/dist/cli/output.js +0 -437
  73. package/dist/cli/utils.d.ts +0 -59
  74. package/dist/cli/utils.js +0 -76
  75. package/dist/context/createContext.d.ts +0 -90
  76. package/dist/context/createContext.js +0 -113
  77. package/dist/context/index.d.ts +0 -30
  78. package/dist/context/index.js +0 -35
  79. package/dist/core/CReact.d.ts +0 -409
  80. package/dist/core/CReact.js +0 -1151
  81. package/dist/core/CloudDOMBuilder.d.ts +0 -447
  82. package/dist/core/CloudDOMBuilder.js +0 -1234
  83. package/dist/core/ContextDependencyTracker.d.ts +0 -165
  84. package/dist/core/ContextDependencyTracker.js +0 -448
  85. package/dist/core/ErrorRecoveryManager.d.ts +0 -145
  86. package/dist/core/ErrorRecoveryManager.js +0 -443
  87. package/dist/core/EventBus.d.ts +0 -91
  88. package/dist/core/EventBus.js +0 -185
  89. package/dist/core/ProviderOutputTracker.d.ts +0 -211
  90. package/dist/core/ProviderOutputTracker.js +0 -476
  91. package/dist/core/ReactiveUpdateQueue.d.ts +0 -76
  92. package/dist/core/ReactiveUpdateQueue.js +0 -121
  93. package/dist/core/Reconciler.d.ts +0 -415
  94. package/dist/core/Reconciler.js +0 -1044
  95. package/dist/core/RenderScheduler.d.ts +0 -153
  96. package/dist/core/RenderScheduler.js +0 -519
  97. package/dist/core/Renderer.d.ts +0 -336
  98. package/dist/core/Renderer.js +0 -944
  99. package/dist/core/Runtime.d.ts +0 -246
  100. package/dist/core/Runtime.js +0 -640
  101. package/dist/core/StateBindingManager.d.ts +0 -121
  102. package/dist/core/StateBindingManager.js +0 -309
  103. package/dist/core/StateMachine.d.ts +0 -441
  104. package/dist/core/StateMachine.js +0 -883
  105. package/dist/core/StructuralChangeDetector.d.ts +0 -140
  106. package/dist/core/StructuralChangeDetector.js +0 -363
  107. package/dist/core/Validator.d.ts +0 -127
  108. package/dist/core/Validator.js +0 -279
  109. package/dist/core/errors.d.ts +0 -153
  110. package/dist/core/errors.js +0 -202
  111. package/dist/core/index.d.ts +0 -38
  112. package/dist/core/index.js +0 -64
  113. package/dist/core/types.d.ts +0 -265
  114. package/dist/core/types.js +0 -48
  115. package/dist/hooks/context.d.ts +0 -147
  116. package/dist/hooks/context.js +0 -334
  117. package/dist/hooks/useContext.d.ts +0 -113
  118. package/dist/hooks/useContext.js +0 -169
  119. package/dist/hooks/useEffect.d.ts +0 -105
  120. package/dist/hooks/useEffect.js +0 -540
  121. package/dist/hooks/useInstance.d.ts +0 -139
  122. package/dist/hooks/useInstance.js +0 -455
  123. package/dist/hooks/useState.d.ts +0 -120
  124. package/dist/hooks/useState.js +0 -298
  125. package/dist/jsx.d.ts +0 -143
  126. package/dist/jsx.js +0 -76
  127. package/dist/providers/DummyBackendProvider.d.ts +0 -193
  128. package/dist/providers/DummyBackendProvider.js +0 -189
  129. package/dist/providers/DummyCloudProvider.d.ts +0 -128
  130. package/dist/providers/DummyCloudProvider.js +0 -157
  131. package/dist/providers/IBackendProvider.d.ts +0 -177
  132. package/dist/providers/IBackendProvider.js +0 -31
  133. package/dist/providers/ICloudProvider.d.ts +0 -230
  134. package/dist/providers/ICloudProvider.js +0 -31
  135. package/dist/providers/index.d.ts +0 -31
  136. package/dist/providers/index.js +0 -31
  137. package/dist/test-event-callbacks.d.ts +0 -0
  138. package/dist/test-event-callbacks.js +0 -1
  139. package/dist/utils/Logger.d.ts +0 -144
  140. package/dist/utils/Logger.js +0 -220
  141. package/dist/utils/Output.d.ts +0 -161
  142. package/dist/utils/Output.js +0 -401
  143. package/dist/utils/deepEqual.d.ts +0 -71
  144. package/dist/utils/deepEqual.js +0 -276
  145. package/dist/utils/naming.d.ts +0 -241
  146. package/dist/utils/naming.js +0 -376
@@ -1,194 +0,0 @@
1
- "use strict";
2
- /**
3
-
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
-
6
- * you may not use this file except in compliance with the License.
7
-
8
- * You may obtain a copy of the License at
9
-
10
- *
11
-
12
- * http://www.apache.org/licenses/LICENSE-2.0
13
-
14
- *
15
-
16
- * Unless required by applicable law or agreed to in writing, software
17
-
18
- * distributed under the License is distributed on an "AS IS" BASIS,
19
-
20
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
-
22
- * See the License for the specific language governing permissions and
23
-
24
- * limitations under the License.
25
-
26
- *
27
-
28
- * Copyright 2025 Daniel Coutinho Ribeiro
29
-
30
- */
31
- Object.defineProperty(exports, "__esModule", { value: true });
32
- exports.DeployCommand = void 0;
33
- /**
34
- * Deploy Command - deploys CloudDOM to cloud provider
35
- */
36
- const BaseCommand_1 = require("../core/BaseCommand");
37
- const CLIContext_1 = require("../core/CLIContext");
38
- const Output_1 = require("../../utils/Output");
39
- const Reconciler_1 = require("../../core/Reconciler");
40
- const Logger_1 = require("../../utils/Logger");
41
- const logger = Logger_1.LoggerFactory.getLogger('cli');
42
- class DeployCommand extends BaseCommand_1.BaseCommand {
43
- getName() {
44
- return 'deploy';
45
- }
46
- getDescription() {
47
- return 'Deploy CloudDOM to cloud provider';
48
- }
49
- async execute() {
50
- const output = (0, Output_1.createOutputManager)({
51
- json: this.json,
52
- quiet: !!this.context.flags.quiet,
53
- verbose: this.verbose,
54
- });
55
- const dryRun = !!this.context.flags['dry-run'];
56
- try {
57
- // Find entry file
58
- logger.debug('DeployCommand: Starting execution');
59
- let entryPath;
60
- try {
61
- entryPath = CLIContext_1.CLIContextManager.findEntryFile(this.context.flags.entry);
62
- logger.debug(`DeployCommand: Entry file resolved to ${entryPath}`);
63
- }
64
- catch (error) {
65
- output.showError('Entry file resolution failed', {
66
- cause: error.message,
67
- stackTrace: this.verbose ? error.stack : undefined,
68
- });
69
- return { exitCode: 1 };
70
- }
71
- // Load entry file and create CLI instance
72
- output.showInfo('Loading entry file and configuring providers...');
73
- let result;
74
- try {
75
- result = await CLIContext_1.CLIContextManager.createCLIInstance(entryPath, this.verbose);
76
- logger.debug(`DeployCommand: CloudDOM built with ${result.cloudDOM.length} resources`);
77
- }
78
- catch (error) {
79
- output.showError('Failed to load entry file and configure providers', {
80
- cause: error.message,
81
- stackTrace: this.verbose ? error.stack : undefined,
82
- });
83
- return { exitCode: 1 };
84
- }
85
- output.showSuccess('Entry file loaded and providers configured');
86
- // Validate providers
87
- output.showInfo('Validating providers...');
88
- if (!result.instance.getCloudProvider()) {
89
- output.showError('Cloud provider not configured', {
90
- cause: 'CReact.cloudProvider must be set in entry file',
91
- });
92
- return { exitCode: 1 };
93
- }
94
- if (!result.instance.getBackendProvider()) {
95
- output.showError('Backend provider not configured', {
96
- cause: 'CReact.backendProvider must be set in entry file',
97
- });
98
- return { exitCode: 1 };
99
- }
100
- output.showSuccess('Providers validated');
101
- // Load previous state and show plan
102
- output.showInfo('Loading previous state...');
103
- let previousCloudDOM = [];
104
- try {
105
- const previousState = await result.instance.getBackendProvider().getState(result.stackName);
106
- if (previousState && previousState.cloudDOM) {
107
- previousCloudDOM = previousState.cloudDOM;
108
- logger.debug(`DeployCommand: Previous CloudDOM loaded with ${previousCloudDOM.length} resources`);
109
- }
110
- else {
111
- logger.debug('DeployCommand: No previous state found (first deployment)');
112
- }
113
- }
114
- catch (stateError) {
115
- logger.debug(`DeployCommand: Could not load previous state: ${stateError.message}`);
116
- }
117
- // Compute and show plan
118
- const reconciler = new Reconciler_1.Reconciler();
119
- const changeSet = reconciler.reconcile(previousCloudDOM, result.cloudDOM);
120
- output.showPlanHeader(result.stackName);
121
- output.showPlanChanges(changeSet);
122
- output.showPlanSummary(changeSet);
123
- if (dryRun) {
124
- logger.debug('DeployCommand: Dry run mode - deployment will be simulated');
125
- output.showInfo('Dry run mode - no changes will be applied');
126
- return { exitCode: 0 };
127
- }
128
- // Deploy using CReact instance
129
- output.showDeployHeader();
130
- const startTime = Date.now();
131
- const deployedResources = [];
132
- try {
133
- // Track deployment progress
134
- for (const nodeId of changeSet.deploymentOrder) {
135
- const node = [...changeSet.creates, ...changeSet.updates].find((n) => n.id === nodeId);
136
- if (node) {
137
- const action = changeSet.creates.includes(node) ? 'Creating' : 'Updating';
138
- const resourceStart = Date.now();
139
- output.showResourceProgress(nodeId, action);
140
- // Actual deployment happens in CReact.deploy()
141
- // This is just for progress tracking
142
- deployedResources.push(nodeId);
143
- const resourceDuration = (Date.now() - resourceStart) / 1000;
144
- output.showResourceComplete(nodeId, action.replace('ing', 'ed'), resourceDuration);
145
- }
146
- }
147
- await result.instance.deploy(result.cloudDOM, result.stackName, 'cli-user');
148
- const duration = (Date.now() - startTime) / 1000;
149
- const deployResult = {
150
- resourceCount: result.cloudDOM.length,
151
- duration,
152
- creates: changeSet.creates.length,
153
- updates: changeSet.updates.length,
154
- deletes: changeSet.deletes.length,
155
- };
156
- output.showDeploySummary(deployResult);
157
- if (this.json) {
158
- console.log(JSON.stringify({
159
- status: 'success',
160
- ...deployResult,
161
- stackName: result.stackName,
162
- entryFile: entryPath,
163
- }, null, 2));
164
- }
165
- return { exitCode: 0 };
166
- }
167
- catch (deployError) {
168
- const duration = (Date.now() - startTime) / 1000;
169
- const deployResult = {
170
- resourceCount: result.cloudDOM.length,
171
- duration,
172
- creates: changeSet.creates.length,
173
- updates: changeSet.updates.length,
174
- deletes: changeSet.deletes.length,
175
- errors: [{ resourceId: 'unknown', message: deployError.message }],
176
- };
177
- output.showDeploySummary(deployResult);
178
- output.showError('Deployment failed', {
179
- cause: deployError.message,
180
- stackTrace: this.verbose ? deployError.stack : undefined,
181
- });
182
- return { exitCode: 1 };
183
- }
184
- }
185
- catch (error) {
186
- output.showError('Deploy command failed', {
187
- cause: error.message,
188
- stackTrace: this.verbose ? error.stack : undefined,
189
- });
190
- return { exitCode: 1 };
191
- }
192
- }
193
- }
194
- exports.DeployCommand = DeployCommand;
@@ -1,52 +0,0 @@
1
- /**
2
-
3
- * Licensed under the Apache License, Version 2.0 (the "License");
4
-
5
- * you may not use this file except in compliance with the License.
6
-
7
- * You may obtain a copy of the License at
8
-
9
- *
10
-
11
- * http://www.apache.org/licenses/LICENSE-2.0
12
-
13
- *
14
-
15
- * Unless required by applicable law or agreed to in writing, software
16
-
17
- * distributed under the License is distributed on an "AS IS" BASIS,
18
-
19
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
-
21
- * See the License for the specific language governing permissions and
22
-
23
- * limitations under the License.
24
-
25
- *
26
-
27
- * Copyright 2025 Daniel Coutinho Ribeiro
28
-
29
- */
30
- /**
31
- * Dev Command - hot reload development mode with auto/manual approval
32
- */
33
- import { BaseCommand, CommandResult } from '../core/BaseCommand';
34
- export declare class DevCommand extends BaseCommand {
35
- private isWatching;
36
- private watchTimeout;
37
- private autoApprove;
38
- private currentReadline;
39
- private output;
40
- private state;
41
- getName(): string;
42
- getDescription(): string;
43
- execute(): Promise<CommandResult>;
44
- private performInitialDeploy;
45
- private performHotReload;
46
- private deployChanges;
47
- private promptForApproval;
48
- private startWatching;
49
- private shouldIgnoreFile;
50
- private keepAlive;
51
- private stopWatching;
52
- }
@@ -1,394 +0,0 @@
1
- "use strict";
2
- /**
3
-
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
-
6
- * you may not use this file except in compliance with the License.
7
-
8
- * You may obtain a copy of the License at
9
-
10
- *
11
-
12
- * http://www.apache.org/licenses/LICENSE-2.0
13
-
14
- *
15
-
16
- * Unless required by applicable law or agreed to in writing, software
17
-
18
- * distributed under the License is distributed on an "AS IS" BASIS,
19
-
20
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
-
22
- * See the License for the specific language governing permissions and
23
-
24
- * limitations under the License.
25
-
26
- *
27
-
28
- * Copyright 2025 Daniel Coutinho Ribeiro
29
-
30
- */
31
- var __importDefault = (this && this.__importDefault) || function (mod) {
32
- return (mod && mod.__esModule) ? mod : { "default": mod };
33
- };
34
- Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.DevCommand = void 0;
36
- /**
37
- * Dev Command - hot reload development mode with auto/manual approval
38
- */
39
- const BaseCommand_1 = require("../core/BaseCommand");
40
- const CLIContext_1 = require("../core/CLIContext");
41
- const Output_1 = require("../../utils/Output");
42
- const fs_1 = require("fs");
43
- const path_1 = require("path");
44
- const readline_1 = require("readline");
45
- const Reconciler_1 = require("../../core/Reconciler");
46
- const Logger_1 = require("../../utils/Logger");
47
- const chalk_1 = __importDefault(require("chalk"));
48
- const logger = Logger_1.LoggerFactory.getLogger('cli');
49
- class DevCommand extends BaseCommand_1.BaseCommand {
50
- constructor() {
51
- super(...arguments);
52
- this.isWatching = false;
53
- this.watchTimeout = null;
54
- this.autoApprove = false;
55
- this.currentReadline = null;
56
- this.state = {
57
- lastCloudDOM: null,
58
- lastStackName: null,
59
- instance: null,
60
- };
61
- }
62
- getName() {
63
- return 'dev';
64
- }
65
- getDescription() {
66
- return 'Hot reload development mode with auto/manual approval';
67
- }
68
- async execute() {
69
- this.output = (0, Output_1.createOutputManager)({
70
- json: this.json,
71
- quiet: !!this.context.flags.quiet,
72
- verbose: this.verbose,
73
- });
74
- try {
75
- // Check for auto-approve flag
76
- this.autoApprove = !!this.context.flags['auto-approve'] || !!this.context.flags.auto;
77
- // Find entry file
78
- logger.debug('DevCommand: Starting execution');
79
- let entryPath;
80
- try {
81
- entryPath = CLIContext_1.CLIContextManager.findEntryFile(this.context.flags.entry);
82
- logger.debug(`DevCommand: Entry file resolved to ${entryPath}`);
83
- }
84
- catch (error) {
85
- this.output.showError('Entry file resolution failed', {
86
- cause: error.message,
87
- stackTrace: this.verbose ? error.stack : undefined,
88
- });
89
- return { exitCode: 1 };
90
- }
91
- // Show mode information
92
- this.output.showInfo('Starting CReact development mode...');
93
- const mode = this.autoApprove ? chalk_1.default.yellow('Auto-approve') : chalk_1.default.blue('Manual approval');
94
- this.output.showInfo(`Mode: ${mode}`);
95
- if (!this.autoApprove) {
96
- this.output.showInfo('Tip: Use --auto-approve to automatically deploy changes');
97
- }
98
- // Start file watching BEFORE initial deploy
99
- this.startWatching(entryPath);
100
- // Initial build and deploy
101
- await this.performInitialDeploy(entryPath);
102
- // Keep process alive
103
- this.output.showInfo('Watching for changes... (Press Ctrl+C to stop)');
104
- // Handle graceful shutdown
105
- process.on('SIGINT', () => {
106
- this.output.showInfo('\nStopping development mode...');
107
- this.stopWatching();
108
- process.exit(0);
109
- });
110
- // Keep the process alive indefinitely
111
- await this.keepAlive();
112
- return { exitCode: 0 };
113
- }
114
- catch (error) {
115
- this.output.showError('Dev mode failed to start', {
116
- cause: error.message,
117
- stackTrace: this.verbose ? error.stack : undefined,
118
- });
119
- return { exitCode: 1 };
120
- }
121
- }
122
- async performInitialDeploy(entryPath) {
123
- try {
124
- this.output.showInfo('Building initial state...');
125
- const result = await CLIContext_1.CLIContextManager.createCLIInstance(entryPath, this.verbose);
126
- logger.debug(`DevCommand: Initial CloudDOM built with ${result.cloudDOM.length} resources`);
127
- // Load backend state for comparison
128
- let previousCloudDOM = [];
129
- try {
130
- const backendState = await result.instance.getBackendProvider().getState(result.stackName);
131
- previousCloudDOM = backendState?.cloudDOM || [];
132
- }
133
- catch (error) {
134
- logger.debug(`DevCommand: Could not load previous state: ${error.message}`);
135
- }
136
- // Compute diff using Reconciler
137
- const reconciler = new Reconciler_1.Reconciler();
138
- const changeSet = reconciler.reconcile(previousCloudDOM, result.cloudDOM);
139
- const totalChanges = (0, Reconciler_1.getTotalChanges)(changeSet);
140
- logger.debug(`DevCommand: Total changes: ${totalChanges}`);
141
- // Store state for future comparisons
142
- this.state.lastCloudDOM = result.cloudDOM;
143
- this.state.lastStackName = result.stackName;
144
- this.state.instance = result.instance;
145
- // Check if there are any changes
146
- if (totalChanges === 0) {
147
- this.output.showSuccess('No changes detected - infrastructure is up to date');
148
- return;
149
- }
150
- this.output.showSuccess(`Changes detected: ${totalChanges} changes`);
151
- // Show plan
152
- this.output.showPlanHeader(result.stackName);
153
- this.output.showPlanChanges(changeSet);
154
- this.output.showPlanSummary(changeSet);
155
- if (this.autoApprove) {
156
- this.output.showWarning('Auto-approving changes...');
157
- await this.deployChanges(result, changeSet);
158
- }
159
- else {
160
- const shouldDeploy = await this.promptForApproval();
161
- if (shouldDeploy) {
162
- await this.deployChanges(result, changeSet);
163
- }
164
- else {
165
- this.output.showInfo('Deployment skipped');
166
- }
167
- }
168
- }
169
- catch (error) {
170
- this.output.showError('Initial deployment failed', {
171
- cause: error.message,
172
- stackTrace: this.verbose ? error.stack : undefined,
173
- });
174
- }
175
- }
176
- async performHotReload(entryPath) {
177
- try {
178
- this.output.showHotReloadStart();
179
- if (!this.state.lastCloudDOM || !this.state.instance) {
180
- this.output.showError('No previous state found');
181
- return;
182
- }
183
- // Create new instance
184
- const result = await CLIContext_1.CLIContextManager.createCLIInstance(entryPath, this.verbose);
185
- logger.debug(`DevCommand: Hot reload CloudDOM built with ${result.cloudDOM.length} resources`);
186
- // Load drift-corrected state for comparison
187
- let previousCloudDOM = this.state.lastCloudDOM;
188
- try {
189
- const backendState = await result.instance.getBackendProvider().getState(result.stackName);
190
- previousCloudDOM = backendState?.cloudDOM || this.state.lastCloudDOM;
191
- logger.debug(`DevCommand: Comparing against drift-corrected state with ${previousCloudDOM?.length || 0} resources`);
192
- }
193
- catch (error) {
194
- logger.debug(`DevCommand: Using cached state for comparison: ${error.message}`);
195
- }
196
- // Compute diff using Reconciler
197
- const reconciler = new Reconciler_1.Reconciler();
198
- const changeSet = reconciler.reconcile(previousCloudDOM, result.cloudDOM);
199
- const totalChanges = (0, Reconciler_1.getTotalChanges)(changeSet);
200
- logger.debug(`DevCommand: Hot reload total changes: ${totalChanges}`);
201
- // Always update state to preserve reactive changes
202
- this.state.lastCloudDOM = result.cloudDOM;
203
- this.state.instance = result.instance;
204
- // Check if there are any changes
205
- if (totalChanges === 0) {
206
- this.output.showSuccess('No changes detected');
207
- return;
208
- }
209
- this.output.showSuccess(`Changes detected: ${totalChanges} changes`);
210
- // Show plan
211
- this.output.showPlanHeader(result.stackName);
212
- this.output.showPlanChanges(changeSet);
213
- this.output.showPlanSummary(changeSet);
214
- if (this.autoApprove) {
215
- this.output.showWarning('Auto-approving changes...');
216
- await this.deployChanges(result, changeSet);
217
- }
218
- else {
219
- const shouldDeploy = await this.promptForApproval();
220
- if (shouldDeploy) {
221
- await this.deployChanges(result, changeSet);
222
- }
223
- else {
224
- this.output.showInfo('Changes skipped');
225
- }
226
- }
227
- }
228
- catch (error) {
229
- this.output.showError('Hot reload failed', {
230
- cause: error.message,
231
- stackTrace: this.verbose ? error.stack : undefined,
232
- });
233
- }
234
- }
235
- async deployChanges(result, changeSet) {
236
- try {
237
- // Reactive deployment loop - continue until no more changes
238
- let deploymentCycle = 1;
239
- let hasMoreChanges = true;
240
- let currentCloudDOM = result.cloudDOM;
241
- while (hasMoreChanges) {
242
- if (deploymentCycle > 1) {
243
- this.output.showInfo(`\nReactive deployment cycle #${deploymentCycle}`);
244
- }
245
- this.output.showDeployHeader();
246
- const startTime = Date.now();
247
- // Deploy
248
- await result.instance.deploy(currentCloudDOM, result.stackName, 'dev-user');
249
- const duration = (Date.now() - startTime) / 1000;
250
- // Update state
251
- this.state.lastCloudDOM = currentCloudDOM;
252
- const deployResult = {
253
- resourceCount: currentCloudDOM.length,
254
- duration,
255
- creates: changeSet.creates.length,
256
- updates: changeSet.updates.length,
257
- deletes: changeSet.deletes.length,
258
- };
259
- this.output.showDeploySummary(deployResult);
260
- // Check if reactive changes were detected
261
- const reactiveInfo = await result.instance.getReactiveDeploymentInfo(result.stackName);
262
- if (reactiveInfo && (0, Reconciler_1.getTotalChanges)(reactiveInfo.changeSet) > 0) {
263
- this.output.showReactiveChangesDetected();
264
- this.output.showPlanChanges(reactiveInfo.changeSet);
265
- this.output.showPlanSummary(reactiveInfo.changeSet);
266
- let shouldContinue = this.autoApprove;
267
- if (!this.autoApprove) {
268
- shouldContinue = await this.promptForApproval();
269
- }
270
- else {
271
- this.output.showWarning('Auto-approving reactive changes...');
272
- }
273
- if (shouldContinue) {
274
- currentCloudDOM = reactiveInfo.cloudDOM;
275
- changeSet = reactiveInfo.changeSet;
276
- deploymentCycle++;
277
- }
278
- else {
279
- this.output.showInfo('Reactive changes skipped');
280
- hasMoreChanges = false;
281
- }
282
- }
283
- else {
284
- hasMoreChanges = false;
285
- }
286
- }
287
- }
288
- catch (error) {
289
- this.output.showError('Deployment failed', {
290
- cause: error.message,
291
- stackTrace: this.verbose ? error.stack : undefined,
292
- });
293
- }
294
- }
295
- async promptForApproval() {
296
- // Close any existing readline interface
297
- if (this.currentReadline) {
298
- this.currentReadline.close();
299
- this.currentReadline = null;
300
- }
301
- const rl = (0, readline_1.createInterface)({
302
- input: process.stdin,
303
- output: process.stdout,
304
- });
305
- this.currentReadline = rl;
306
- return new Promise((resolve) => {
307
- rl.question(chalk_1.default.bold('Deploy these changes? (y/N/a=auto-approve): '), (answer) => {
308
- this.currentReadline = null;
309
- rl.close();
310
- const response = answer.toLowerCase().trim();
311
- if (response === 'a' || response === 'auto') {
312
- this.output.showWarning('Switching to auto-approve mode');
313
- this.autoApprove = true;
314
- resolve(true);
315
- }
316
- else if (response === 'y' || response === 'yes') {
317
- resolve(true);
318
- }
319
- else {
320
- resolve(false);
321
- }
322
- });
323
- });
324
- }
325
- startWatching(entryPath) {
326
- if (this.isWatching)
327
- return;
328
- this.isWatching = true;
329
- const absoluteEntryPath = (0, path_1.resolve)(process.cwd(), entryPath);
330
- const entryDir = (0, path_1.dirname)(absoluteEntryPath);
331
- logger.debug(`DevCommand: Watching directory: ${entryDir}`);
332
- try {
333
- (0, fs_1.watch)(entryDir, { recursive: true }, (eventType, filename) => {
334
- if (!filename)
335
- return;
336
- // Skip certain file types
337
- if (this.shouldIgnoreFile(filename)) {
338
- return;
339
- }
340
- logger.debug(`DevCommand: File event: ${eventType} - ${filename}`);
341
- // Debounce file changes
342
- if (this.watchTimeout) {
343
- clearTimeout(this.watchTimeout);
344
- }
345
- this.watchTimeout = setTimeout(() => {
346
- // Skip hot reload if we don't have initial state yet
347
- if (!this.state.lastCloudDOM) {
348
- logger.debug('DevCommand: Skipping hot reload - waiting for initial deployment');
349
- return;
350
- }
351
- // Cancel any pending prompts
352
- if (this.currentReadline) {
353
- this.output.showInfo('\nNew changes detected, canceling previous prompt...');
354
- this.currentReadline.close();
355
- this.currentReadline = null;
356
- }
357
- this.output.showFileChanged(filename);
358
- this.performHotReload(entryPath);
359
- }, 300);
360
- });
361
- logger.debug('DevCommand: File watcher started successfully');
362
- }
363
- catch (error) {
364
- logger.warn(`DevCommand: Could not watch ${entryDir}: ${error.message}`);
365
- }
366
- }
367
- shouldIgnoreFile(filename) {
368
- // Only watch TypeScript and JavaScript files
369
- const allowedExtensions = ['.ts', '.tsx', '.js', '.jsx'];
370
- const hasAllowedExtension = allowedExtensions.some((ext) => filename.endsWith(ext));
371
- if (!hasAllowedExtension) {
372
- return true;
373
- }
374
- // Ignore certain patterns
375
- const ignoredPatterns = ['node_modules', '.git', 'dist', '.next', '.cache', 'test', 'spec'];
376
- if (ignoredPatterns.some((pattern) => filename.includes(pattern))) {
377
- return true;
378
- }
379
- return false;
380
- }
381
- async keepAlive() {
382
- return new Promise(() => {
383
- // This promise never resolves, keeping the process alive
384
- });
385
- }
386
- stopWatching() {
387
- this.isWatching = false;
388
- if (this.watchTimeout) {
389
- clearTimeout(this.watchTimeout);
390
- this.watchTimeout = null;
391
- }
392
- }
393
- }
394
- exports.DevCommand = DevCommand;
@@ -1,39 +0,0 @@
1
- /**
2
-
3
- * Licensed under the Apache License, Version 2.0 (the "License");
4
-
5
- * you may not use this file except in compliance with the License.
6
-
7
- * You may obtain a copy of the License at
8
-
9
- *
10
-
11
- * http://www.apache.org/licenses/LICENSE-2.0
12
-
13
- *
14
-
15
- * Unless required by applicable law or agreed to in writing, software
16
-
17
- * distributed under the License is distributed on an "AS IS" BASIS,
18
-
19
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
-
21
- * See the License for the specific language governing permissions and
22
-
23
- * limitations under the License.
24
-
25
- *
26
-
27
- * Copyright 2025 Daniel Coutinho Ribeiro
28
-
29
- */
30
- /**
31
- * Plan Command - shows diff between current and previous CloudDOM
32
- */
33
- import { BaseCommand, CommandResult } from '../core/BaseCommand';
34
- export declare class PlanCommand extends BaseCommand {
35
- getName(): string;
36
- getDescription(): string;
37
- execute(): Promise<CommandResult>;
38
- private printVerboseOutput;
39
- }