Skip to content

Commit 699878a

Browse files
neo773ericallam
andauthored
feat: Add update checker for CLI (#412)
* feat: Add update checker for CLI * Create soft-hounds-clap.md --------- Co-authored-by: Eric Allam <[email protected]>
1 parent d2c9b64 commit 699878a

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

.changeset/soft-hounds-clap.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@trigger.dev/cli": patch
3+
---
4+
5+
feat: Checks for outdated packages when running the dev command with instructions on how to update

packages/cli/src/commands/dev.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import { getTriggerApiDetails } from "../utils/getTriggerApiDetails";
1212
import { logger } from "../utils/logger";
1313
import { resolvePath } from "../utils/parseNameAndPath";
1414
import { TriggerApi } from "../utils/triggerApi";
15+
import { run as ncuRun } from 'npm-check-updates'
16+
import chalk from "chalk";
1517

1618
const asyncExecFile = util.promisify(childProcess.execFile);
1719

@@ -45,6 +47,7 @@ export async function devCommand(path: string, anyOptions: any) {
4547
const options = result.data;
4648

4749
const resolvedPath = resolvePath(path);
50+
await checkForOutdatedPackages(resolvedPath)
4851

4952
// Read from package.json to get the endpointId
5053
const endpointId = await getEndpointIdFromPackageJson(resolvedPath, options);
@@ -205,6 +208,36 @@ export async function devCommand(path: string, anyOptions: any) {
205208
throttle(refresh, throttleTimeMs);
206209
}
207210

211+
export async function checkForOutdatedPackages(path: string) {
212+
213+
const updates = await ncuRun({
214+
packageFile: `${path}/package.json`,
215+
filter: "/trigger.dev\/.+$/",
216+
upgrade: false,
217+
}) as {
218+
[key: string]: string;
219+
}
220+
221+
if (typeof updates === 'undefined' || Object.keys(updates).length === 0) {
222+
return;
223+
}
224+
225+
const packageFile = await fs.readFile(`${path}/package.json`);
226+
const data = JSON.parse(Buffer.from(packageFile).toString('utf8'));
227+
const dependencies = data.dependencies;
228+
console.log(
229+
chalk.bgYellow('Updates available for trigger.dev packages')
230+
);
231+
console.log(
232+
chalk.bgBlue('Run npx @trigger.dev/cli@latest update')
233+
);
234+
235+
for (let dep in updates) {
236+
console.log(`${dep} ${dependencies[dep]}${updates[dep]}`);
237+
}
238+
239+
}
240+
208241
export async function getEndpointIdFromPackageJson(path: string, options: DevCommandOptions) {
209242
if (options.clientId) {
210243
return options.clientId;

0 commit comments

Comments
 (0)