nx/packages/angular/src/generators/utils/get-new-project-name.ts
2023-06-28 10:26:45 -04:00

16 lines
400 B
TypeScript

import { normalizePath } from '@nx/devkit';
/**
* Joins path segments replacing slashes with dashes
*
* @param path
*/
export function getNewProjectName(path: string): string {
// strip leading '/' or './' or '../' and trailing '/' and replaces '/' with '-'
return normalizePath(path)
.replace(/(^\.{0,2}\/|\.{1,2}\/|\/$)/g, '')
.split('/')
.filter((x) => !!x)
.join('-');
}