nx/packages/nx-plugin/src/schematics/executor/lib/update-executor-json.ts
Vivek More 🧐 212fb00548 cleanup(misc): use more es6 features
- Single char alternation (e.g. a|b|c|d) in a RegExp can be simplified to use a character class ([abcd]) instead.
  This usually also provides slightly better matching performance.
- Character escapes that are replaceable with the unescaped character without a change in meaning. Inside the square brackets of a character class, many escapes are unnecessary that would be necessary outside of a character class. For example the regex [\.] is identical to [.]
- If several qualified expressions occur after the qualifier having been checked for nullable, they can be replaced with optional chaining
2021-03-24 20:11:32 -04:00

30 lines
928 B
TypeScript

import { Rule, Tree } from '@angular-devkit/schematics';
import { updateJsonInTree } from '@nrwl/workspace';
import * as path from 'path';
import { NormalizedSchema } from '../schema';
export function updateExecutorJson(
host: Tree,
options: NormalizedSchema
): Rule {
let executorPath: string;
if (host.exists(path.join(options.projectRoot, 'executors.json'))) {
executorPath = path.join(options.projectRoot, 'executors.json');
} else {
executorPath = path.join(options.projectRoot, 'builders.json');
}
return updateJsonInTree(executorPath, (json) => {
let executors = json.executors ?? json.builders;
executors = executors || {};
executors[options.name] = {
implementation: `./src/executors/${options.name}/executor`,
schema: `./src/executors/${options.name}/schema.json`,
description: options.description,
};
json.executors = executors;
return json;
});
}