Skip to content

Commit

Permalink
allow to create wdio project with certain npm tag
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-bromann committed Sep 8, 2022
1 parent 75ccd97 commit 4e76ca4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import chalk from 'chalk'

export const DEFAULT_NPM_TAG = 'latest'
const colorItBold = chalk.bold.rgb(234, 89, 6)
const colorIt = chalk.rgb(234, 89, 6)

Expand Down
27 changes: 17 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ import { Command } from 'commander'
import semver from 'semver'

import { exists, runProgram, shouldUseYarn, checkThatNpmCanReadCwd } from './utils'
import { ASCII_ROBOT, PROGRAM_TITLE, UNSUPPORTED_NODE_VERSION } from './constants'
import { ASCII_ROBOT, PROGRAM_TITLE, UNSUPPORTED_NODE_VERSION, DEFAULT_NPM_TAG } from './constants'
import type { ProgramOpts } from './types'

let pkg = { version: 'unknown' }
try { pkg = JSON.parse(fs.readFileSync(__dirname + '/../package.json').toString()) } catch (e: any) { /* ignore */ }
try {
pkg = JSON.parse(fs.readFileSync(__dirname + '/../package.json').toString())
} catch (e: any) {
/* ignore */
}

let projectName: string | undefined
let useYarn: boolean | undefined
Expand All @@ -28,10 +32,11 @@ export function run (operation = createWebdriverIO) {
.arguments('[project]')
.usage(`${chalk.green('[project]')} [options]`)
.action(name => (projectName = name))
.option('--use-yarn', 'Use Yarn package manager to install packages', false)
.option('--verbose', 'print additional logs')
.option('--yes', 'will fill in all config defaults without prompting', false)
.option('--dev', 'Install all packages as into devDependencies', true)
.option('-t, --npm-tag <tag>', 'Which NPM version you like to install, e.g. @next', DEFAULT_NPM_TAG)
.option('-u, --use-yarn', 'Use Yarn package manager to install packages', false)
.option('-v, --verbose', 'print additional logs')
.option('-y, --yes', 'will fill in all config defaults without prompting', false)
.option('-d, --dev', 'Install all packages as into devDependencies', true)

.allowUnknownOption()
.on('--help', () => console.log())
Expand All @@ -57,7 +62,8 @@ export function run (operation = createWebdriverIO) {
}

async function createWebdriverIO(opts: ProgramOpts) {
const ewd = process.cwd()
const cwd = process.cwd()
const npmTag = opts.npmTag.startsWith('@') ? opts.npmTag : `@${opts.npmTag}`

const unsupportedNodeVersion = !semver.satisfies(process.version, '>=12')
if (unsupportedNodeVersion) {
Expand Down Expand Up @@ -90,8 +96,9 @@ async function createWebdriverIO(opts: ProgramOpts) {
}
await fs.promises.writeFile(pkgJsonPath, JSON.stringify(pkgJson, null, 4))
}

const deps = ['@wdio/cli']

const deps = [`@wdio/cli${npmTag}`]

await install(deps.flat(), root, opts)
console.log('\nFinished installing packages.')

Expand All @@ -112,7 +119,7 @@ async function createWebdriverIO(opts: ProgramOpts) {
}

console.log(`\n🤖 Successfully setup project at ${root} 🎉`)
if (root != ewd) {
if (root != cwd) {
console.log(`\n${chalk.yellow('⚠')} First, change the directory via: ${chalk.cyan('$ cd')} ${chalk.green(root)}`)
}
}
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export interface ProgramOpts {
info: boolean
dev: boolean
yes: boolean
npmTag: string
}

0 comments on commit 4e76ca4

Please sign in to comment.