@nx/next
Version:
63 lines (62 loc) • 2.52 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.servePosTargetTransformer = servePosTargetTransformer;
function servePosTargetTransformer(migrationLogs) {
return (target, _tree, projectDetails, inferredTargetConfiguration) => {
if (target.options) {
handlePropertiesFromTargetOptions(target.options);
}
if (target.configurations) {
for (const configurationName in target.configurations) {
const configuration = target.configurations[configurationName];
handlePropertiesFromTargetOptions(configuration);
}
if (Object.keys(target.configurations).length === 0) {
if ('defaultConfiguration' in target) {
delete target.defaultConfiguration;
}
delete target.configurations;
}
if ('defaultConfiguration' in target &&
!target.configurations[target.defaultConfiguration]) {
delete target.defaultConfiguration;
}
}
migrationLogs.addLog({
project: projectDetails.projectName,
executorName: '@nx/next:server',
log: `Note that "nx run ${projectDetails.projectName}:${inferredTargetConfiguration.name}" only runs the dev server after the migration. To start the prod server, use "nx run ${projectDetails.projectName}:start".`,
});
return target;
};
}
const executorFieldsToRename = [
'experimentalHttps',
'experimentalHttpsCa',
'experimentalHttpsKey',
'keepAliveTimeout',
];
const executorFieldsToRemain = [
'port',
'hostname',
];
const camelCaseToKebabCase = (str) => str.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
function handlePropertiesFromTargetOptions(options) {
Object.keys(options).forEach((key) => {
if (!executorFieldsToRename.includes(key) &&
!executorFieldsToRemain.includes(key)) {
delete options[key];
}
else {
if (executorFieldsToRename.includes(key)) {
const value = options[key];
const kebabCase = camelCaseToKebabCase(key);
options['args'] ??= [];
if (value === true || typeof value !== 'boolean') {
options['args'].push(`--${kebabCase}` + (typeof value !== 'boolean' ? ` ${value}` : ''));
}
delete options[key];
}
}
});
}