MCPcopy Create free account
hub / github.com/webdriverio/webdriverio / createPackageJSON

Function createPackageJSON

packages/create-wdio/src/utils.ts:254–286  ·  view source on GitHub ↗
(parsedAnswers: ParsedAnswers)

Source from the content-addressed store, hash-verified

252 * create package.json if not already existing
253 */
254export 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

Callers 2

runConfigCommandFunction · 0.85
utils.test.tsFile · 0.85

Calls 3

thenMethod · 0.80
boldMethod · 0.80
logMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…