UNPKG

@nx/detox

Version:

The Nx Plugin for Detox contains executors and generators for allowing your workspace to use the powerful Detox integration testing capabilities.

55 lines (54 loc) 2.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.detoxInitGenerator = detoxInitGenerator; exports.detoxInitGeneratorInternal = detoxInitGeneratorInternal; exports.updateDependencies = updateDependencies; const devkit_1 = require("@nx/devkit"); const add_plugin_1 = require("@nx/devkit/src/utils/add-plugin"); const plugin_1 = require("../../plugins/plugin"); const versions_1 = require("../../utils/versions"); function detoxInitGenerator(host, schema) { return detoxInitGeneratorInternal(host, { addPlugin: false, ...schema }); } async function detoxInitGeneratorInternal(host, schema) { const tasks = []; const nxJson = (0, devkit_1.readNxJson)(host); const addPluginDefault = process.env.NX_ADD_PLUGINS !== 'false' && nxJson.useInferencePlugins !== false; schema.addPlugin ??= addPluginDefault; if (!schema.skipPackageJson) { tasks.push(moveDependency(host)); tasks.push(updateDependencies(host, schema)); } if (schema.addPlugin) { await (0, add_plugin_1.addPlugin)(host, await (0, devkit_1.createProjectGraphAsync)(), '@nx/detox/plugin', plugin_1.createNodesV2, { buildTargetName: ['build', 'detox:build', 'detox-build'], startTargetName: ['start', 'detox:start', 'detox-start'], testTargetName: ['test', 'detox:test', 'detox-test'], buildDepsTargetName: [ 'build-deps', 'detox:build-deps', 'detox-build-deps', ], watchDepsTargetName: [ 'watch-deps', 'detox:watch-deps', 'detox-watch-deps', ], }, schema.updatePackageScripts); } if (!schema.skipFormat) { await (0, devkit_1.formatFiles)(host); } return (0, devkit_1.runTasksInSerial)(...tasks); } function updateDependencies(host, schema) { return (0, devkit_1.addDependenciesToPackageJson)(host, {}, { '@nx/detox': versions_1.nxVersion, detox: versions_1.detoxVersion, }, undefined, schema.keepExistingVersions); } function moveDependency(host) { return (0, devkit_1.removeDependenciesFromPackageJson)(host, ['@nx/detox'], []); } exports.default = detoxInitGenerator;