-
Notifications
You must be signed in to change notification settings - Fork 738
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cli): keepPackageJsonClean开启后lock不要修改
- Loading branch information
Showing
3 changed files
with
57 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
export const backupFile = (runtimeSource: string, file: string) => { | ||
const filePath = path.join(runtimeSource, file); | ||
|
||
if (fs.existsSync(filePath)) { | ||
fs.copyFileSync(filePath, `${filePath}.bak`); | ||
} | ||
}; | ||
|
||
export const backupPnpmLock = (runtimeSource: string) => backupFile(runtimeSource, 'pnpm-lock.yaml'); | ||
export const backupYarnLock = (runtimeSource: string) => backupFile(runtimeSource, 'yarn-lock.json'); | ||
export const backupNpmLock = (runtimeSource: string) => backupFile(runtimeSource, 'package-lock.json'); | ||
export const backupPackageJson = (runtimeSource: string) => backupFile(runtimeSource, 'package.json'); | ||
|
||
export const backupLock = (runtimeSource: string, npmType: string) => { | ||
if (npmType === 'pnpm') { | ||
backupPnpmLock(runtimeSource); | ||
} else if (npmType === 'yarn') { | ||
backupYarnLock(runtimeSource); | ||
} | ||
if (npmType === 'npm') { | ||
backupNpmLock(runtimeSource); | ||
} | ||
}; | ||
|
||
export const restoreFile = (runtimeSource: string, file: string) => { | ||
const filePath = path.join(runtimeSource, file); | ||
|
||
if (fs.existsSync(filePath)) { | ||
fs.unlinkSync(filePath); | ||
fs.renameSync(`${filePath}.bak`, filePath); | ||
} | ||
}; | ||
|
||
export const restorePnpmLock = (runtimeSource: string) => restoreFile(runtimeSource, 'pnpm-lock.yaml'); | ||
export const restoreYarnLock = (runtimeSource: string) => restoreFile(runtimeSource, 'yarn-lock.json'); | ||
export const restoreNpmLock = (runtimeSource: string) => restoreFile(runtimeSource, 'package-lock.json'); | ||
export const restorePackageJson = (runtimeSource: string) => restoreFile(runtimeSource, 'package.json'); | ||
|
||
export const restoreLock = (runtimeSource: string, npmType: string) => { | ||
if (npmType === 'pnpm') { | ||
restorePnpmLock(runtimeSource); | ||
} else if (npmType === 'yarn') { | ||
restoreYarnLock(runtimeSource); | ||
} | ||
if (npmType === 'npm') { | ||
restoreNpmLock(runtimeSource); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters