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.`
);
});
test('should not add router dependencies', () => {
const tree = testRunner.runSchematic('ng-add', { routing: false }, defaultAppTree);
const mainModuleContent = getFileContent(tree, '/projects/ss-angular-cli-app/src/main.single-spa.ts')
expect(mainModuleContent.indexOf('@angular/router')).toBe(-1);
});
it('should handle the webpack flag', () => {
const options = { ...defaultOptions, webpack: false };
const tree = schematicRunner.runSchematic('application', options);
const packageJson = '/foo/package.json';
expect(getFileContent(tree, packageJson))
.not
.toMatch(new RegExp('nativescript-dev-webpack'));
const files = tree!.files;
expect(files).not.toContain('/foo/webpack.config.js');
});
it('should update the parent module', async () => {
appTree = createApp(appTree, 'myapp');
const tree = await runSchematic(
'lib',
{
name: 'myLib',
directory: 'myDir',
routing: true,
lazy: true,
framework: 'angular',
parentModule: 'apps/myapp/src/app/app.module.ts'
},
appTree
);
const moduleContents = getFileContent(
tree,
'apps/myapp/src/app/app.module.ts'
);
expect(moduleContents).toContain('RouterModule.forRoot([');
expect(moduleContents).toContain(
`{path: 'my-dir-my-lib', loadChildren: '@proj/my-dir/my-lib#MyDirMyLibModule'}`
);
const tsConfigAppJson = JSON.parse(
stripJsonComments(
getFileContent(tree, 'apps/myapp/tsconfig.app.json')
)
);
expect(tsConfigAppJson.include).toEqual([
'**/*.ts',
'../../libs/my-dir/my-lib/src/index.ts'
tree => {
const packageJsonSource = JSON.parse(getFileContent(tree, `${options.directory}/package.json`));
if (packageJsonSource.dependencies['@ng-toolkit/serverless']) {
tree.delete(`${options.directory}/local.js`);
tree.delete(`${options.directory}/server.ts`);
tree.delete(`${options.directory}/webpack.server.config.js`);
}
},
function addOrReplaceScriptInPackageJson(tree: Tree, options: any, name: string, script: string) {
const packageJsonSource = JSON.parse(getFileContent(tree, `${options.directory}/package.json`));
packageJsonSource.scripts[name] = script;
tree.overwrite(`${options.directory}/package.json`, JSON.stringify(packageJsonSource, null, " "));
}
expect(moduleContents).toContain(
"{path: 'my-dir-my-lib', children: myDirMyLibRoutes}"
);
const tree2 = await runSchematic(
'lib',
{
name: 'myLib2',
directory: 'myDir',
routing: true,
framework: 'angular',
parentModule: 'apps/myapp/src/app/app.module.ts'
},
tree
);
const moduleContents2 = getFileContent(
tree2,
'apps/myapp/src/app/app.module.ts'
);
expect(moduleContents2).toContain('MyDirMyLib2Module');
expect(moduleContents2).toContain('RouterModule.forRoot([');
expect(moduleContents2).toContain(
"{path: 'my-dir-my-lib', children: myDirMyLibRoutes}"
);
expect(moduleContents2).toContain(
"{path: 'my-dir-my-lib2', children: myDirMyLib2Routes}"
);
const tree3 = await runSchematic(
'lib',
{
name: 'myLib3',
framework: 'angular',
routing: true
},
appTree
);
expect(
tree.exists('libs/my-dir/my-lib/src/lib/my-dir-my-lib.module.ts')
).toBeTruthy();
expect(
getFileContent(
tree,
'libs/my-dir/my-lib/src/lib/my-dir-my-lib.module.ts'
)
).toContain('RouterModule');
expect(
getFileContent(
tree,
'libs/my-dir/my-lib/src/lib/my-dir-my-lib.module.ts'
)
).toContain('const myDirMyLibRoutes: Route[] = ');
const tree2 = await runSchematic(
'lib',
{
name: 'myLib2',
directory: 'myDir',
routing: true,
framework: 'angular',
simpleModuleName: true
},
tree
);