index.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. /**
  4. * @license
  5. * Copyright Google Inc. All Rights Reserved.
  6. *
  7. * Use of this source code is governed by an MIT-style license that can be
  8. * found in the LICENSE file at https://angular.io/license
  9. */
  10. const schematics_1 = require("@angular-devkit/schematics");
  11. const tasks_1 = require("@angular-devkit/schematics/tasks");
  12. function default_1(options) {
  13. if (!options.name) {
  14. throw new schematics_1.SchematicsException(`Invalid options, "name" is required.`);
  15. }
  16. if (!options.directory) {
  17. options.directory = options.name;
  18. }
  19. const workspaceOptions = {
  20. name: options.name,
  21. version: options.version,
  22. newProjectRoot: options.newProjectRoot,
  23. minimal: options.minimal,
  24. strict: options.strict,
  25. packageManager: options.packageManager,
  26. };
  27. const applicationOptions = {
  28. projectRoot: '',
  29. name: options.name,
  30. inlineStyle: options.inlineStyle,
  31. inlineTemplate: options.inlineTemplate,
  32. prefix: options.prefix,
  33. viewEncapsulation: options.viewEncapsulation,
  34. routing: options.routing,
  35. style: options.style,
  36. skipTests: options.skipTests,
  37. skipPackageJson: false,
  38. // always 'skipInstall' here, so that we do it after the move
  39. skipInstall: true,
  40. minimal: options.minimal,
  41. };
  42. return schematics_1.chain([
  43. schematics_1.mergeWith(schematics_1.apply(schematics_1.empty(), [
  44. schematics_1.schematic('workspace', workspaceOptions),
  45. options.createApplication ? schematics_1.schematic('application', applicationOptions) : schematics_1.noop,
  46. schematics_1.move(options.directory),
  47. ])),
  48. (_host, context) => {
  49. let packageTask;
  50. if (!options.skipInstall) {
  51. packageTask = context.addTask(new tasks_1.NodePackageInstallTask({
  52. workingDirectory: options.directory,
  53. packageManager: options.packageManager,
  54. }));
  55. if (options.linkCli) {
  56. packageTask = context.addTask(new tasks_1.NodePackageLinkTask('@angular/cli', options.directory), [packageTask]);
  57. }
  58. }
  59. if (!options.skipGit) {
  60. const commit = typeof options.commit == 'object'
  61. ? options.commit
  62. : (!!options.commit ? {} : false);
  63. context.addTask(new tasks_1.RepositoryInitializerTask(options.directory, commit), packageTask ? [packageTask] : []);
  64. }
  65. },
  66. ]);
  67. }
  68. exports.default = default_1;