Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function getServerDistFolder(tree: Tree, options: any): string {
const cliConfig: any = JSON.parse(getFileContent(tree, `${options.directory}/angular.json`));
// console.log(getFileContent(tree, `${options.directory}/angular.json`));
const project: any = cliConfig.projects[options.project].architect;
for (let property in project) {
if (project.hasOwnProperty(property) && project[property].builder === '@angular-devkit/build-angular:server') {
return project[property].options.outputPath;
}
}
return '';
}
const files = tree.files;
// console.log(files);
// xplat helpers
expect(files.indexOf('/xplat/nativescript/utils/@nativescript/core.ts')).toBeGreaterThanOrEqual(0);
expect(files.indexOf('/xplat/nativescript/utils/@nativescript/ui.ts')).toBeGreaterThanOrEqual(0);
expect(files.indexOf('/xplat/nativescript/utils/@nativescript/angular/core.ts')).toBeGreaterThanOrEqual(0);
// should update tsconfig files
let filePath = '/tsconfig.json';
let fileContent = JSON.parse(getFileContent(tree, filePath));
// console.log(fileContent);
expect(fileContent.compilerOptions.paths['@nativescript/*'][0]).toBe('xplat/nativescript/utils/@nativescript/*');
filePath = '/apps/nativescript-foo/tsconfig.json';
fileContent = JSON.parse(getFileContent(tree, filePath));
// console.log(fileContent);
expect(fileContent.compilerOptions.paths['@nativescript/*'][0]).toBe('../../xplat/nativescript/utils/@nativescript/*');
});
npmScope: 'testing',
prefix: 'tt',
platforms: 'web,nativescript'
};
appTree = schematicRunner.runSchematic('xplat', optionsXplat, appTree);
const appOptions: AppWebOptions = {
name: 'foo',
prefix: 'tt',
e2eTestRunner: 'cypress'
};
// console.log('appTree:', appTree);
appTree = await schematicRunner.runSchematicAsync('app', appOptions, appTree).toPromise();
const cypressJsonPath = '/apps/web-foo-e2e/cypress.json';
let fileContent = getFileContent(appTree, cypressJsonPath);
let cypressJson = JSON.parse(fileContent);
expect(cypressJson.supportFile).toBe(false);
const options: HelperOptions = {
name: 'applitools',
platforms: 'web'
};
// console.log('appTree:', appTree);
let tree;
expect(
() => (tree = schematicRunner.runSchematic('xplat-helper', options, appTree))
).toThrowError(
`The xplat-helper "applitools" requires the --target flag.`
);
});
it('should not add NoopAnimationsModule if BrowserAnimationsModule is set up', () => {
const workspace = getWorkspace(appTree);
const project = getProjectFromWorkspace(workspace);
// Simulate the case where a developer uses `ng-add` on an Angular CLI project which already
// explicitly uses the `BrowserAnimationsModule`. It would be wrong to forcibly change
// to noop animations.
const fileContent = addModuleImportToRootModule(appTree, 'BrowserAnimationsModule',
'@angular/platform-browser/animations', project);
runSetupSchematic({ animations: false });
expect(fileContent).not.toContain('NoopAnimationsModule',
'Expected the project app module to not import the "NoopAnimationsModule".');
});
});
// unnecessary path segments and windows backslash delimiters.
const customThemePath = normalize(join(project.sourceRoot, defaultCustomThemeFilename));
if (host.exists(customThemePath)) {
console.log();
console.warn(chalk.yellow(`Cannot create a custom NG-ZORRO theme because
${chalk.bold(customThemePath)} already exists. Skipping custom theme generation.`));
return;
}
host.create(customThemePath, themeContent);
addThemeStyleToTarget(project, 'build', host, customThemePath, workspace);
return;
}
const insertion = new InsertChange(stylesPath, 0, themeContent);
const recorder = host.beginUpdate(stylesPath);
recorder.insertLeft(insertion.pos, insertion.toAdd);
host.commitUpdate(recorder);
}
return (host: Tree) => {
const workspace = getWorkspace(host);
const project = getProjectFromWorkspace(workspace, options.project);
const appModulePath = getAppModulePath(host, getProjectMainFile(project));
if (options.animations) {
// In case the project explicitly uses the NoopAnimationsModule, we should print a warning
// message that makes the user aware of the fact that we won't automatically set up
// animations. If we would add the BrowserAnimationsModule while the NoopAnimationsModule
// is already configured, we would cause unexpected behavior and runtime exceptions.
if (hasNgModuleImport(host, appModulePath, noopAnimationsModuleName)) {
return console.warn(
chalk.red(
`Could not set up "${chalk.bold(browserAnimationsModuleName)}" ` +
`because "${chalk.bold(noopAnimationsModuleName)}" is already imported. Please ` +
`manually set up browser animations.`
)
);
}
return (host: Tree) => {
const workspace = getWorkspace(host);
const project = getProjectFromWorkspace(workspace, options.project);
const appModulePath = getAppModulePath(host, getProjectMainFile(project));
if (options.animations) {
if (hasNgModuleImport(host, appModulePath, noopAnimationsModuleName)) {
console.warn(chalk.red(`Could not set up "${chalk.bold(browserAnimationsModuleName)}" ` +
`because "${chalk.bold(noopAnimationsModuleName)}" is already imported. Please manually ` +
`set up browser animations.`));
return;
}
addModuleImportToRootModule(host, browserAnimationsModuleName,
'@angular/platform-browser/animations', project);
} else if (!hasNgModuleImport(host, appModulePath, browserAnimationsModuleName)) {
// Do not add the NoopAnimationsModule module if the project already explicitly uses
// the BrowserAnimationsModule.
addModuleImportToRootModule(host, noopAnimationsModuleName,
return (tree: Tree) => {
// tslint:disable-next-line:no-non-null-assertion
const modulePath = getAppModulePath(tree, getProject(tree, options.project)!.architect!.build!.options!.main);
if (options.animations) {
if (hasModuleImport(tree, modulePath, noopAnimationsModuleName)) {
return console.warn(chalk.red(`Could not set up "${chalk.bold(browserAnimationsModuleName)}" ` +
`because "${chalk.bold(noopAnimationsModuleName)}" is already imported. Please manually ` +
`set up browser animations.`));
}
addImportToRootModule(tree, browserAnimationsModuleName,
'@angular/platform-browser/animations', modulePath);
console.log(chalk.green(`✅️ Added ${browserAnimationsModuleName} to root module.`));
} else if (!hasModuleImport(tree, modulePath, browserAnimationsModuleName)) {
addImportToRootModule(tree, noopAnimationsModuleName,
'@angular/platform-browser/animations', modulePath);
console.log(chalk.green(`✅️ Added ${noopAnimationsModuleName} to root module.`));
}
return tree;
function determineRoutingModule(host, options) {
const project = project_1.getProject(host, options.project);
let routingModuleLocation;
let child;
const match = options.name.match(/(.*)\-([a-z0-9]+)/);
if (match && match[1] && match[2]) {
const parent = match[1];
child = match[2];
// tslint:disable-next-line:no-console
console.log(`detected subpage, will insert '${child}' as sub page of '${parent}'`);
routingModuleLocation = options.extension
? `extensions/${options.extension}/pages/${parent}/${parent}-page.module.ts`
: `pages/${parent}/${parent}-page.module.ts`;
}
else {
routingModuleLocation = options.extension
? `extensions/${options.extension}/pages/${options.extension}-routing.module.ts`
: 'pages/app-routing.module.ts';
const match = options.name.match(/(.*)\-([a-z0-9]+)/);
if (match && match[1] && match[2]) {
const parent = match[1];
child = match[2];
// tslint:disable-next-line:no-console
console.log(`detected subpage, will insert '${child}' as sub page of '${parent}'`);
routingModuleLocation = options.extension
? `extensions/${options.extension}/pages/${parent}/${parent}-page.module.ts`
: `pages/${parent}/${parent}-page.module.ts`;
}
else {
routingModuleLocation = options.extension
? `extensions/${options.extension}/pages/${options.extension}-routing.module.ts`
: 'pages/app-routing.module.ts';
}
const routingModule = core_1.normalize(`${project_1.buildDefaultPath(project)}/${routingModuleLocation}`);
return Object.assign({}, options, { routingModule,
child });
}
function addRouteToRoutingModule(options) {