schematic-options.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. "use strict";
  2. /**
  3. * @license
  4. * Copyright Google LLC All Rights Reserved.
  5. *
  6. * Use of this source code is governed by an MIT-style license that can be
  7. * found in the LICENSE file at https://angular.io/license
  8. */
  9. Object.defineProperty(exports, "__esModule", { value: true });
  10. /**
  11. * Returns the default options for the `@schematics/angular:component` schematic which would
  12. * have been specified at project initialization (ng new or ng init).
  13. *
  14. * This is necessary because the Angular CLI only exposes the default values for the "--style",
  15. * "--inlineStyle", "--skipTests" and "--inlineTemplate" options to the "component" schematic.
  16. */
  17. function getDefaultComponentOptions(project) {
  18. // Note: Not all options which are available when running "ng new" will be stored in the
  19. // workspace config. List of options which will be available in the configuration:
  20. // angular/angular-cli/blob/master/packages/schematics/angular/application/index.ts#L109-L131
  21. let skipTests = getDefaultComponentOption(project, ['skipTests'], null);
  22. // In case "skipTests" is not set explicitly, also look for the "spec" option. The "spec"
  23. // option has been deprecated but can be still used in older Angular CLI projects.
  24. // See: https://github.com/angular/angular-cli/commit/a12a4e02a4689b5bdbc6e740c0d9865afb55671a
  25. if (skipTests === null) {
  26. skipTests = !getDefaultComponentOption(project, ['spec'], true);
  27. }
  28. return {
  29. style: getDefaultComponentOption(project, ['style', 'styleext'], 'css'),
  30. inlineStyle: getDefaultComponentOption(project, ['inlineStyle'], false),
  31. inlineTemplate: getDefaultComponentOption(project, ['inlineTemplate'], false),
  32. skipTests: skipTests,
  33. };
  34. }
  35. exports.getDefaultComponentOptions = getDefaultComponentOptions;
  36. /**
  37. * Gets the default value for the specified option. The default options will be determined
  38. * by looking at the stored schematic options for `@schematics/angular:component` in the
  39. * CLI workspace configuration.
  40. */
  41. function getDefaultComponentOption(project, optionNames, fallbackValue) {
  42. for (let optionName of optionNames) {
  43. if (project.schematics &&
  44. project.schematics['@schematics/angular:component'] &&
  45. project.schematics['@schematics/angular:component'][optionName] != null) {
  46. return project.schematics['@schematics/angular:component'][optionName];
  47. }
  48. }
  49. return fallbackValue;
  50. }
  51. //# sourceMappingURL=schematic-options.js.map