forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(utilities): add a getConstConfig utility
getConstConfig permit to get an exported const string value from a module.ts file see angular#3452
- Loading branch information
Showing
3 changed files
with
28 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import findParentModule from './find-parent-module'; | ||
import * as astUtils from './ast-utils'; | ||
import * as ts from 'typescript'; | ||
|
||
export default function getConstConfig(project: any, dir: string, identifier: string): string { | ||
let modulePrefix = ''; | ||
try { | ||
let pathToModule = findParentModule(project, dir); | ||
console.log(pathToModule); | ||
|
||
astUtils.getSourceNodes(astUtils.getSource(pathToModule)) | ||
.last((node: ts.Node) => { | ||
// tslint:disable-next-line:no-bitwise | ||
return (node.flags & ts.NodeFlags.Export) !== 0 | ||
&& node.getText().includes(identifier); | ||
}) | ||
.subscribe((node: ts.Node) => { | ||
modulePrefix = /= ?['"]([\w-]+)["']/.exec(node.getText())[1]; | ||
}); | ||
} catch (e) { | ||
console.log(`no const configuration found for ${identifier} in the parent module\n\t`); | ||
} | ||
return modulePrefix; | ||
} |