create-wdio 8.3.4 → 8.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/index.js +43 -34
- package/package.json +4 -5
package/build/index.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
+
import { pathToFileURL } from 'node:url';
|
|
3
4
|
import chalk from 'chalk';
|
|
4
5
|
import semver from 'semver';
|
|
5
|
-
import { detect } from 'detect-package-manager';
|
|
6
|
-
import { readPackageUp } from 'read-pkg-up';
|
|
7
6
|
import { Command } from 'commander';
|
|
7
|
+
import { resolve } from 'import-meta-resolve';
|
|
8
8
|
import { runProgram, getPackageVersion } from './utils.js';
|
|
9
9
|
import { ASCII_ROBOT, PROGRAM_TITLE, UNSUPPORTED_NODE_VERSION, DEFAULT_NPM_TAG, INSTALL_COMMAND, DEV_FLAG, PMs } from './constants.js';
|
|
10
|
+
import { execSync } from 'node:child_process';
|
|
10
11
|
const WDIO_COMMAND = 'wdio';
|
|
11
12
|
let projectDir;
|
|
12
13
|
export async function run(operation = createWebdriverIO) {
|
|
@@ -42,46 +43,54 @@ export async function createWebdriverIO(opts) {
|
|
|
42
43
|
const npmTag = opts.npmTag.startsWith('@') ? opts.npmTag : `@${opts.npmTag}`;
|
|
43
44
|
const root = path.resolve(process.cwd(), projectDir || '');
|
|
44
45
|
/**
|
|
45
|
-
*
|
|
46
|
+
* find package manager that was used to create project
|
|
46
47
|
*/
|
|
47
|
-
const
|
|
48
|
-
|
|
48
|
+
const pm = PMs.find((pm) => (
|
|
49
|
+
// for pnpm check for "~/Library/pnpm/store/v3/..."
|
|
50
|
+
process.argv[1].includes(`${path.sep}${pm}${path.sep}`) ||
|
|
51
|
+
// for NPM and Yarn check for "~/.npm/npx/..." or "~/.yarn/bin/create-wdio"
|
|
52
|
+
process.argv[1].includes(`${path.sep}.${pm}${path.sep}`))) || 'npm';
|
|
53
|
+
const hasPackageJson = await fs.access(path.resolve(root, 'package.json')).then(() => true).catch(() => false);
|
|
54
|
+
if (!hasPackageJson) {
|
|
49
55
|
await fs.mkdir(root, { recursive: true });
|
|
50
56
|
await fs.writeFile(path.resolve(root, 'package.json'), JSON.stringify({
|
|
51
|
-
name: '
|
|
57
|
+
name: root.replace(/\/$/, '').split('/').pop(),
|
|
52
58
|
type: 'module'
|
|
53
59
|
}, null, 2));
|
|
54
|
-
/**
|
|
55
|
-
* find package manager that was used to create project
|
|
56
|
-
*/
|
|
57
|
-
const pm = PMs.find((pm) => (
|
|
58
|
-
// for pnpm check for "~/Library/pnpm/store/v3/..."
|
|
59
|
-
process.argv[1].includes(`${path.sep}${pm}${path.sep}`) ||
|
|
60
|
-
// for NPM and Yarn check for "~/.npm/npx/..." or "~/.yarn/bin/create-wdio"
|
|
61
|
-
process.argv[1].includes(`${path.sep}.${pm}${path.sep}`))) || 'npm';
|
|
62
|
-
/**
|
|
63
|
-
* create a package-lock.json, yarn.lock or pnpm-lock.yaml so
|
|
64
|
-
* that `detect-package-manager` doesn't mark it as a default
|
|
65
|
-
* Yarn project
|
|
66
|
-
* @see https://github.com/egoist/detect-package-manager/issues/11
|
|
67
|
-
*/
|
|
68
|
-
await runProgram(pm, ['install'], { cwd: root, stdio: 'ignore' });
|
|
69
60
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
61
|
+
const cliInstalled = await isCLIInstalled(root);
|
|
62
|
+
if (!cliInstalled) {
|
|
63
|
+
console.log(`\nInstalling ${chalk.bold('@wdio/cli')} to initialize project...`);
|
|
64
|
+
const args = [INSTALL_COMMAND[pm]];
|
|
65
|
+
if (pm === 'yarn') {
|
|
66
|
+
args.push('--exact', '--cwd', root);
|
|
67
|
+
}
|
|
68
|
+
if (opts.dev) {
|
|
69
|
+
args.push(DEV_FLAG[pm]);
|
|
70
|
+
}
|
|
71
|
+
args.push(`@wdio/cli${npmTag}`);
|
|
72
|
+
await runProgram(pm, args, { cwd: root, stdio: 'ignore' });
|
|
73
|
+
console.log(chalk.green.bold('✔ Success!'));
|
|
75
74
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
args.push(`@wdio/cli${npmTag}`);
|
|
80
|
-
await runProgram(pm, args, { cwd: root, stdio: 'ignore' });
|
|
81
|
-
console.log(chalk.green.bold('✔ Success!'));
|
|
82
|
-
return runProgram('npx', [
|
|
83
|
-
WDIO_COMMAND,
|
|
75
|
+
return runProgram(pm === 'npm' ? 'npx' : pm, [
|
|
76
|
+
`${pm === 'npm' ? '' : 'run '}${WDIO_COMMAND}`,
|
|
84
77
|
'config',
|
|
85
78
|
...(opts.yes ? ['--yes'] : [])
|
|
86
79
|
], { cwd: root });
|
|
87
80
|
}
|
|
81
|
+
async function isCLIInstalled(path) {
|
|
82
|
+
try {
|
|
83
|
+
// can be replaced with import.meta.resolve('@wdio/cli', new URL(`file:///${root}`).href) in the future
|
|
84
|
+
// check if the cli is installed in the project
|
|
85
|
+
resolve('@wdio/cli', pathToFileURL(path).href);
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
// check of the cli is installed globally
|
|
90
|
+
const output = execSync('npm ls -g', { encoding: 'utf-8' });
|
|
91
|
+
if (output.includes('@wdio/cli')) {
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-wdio",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.4.0",
|
|
4
4
|
"description": "Install and setup a WebdriverIO project with all its dependencies in a single run",
|
|
5
5
|
"author": "Christian Bromann <mail@bromann.dev>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -46,9 +46,9 @@
|
|
|
46
46
|
"@vitest/coverage-v8": "^0.34.1",
|
|
47
47
|
"eslint": "^8.45.0",
|
|
48
48
|
"eslint-plugin-import": "^2.27.5",
|
|
49
|
-
"eslint-plugin-unicorn": "^
|
|
49
|
+
"eslint-plugin-unicorn": "^49.0.0",
|
|
50
50
|
"npm-run-all": "^4.1.5",
|
|
51
|
-
"release-it": "^
|
|
51
|
+
"release-it": "^17.0.0",
|
|
52
52
|
"typescript": "^5.1.6",
|
|
53
53
|
"vitest": "^0.34.1"
|
|
54
54
|
},
|
|
@@ -56,8 +56,7 @@
|
|
|
56
56
|
"chalk": "^5.3.0",
|
|
57
57
|
"commander": "^11.0.0",
|
|
58
58
|
"cross-spawn": "^7.0.3",
|
|
59
|
-
"
|
|
60
|
-
"read-pkg-up": "^10.0.0",
|
|
59
|
+
"import-meta-resolve": "^4.0.0",
|
|
61
60
|
"semver": "^7.5.4"
|
|
62
61
|
}
|
|
63
62
|
}
|