|
1 |
| -import fs from "fs"; |
2 | 1 | import path from "path";
|
3 | 2 | import inquirer from "inquirer";
|
4 | 3 | import { run, RunOptions } from "npm-check-updates";
|
5 | 4 | import { installDependencies } from "../utils/installDependencies.js";
|
6 | 5 | 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"; |
26 | 7 |
|
27 | 8 | export async function updateCommand(projectPath: string) {
|
28 | 9 | const triggerDevPackage = "@trigger.dev";
|
29 |
| - const packageData = getPackageJSON(projectPath); |
| 10 | + const packageJSONPath = path.join(projectPath, "package.json") |
| 11 | + const packageData = readJSONFileSync(packageJSONPath); |
30 | 12 |
|
31 | 13 | if (!packageData) {
|
32 | 14 | return;
|
@@ -113,7 +95,7 @@ export async function updateCommand(projectPath: string) {
|
113 | 95 | newPackageJSON[tmp.type][packageName] = updatedDependencies[packageName];
|
114 | 96 | }
|
115 | 97 | });
|
116 |
| - setPackageJSON(projectPath, newPackageJSON); |
| 98 | + await writeJSONFile(packageJSONPath, newPackageJSON); |
117 | 99 | console.log("package.json updated. Reinstalling dependencies...");
|
118 | 100 | await installDependencies(projectPath);
|
119 | 101 | } else {
|
|
0 commit comments