Skip to content

Commit 367ce2e

Browse files
author
Rishi Raj Jain
committed
use exitsing methods
1 parent 92f80fd commit 367ce2e

File tree

1 file changed

+4
-22
lines changed

1 file changed

+4
-22
lines changed

packages/cli/src/commands/update.ts

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,14 @@
1-
import fs from "fs";
21
import path from "path";
32
import inquirer from "inquirer";
43
import { run, RunOptions } from "npm-check-updates";
54
import { installDependencies } from "../utils/installDependencies.js";
65
import { Index } from "npm-check-updates/build/src/types/IndexType.js";
7-
8-
function getPackageJSON(projectPath: string) {
9-
const packageJsonPath = path.join(projectPath, "package.json");
10-
if (!fs.existsSync(packageJsonPath)) {
11-
console.error(`package.json not found in the ${projectPath} directory.`);
12-
return;
13-
}
14-
return JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
15-
}
16-
17-
function setPackageJSON(projectPath: string, updatedPackageJSON: Index) {
18-
const packageJsonPath = path.join(projectPath, "package.json");
19-
if (!fs.existsSync(packageJsonPath)) {
20-
console.error(`package.json not found in the ${projectPath} directory.`);
21-
return;
22-
}
23-
fs.writeFileSync(packageJsonPath, JSON.stringify(updatedPackageJSON, null, 2), "utf8");
24-
return;
25-
}
6+
import { readJSONFileSync, writeJSONFile } from "../utils/fileSystem.js";
267

278
export async function updateCommand(projectPath: string) {
289
const triggerDevPackage = "@trigger.dev";
29-
const packageData = getPackageJSON(projectPath);
10+
const packageJSONPath = path.join(projectPath, "package.json")
11+
const packageData = readJSONFileSync(packageJSONPath);
3012

3113
if (!packageData) {
3214
return;
@@ -113,7 +95,7 @@ export async function updateCommand(projectPath: string) {
11395
newPackageJSON[tmp.type][packageName] = updatedDependencies[packageName];
11496
}
11597
});
116-
setPackageJSON(projectPath, newPackageJSON);
98+
await writeJSONFile(packageJSONPath, newPackageJSON);
11799
console.log("package.json updated. Reinstalling dependencies...");
118100
await installDependencies(projectPath);
119101
} else {

0 commit comments

Comments
 (0)