nx/packages/remix/src/generators/convert-to-inferred/lib/serve-post-target-transformer.ts
Colum Ferry b1713be2c3
feat(remix): add convert-to-inferred generator (#26601)
- feat(remix): add convert-to-inferred migration
- feat(remix): add serve executor logic

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #
2024-06-21 11:01:53 -04:00

76 lines
1.9 KiB
TypeScript

import { type Tree, type TargetConfiguration } from '@nx/devkit';
import { AggregatedLog } from '@nx/devkit/src/generators/plugin-migrations/aggregate-log-util';
import { REMIX_PROPERTY_MAPPINGS } from './utils';
export function servePostTargetTransformer(migrationLogs: AggregatedLog) {
return (
target: TargetConfiguration,
tree: Tree,
projectDetails: { projectName: string; root: string },
inferredTargetConfiguration: TargetConfiguration
) => {
if (target.options) {
handlePropertiesFromTargetOptions(
tree,
target.options,
projectDetails.projectName,
projectDetails.root
);
}
if (target.configurations) {
for (const configurationName in target.configurations) {
const configuration = target.configurations[configurationName];
handlePropertiesFromTargetOptions(
tree,
configuration,
projectDetails.projectName,
projectDetails.root
);
}
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;
}
}
return target;
};
}
function handlePropertiesFromTargetOptions(
tree: Tree,
options: any,
projectName: string,
projectRoot: string
) {
if ('debug' in options) {
delete options.debug;
}
if ('port' in options) {
options.env ??= {};
options.env.PORT = `${options.port}`;
delete options.port;
}
for (const [prevKey, newKey] of Object.entries(REMIX_PROPERTY_MAPPINGS)) {
if (prevKey in options) {
let prevValue = options[prevKey];
delete options[prevKey];
options[newKey] = prevValue;
}
}
}