create-wdio
Advanced tools
Comparing version 8.3.4 to 8.4.0
import fs from 'node:fs/promises'; | ||
import path from 'node:path'; | ||
import { pathToFileURL } from 'node:url'; | ||
import chalk from 'chalk'; | ||
import semver from 'semver'; | ||
import { detect } from 'detect-package-manager'; | ||
import { readPackageUp } from 'read-pkg-up'; | ||
import { Command } from 'commander'; | ||
import { resolve } from 'import-meta-resolve'; | ||
import { runProgram, getPackageVersion } from './utils.js'; | ||
import { ASCII_ROBOT, PROGRAM_TITLE, UNSUPPORTED_NODE_VERSION, DEFAULT_NPM_TAG, INSTALL_COMMAND, DEV_FLAG, PMs } from './constants.js'; | ||
import { execSync } from 'node:child_process'; | ||
const WDIO_COMMAND = 'wdio'; | ||
@@ -45,41 +46,33 @@ let projectDir; | ||
/** | ||
* check if a package.json exists and if not create one | ||
* find package manager that was used to create project | ||
*/ | ||
const project = await readPackageUp({ cwd: root }); | ||
if (!project) { | ||
const pm = PMs.find((pm) => ( | ||
// for pnpm check for "~/Library/pnpm/store/v3/..." | ||
process.argv[1].includes(`${path.sep}${pm}${path.sep}`) || | ||
// for NPM and Yarn check for "~/.npm/npx/..." or "~/.yarn/bin/create-wdio" | ||
process.argv[1].includes(`${path.sep}.${pm}${path.sep}`))) || 'npm'; | ||
const hasPackageJson = await fs.access(path.resolve(root, 'package.json')).then(() => true).catch(() => false); | ||
if (!hasPackageJson) { | ||
await fs.mkdir(root, { recursive: true }); | ||
await fs.writeFile(path.resolve(root, 'package.json'), JSON.stringify({ | ||
name: 'my-new-project', | ||
name: root.replace(/\/$/, '').split('/').pop(), | ||
type: 'module' | ||
}, null, 2)); | ||
/** | ||
* find package manager that was used to create project | ||
*/ | ||
const pm = PMs.find((pm) => ( | ||
// for pnpm check for "~/Library/pnpm/store/v3/..." | ||
process.argv[1].includes(`${path.sep}${pm}${path.sep}`) || | ||
// for NPM and Yarn check for "~/.npm/npx/..." or "~/.yarn/bin/create-wdio" | ||
process.argv[1].includes(`${path.sep}.${pm}${path.sep}`))) || 'npm'; | ||
/** | ||
* create a package-lock.json, yarn.lock or pnpm-lock.yaml so | ||
* that `detect-package-manager` doesn't mark it as a default | ||
* Yarn project | ||
* @see https://github.com/egoist/detect-package-manager/issues/11 | ||
*/ | ||
await runProgram(pm, ['install'], { cwd: root, stdio: 'ignore' }); | ||
} | ||
console.log(`\nInstalling ${chalk.bold('@wdio/cli')} to initialize project...`); | ||
const pm = await detect({ cwd: root }); | ||
const args = [INSTALL_COMMAND[pm]]; | ||
if (pm === 'yarn') { | ||
args.push('--exact', '--cwd', root); | ||
const cliInstalled = await isCLIInstalled(root); | ||
if (!cliInstalled) { | ||
console.log(`\nInstalling ${chalk.bold('@wdio/cli')} to initialize project...`); | ||
const args = [INSTALL_COMMAND[pm]]; | ||
if (pm === 'yarn') { | ||
args.push('--exact', '--cwd', root); | ||
} | ||
if (opts.dev) { | ||
args.push(DEV_FLAG[pm]); | ||
} | ||
args.push(`@wdio/cli${npmTag}`); | ||
await runProgram(pm, args, { cwd: root, stdio: 'ignore' }); | ||
console.log(chalk.green.bold('✔ Success!')); | ||
} | ||
if (opts.dev) { | ||
args.push(DEV_FLAG[pm]); | ||
} | ||
args.push(`@wdio/cli${npmTag}`); | ||
await runProgram(pm, args, { cwd: root, stdio: 'ignore' }); | ||
console.log(chalk.green.bold('✔ Success!')); | ||
return runProgram('npx', [ | ||
WDIO_COMMAND, | ||
return runProgram(pm === 'npm' ? 'npx' : pm, [ | ||
`${pm === 'npm' ? '' : 'run '}${WDIO_COMMAND}`, | ||
'config', | ||
@@ -89,1 +82,17 @@ ...(opts.yes ? ['--yes'] : []) | ||
} | ||
async function isCLIInstalled(path) { | ||
try { | ||
// can be replaced with import.meta.resolve('@wdio/cli', new URL(`file:///${root}`).href) in the future | ||
// check if the cli is installed in the project | ||
resolve('@wdio/cli', pathToFileURL(path).href); | ||
return true; | ||
} | ||
catch (error) { | ||
// check of the cli is installed globally | ||
const output = execSync('npm ls -g', { encoding: 'utf-8' }); | ||
if (output.includes('@wdio/cli')) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
} |
{ | ||
"name": "create-wdio", | ||
"version": "8.3.4", | ||
"version": "8.4.0", | ||
"description": "Install and setup a WebdriverIO project with all its dependencies in a single run", | ||
@@ -49,5 +49,5 @@ "author": "Christian Bromann <mail@bromann.dev>", | ||
"eslint-plugin-import": "^2.27.5", | ||
"eslint-plugin-unicorn": "^48.0.0", | ||
"eslint-plugin-unicorn": "^49.0.0", | ||
"npm-run-all": "^4.1.5", | ||
"release-it": "^16.1.2", | ||
"release-it": "^17.0.0", | ||
"typescript": "^5.1.6", | ||
@@ -60,6 +60,5 @@ "vitest": "^0.34.1" | ||
"cross-spawn": "^7.0.3", | ||
"detect-package-manager": "^3.0.1", | ||
"read-pkg-up": "^10.0.0", | ||
"import-meta-resolve": "^4.0.0", | ||
"semver": "^7.5.4" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17054
5
292
+ Addedimport-meta-resolve@^4.0.0
+ Addedimport-meta-resolve@4.1.0(transitive)
- Removeddetect-package-manager@^3.0.1
- Removedread-pkg-up@^10.0.0
- Removed@babel/code-frame@7.26.2(transitive)
- Removed@babel/helper-validator-identifier@7.25.9(transitive)
- Removed@types/normalize-package-data@2.4.4(transitive)
- Removeddetect-package-manager@3.0.2(transitive)
- Removederror-ex@1.3.2(transitive)
- Removedexeca@5.1.1(transitive)
- Removedfind-up@6.3.0(transitive)
- Removedget-stream@6.0.1(transitive)
- Removedhosted-git-info@7.0.2(transitive)
- Removedhuman-signals@2.1.0(transitive)
- Removedis-arrayish@0.2.1(transitive)
- Removedis-stream@2.0.1(transitive)
- Removedjs-tokens@4.0.0(transitive)
- Removedjson-parse-even-better-errors@3.0.2(transitive)
- Removedlines-and-columns@2.0.4(transitive)
- Removedlocate-path@7.2.0(transitive)
- Removedlru-cache@10.4.3(transitive)
- Removedmerge-stream@2.0.0(transitive)
- Removedmimic-fn@2.1.0(transitive)
- Removednormalize-package-data@6.0.2(transitive)
- Removednpm-run-path@4.0.1(transitive)
- Removedonetime@5.1.2(transitive)
- Removedp-limit@4.0.0(transitive)
- Removedp-locate@6.0.0(transitive)
- Removedparse-json@7.1.1(transitive)
- Removedpath-exists@5.0.0(transitive)
- Removedpicocolors@1.1.1(transitive)
- Removedread-pkg@8.1.0(transitive)
- Removedread-pkg-up@10.1.0(transitive)
- Removedsignal-exit@3.0.7(transitive)
- Removedspdx-correct@3.2.0(transitive)
- Removedspdx-exceptions@2.5.0(transitive)
- Removedspdx-expression-parse@3.0.1(transitive)
- Removedspdx-license-ids@3.0.20(transitive)
- Removedstrip-final-newline@2.0.0(transitive)
- Removedtype-fest@3.13.14.29.0(transitive)
- Removedvalidate-npm-package-license@3.0.4(transitive)
- Removedyocto-queue@1.1.1(transitive)