Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
snake-py committed Sep 21, 2024
1 parent 791faec commit d58403f
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions vike/node/cli/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,29 @@ cli
}
console.log('Ejected dependencies:', successFullEjections)
if (successFullEjections.length > 0) {
updatePackageJson(successFullEjections)
updatePackageJson(successFullEjections, 'dependencies')
updatePackageJson(successFullEjections, 'devDependencies')
console.log('we updated your package.json and linked the dependencies to the ejected folder')
console.log('finalize the ejection by running npm install')
} else {
console.log('No dependencies ejected')
}
})

function updatePackageJson(successFullEjections: string[]) {
function updatePackageJson(successFullEjections: string[], type: 'dependencies' | 'devDependencies') {
const packageJson = require(resolve('./package.json'))
const updatedDependencies: Record<string, string> = {}
for (const key in packageJson.dependencies) {
for (const key in packageJson[type]) {
if (!successFullEjections.includes(key)) {
updatedDependencies[key] = packageJson.dependencies[key]
updatedDependencies[key] = packageJson[type][key]
} else {
updatedDependencies[key] = packageJson.dependencies[`file:./ejected/${key}`]
updatedDependencies[key] = `file:./ejected/${key}`
}
}
packageJson.dependencies = updatedDependencies
packageJson[type] = updatedDependencies
fs.writeFile(resolve('./package.json'), JSON.stringify(packageJson, null, 2), (err) => {
if (err) {
// console.log('Error Found:', err)
} else {
console.log('Updated package.json')
console.log('Error Found:', err)
}
})
}
Expand Down

0 comments on commit d58403f

Please sign in to comment.