@robby-rabbitman/nx-plus-web-dev-server
Version:
Web Dev Server plugin for Nx workspaces.
58 lines • 2.35 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.webDevServerInitGenerator = void 0;
const devkit_1 = require("@nx/devkit");
const web_dev_server_plugin_1 = require("../plugins/web-dev-server.plugin");
const WEB_DEV_SERVER_PLUGIN_PATH = '@robby-rabbitman/nx-plus-web-dev-server/plugins/web-dev-server';
/**
* Adds the `@robby-rabbitman/nx-plus-web-dev-server/plugins/web-dev-server`
* plugin to the `nx.json` file.
*/
const webDevServerInitGenerator = async (tree, schema) => {
const options = normalizeWebDevServerInitGeneratorOptions(schema);
const { skipAddPlugin, skipFormat } = options;
if (skipAddPlugin) {
return;
}
const nxJson = (0, devkit_1.readNxJson)(tree) ?? {};
nxJson.plugins ??= [];
const hasWebDevServerPlugin = nxJson.plugins.some((pluginConfig) => {
/**
* `pluginConfig` can be a string representing the plugin name or a object
* with a plugin property representing the plugin name
*/
if (typeof pluginConfig === 'string') {
return pluginConfig === WEB_DEV_SERVER_PLUGIN_PATH;
}
return pluginConfig.plugin === WEB_DEV_SERVER_PLUGIN_PATH;
});
/** When the plugin is not already added to the `nx.json` file, add it. */
if (!hasWebDevServerPlugin) {
nxJson.plugins.push({
plugin: WEB_DEV_SERVER_PLUGIN_PATH,
options: {
serveTargetName: options.serveTargetName,
},
});
(0, devkit_1.updateNxJson)(tree, nxJson);
}
if (!skipFormat) {
await (0, devkit_1.formatFiles)(tree);
}
};
exports.webDevServerInitGenerator = webDevServerInitGenerator;
exports.default = exports.webDevServerInitGenerator;
function normalizeWebDevServerInitGeneratorOptions(userOptions) {
const normalizedOptions = {
skipAddPlugin: false,
skipFormat: false,
serveTargetName: web_dev_server_plugin_1.DEFAULT_WEB_DEV_SERVER_TARGET_NAME,
...userOptions,
};
/** Make sure `serveTargetName` is not an empty string */
if (normalizedOptions.serveTargetName === '') {
normalizedOptions.serveTargetName = web_dev_server_plugin_1.DEFAULT_WEB_DEV_SERVER_TARGET_NAME;
}
return normalizedOptions;
}
//# sourceMappingURL=web-dev-server-init.generator.js.map
;