Jonathan Cammisuli d9aef75bd5
chore(react): move react schematics to generators (#4745)
* chore(react): move react schematics to generators

* chore(react): update lib generators

* chore(react): update redux generators

* chore(react): move react story book generators

* chore(react): add old implementation for update babel in next

* chore(react): rename tsconfig json template files to include __tmpl__

* chore(react): update deps

* chore(react): fix component template file

* chore(react): remove angular-devkit deps

* chore(react): remove angular-devkit deps
2021-02-10 21:30:55 -05:00

83 lines
2.4 KiB
TypeScript

import { extraEslintDependencies, reactEslintJson } from '../../utils/lint';
import { NormalizedSchema, Schema } from './schema';
import { createApplicationFiles } from './lib/create-application-files';
import { updateJestConfig } from './lib/update-jest-config';
import { normalizeOptions } from './lib/normalize-options';
import { addProject } from './lib/add-project';
import { addCypress } from './lib/add-cypress';
import { addJest } from './lib/add-jest';
import { addRouting } from './lib/add-routing';
import { setDefaults } from './lib/set-defaults';
import { addStyledModuleDependencies } from '../../rules/add-styled-dependencies';
import {
addDependenciesToPackageJson,
convertNxGenerator,
formatFiles,
GeneratorCallback,
joinPathFragments,
Tree,
updateJson,
} from '@nrwl/devkit';
import reactInitGenerator from '../init/init';
import { lintProjectGenerator } from '@nrwl/linter';
async function addLinting(host: Tree, options: NormalizedSchema) {
let installTask: GeneratorCallback;
installTask = await lintProjectGenerator(host, {
linter: options.linter,
project: options.projectName,
tsConfigPaths: [
joinPathFragments(options.appProjectRoot, 'tsconfig.app.json'),
],
eslintFilePatterns: [`${options.appProjectRoot}/**/*.{ts,tsx,js,jsx}`],
skipFormat: true,
});
updateJson(
host,
joinPathFragments(options.appProjectRoot, '.eslintrc.json'),
(json) => {
json.extends = [...reactEslintJson.extends, ...json.extends];
return json;
}
);
installTask = await addDependenciesToPackageJson(
host,
extraEslintDependencies.dependencies,
extraEslintDependencies.devDependencies
);
return installTask;
}
export async function applicationGenerator(host: Tree, schema: Schema) {
let installTask: GeneratorCallback;
const options = normalizeOptions(host, schema);
installTask = await reactInitGenerator(host, {
...options,
skipFormat: true,
});
createApplicationFiles(host, options);
addProject(host, options);
await addLinting(host, options);
await addCypress(host, options);
await addJest(host, options);
updateJestConfig(host, options);
addStyledModuleDependencies(host, options.styledModule);
addRouting(host, options);
setDefaults(host, options);
if (!options.skipFormat) {
await formatFiles(host);
}
return installTask;
}
export default applicationGenerator;
export const applicationSchematic = convertNxGenerator(applicationGenerator);