Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
fit('should create Nx node', async () => {
appTree = Tree.empty();
appTree = createEmptyWorkspace(appTree);
const options: XplatHelpers.Schema = { ...defaultOptions };
options.platforms = 'node';
const tree = await runSchematic('app', options, appTree);
const files = tree.files;
// console.log('files:', files);
expect(tree.exists('/apps/node-sample/src/main.ts')).toBeTruthy();
let fileContent = getFileContent(tree, '/apps/node-sample/src/main.ts');
// console.log(fileContent);
expect(
fileContent.indexOf(`console.log('Hello World!')`)
).toBeGreaterThanOrEqual(0);
});
it('should create feature module for specified project WITH Routing and adjustSandbox', async () => {
const options: XplatFeatureHelpers.Schema = {
...defaultOptions,
projects: 'nativescript-viewer'
};
appTree = Tree.empty();
appTree = createXplatWithNativeScriptWeb(appTree, true);
// manually update home.component to prep for sandobx
const homeCmpPath = `/apps/nativescript-viewer/src/features/home/components/home.component.html`;
createOrUpdate(appTree, homeCmpPath, sandboxHomeSetup());
// console.log('homecmp:', getFileContent(tree, homeCmpPath));
options.onlyProject = true;
options.adjustSandbox = true;
options.routing = true;
options.name = 'foo-with-dash';
let tree = await runSchematic('feature', options, appTree);
// console.log('---------')
// console.log('homecmp:', getFileContent(tree, homeCmpPath));
});
});
export function updateJsonFile(tree: Tree, path: string, jsonData: any) {
try {
// if (tree.exists(path)) {
tree.overwrite(path, serializeJson(jsonData));
// }
return tree;
} catch (err) {
// console.warn(err);
throw new SchematicsException(`${path}: ${err}`);
}
}
ts.SyntaxKind.CallExpression
) as ts.CallExpression[];
for (const expr of calls) {
const inner = expr.expression;
if (
ts.isPropertyAccessExpression(inner) &&
/ReactDOM/i.test(inner.expression.getText()) &&
inner.name.getText() === 'render'
) {
return expr;
}
}
// 2. Try to find render from 'react-dom'.
const imports = findNodes(
source,
ts.SyntaxKind.ImportDeclaration
) as ts.ImportDeclaration[];
const hasRenderImport = imports.some(
i =>
i.moduleSpecifier.getText().includes('react-dom') &&
/\brender\b/.test(i.importClause.namedBindings.getText())
);
if (hasRenderImport) {
const calls = findNodes(
source,
ts.SyntaxKind.CallExpression
) as ts.CallExpression[];
for (const expr of calls) {
if (expr.expression.getText() === 'render') {
return expr;
export function findMainRenderStatement(
source: ts.SourceFile
): ts.CallExpression | null {
// 1. Try to find ReactDOM.render.
const calls = findNodes(
source,
ts.SyntaxKind.CallExpression
) as ts.CallExpression[];
for (const expr of calls) {
const inner = expr.expression;
if (
ts.isPropertyAccessExpression(inner) &&
/ReactDOM/i.test(inner.expression.getText()) &&
inner.name.getText() === 'render'
) {
return expr;
}
}
// 2. Try to find render from 'react-dom'.
return (host: Tree) => {
// patching the spec file because of a bug in the CLI application schematic
// it hardcodes "app" in the e2e tests
const spec = `${options.e2eProjectRoot}/src/app.e2e-spec.ts`;
const content = host.read(spec).toString();
host.overwrite(
spec,
content.replace('my-app app is running!', `Welcome to ${options.name}!`)
);
return chain([
updateJsonInTree(getWorkspacePath(host), json => {
const project = {
root: options.e2eProjectRoot,
projectType: 'application',
architect: {
e2e: json.projects[options.name].architect.e2e,
lint: {
builder: '@angular-devkit/build-angular:tslint',
options: {
tsConfig: `${options.e2eProjectRoot}/tsconfig.e2e.json`,
exclude: [
'**/node_modules/**',
'!' + join(normalize(options.e2eProjectRoot), '**')
]
}
}
}
export function updateLint(host: Tree, context: SchematicContext) {
const prefix = getPrefix();
return updateJsonInTree('tslint.json', json => {
json.rules = json.rules || {};
// remove forin rule as collides with LogService
delete json.rules['forin'];
// adjust console rules to work with LogService
json.rules['no-console'] = [true, 'debug', 'time', 'timeEnd', 'trace'];
json.rules['directive-selector'] = [true, 'attribute', prefix, 'camelCase'];
json.rules['component-selector'] = [true, 'element', prefix, 'kebab-case'];
return json;
})(host, context);
}
return (): Rule => {
// host.delete(`${options.projectRoot}/tsconfig.e2e.json`);
return mergeWith(
apply(url('./files'), [
template({
tmpl: '',
...options,
offsetFromRoot: offsetFromRoot(options.projectRoot)
}),
move(options.projectRoot)
])
);
};
}
options.projectDirectory
}').then(module => module.${options.moduleName})}`
)
]);
const tsConfig = findClosestTsConfigApp(host, options.parentModule);
if (tsConfig) {
const tsConfigAppSource = host.read(tsConfig)!.toString('utf-8');
const tsConfigAppFile = ts.createSourceFile(
tsConfig,
tsConfigAppSource,
ts.ScriptTarget.Latest,
true
);
const offset = offsetFromRoot(path.dirname(tsConfig));
insert(host, tsConfig, [
...addIncludeToTsConfig(
tsConfig,
tsConfigAppFile,
`\n , "${offset}${options.projectRoot}/src/index.ts"\n`
)
]);
} else {
// we should warn the user about not finding the config
}
return host;
};
}
run: () => {
updateJsonFile('tslint.json', json => {
const ruleName = 'nx-enforce-module-boundaries';
const rule = ruleName in json.rules ? json.rules[ruleName] : null;
// Only modify when the rule is configured with optional arguments
if (
Array.isArray(rule) &&
typeof rule[1] === 'object' &&
rule[1] !== null
) {
rule[1].npmScope = undefined;
}
});
}
};