-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtrigger-dev.mjs
More file actions
executable file
·58 lines (45 loc) · 1.6 KB
/
trigger-dev.mjs
File metadata and controls
executable file
·58 lines (45 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env node
import { readFileSync } from 'fs';
import { spawn } from 'child_process';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
const __dirname = dirname(fileURLToPath(import.meta.url));
const packageJsonPath = join(__dirname, '..', 'package.json');
// Read and parse package.json
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
// Get the version from either dependencies or devDependencies
const triggerVersion =
packageJson.dependencies?.['@trigger.dev/sdk'] ||
packageJson.devDependencies?.['@trigger.dev/build'] ||
packageJson.devDependencies?.['@trigger.dev/sdk'];
if (!triggerVersion) {
console.error(
'❌ Could not find @trigger.dev/sdk or @trigger.dev/build in package.json'
);
process.exit(1);
}
// Extract the version (remove ^ or ~ if present)
const cleanVersion = triggerVersion.replace(/^[\^~]/, '');
console.log(`📦 Using Trigger.dev version: ${cleanVersion}`);
// Get the command (dev, deploy, etc.) from command line arguments
const command = process.argv[2] || 'dev';
const additionalArgs = process.argv.slice(3);
// Construct the npx command
const npxCommand = `trigger.dev@${cleanVersion}`;
const args = [npxCommand, command, ...additionalArgs];
console.log(
`🚀 Running: npx ${npxCommand} ${command} ${additionalArgs.join(' ')}`
);
// Spawn the process
const child = spawn('npx', args, {
stdio: 'inherit',
shell: true,
});
// Handle process exit
child.on('close', (code) => {
process.exit(code);
});
child.on('error', (error) => {
console.error('❌ Failed to start trigger.dev:', error);
process.exit(1);
});