Created
May 21, 2020 15:43
-
-
Save adrianlemess/ddd114b8862f6e2b47b07bc863742101 to your computer and use it in GitHub Desktop.
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
export function forms(_options: OptionsFormSchema): Rule { | |
return (tree: Tree, _context: SchematicContext) => { | |
// Log | |
// context.logger.info('Info message'); | |
// context.logger.warn('Warn message'); | |
// context.logger.error('Error message'); | |
const workspaceConfig = tree.read('/angular.json'); | |
if (!workspaceConfig) { | |
throw new NotValidAngularWorkspace(); | |
} | |
const workspaceContent = workspaceConfig.toString(); | |
const workspace: workspace.WorkspaceSchema = JSON.parse( | |
workspaceContent | |
); | |
if (!_options.project) { | |
_options.project = workspace.defaultProject || ''; | |
} | |
const projectName = _options.project; | |
const project = workspace.projects[projectName]; | |
const jsonFormConfig = tree.read(`${_options.config}`); | |
if (!jsonFormConfig) { | |
throw new FormJsonNotFoundError(); | |
} | |
const jsonFormContent = jsonFormConfig.toString(); | |
const formJsonObj = new FormJson(JSON.parse(jsonFormContent)); | |
const projectType = | |
project.projectType === 'application' | |
? ProjetTypeEnum.APP | |
: ProjetTypeEnum.LIB; | |
if (!_options.path) { | |
_options.path = `${project.sourceRoot}/${projectType}`; | |
} | |
const parsedOptions = parseName(_options.path, _options.name); | |
_options = { ..._options, ...parsedOptions }; | |
const templateSource = apply(url('./templates/forms'), [ | |
renameTemplateFiles(), | |
template({ | |
...strings, | |
..._options, | |
formJsonObj | |
}), | |
move(normalize((_options.path + '/' + _options.name) as string)) | |
]); | |
return chain([ | |
branchAndMerge(chain([mergeWith(templateSource)])), | |
addTreeModulesToModule(_options), | |
addDeclarationsToModule(_options) | |
])(tree, _context); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment