nx/packages/angular/src/generators/move/lib/update-ng-package.ts
Leosvel Pérez Espinosa 8564d9ba12
feat(misc): support new format to determine new project name and destination in move generators (#18878)
Co-authored-by: Jason Jean <jasonjean1993@gmail.com>
2023-09-05 09:40:16 -04:00

52 lines
1.2 KiB
TypeScript

import {
getOutputsForTargetAndConfiguration,
normalizePath,
readProjectConfiguration,
Tree,
updateJson,
workspaceRoot,
} from '@nx/devkit';
import { join, relative } from 'path';
import type { MoveImplOptions } from './types';
export function updateNgPackage(tree: Tree, schema: MoveImplOptions): void {
const project = readProjectConfiguration(tree, schema.newProjectName);
if (project.projectType === 'application') {
return;
}
const ngPackagePath = `${project.root}/ng-package.json`;
if (!tree.exists(ngPackagePath)) {
return;
}
const rootOffset = normalizePath(
relative(join(workspaceRoot, project.root), workspaceRoot)
);
const outputs = getOutputsForTargetAndConfiguration(
{
target: {
project: schema.newProjectName,
target: 'build',
},
overrides: {},
},
{
name: schema.newProjectName,
type: 'lib',
data: {
root: project.root,
targets: project.targets,
},
} as any
);
const output = outputs[0] ?? `dist/${project.root}`;
updateJson(tree, ngPackagePath, (json) => {
json.dest = `${rootOffset}/${output}`;
return json;
});
}