Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
}
host.commitUpdate(declarationRecorder);
if (options.export) {
// Need to refresh the AST because we overwrote the file in the host.
const text = host.read(modulePath);
if (text === null) {
throw new SchematicsException(`File ${modulePath} does not exist.`);
}
const sourceText = text.toString('utf-8');
const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);
const exportRecorder = host.beginUpdate(modulePath);
const exportChanges = addExportToModule(source, modulePath,
strings.classify(`${options.name}Component`),
relativePath);
for (const change of exportChanges) {
if (change instanceof InsertChange) {
exportRecorder.insertLeft(change.pos, change.toAdd);
}
}
host.commitUpdate(exportRecorder);
}
return host;
};
}
}
}
host.commitUpdate(exportRecorder);
}
if (options.entryComponent) {
// Need to refresh the AST because we overwrote the file in the host.
source = readIntoSourceFile(host, modulePath);
const entryComponentRecorder = host.beginUpdate(modulePath);
const entryComponentChanges = addEntryComponentToModule(
// TODO: TypeScript version mismatch due to @schematics/angular using a different version
// Cast to any to avoid the type assignment failure.
source as any,
modulePath,
strings.classify(`${options.name}Component`),
relativePath);
for (const change of entryComponentChanges) {
if (change instanceof InsertChange) {
entryComponentRecorder.insertLeft(change.pos, change.toAdd);
}
}
host.commitUpdate(entryComponentRecorder);
}
return host;
};
}
function buildComponentName(schema: CommonSchema, _projectPrefix: string) {
const ret: string[] = [schema.module!];
if (schema.target && schema.target.length > 0) {
ret.push(...schema.target.split('/'));
}
ret.push(schema.name!);
ret.push(`Component`);
return strings.classify(ret.join('-'));
}
it('should update routing', async () => {
appTree = await yangSchematicRunner.runSchematicAsync('feature', {
name: featureName
}, appTree).toPromise();
const fileContent = getFileContent(appTree, YangUtils.FEATURES_MODULE_FILE);
const path = `{ path: '${strings.dasherize(featureName)}', loadChildren: () => import('@app/features/${strings.dasherize(featureName)}/${strings.dasherize(featureName)}.module').then(m => m.${strings.classify(featureName)}Module) }`
expect(fileContent).toContain(path);
});
});
'src',
'ui-test-app',
'ui-test-app-module.ts',
);
const sourceFile = getSourceFile(host, sourceFilePath);
const changes: InsertChange[] = [];
/** @dynatrace/angular-component import */
changes.push(
addDynatraceSubPackageImport(sourceFilePath, sourceFile, options),
);
/**
* relative UI import
*/
const uiImportName = `${strings.classify(options.name)}UI`;
const uiImportLocation = `'./${strings.dasherize(
options.name,
)}/${strings.dasherize(options.name)}-ui';`;
changes.push(
addImport(sourceFilePath, sourceFile, uiImportName, uiImportLocation),
);
/**
* add to exports of DynatraceAngularCompModule
*/
changes.push(
addToNgModule(sourceFilePath, sourceFile, options.moduleName, 'exports'),
);
/**
* Add to declarations of UiTestAppModule
sourceFile,
ts.SyntaxKind.PropertyAssignment,
) as ts.PropertyAssignment[];
const assignment = assignments.find(
(a: ts.PropertyAssignment) => a.name.getText() === 'declarations',
);
if (assignment === undefined) {
throw Error("No AppModule 'declarations' section found");
}
const arrLiteral = assignment.initializer as ts.ArrayLiteralExpression;
const elements = arrLiteral.elements;
const end = arrLiteral.elements.end;
const indentation = getIndentation(elements);
const toInsert = `${indentation}${strings.classify(name)}Demo,`;
const importsChange = new InsertChange(modulePath, end, toInsert);
const changes = [importChange, importsChange];
return commitChanges(host, changes, modulePath);
};
}
throw new SchematicsException(`File ${module} does not exist.`);
}
const sourceText = text.toString('utf8');
const source = ts.createSourceFile(module, sourceText, ts.ScriptTarget.Latest, true);
const pagePath = (
`/${options.path}/` +
(options.flat ? '' : `${strings.dasherize(options.name)}/`) +
`${strings.dasherize(options.name)}.module`
);
const relativePath = buildRelativePath(module, pagePath);
const routePath = options.routePath ? options.routePath : options.name;
const routeLoadChildren = `${relativePath}#${strings.classify(options.name)}PageModule`;
const changes = addRouteToRoutesArray(source, module, routePath, routeLoadChildren);
const recorder = host.beginUpdate(module);
for (const change of changes) {
if (change instanceof InsertChange) {
recorder.insertLeft(change.pos, change.toAdd);
}
}
host.commitUpdate(recorder);
return host;
};
}
return async (host: Tree, context: SchematicContext) => {
const globalGitConfig = gitParse.sync({ path: gitPath({ type: 'global' }), cwd: '/' }) || {};
const localGitConfig = gitParse.sync({ path: gitPath({ type: 'local' }), cwd: '/' }) || {};
const user = {
name: (localGitConfig.user && localGitConfig.user.name) || globalGitConfig.user.name,
email: (localGitConfig.user && localGitConfig.user.email) || globalGitConfig.user.email
};
const pkg = JSON.parse((await readFile(join(process.cwd(), './package.json'))).toString());
const filename = strings.dasherize(schema.name);
const dest = `libs/angular-components/${filename}`;
const classNamePrefix = strings.classify(schema.name);
const templateSource = apply(url('./files'), [
applyTemplates({
...strings,
className: classNamePrefix,
filename,
version: pkg.version,
author: `${user.name} <${user.email}>`
}),
move(dest)
]);
return chain([
addToIndex({
indexPath: 'libs/angular-components/index.ts',
filename
}
let fileContent = addToModuleDecorator(
tree.read(module)!.toString('utf-8'),
moduleName,
'./services',
strings.classify(crudName) + 'CrudService',
'providers',
false,
);
fileContent = addToModuleDecorator(
fileContent!,
moduleName,
'./controllers',
strings.classify(crudName) + 'CrudController',
'controllers',
false,
);
if (fileContent) {
tree.overwrite(module, formatTsFile(fileContent));
}
addBarrels(tree, join(modulePath as Path, 'services'), crudName + '.crud.service');
addBarrels(tree, join(modulePath as Path, 'controllers'), crudName + '.crud.controller');
return tree;
};
}
return host;
}
const modulePath = options.module;
const text = host.read(modulePath);
if (text === null) {
throw new SchematicsException(`File ${modulePath} does not exist.`);
}
const sourceText = text.toString();
const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);
const relativePath = buildRelativeModulePath(options, modulePath);
const changes = addImportToModule(source,
modulePath,
strings.classify(`${options.name}Module`),
relativePath);
const recorder = host.beginUpdate(modulePath);
for (const change of changes) {
if (change instanceof InsertChange) {
recorder.insertLeft(change.pos, change.toAdd);
}
}
host.commitUpdate(recorder);
return host;
};
}