generate-from-files.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536
  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.dev/license
  8. */
  9. Object.defineProperty(exports, "__esModule", { value: true });
  10. exports.generateFromFiles = generateFromFiles;
  11. const schematics_1 = require("@angular-devkit/schematics");
  12. const parse_name_1 = require("./parse-name");
  13. const validation_1 = require("./validation");
  14. const workspace_1 = require("./workspace");
  15. function generateFromFiles(options, extraTemplateValues = {}) {
  16. return async (host) => {
  17. options.path ??= await (0, workspace_1.createDefaultPath)(host, options.project);
  18. options.prefix ??= '';
  19. options.flat ??= true;
  20. const parsedPath = (0, parse_name_1.parseName)(options.path, options.name);
  21. options.name = parsedPath.name;
  22. options.path = parsedPath.path;
  23. (0, validation_1.validateClassName)(schematics_1.strings.classify(options.name));
  24. const templateFilesDirectory = options.templateFilesDirectory ?? './files';
  25. const templateSource = (0, schematics_1.apply)((0, schematics_1.url)(templateFilesDirectory), [
  26. options.skipTests ? (0, schematics_1.filter)((path) => !path.endsWith('.spec.ts.template')) : (0, schematics_1.noop)(),
  27. (0, schematics_1.applyTemplates)({
  28. ...schematics_1.strings,
  29. ...options,
  30. ...extraTemplateValues,
  31. }),
  32. (0, schematics_1.move)(parsedPath.path + (options.flat ? '' : '/' + schematics_1.strings.dasherize(options.name))),
  33. ]);
  34. return (0, schematics_1.chain)([(0, schematics_1.mergeWith)(templateSource)]);
  35. };
  36. }