Skip to content

Commit

Permalink
Retain original package name property
Browse files Browse the repository at this point in the history
  • Loading branch information
BenSurgisonGDS committed Nov 18, 2022
1 parent a13b478 commit d141c9a
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions bin/cli
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ const packageJson = {
}
}

async function updatePackageJson (packageJsonPath) {
let newPackageJson = Object.assign({}, packageJson)
async function updatePackageJson (packageJsonPath, data = {}) {
let newPackageJson = Object.assign(data, packageJson)
newPackageJson = Object.assign(newPackageJson, await fs.readJson(packageJsonPath))
await fs.writeJson(packageJsonPath, newPackageJson, packageJsonFormat)
}
Expand Down Expand Up @@ -236,8 +236,13 @@ function warnIfNpmStart (argv, env) {

const projectDirectory = process.argv[4]

// extract the name from the original package.json
const pkgJson = await fs.readJson(path.join(projectDirectory, 'package.json'))
// if the name doesn't exist, use the name of the project directory
const { name = projectDirectory.split('/').pop() } = pkgJson || {}

await Promise.all([
updatePackageJson(path.join(projectDirectory, 'package.json')),
updatePackageJson(path.join(projectDirectory, 'package.json'), { name }),
fs.writeFile(path.join(projectDirectory, '.npmrc'), npmrc, 'utf8'),
fs.access(path.join(projectDirectory, '.gitignore'))
.catch(() => fs.writeFile(path.join(projectDirectory, '.gitignore'), gitignore, 'utf8'))
Expand Down

0 comments on commit d141c9a

Please sign in to comment.