@robby-rabbitman/nx-plus-web-test-runner
Version:
Web Test Runner integration for Nx workspaces.
59 lines • 2.41 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.webTestRunnerInitGenerator = void 0;
const devkit_1 = require("@nx/devkit");
const web_test_runner_plugin_1 = require("../plugins/web-test-runner.plugin");
const WEB_TEST_RUNNER_PLUGIN_PATH = '@robby-rabbitman/nx-plus-web-test-runner/plugins/web-test-runner';
/**
* Adds the `@robby-rabbitman/nx-plus-web-test-runner/plugins/web-test-runner`
* plugin to the `nx.json` file.
*/
const webTestRunnerInitGenerator = async (tree, userOptions) => {
const options = normalizeWebTestRunnerInitGeneratorOptions(userOptions);
const { skipAddPlugin, skipFormat } = options;
if (skipAddPlugin) {
return;
}
const nxJson = (0, devkit_1.readNxJson)(tree) ?? {};
nxJson.plugins ??= [];
const hasWebTestRunnerPlugin = nxJson.plugins.some((pluginConfig) => {
/**
* `pluginConfig` can be a string representing the plugin name or an object
* with a plugin property representing the plugin name. So we need to check
* both.
*/
if (typeof pluginConfig === 'string') {
return pluginConfig === WEB_TEST_RUNNER_PLUGIN_PATH;
}
return pluginConfig.plugin === WEB_TEST_RUNNER_PLUGIN_PATH;
});
/** When the plugin is not already added to the `nx.json` file, add it. */
if (!hasWebTestRunnerPlugin) {
nxJson.plugins.push({
plugin: WEB_TEST_RUNNER_PLUGIN_PATH,
options: {
testTargetName: options.testTargetName,
},
});
(0, devkit_1.updateNxJson)(tree, nxJson);
}
if (!skipFormat) {
await (0, devkit_1.formatFiles)(tree);
}
};
exports.webTestRunnerInitGenerator = webTestRunnerInitGenerator;
exports.default = exports.webTestRunnerInitGenerator;
function normalizeWebTestRunnerInitGeneratorOptions(userOptions) {
const normalizedOptions = {
skipAddPlugin: false,
skipFormat: false,
testTargetName: web_test_runner_plugin_1.DEFAULT_WEB_TEST_RUNNER_TARGET_NAME,
...userOptions,
};
/** Make sure `testTargetName` is not an empty string. */
if (normalizedOptions.testTargetName === '') {
normalizedOptions.testTargetName = web_test_runner_plugin_1.DEFAULT_WEB_TEST_RUNNER_TARGET_NAME;
}
return normalizedOptions;
}
//# sourceMappingURL=web-test-runner-init.generator.js.map