(parsedAnswers: ParsedAnswers)
| 252 | * create package.json if not already existing |
| 253 | */ |
| 254 | export async function createPackageJSON(parsedAnswers: ParsedAnswers) { |
| 255 | const packageJsonExists = await fs.access(path.resolve(process.cwd(), 'package.json')).then(() => true, () => false) |
| 256 | |
| 257 | // Use the existing package.json if it already exists. |
| 258 | if (packageJsonExists) { |
| 259 | return |
| 260 | } |
| 261 | |
| 262 | // If a user said no to creating a package.json, but it doesn't exist, abort. |
| 263 | if (parsedAnswers.createPackageJSON === false) { |
| 264 | /* istanbul ignore if */ |
| 265 | if (!packageJsonExists) { |
| 266 | console.log(`No WebdriverIO configuration found in "${parsedAnswers.wdioConfigPath}"`) |
| 267 | return !process.env.WDIO_UNIT_TESTS && process.exit(0) |
| 268 | } |
| 269 | return |
| 270 | } |
| 271 | |
| 272 | // Only create if the user gave explicit permission to |
| 273 | if (parsedAnswers.createPackageJSON) { |
| 274 | console.log(`Creating a ${chalk.bold('package.json')} for the directory...`) |
| 275 | await fs.writeFile(path.resolve(process.cwd(), 'package.json'), JSON.stringify({ |
| 276 | name: 'webdriverio-tests', |
| 277 | version: '0.0.0', |
| 278 | private: true, |
| 279 | license: 'ISC', |
| 280 | type: 'module', |
| 281 | dependencies: {}, |
| 282 | devDependencies: {} |
| 283 | }, null, 2)) |
| 284 | console.log(chalk.green(chalk.bold('✔ Success!\n'))) |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | /** |
| 289 | * set up TypeScript if it is desired but not installed |
no test coverage detected
searching dependent graphs…