-
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.
- Loading branch information
1 parent
9fbd00e
commit fbe1f40
Showing
1 changed file
with
39 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,53 @@ | ||
import { Tree } from '@nx/devkit'; | ||
import { dasherize } from '@nx/devkit/src/utils/string-utils'; | ||
import { | ||
applyChangesToString, | ||
ChangeType, | ||
joinPathFragments, | ||
readProjectConfiguration, | ||
Tree, | ||
} from '@nx/devkit'; | ||
import { classify, dasherize } from '@nx/devkit/src/utils/string-utils'; | ||
import { wrapAngularDevkitSchematic } from 'nx/src/adapter/ngcli-adapter'; | ||
import { Identifier, isIdentifier, isVariableStatement } from 'typescript'; | ||
import { getSourceFile } from '../utils/get-source-file'; | ||
import { MyStepGeneratorSchema } from './schema'; | ||
|
||
export async function myStepGenerator( | ||
tree: Tree, | ||
options: MyStepGeneratorSchema | ||
) { | ||
const componentSchematic = wrapAngularDevkitSchematic('@schematics/angular', 'component'); | ||
const componentSchematic = wrapAngularDevkitSchematic( | ||
'@schematics/angular', | ||
'component' | ||
); | ||
await componentSchematic(tree, { | ||
name: dasherize(options.name), | ||
project: options.project, | ||
}); | ||
|
||
const projectDir = readProjectConfiguration(tree, options.project).root; | ||
const workflowFileName = joinPathFragments( | ||
projectDir, | ||
'src', | ||
'app', | ||
'app.workflow.ts' | ||
); | ||
const sourceFile = getSourceFile(tree, workflowFileName); | ||
|
||
const stepsDeclaration = sourceFile.statements | ||
.filter(isVariableStatement) | ||
.map((s) => s.declarationList.declarations[0]) | ||
.filter((d) => isIdentifier(d.name)) | ||
.find((d) => (d.name as Identifier).escapedText === 'loginSteps'); | ||
|
||
const stepToAdd = `"${classify(options.name)}",`; | ||
const newContents = applyChangesToString(sourceFile.text, [ | ||
{ | ||
type: ChangeType.Insert, | ||
index: stepsDeclaration.end - 1, | ||
text: stepToAdd | ||
}, | ||
]); | ||
tree.write(workflowFileName, newContents); | ||
} | ||
|
||
export default myStepGenerator; |