Skip to content

Commit

Permalink
Only load package-json if existent (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-bromann authored Nov 3, 2021
1 parent e51d768 commit a05336b
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,22 @@ async function createWebdriverIO(opts: ProgramOpts) {
const deps = ['@wdio/cli']
await install(deps.flat(), root, opts)
console.log('\nFinished installing packages.')

console.log('\nRunning WDIO CLI Wizard...')
await runProgram('npx', ['wdio', 'config', ...(useYarn ? ['--yarn'] : []), ...(opts.yes ? ['--yes'] : [])])

console.log('Adding scripts to package.json')
const isUsingTypescript = await exists('wdio.conf.ts')
const pkgJson = require(pkgJsonPath)
if (!pkgJson.scripts) {
pkgJson.scripts = {}

if (await exists(pkgJsonPath)) {
console.log('Adding scripts to package.json')

const pkgJson = require(pkgJsonPath)
const isUsingTypescript = await exists('wdio.conf.ts')

if (!pkgJson.scripts) {
pkgJson.scripts = {}
}
pkgJson.scripts['wdio'] = `wdio run wdio.conf.${isUsingTypescript ? 'ts' : 'js'}`
await fs.promises.writeFile(pkgJsonPath, JSON.stringify(pkgJson, null, 4))
}
pkgJson.scripts['wdio'] = `wdio run wdio.conf.${isUsingTypescript ? 'ts' : 'js'}`
await fs.promises.writeFile(pkgJsonPath, JSON.stringify(pkgJson, null, 4))

console.log(`\n🤖 Successfully setup project at ${root} 🎉`)
if (root != ewd) {
Expand Down

0 comments on commit a05336b

Please # to comment.