Skip to content

Instantly share code, notes, and snippets.

@adrianlemess
Created May 21, 2020 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adrianlemess/ddd114b8862f6e2b47b07bc863742101 to your computer and use it in GitHub Desktop.
Save adrianlemess/ddd114b8862f6e2b47b07bc863742101 to your computer and use it in GitHub Desktop.
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