@solidactions/cli 0.2.7 → 0.3.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.
- package/dist/commands/dev.js +129 -0
- package/dist/index.js +9 -0
- package/package.json +1 -1
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.dev = dev;
|
|
7
|
+
const child_process_1 = require("child_process");
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
11
|
+
async function dev(file, options) {
|
|
12
|
+
// Resolve the workflow file path
|
|
13
|
+
const filePath = path_1.default.resolve(file);
|
|
14
|
+
if (!fs_1.default.existsSync(filePath)) {
|
|
15
|
+
console.error(chalk_1.default.red(`File not found: ${filePath}`));
|
|
16
|
+
process.exit(1);
|
|
17
|
+
}
|
|
18
|
+
// Find the project root (directory containing package.json)
|
|
19
|
+
const projectDir = findProjectRoot(filePath);
|
|
20
|
+
if (!projectDir) {
|
|
21
|
+
console.error(chalk_1.default.red('Could not find package.json in parent directories.'));
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
// Check that @solidactions/sdk is installed
|
|
25
|
+
const sdkPath = path_1.default.join(projectDir, 'node_modules', '@solidactions', 'sdk');
|
|
26
|
+
if (!fs_1.default.existsSync(sdkPath)) {
|
|
27
|
+
console.error(chalk_1.default.red('@solidactions/sdk is not installed in this project.'));
|
|
28
|
+
console.log(chalk_1.default.gray('Run: npm install @solidactions/sdk'));
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
31
|
+
// Check that the testing export exists
|
|
32
|
+
const testingPath = path_1.default.join(sdkPath, 'dist', 'src', 'testing');
|
|
33
|
+
if (!fs_1.default.existsSync(testingPath)) {
|
|
34
|
+
console.error(chalk_1.default.red('@solidactions/sdk version does not include testing utilities.'));
|
|
35
|
+
console.log(chalk_1.default.gray('Update to the latest SDK version: npm install @solidactions/sdk@latest'));
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
// Validate input JSON if provided
|
|
39
|
+
const input = options.input || '{}';
|
|
40
|
+
try {
|
|
41
|
+
JSON.parse(input);
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
console.error(chalk_1.default.red('Invalid JSON input. Use -i \'{"key": "value"}\''));
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
|
47
|
+
// Write temp bootstrap file
|
|
48
|
+
const bootstrapPath = path_1.default.join(projectDir, '.solidactions-dev-bootstrap.mjs');
|
|
49
|
+
const bootstrapContent = generateBootstrap(filePath, input);
|
|
50
|
+
try {
|
|
51
|
+
fs_1.default.writeFileSync(bootstrapPath, bootstrapContent);
|
|
52
|
+
console.log(chalk_1.default.blue('SolidActions local dev mode'));
|
|
53
|
+
console.log(chalk_1.default.gray(`File: ${path_1.default.relative(projectDir, filePath)}`));
|
|
54
|
+
console.log(chalk_1.default.gray(`Input: ${input}`));
|
|
55
|
+
console.log(chalk_1.default.gray('---'));
|
|
56
|
+
// Spawn npx tsx with the bootstrap file
|
|
57
|
+
const child = (0, child_process_1.spawn)('npx', ['tsx', bootstrapPath], {
|
|
58
|
+
stdio: 'inherit',
|
|
59
|
+
cwd: projectDir,
|
|
60
|
+
});
|
|
61
|
+
child.on('error', (err) => {
|
|
62
|
+
cleanup(bootstrapPath);
|
|
63
|
+
if (err.code === 'ENOENT') {
|
|
64
|
+
console.error(chalk_1.default.red('npx not found. Make sure Node.js is installed.'));
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
console.error(chalk_1.default.red(`Failed to start: ${err.message}`));
|
|
68
|
+
}
|
|
69
|
+
process.exit(1);
|
|
70
|
+
});
|
|
71
|
+
child.on('exit', (code) => {
|
|
72
|
+
cleanup(bootstrapPath);
|
|
73
|
+
process.exit(code ?? 1);
|
|
74
|
+
});
|
|
75
|
+
// Also clean up on signals
|
|
76
|
+
process.on('SIGINT', () => {
|
|
77
|
+
cleanup(bootstrapPath);
|
|
78
|
+
child.kill('SIGINT');
|
|
79
|
+
});
|
|
80
|
+
process.on('SIGTERM', () => {
|
|
81
|
+
cleanup(bootstrapPath);
|
|
82
|
+
child.kill('SIGTERM');
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
catch (err) {
|
|
86
|
+
cleanup(bootstrapPath);
|
|
87
|
+
console.error(chalk_1.default.red(`Failed: ${err.message}`));
|
|
88
|
+
process.exit(1);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function generateBootstrap(workflowFile, input) {
|
|
92
|
+
// Use forward slashes for the import path (works cross-platform in ESM)
|
|
93
|
+
const importPath = workflowFile.replace(/\\/g, '/');
|
|
94
|
+
return `// Auto-generated by solidactions dev - do not commit
|
|
95
|
+
import { createMockServer } from '@solidactions/sdk/testing';
|
|
96
|
+
|
|
97
|
+
const server = await createMockServer();
|
|
98
|
+
|
|
99
|
+
process.env.SOLIDACTIONS_API_URL = server.baseUrl;
|
|
100
|
+
process.env.SOLIDACTIONS_API_KEY = 'local-dev';
|
|
101
|
+
process.env.WORKFLOW_INPUT = ${JSON.stringify(input)};
|
|
102
|
+
|
|
103
|
+
// Import the workflow file - this triggers SolidActions.run() at module level
|
|
104
|
+
await import(${JSON.stringify(importPath)});
|
|
105
|
+
`;
|
|
106
|
+
}
|
|
107
|
+
function findProjectRoot(startPath) {
|
|
108
|
+
let dir = path_1.default.dirname(startPath);
|
|
109
|
+
for (let i = 0; i < 10; i++) {
|
|
110
|
+
if (fs_1.default.existsSync(path_1.default.join(dir, 'package.json'))) {
|
|
111
|
+
return dir;
|
|
112
|
+
}
|
|
113
|
+
const parent = path_1.default.dirname(dir);
|
|
114
|
+
if (parent === dir)
|
|
115
|
+
break;
|
|
116
|
+
dir = parent;
|
|
117
|
+
}
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
function cleanup(filePath) {
|
|
121
|
+
try {
|
|
122
|
+
if (fs_1.default.existsSync(filePath)) {
|
|
123
|
+
fs_1.default.unlinkSync(filePath);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
// Ignore cleanup errors
|
|
128
|
+
}
|
|
129
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -18,6 +18,7 @@ const schedule_set_1 = require("./commands/schedule-set");
|
|
|
18
18
|
const schedule_list_1 = require("./commands/schedule-list");
|
|
19
19
|
const schedule_delete_1 = require("./commands/schedule-delete");
|
|
20
20
|
const webhooks_1 = require("./commands/webhooks");
|
|
21
|
+
const dev_1 = require("./commands/dev");
|
|
21
22
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
22
23
|
const pkg = require('../package.json');
|
|
23
24
|
const program = new commander_1.Command();
|
|
@@ -92,6 +93,14 @@ program
|
|
|
92
93
|
.action((project, options) => {
|
|
93
94
|
(0, runs_1.runs)(project, options);
|
|
94
95
|
});
|
|
96
|
+
program
|
|
97
|
+
.command('dev')
|
|
98
|
+
.description('Run a workflow locally using an in-memory mock server (no deploy needed)')
|
|
99
|
+
.argument('<file>', 'Workflow file to run (e.g., src/simple-steps.ts)')
|
|
100
|
+
.option('-i, --input <json>', 'JSON input for the workflow', '{}')
|
|
101
|
+
.action((file, options) => {
|
|
102
|
+
(0, dev_1.dev)(file, options);
|
|
103
|
+
});
|
|
95
104
|
// =============================================================================
|
|
96
105
|
// Logs
|
|
97
106
|
// =============================================================================
|