cleanup(angular): stories generator adjustments (#6102)
This commit is contained in:
parent
3e1a612e62
commit
54d38105cf
@ -1,5 +1,6 @@
|
|||||||
import type { Tree } from '@nrwl/devkit';
|
import type { Tree } from '@nrwl/devkit';
|
||||||
import { joinPathFragments, logger } from '@nrwl/devkit';
|
import { joinPathFragments, logger } from '@nrwl/devkit';
|
||||||
|
import { basename, dirname } from 'path';
|
||||||
import type { Statement } from 'typescript';
|
import type { Statement } from 'typescript';
|
||||||
import { SyntaxKind } from 'typescript';
|
import { SyntaxKind } from 'typescript';
|
||||||
import { getTsSourceFile } from '../../../utils/nx-devkit/ast-utils';
|
import { getTsSourceFile } from '../../../utils/nx-devkit/ast-utils';
|
||||||
@ -32,10 +33,8 @@ export function getComponentsInfo(
|
|||||||
const imports = file.statements.filter(
|
const imports = file.statements.filter(
|
||||||
(statement) => statement.kind === SyntaxKind.ImportDeclaration
|
(statement) => statement.kind === SyntaxKind.ImportDeclaration
|
||||||
);
|
);
|
||||||
const moduleFolderPath = moduleFilePath.substr(
|
|
||||||
0,
|
const moduleFolderPath = dirname(moduleFilePath);
|
||||||
moduleFilePath.lastIndexOf('/')
|
|
||||||
);
|
|
||||||
|
|
||||||
const componentsInfo = declaredComponents.map((componentName) =>
|
const componentsInfo = declaredComponents.map((componentName) =>
|
||||||
getComponentInfo(tree, imports, moduleFolderPath, componentName)
|
getComponentInfo(tree, imports, moduleFolderPath, componentName)
|
||||||
@ -102,11 +101,10 @@ function getComponentInfo(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return getComponentInfoFromFile(
|
const path = dirname(componentFilePathRelativeToModule);
|
||||||
moduleFolderPath,
|
const componentFileName = basename(componentFilePathRelativeToModule);
|
||||||
componentName,
|
|
||||||
componentFilePathRelativeToModule
|
return { componentFileName, moduleFolderPath, name: componentName, path };
|
||||||
);
|
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
`Could not generate a story for ${componentName}. Error: ${ex}`
|
`Could not generate a story for ${componentName}. Error: ${ex}`
|
||||||
@ -149,22 +147,6 @@ function getComponentInfoFromDir(
|
|||||||
return { componentFileName, moduleFolderPath, name: componentName, path };
|
return { componentFileName, moduleFolderPath, name: componentName, path };
|
||||||
}
|
}
|
||||||
|
|
||||||
function getComponentInfoFromFile(
|
|
||||||
moduleFolderPath: string,
|
|
||||||
componentName: string,
|
|
||||||
componentFilePathRelativeToModule: string
|
|
||||||
): ComponentInfo {
|
|
||||||
const path = componentFilePathRelativeToModule.slice(
|
|
||||||
0,
|
|
||||||
componentFilePathRelativeToModule.lastIndexOf('/')
|
|
||||||
);
|
|
||||||
const componentFileName = componentFilePathRelativeToModule.slice(
|
|
||||||
componentFilePathRelativeToModule.lastIndexOf('/') + 1
|
|
||||||
);
|
|
||||||
|
|
||||||
return { componentFileName, moduleFolderPath, name: componentName, path };
|
|
||||||
}
|
|
||||||
|
|
||||||
function getFullComponentFilePath(
|
function getFullComponentFilePath(
|
||||||
moduleFolderPath: string,
|
moduleFolderPath: string,
|
||||||
componentFilePath: string
|
componentFilePath: string
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user