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 347bdbc commit 1796a55
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 1796a55

Please sign in to comment.