Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
+ '.component';
const relativePath = find_module_1.buildRelativePath(modulePath, componentPath);
const classifiedName = core_1.strings.classify(`${options.name}Component`);
const declarationChanges = ast_utils_1.addDeclarationToModule(source, modulePath, classifiedName, relativePath);
const declarationRecorder = host.beginUpdate(modulePath);
for (const change of declarationChanges) {
if (change instanceof change_1.InsertChange) {
declarationRecorder.insertLeft(change.pos, change.toAdd);
}
}
host.commitUpdate(declarationRecorder);
if (options.export) {
// Need to refresh the AST because we overwrote the file in the host.
const source = readIntoSourceFile(host, modulePath);
const exportRecorder = host.beginUpdate(modulePath);
const exportChanges = ast_utils_1.addExportToModule(source, modulePath, core_1.strings.classify(`${options.name}Component`), relativePath);
for (const change of exportChanges) {
if (change instanceof change_1.InsertChange) {
exportRecorder.insertLeft(change.pos, change.toAdd);
}
}
host.commitUpdate(exportRecorder);
}
if (options.entryComponent) {
// Need to refresh the AST because we overwrote the file in the host.
const source = readIntoSourceFile(host, modulePath);
const entryComponentRecorder = host.beginUpdate(modulePath);
const entryComponentChanges = ast_utils_1.addEntryComponentToModule(source, modulePath, core_1.strings.classify(`${options.name}Component`), relativePath);
for (const change of entryComponentChanges) {
if (change instanceof change_1.InsertChange) {
entryComponentRecorder.insertLeft(change.pos, change.toAdd);
}
return (host) => {
if (options.skipImport || !options.module) {
return host;
}
const modulePath = options.module;
const text = host.read(modulePath);
if (text === null) {
throw new schematics_1.SchematicsException(`File ${modulePath} does not exist.`);
}
const sourceText = text.toString('utf-8');
const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);
const directivePath = `/${options.path}/`
+ (options.flat ? '' : core_1.strings.dasherize(options.name) + '/')
+ core_1.strings.dasherize(options.name)
+ '.directive';
const relativePath = find_module_1.buildRelativePath(modulePath, directivePath);
const classifiedName = core_1.strings.classify(`${options.name}Directive`);
const declarationChanges = ast_utils_1.addDeclarationToModule(source, modulePath, classifiedName, relativePath);
const declarationRecorder = host.beginUpdate(modulePath);
for (const change of declarationChanges) {
if (change instanceof change_1.InsertChange) {
declarationRecorder.insertLeft(change.pos, change.toAdd);
}
}
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) {
};
return schematics_1.chain([
addAppToWorkspaceFile(options, workspace),
schematics_1.mergeWith(schematics_1.apply(schematics_1.url('./files/src'), [
options.minimal ? schematics_1.filter(minimalPathFilter) : schematics_1.noop(),
schematics_1.template(Object.assign({ utils: core_1.strings }, options, { 'dot': '.', relativePathToWorkspaceRoot })),
schematics_1.move(sourceRoot),
])),
schematics_1.mergeWith(schematics_1.apply(schematics_1.url('./files/root'), [
options.minimal ? schematics_1.filter(minimalPathFilter) : schematics_1.noop(),
schematics_1.template(Object.assign({ utils: core_1.strings }, options, { 'dot': '.', relativePathToWorkspaceRoot,
rootInSrc })),
schematics_1.move(appDir),
])),
options.minimal ? schematics_1.noop() : schematics_1.mergeWith(schematics_1.apply(schematics_1.url('./files/lint'), [
schematics_1.template(Object.assign({ utils: core_1.strings }, options, { tsLintRoot,
relativePathToWorkspaceRoot,
prefix })),
])),
schematics_1.schematic('module', {
name: 'app',
commonModule: false,
flat: true,
routing: options.routing,
routingScope: 'Root',
path: sourceDir,
project: options.name,
}),
schematics_1.schematic('component', Object.assign({ name: 'app', selector: appRootSelector, flat: true, path: sourceDir, skipImport: true, project: options.name }, componentOptions)),
schematics_1.mergeWith(schematics_1.apply(schematics_1.url('./other-files'), [
componentOptions.inlineTemplate ? schematics_1.filter(path => !path.endsWith('.html')) : schematics_1.noop(),
componentOptions.skipTests ? schematics_1.filter(path => !/[.|-]spec.ts$/.test(path)) : schematics_1.noop(),
function findModuleFromOptions(host, options) {
if (options.hasOwnProperty('skipImport') && options.skipImport) {
return undefined;
}
if (!options.module) {
const pathToCheck = (options.path || '') +
(options.flat ? '' : '/' + core_1.strings.dasherize(options.name));
return core_1.normalize(findModule(host, pathToCheck));
}
else {
const modulePath = core_1.normalize('/' + options.path + '/' + options.module);
const moduleBaseName = core_1.normalize(modulePath)
.split('/')
.pop();
if (host.exists(modulePath)) {
return core_1.normalize(modulePath);
}
else if (host.exists(modulePath + '.ts')) {
return core_1.normalize(modulePath + '.ts');
}
else if (host.exists(modulePath + '.module.ts')) {
return core_1.normalize(modulePath + '.module.ts');
}
const outDir = getTsConfigOutDir(host, clientTargets);
if (!clientTargets.build) {
throw project_targets_1.targetBuildNotFoundError();
}
const tsConfigExtends = core_1.basename(core_1.normalize(clientTargets.build.options.tsConfig));
const rootInSrc = clientProject.root === '';
const tsConfigDirectory = core_1.join(core_1.normalize(clientProject.root), rootInSrc ? 'src' : '');
if (!options.skipInstall) {
context.addTask(new tasks_1.NodePackageInstallTask());
}
const templateSource = schematics_1.apply(schematics_1.url('./files/src'), [
schematics_1.template(Object.assign({}, core_1.strings, options, { stripTsExtension: (s) => s.replace(/\.ts$/, '') })),
schematics_1.move(core_1.join(core_1.normalize(clientProject.root), 'src')),
]);
const rootSource = schematics_1.apply(schematics_1.url('./files/root'), [
schematics_1.template(Object.assign({}, core_1.strings, options, { stripTsExtension: (s) => s.replace(/\.ts$/, ''), outDir,
tsConfigExtends,
rootInSrc })),
schematics_1.move(tsConfigDirectory),
]);
return schematics_1.chain([
schematics_1.mergeWith(templateSource),
schematics_1.mergeWith(rootSource),
addDependencies(),
updateConfigFile(options, tsConfigDirectory),
wrapBootstrapCall(options),
addServerTransition(options),
]);
};
}
if (options.skipImport || !options.module) {
return host;
}
const modulePath = options.module;
const text = host.read(modulePath);
if (text === null) {
throw new schematics_1.SchematicsException(`File ${modulePath} does not exist.`);
}
const sourceText = text.toString('utf-8');
const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);
const pipePath = `/${options.path}/`
+ (options.flat ? '' : core_1.strings.dasherize(options.name) + '/')
+ core_1.strings.dasherize(options.name)
+ '.pipe';
const relativePath = find_module_1.buildRelativePath(modulePath, pipePath);
const changes = ast_utils_1.addDeclarationToModule(source, modulePath, core_1.strings.classify(`${options.name}Pipe`), relativePath);
const recorder = host.beginUpdate(modulePath);
for (const change of changes) {
if (change instanceof change_1.InsertChange) {
recorder.insertLeft(change.pos, change.toAdd);
}
}
host.commitUpdate(recorder);
if (options.export) {
const text = host.read(modulePath);
if (text === null) {
throw new schematics_1.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 = ast_utils_1.addExportToModule(source, modulePath, core_1.strings.classify(`${options.name}Pipe`), relativePath);
function buildSelector(options, projectPrefix) {
let selector = options.name;
if (options.prefix) {
selector = `${options.prefix}-${selector}`;
}
else if (options.prefix === undefined && projectPrefix) {
selector = `${projectPrefix}-${selector}`;
}
return core_1.strings.camelize(selector);
}
function default_1(options) {
apply(directory) {
const iconBaseImport = () => `${'../'.repeat(this.modules.length)}icon-base`;
return schematics.mergeWith(schematics.apply(schematics.url('./files/icon'), [
schematics.template(Object.assign({}, core.strings, { iconBaseImport }, this._files[0], (this._files.some(f => ['large', 'medium', 'small'].includes(f.size))
? { width: '24px', height: '24px', ratio: 1 }
: undefined), (this._files.length > 1 ? { template: this._mergeTemplates() } : undefined))),
schematics.move(directory.path)
]));
}
_mergeTemplates() {