@schematics/angular 14.0.0-next.10 → 14.0.0-next.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/app-shell/index.js +4 -8
  2. package/application/index.js +3 -3
  3. package/component/files/__name@dasherize@if-flat__/__name@dasherize__.__type@dasherize__.spec.ts.template +1 -1
  4. package/component/files/__name@dasherize@if-flat__/__name@dasherize__.__type@dasherize__.ts.template +5 -2
  5. package/component/index.js +9 -14
  6. package/component/schema.d.ts +4 -0
  7. package/component/schema.json +6 -0
  8. package/directive/files/__name@dasherize@if-flat__/__name@dasherize__.directive.ts.template +2 -1
  9. package/directive/index.js +9 -18
  10. package/directive/schema.d.ts +4 -0
  11. package/directive/schema.json +6 -0
  12. package/e2e/index.js +4 -4
  13. package/library/index.js +2 -2
  14. package/module/index.js +8 -16
  15. package/package.json +10 -3
  16. package/pipe/files/__name@dasherize@if-flat__/__name@dasherize__.pipe.ts.template +2 -1
  17. package/pipe/index.js +8 -17
  18. package/pipe/schema.d.ts +4 -0
  19. package/pipe/schema.json +6 -0
  20. package/service-worker/index.js +4 -8
  21. package/universal/index.js +3 -7
  22. package/utility/dependency.d.ts +45 -0
  23. package/utility/dependency.js +97 -0
  24. package/utility/find-module.d.ts +1 -0
  25. package/utility/find-module.js +1 -2
  26. package/utility/generate-from-files.js +2 -3
  27. package/utility/index.d.ts +10 -0
  28. package/utility/index.js +21 -0
  29. package/utility/json-file.js +1 -7
  30. package/utility/ng-ast-utils.js +2 -10
  31. package/utility/parse-name.js +0 -1
  32. package/utility/validation.js +1 -3
  33. package/utility/workspace-models.d.ts +6 -0
  34. package/utility/workspace-models.js +6 -0
  35. package/utility/workspace.d.ts +36 -3
  36. package/utility/workspace.js +70 -34
  37. package/web-worker/index.js +2 -2
  38. package/workspace/index.js +1 -2
@@ -40,11 +40,7 @@ const project_targets_1 = require("../utility/project-targets");
40
40
  const workspace_1 = require("../utility/workspace");
41
41
  const workspace_models_1 = require("../utility/workspace-models");
42
42
  function getSourceFile(host, path) {
43
- const buffer = host.read(path);
44
- if (!buffer) {
45
- throw new schematics_1.SchematicsException(`Could not find ${path}.`);
46
- }
47
- const content = buffer.toString();
43
+ const content = host.readText(path);
48
44
  const source = ts.createSourceFile(path, content, ts.ScriptTarget.Latest, true);
49
45
  return source;
50
46
  }
@@ -76,10 +72,10 @@ function getComponentTemplate(host, compPath, tmplInfo) {
76
72
  const templateUrl = tmplInfo.templateUrlProp.initializer.text;
77
73
  const dir = (0, core_1.dirname)((0, core_1.normalize)(compPath));
78
74
  const templatePath = (0, core_1.join)(dir, templateUrl);
79
- const buffer = host.read(templatePath);
80
- if (buffer) {
81
- template = buffer.toString();
75
+ try {
76
+ template = host.readText(templatePath);
82
77
  }
78
+ catch { }
83
79
  }
84
80
  return template;
85
81
  }
@@ -233,7 +233,7 @@ function default_1(options) {
233
233
  // If scoped project (i.e. "@foo/bar"), convert dir to "foo/bar".
234
234
  let folderName = options.name.startsWith('@') ? options.name.slice(1) : options.name;
235
235
  if (/[A-Z]/.test(folderName)) {
236
- folderName = core_1.strings.dasherize(folderName);
236
+ folderName = schematics_1.strings.dasherize(folderName);
237
237
  }
238
238
  const appDir = isRootApp
239
239
  ? (0, core_1.normalize)(options.projectRoot || '')
@@ -244,7 +244,7 @@ function default_1(options) {
244
244
  (0, schematics_1.mergeWith)((0, schematics_1.apply)((0, schematics_1.url)('./files'), [
245
245
  options.minimal ? (0, schematics_1.filter)(minimalPathFilter) : (0, schematics_1.noop)(),
246
246
  (0, schematics_1.applyTemplates)({
247
- utils: core_1.strings,
247
+ utils: schematics_1.strings,
248
248
  ...options,
249
249
  relativePathToWorkspaceRoot: (0, paths_1.relativePathToWorkspaceRoot)(appDir),
250
250
  appName: options.name,
@@ -280,7 +280,7 @@ function default_1(options) {
280
280
  ? (0, schematics_1.filter)((path) => !path.endsWith('.spec.ts.template'))
281
281
  : (0, schematics_1.noop)(),
282
282
  (0, schematics_1.applyTemplates)({
283
- utils: core_1.strings,
283
+ utils: schematics_1.strings,
284
284
  ...options,
285
285
  selector: appRootSelector,
286
286
  ...componentOptions,
@@ -8,7 +8,7 @@ describe('<%= classify(name) %><%= classify(type) %>', () => {
8
8
 
9
9
  beforeEach(async () => {
10
10
  await TestBed.configureTestingModule({
11
- declarations: [ <%= classify(name) %><%= classify(type) %> ]
11
+ <%= standalone ? 'imports' : 'declarations' %>: [ <%= classify(name) %><%= classify(type) %> ]
12
12
  })
13
13
  .compileComponents();
14
14
 
@@ -1,7 +1,10 @@
1
- import { Component, OnInit<% if(!!viewEncapsulation) { %>, ViewEncapsulation<% }%><% if(changeDetection !== 'Default') { %>, ChangeDetectionStrategy<% }%> } from '@angular/core';
1
+ import { Component, OnInit<% if(!!viewEncapsulation) { %>, ViewEncapsulation<% }%><% if(changeDetection !== 'Default') { %>, ChangeDetectionStrategy<% }%> } from '@angular/core';<% if(standalone) {%>
2
+ import { CommonModule } from '@angular/common';<% } %>
2
3
 
3
4
  @Component({<% if(!skipSelector) {%>
4
- selector: '<%= selector %>',<%}%><% if(inlineTemplate) { %>
5
+ selector: '<%= selector %>',<%}%><% if(standalone) {%>
6
+ standalone: true,
7
+ imports: [CommonModule], <%}%><% if(inlineTemplate) { %>
5
8
  template: `
6
9
  <p>
7
10
  <%= dasherize(name) %> works!
@@ -30,7 +30,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
30
30
  return result;
31
31
  };
32
32
  Object.defineProperty(exports, "__esModule", { value: true });
33
- const core_1 = require("@angular-devkit/core");
34
33
  const schematics_1 = require("@angular-devkit/schematics");
35
34
  const ts = __importStar(require("../third_party/github.com/Microsoft/TypeScript/lib/typescript"));
36
35
  const ast_utils_1 = require("../utility/ast-utils");
@@ -41,28 +40,24 @@ const validation_1 = require("../utility/validation");
41
40
  const workspace_1 = require("../utility/workspace");
42
41
  const schema_1 = require("./schema");
43
42
  function readIntoSourceFile(host, modulePath) {
44
- const text = host.read(modulePath);
45
- if (text === null) {
46
- throw new schematics_1.SchematicsException(`File ${modulePath} does not exist.`);
47
- }
48
- const sourceText = text.toString('utf-8');
43
+ const sourceText = host.readText(modulePath);
49
44
  return ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);
50
45
  }
51
46
  function addDeclarationToNgModule(options) {
52
47
  return (host) => {
53
- if (options.skipImport || !options.module) {
48
+ if (options.skipImport || options.standalone || !options.module) {
54
49
  return host;
55
50
  }
56
51
  options.type = options.type != null ? options.type : 'Component';
57
52
  const modulePath = options.module;
58
53
  const source = readIntoSourceFile(host, modulePath);
59
54
  const componentPath = `/${options.path}/` +
60
- (options.flat ? '' : core_1.strings.dasherize(options.name) + '/') +
61
- core_1.strings.dasherize(options.name) +
55
+ (options.flat ? '' : schematics_1.strings.dasherize(options.name) + '/') +
56
+ schematics_1.strings.dasherize(options.name) +
62
57
  (options.type ? '.' : '') +
63
- core_1.strings.dasherize(options.type);
58
+ schematics_1.strings.dasherize(options.type);
64
59
  const relativePath = (0, find_module_1.buildRelativePath)(modulePath, componentPath);
65
- const classifiedName = core_1.strings.classify(options.name) + core_1.strings.classify(options.type);
60
+ const classifiedName = schematics_1.strings.classify(options.name) + schematics_1.strings.classify(options.type);
66
61
  const declarationChanges = (0, ast_utils_1.addDeclarationToModule)(source, modulePath, classifiedName, relativePath);
67
62
  const declarationRecorder = host.beginUpdate(modulePath);
68
63
  for (const change of declarationChanges) {
@@ -75,7 +70,7 @@ function addDeclarationToNgModule(options) {
75
70
  // Need to refresh the AST because we overwrote the file in the host.
76
71
  const source = readIntoSourceFile(host, modulePath);
77
72
  const exportRecorder = host.beginUpdate(modulePath);
78
- const exportChanges = (0, ast_utils_1.addExportToModule)(source, modulePath, core_1.strings.classify(options.name) + core_1.strings.classify(options.type), relativePath);
73
+ const exportChanges = (0, ast_utils_1.addExportToModule)(source, modulePath, schematics_1.strings.classify(options.name) + schematics_1.strings.classify(options.type), relativePath);
79
74
  for (const change of exportChanges) {
80
75
  if (change instanceof change_1.InsertChange) {
81
76
  exportRecorder.insertLeft(change.pos, change.toAdd);
@@ -87,7 +82,7 @@ function addDeclarationToNgModule(options) {
87
82
  };
88
83
  }
89
84
  function buildSelector(options, projectPrefix) {
90
- let selector = core_1.strings.dasherize(options.name);
85
+ let selector = schematics_1.strings.dasherize(options.name);
91
86
  if (options.prefix) {
92
87
  selector = `${options.prefix}-${selector}`;
93
88
  }
@@ -119,7 +114,7 @@ function default_1(options) {
119
114
  skipStyleFile ? (0, schematics_1.filter)((path) => !path.endsWith('.__style__.template')) : (0, schematics_1.noop)(),
120
115
  options.inlineTemplate ? (0, schematics_1.filter)((path) => !path.endsWith('.html.template')) : (0, schematics_1.noop)(),
121
116
  (0, schematics_1.applyTemplates)({
122
- ...core_1.strings,
117
+ ...schematics_1.strings,
123
118
  'if-flat': (s) => (options.flat ? '' : s),
124
119
  ...options,
125
120
  }),
@@ -65,6 +65,10 @@ export interface Schema {
65
65
  * Do not create "spec.ts" test files for the new component.
66
66
  */
67
67
  skipTests?: boolean;
68
+ /**
69
+ * Whether the generated component is standalone.
70
+ */
71
+ standalone?: boolean;
68
72
  /**
69
73
  * The file extension or preprocessor to use for style files, or 'none' to skip generating
70
74
  * the style file.
@@ -48,6 +48,12 @@
48
48
  "alias": "t",
49
49
  "x-user-analytics": 10
50
50
  },
51
+ "standalone": {
52
+ "description": "Whether the generated component is standalone.",
53
+ "type": "boolean",
54
+ "default": false,
55
+ "x-user-analytics": 15
56
+ },
51
57
  "viewEncapsulation": {
52
58
  "description": "The view encapsulation strategy to use in the new component.",
53
59
  "enum": ["Emulated", "None", "ShadowDom"],
@@ -1,7 +1,8 @@
1
1
  import { Directive } from '@angular/core';
2
2
 
3
3
  @Directive({
4
- selector: '[<%= selector %>]'
4
+ selector: '[<%= selector %>]'<% if(standalone) {%>,
5
+ standalone: true<%}%>
5
6
  })
6
7
  export class <%= classify(name) %>Directive {
7
8
 
@@ -30,7 +30,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
30
30
  return result;
31
31
  };
32
32
  Object.defineProperty(exports, "__esModule", { value: true });
33
- const core_1 = require("@angular-devkit/core");
34
33
  const schematics_1 = require("@angular-devkit/schematics");
35
34
  const ts = __importStar(require("../third_party/github.com/Microsoft/TypeScript/lib/typescript"));
36
35
  const ast_utils_1 = require("../utility/ast-utils");
@@ -41,22 +40,18 @@ const validation_1 = require("../utility/validation");
41
40
  const workspace_1 = require("../utility/workspace");
42
41
  function addDeclarationToNgModule(options) {
43
42
  return (host) => {
44
- if (options.skipImport || !options.module) {
43
+ if (options.skipImport || options.standalone || !options.module) {
45
44
  return host;
46
45
  }
47
46
  const modulePath = options.module;
48
- const text = host.read(modulePath);
49
- if (text === null) {
50
- throw new schematics_1.SchematicsException(`File ${modulePath} does not exist.`);
51
- }
52
- const sourceText = text.toString('utf-8');
47
+ const sourceText = host.readText(modulePath);
53
48
  const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);
54
49
  const directivePath = `/${options.path}/` +
55
- (options.flat ? '' : core_1.strings.dasherize(options.name) + '/') +
56
- core_1.strings.dasherize(options.name) +
50
+ (options.flat ? '' : schematics_1.strings.dasherize(options.name) + '/') +
51
+ schematics_1.strings.dasherize(options.name) +
57
52
  '.directive';
58
53
  const relativePath = (0, find_module_1.buildRelativePath)(modulePath, directivePath);
59
- const classifiedName = core_1.strings.classify(`${options.name}Directive`);
54
+ const classifiedName = schematics_1.strings.classify(`${options.name}Directive`);
60
55
  const declarationChanges = (0, ast_utils_1.addDeclarationToModule)(source, modulePath, classifiedName, relativePath);
61
56
  const declarationRecorder = host.beginUpdate(modulePath);
62
57
  for (const change of declarationChanges) {
@@ -67,14 +62,10 @@ function addDeclarationToNgModule(options) {
67
62
  host.commitUpdate(declarationRecorder);
68
63
  if (options.export) {
69
64
  // Need to refresh the AST because we overwrote the file in the host.
70
- const text = host.read(modulePath);
71
- if (text === null) {
72
- throw new schematics_1.SchematicsException(`File ${modulePath} does not exist.`);
73
- }
74
- const sourceText = text.toString('utf-8');
65
+ const sourceText = host.readText(modulePath);
75
66
  const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);
76
67
  const exportRecorder = host.beginUpdate(modulePath);
77
- const exportChanges = (0, ast_utils_1.addExportToModule)(source, modulePath, core_1.strings.classify(`${options.name}Directive`), relativePath);
68
+ const exportChanges = (0, ast_utils_1.addExportToModule)(source, modulePath, schematics_1.strings.classify(`${options.name}Directive`), relativePath);
78
69
  for (const change of exportChanges) {
79
70
  if (change instanceof change_1.InsertChange) {
80
71
  exportRecorder.insertLeft(change.pos, change.toAdd);
@@ -93,7 +84,7 @@ function buildSelector(options, projectPrefix) {
93
84
  else if (options.prefix === undefined && projectPrefix) {
94
85
  selector = `${projectPrefix}-${selector}`;
95
86
  }
96
- return core_1.strings.camelize(selector);
87
+ return schematics_1.strings.camelize(selector);
97
88
  }
98
89
  function default_1(options) {
99
90
  return async (host) => {
@@ -114,7 +105,7 @@ function default_1(options) {
114
105
  const templateSource = (0, schematics_1.apply)((0, schematics_1.url)('./files'), [
115
106
  options.skipTests ? (0, schematics_1.filter)((path) => !path.endsWith('.spec.ts.template')) : (0, schematics_1.noop)(),
116
107
  (0, schematics_1.applyTemplates)({
117
- ...core_1.strings,
108
+ ...schematics_1.strings,
118
109
  'if-flat': (s) => (options.flat ? '' : s),
119
110
  ...options,
120
111
  }),
@@ -43,4 +43,8 @@ export interface Schema {
43
43
  * Do not create "spec.ts" test files for the new class.
44
44
  */
45
45
  skipTests?: boolean;
46
+ /**
47
+ * Whether the generated directive is standalone.
48
+ */
49
+ standalone?: boolean;
46
50
  }
@@ -59,6 +59,12 @@
59
59
  "format": "html-selector",
60
60
  "description": "The HTML selector to use for this directive."
61
61
  },
62
+ "standalone": {
63
+ "description": "Whether the generated directive is standalone.",
64
+ "type": "boolean",
65
+ "default": false,
66
+ "x-user-analytics": 15
67
+ },
62
68
  "flat": {
63
69
  "type": "boolean",
64
70
  "description": "When true (the default), creates the new files at the top level of the current project.",
package/e2e/index.js CHANGED
@@ -9,11 +9,11 @@
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
10
  const core_1 = require("@angular-devkit/core");
11
11
  const schematics_1 = require("@angular-devkit/schematics");
12
+ const utility_1 = require("../utility");
12
13
  const dependencies_1 = require("../utility/dependencies");
13
14
  const json_file_1 = require("../utility/json-file");
14
15
  const latest_versions_1 = require("../utility/latest-versions");
15
16
  const paths_1 = require("../utility/paths");
16
- const workspace_1 = require("../utility/workspace");
17
17
  const workspace_models_1 = require("../utility/workspace-models");
18
18
  function addScriptsToPackageJson() {
19
19
  return (host) => {
@@ -27,7 +27,7 @@ function addScriptsToPackageJson() {
27
27
  function default_1(options) {
28
28
  return async (host) => {
29
29
  const appProject = options.relatedAppName;
30
- const workspace = await (0, workspace_1.getWorkspace)(host);
30
+ const workspace = await (0, utility_1.readWorkspace)(host);
31
31
  const project = workspace.projects.get(appProject);
32
32
  if (!project) {
33
33
  throw new schematics_1.SchematicsException(`Project name "${appProject}" doesn't not exist.`);
@@ -49,11 +49,11 @@ function default_1(options) {
49
49
  },
50
50
  },
51
51
  });
52
+ await (0, utility_1.writeWorkspace)(host, workspace);
52
53
  return (0, schematics_1.chain)([
53
- (0, workspace_1.updateWorkspace)(workspace),
54
54
  (0, schematics_1.mergeWith)((0, schematics_1.apply)((0, schematics_1.url)('./files'), [
55
55
  (0, schematics_1.applyTemplates)({
56
- utils: core_1.strings,
56
+ utils: schematics_1.strings,
57
57
  ...options,
58
58
  relativePathToWorkspaceRoot: (0, paths_1.relativePathToWorkspaceRoot)(root),
59
59
  }),
package/library/index.js CHANGED
@@ -108,7 +108,7 @@ function default_1(options) {
108
108
  const newProjectRoot = workspace.extensions.newProjectRoot || '';
109
109
  let folderName = packageName.startsWith('@') ? packageName.slice(1) : packageName;
110
110
  if (/[A-Z]/.test(folderName)) {
111
- folderName = core_1.strings.dasherize(folderName);
111
+ folderName = schematics_1.strings.dasherize(folderName);
112
112
  }
113
113
  const projectRoot = (0, core_1.join)((0, core_1.normalize)(newProjectRoot), folderName);
114
114
  const distRoot = `dist/${folderName}`;
@@ -116,7 +116,7 @@ function default_1(options) {
116
116
  const sourceDir = `${projectRoot}/src/lib`;
117
117
  const templateSource = (0, schematics_1.apply)((0, schematics_1.url)('./files'), [
118
118
  (0, schematics_1.applyTemplates)({
119
- ...core_1.strings,
119
+ ...schematics_1.strings,
120
120
  ...options,
121
121
  packageName,
122
122
  projectRoot,
package/module/index.js CHANGED
@@ -41,8 +41,8 @@ const workspace_1 = require("../utility/workspace");
41
41
  const schema_1 = require("./schema");
42
42
  function buildRelativeModulePath(options, modulePath) {
43
43
  const importModulePath = (0, core_1.normalize)(`/${options.path}/` +
44
- (options.flat ? '' : core_1.strings.dasherize(options.name) + '/') +
45
- core_1.strings.dasherize(options.name) +
44
+ (options.flat ? '' : schematics_1.strings.dasherize(options.name) + '/') +
45
+ schematics_1.strings.dasherize(options.name) +
46
46
  '.module');
47
47
  return (0, find_module_1.buildRelativePath)(modulePath, importModulePath);
48
48
  }
@@ -52,14 +52,10 @@ function addDeclarationToNgModule(options) {
52
52
  return host;
53
53
  }
54
54
  const modulePath = options.module;
55
- const text = host.read(modulePath);
56
- if (text === null) {
57
- throw new schematics_1.SchematicsException(`File ${modulePath} does not exist.`);
58
- }
59
- const sourceText = text.toString();
55
+ const sourceText = host.readText(modulePath);
60
56
  const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);
61
57
  const relativePath = buildRelativeModulePath(options, modulePath);
62
- const changes = (0, ast_utils_1.addImportToModule)(source, modulePath, core_1.strings.classify(`${options.name}Module`), relativePath);
58
+ const changes = (0, ast_utils_1.addImportToModule)(source, modulePath, schematics_1.strings.classify(`${options.name}Module`), relativePath);
63
59
  const recorder = host.beginUpdate(modulePath);
64
60
  for (const change of changes) {
65
61
  if (change instanceof change_1.InsertChange) {
@@ -85,11 +81,7 @@ function addRouteDeclarationToNgModule(options, routingModulePath) {
85
81
  else {
86
82
  path = options.module;
87
83
  }
88
- const text = host.read(path);
89
- if (!text) {
90
- throw new Error(`Couldn't find the module nor its routing module.`);
91
- }
92
- const sourceText = text.toString();
84
+ const sourceText = host.readText(path);
93
85
  const addDeclaration = (0, ast_utils_1.addRouteDeclarationToModule)(ts.createSourceFile(path, sourceText, ts.ScriptTarget.Latest, true), path, buildRoute(options, options.module));
94
86
  const recorder = host.beginUpdate(path);
95
87
  recorder.insertLeft(addDeclaration.pos, addDeclaration.toAdd);
@@ -105,7 +97,7 @@ function getRoutingModulePath(host, modulePath) {
105
97
  }
106
98
  function buildRoute(options, modulePath) {
107
99
  const relativeModulePath = buildRelativeModulePath(options, modulePath);
108
- const moduleName = `${core_1.strings.classify(options.name)}Module`;
100
+ const moduleName = `${schematics_1.strings.classify(options.name)}Module`;
109
101
  const loadChildren = `() => import('${relativeModulePath}').then(m => m.${moduleName})`;
110
102
  return `{ path: '${options.route}', loadChildren: ${loadChildren} }`;
111
103
  }
@@ -131,7 +123,7 @@ function default_1(options) {
131
123
  ? (0, schematics_1.noop)()
132
124
  : (0, schematics_1.filter)((path) => !path.endsWith('-routing.module.ts.template')),
133
125
  (0, schematics_1.applyTemplates)({
134
- ...core_1.strings,
126
+ ...schematics_1.strings,
135
127
  'if-flat': (s) => (options.flat ? '' : s),
136
128
  lazyRoute: isLazyLoadedModuleGen,
137
129
  lazyRouteWithoutRouteModule: isLazyLoadedModuleGen && !routingModulePath,
@@ -140,7 +132,7 @@ function default_1(options) {
140
132
  }),
141
133
  (0, schematics_1.move)(parsedPath.path),
142
134
  ]);
143
- const moduleDasherized = core_1.strings.dasherize(options.name);
135
+ const moduleDasherized = schematics_1.strings.dasherize(options.name);
144
136
  const modulePath = `${!options.flat ? moduleDasherized + '/' : ''}${moduleDasherized}.module.ts`;
145
137
  const componentOptions = {
146
138
  module: modulePath,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@schematics/angular",
3
- "version": "14.0.0-next.10",
3
+ "version": "14.0.0-next.13",
4
4
  "description": "Schematics specific to Angular",
5
5
  "homepage": "https://github.com/angular/angular-cli",
6
6
  "keywords": [
@@ -13,10 +13,17 @@
13
13
  "code generation",
14
14
  "schematics"
15
15
  ],
16
+ "exports": {
17
+ "./package.json": "./package.json",
18
+ "./utility": "./utility/index.js",
19
+ "./utility/*": "./utility/*.js",
20
+ "./migrations/migration-collection.json": "./migrations/migration-collection.json",
21
+ "./*": "./*.js"
22
+ },
16
23
  "schematics": "./collection.json",
17
24
  "dependencies": {
18
- "@angular-devkit/core": "14.0.0-next.10",
19
- "@angular-devkit/schematics": "14.0.0-next.10",
25
+ "@angular-devkit/core": "14.0.0-next.13",
26
+ "@angular-devkit/schematics": "14.0.0-next.13",
20
27
  "jsonc-parser": "3.0.0"
21
28
  },
22
29
  "repository": {
@@ -1,7 +1,8 @@
1
1
  import { Pipe, PipeTransform } from '@angular/core';
2
2
 
3
3
  @Pipe({
4
- name: '<%= camelize(name) %>'
4
+ name: '<%= camelize(name) %>'<% if(standalone) {%>,
5
+ standalone: true<%}%>
5
6
  })
6
7
  export class <%= classify(name) %>Pipe implements PipeTransform {
7
8
 
package/pipe/index.js CHANGED
@@ -30,7 +30,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
30
30
  return result;
31
31
  };
32
32
  Object.defineProperty(exports, "__esModule", { value: true });
33
- const core_1 = require("@angular-devkit/core");
34
33
  const schematics_1 = require("@angular-devkit/schematics");
35
34
  const ts = __importStar(require("../third_party/github.com/Microsoft/TypeScript/lib/typescript"));
36
35
  const ast_utils_1 = require("../utility/ast-utils");
@@ -40,22 +39,18 @@ const parse_name_1 = require("../utility/parse-name");
40
39
  const workspace_1 = require("../utility/workspace");
41
40
  function addDeclarationToNgModule(options) {
42
41
  return (host) => {
43
- if (options.skipImport || !options.module) {
42
+ if (options.skipImport || options.standalone || !options.module) {
44
43
  return host;
45
44
  }
46
45
  const modulePath = options.module;
47
- const text = host.read(modulePath);
48
- if (text === null) {
49
- throw new schematics_1.SchematicsException(`File ${modulePath} does not exist.`);
50
- }
51
- const sourceText = text.toString('utf-8');
46
+ const sourceText = host.readText(modulePath);
52
47
  const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);
53
48
  const pipePath = `/${options.path}/` +
54
- (options.flat ? '' : core_1.strings.dasherize(options.name) + '/') +
55
- core_1.strings.dasherize(options.name) +
49
+ (options.flat ? '' : schematics_1.strings.dasherize(options.name) + '/') +
50
+ schematics_1.strings.dasherize(options.name) +
56
51
  '.pipe';
57
52
  const relativePath = (0, find_module_1.buildRelativePath)(modulePath, pipePath);
58
- const changes = (0, ast_utils_1.addDeclarationToModule)(source, modulePath, core_1.strings.classify(`${options.name}Pipe`), relativePath);
53
+ const changes = (0, ast_utils_1.addDeclarationToModule)(source, modulePath, schematics_1.strings.classify(`${options.name}Pipe`), relativePath);
59
54
  const recorder = host.beginUpdate(modulePath);
60
55
  for (const change of changes) {
61
56
  if (change instanceof change_1.InsertChange) {
@@ -64,14 +59,10 @@ function addDeclarationToNgModule(options) {
64
59
  }
65
60
  host.commitUpdate(recorder);
66
61
  if (options.export) {
67
- const text = host.read(modulePath);
68
- if (text === null) {
69
- throw new schematics_1.SchematicsException(`File ${modulePath} does not exist.`);
70
- }
71
- const sourceText = text.toString('utf-8');
62
+ const sourceText = host.readText(modulePath);
72
63
  const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);
73
64
  const exportRecorder = host.beginUpdate(modulePath);
74
- const exportChanges = (0, ast_utils_1.addExportToModule)(source, modulePath, core_1.strings.classify(`${options.name}Pipe`), relativePath);
65
+ const exportChanges = (0, ast_utils_1.addExportToModule)(source, modulePath, schematics_1.strings.classify(`${options.name}Pipe`), relativePath);
75
66
  for (const change of exportChanges) {
76
67
  if (change instanceof change_1.InsertChange) {
77
68
  exportRecorder.insertLeft(change.pos, change.toAdd);
@@ -94,7 +85,7 @@ function default_1(options) {
94
85
  const templateSource = (0, schematics_1.apply)((0, schematics_1.url)('./files'), [
95
86
  options.skipTests ? (0, schematics_1.filter)((path) => !path.endsWith('.spec.ts.template')) : (0, schematics_1.noop)(),
96
87
  (0, schematics_1.applyTemplates)({
97
- ...core_1.strings,
88
+ ...schematics_1.strings,
98
89
  'if-flat': (s) => (options.flat ? '' : s),
99
90
  ...options,
100
91
  }),
package/pipe/schema.d.ts CHANGED
@@ -34,4 +34,8 @@ export interface Schema {
34
34
  * Do not create "spec.ts" test files for the new pipe.
35
35
  */
36
36
  skipTests?: boolean;
37
+ /**
38
+ * Whether the generated pipe is standalone.
39
+ */
40
+ standalone?: boolean;
37
41
  }
package/pipe/schema.json CHANGED
@@ -45,6 +45,12 @@
45
45
  "description": "Do not import this pipe into the owning NgModule.",
46
46
  "x-user-analytics": 18
47
47
  },
48
+ "standalone": {
49
+ "description": "Whether the generated pipe is standalone.",
50
+ "type": "boolean",
51
+ "default": false,
52
+ "x-user-analytics": 15
53
+ },
48
54
  "module": {
49
55
  "type": "string",
50
56
  "description": "The declaring NgModule.",
@@ -34,13 +34,13 @@ const core_1 = require("@angular-devkit/core");
34
34
  const schematics_1 = require("@angular-devkit/schematics");
35
35
  const tasks_1 = require("@angular-devkit/schematics/tasks");
36
36
  const ts = __importStar(require("../third_party/github.com/Microsoft/TypeScript/lib/typescript"));
37
+ const utility_1 = require("../utility");
37
38
  const ast_utils_1 = require("../utility/ast-utils");
38
39
  const change_1 = require("../utility/change");
39
40
  const dependencies_1 = require("../utility/dependencies");
40
41
  const ng_ast_utils_1 = require("../utility/ng-ast-utils");
41
42
  const paths_1 = require("../utility/paths");
42
43
  const project_targets_1 = require("../utility/project-targets");
43
- const workspace_1 = require("../utility/workspace");
44
44
  function addDependencies() {
45
45
  return (host, context) => {
46
46
  const packageName = '@angular/service-worker';
@@ -113,17 +113,13 @@ function updateAppModule(mainPath) {
113
113
  };
114
114
  }
115
115
  function getTsSourceFile(host, path) {
116
- const buffer = host.read(path);
117
- if (!buffer) {
118
- throw new schematics_1.SchematicsException(`Could not read file (${path}).`);
119
- }
120
- const content = buffer.toString();
116
+ const content = host.readText(path);
121
117
  const source = ts.createSourceFile(path, content, ts.ScriptTarget.Latest, true);
122
118
  return source;
123
119
  }
124
120
  function default_1(options) {
125
121
  return async (host, context) => {
126
- const workspace = await (0, workspace_1.getWorkspace)(host);
122
+ const workspace = await (0, utility_1.readWorkspace)(host);
127
123
  const project = workspace.projects.get(options.project);
128
124
  if (!project) {
129
125
  throw new schematics_1.SchematicsException(`Invalid project name (${options.project})`);
@@ -152,9 +148,9 @@ function default_1(options) {
152
148
  (0, schematics_1.move)(project.root),
153
149
  ]);
154
150
  context.addTask(new tasks_1.NodePackageInstallTask());
151
+ await (0, utility_1.writeWorkspace)(host, workspace);
155
152
  return (0, schematics_1.chain)([
156
153
  (0, schematics_1.mergeWith)(templateSource),
157
- (0, workspace_1.updateWorkspace)(workspace),
158
154
  addDependencies(),
159
155
  updateAppModule(buildOptions.main),
160
156
  ]);
@@ -96,11 +96,7 @@ function updateConfigFile(options, tsConfigDirectory) {
96
96
  });
97
97
  }
98
98
  function findBrowserModuleImport(host, modulePath) {
99
- const moduleBuffer = host.read(modulePath);
100
- if (!moduleBuffer) {
101
- throw new schematics_1.SchematicsException(`Module file (${modulePath}) not found`);
102
- }
103
- const moduleFileText = moduleBuffer.toString('utf-8');
99
+ const moduleFileText = host.readText(modulePath);
104
100
  const source = ts.createSourceFile(modulePath, moduleFileText, ts.ScriptTarget.Latest, true);
105
101
  const decoratorMetadata = (0, ast_utils_1.getDecoratorMetadata)(source, 'NgModule', '@angular/core')[0];
106
102
  const browserModuleNode = (0, ast_utils_1.findNode)(decoratorMetadata, ts.SyntaxKind.Identifier, 'BrowserModule');
@@ -230,7 +226,7 @@ function default_1(options) {
230
226
  }
231
227
  const templateSource = (0, schematics_1.apply)((0, schematics_1.url)('./files/src'), [
232
228
  (0, schematics_1.applyTemplates)({
233
- ...core_1.strings,
229
+ ...schematics_1.strings,
234
230
  ...options,
235
231
  stripTsExtension: (s) => s.replace(/\.ts$/, ''),
236
232
  hasLocalizePackage: !!(0, dependencies_1.getPackageJsonDependency)(host, '@angular/localize'),
@@ -239,7 +235,7 @@ function default_1(options) {
239
235
  ]);
240
236
  const rootSource = (0, schematics_1.apply)((0, schematics_1.url)('./files/root'), [
241
237
  (0, schematics_1.applyTemplates)({
242
- ...core_1.strings,
238
+ ...schematics_1.strings,
243
239
  ...options,
244
240
  stripTsExtension: (s) => s.replace(/\.ts$/, ''),
245
241
  tsConfigExtends,
@@ -0,0 +1,45 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ import { Rule } from '@angular-devkit/schematics';
9
+ /**
10
+ * An enum used to specify the type of a dependency found within a package manifest
11
+ * file (`package.json`).
12
+ */
13
+ export declare enum DependencyType {
14
+ Default = "dependencies",
15
+ Dev = "devDependencies",
16
+ Peer = "peerDependencies"
17
+ }
18
+ /**
19
+ * Adds a package as a dependency to a `package.json`. By default the `package.json` located
20
+ * at the schematic's root will be used. The `manifestPath` option can be used to explicitly specify
21
+ * a `package.json` in different location. The type of the dependency can also be specified instead
22
+ * of the default of the `dependencies` section by using the `type` option for either `devDependencies`
23
+ * or `peerDependencies`.
24
+ *
25
+ * When using this rule, {@link NodePackageInstallTask} does not need to be included directly by
26
+ * a schematic. A package manager install task will be automatically scheduled as needed.
27
+ *
28
+ * @param name The name of the package to add.
29
+ * @param specifier The package specifier for the package to add. Typically a SemVer range.
30
+ * @param options An optional object that can contain the `type` of the dependency
31
+ * and/or a path (`packageJsonPath`) of a manifest file (`package.json`) to modify.
32
+ * @returns A Schematics {@link Rule}
33
+ */
34
+ export declare function addDependency(name: string, specifier: string, options?: {
35
+ /**
36
+ * The type of the dependency determines the section of the `package.json` to which the
37
+ * dependency will be added. Defaults to {@link DependencyType.Default} (`dependencies`).
38
+ */
39
+ type?: DependencyType;
40
+ /**
41
+ * The path of the package manifest file (`package.json`) that will be modified.
42
+ * Defaults to `/package.json`.
43
+ */
44
+ packageJsonPath?: string;
45
+ }): Rule;
@@ -0,0 +1,97 @@
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
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ var desc = Object.getOwnPropertyDescriptor(m, k);
12
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13
+ desc = { enumerable: true, get: function() { return m[k]; } };
14
+ }
15
+ Object.defineProperty(o, k2, desc);
16
+ }) : (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ o[k2] = m[k];
19
+ }));
20
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
21
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
22
+ }) : function(o, v) {
23
+ o["default"] = v;
24
+ });
25
+ var __importStar = (this && this.__importStar) || function (mod) {
26
+ if (mod && mod.__esModule) return mod;
27
+ var result = {};
28
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
29
+ __setModuleDefault(result, mod);
30
+ return result;
31
+ };
32
+ Object.defineProperty(exports, "__esModule", { value: true });
33
+ exports.addDependency = exports.DependencyType = void 0;
34
+ const tasks_1 = require("@angular-devkit/schematics/tasks");
35
+ const path = __importStar(require("path"));
36
+ const installTasks = new WeakMap();
37
+ /**
38
+ * An enum used to specify the type of a dependency found within a package manifest
39
+ * file (`package.json`).
40
+ */
41
+ var DependencyType;
42
+ (function (DependencyType) {
43
+ DependencyType["Default"] = "dependencies";
44
+ DependencyType["Dev"] = "devDependencies";
45
+ DependencyType["Peer"] = "peerDependencies";
46
+ })(DependencyType = exports.DependencyType || (exports.DependencyType = {}));
47
+ /**
48
+ * Adds a package as a dependency to a `package.json`. By default the `package.json` located
49
+ * at the schematic's root will be used. The `manifestPath` option can be used to explicitly specify
50
+ * a `package.json` in different location. The type of the dependency can also be specified instead
51
+ * of the default of the `dependencies` section by using the `type` option for either `devDependencies`
52
+ * or `peerDependencies`.
53
+ *
54
+ * When using this rule, {@link NodePackageInstallTask} does not need to be included directly by
55
+ * a schematic. A package manager install task will be automatically scheduled as needed.
56
+ *
57
+ * @param name The name of the package to add.
58
+ * @param specifier The package specifier for the package to add. Typically a SemVer range.
59
+ * @param options An optional object that can contain the `type` of the dependency
60
+ * and/or a path (`packageJsonPath`) of a manifest file (`package.json`) to modify.
61
+ * @returns A Schematics {@link Rule}
62
+ */
63
+ function addDependency(name, specifier, options = {}) {
64
+ const { type = DependencyType.Default, packageJsonPath = '/package.json' } = options;
65
+ return (tree, context) => {
66
+ var _a;
67
+ const manifest = tree.readJson(packageJsonPath);
68
+ const dependencySection = manifest[type];
69
+ if (!dependencySection) {
70
+ // Section is not present. The dependency can be added to a new object literal for the section.
71
+ manifest[type] = { [name]: specifier };
72
+ }
73
+ else if (dependencySection[name] === specifier) {
74
+ // Already present with same specifier
75
+ return;
76
+ }
77
+ else if (dependencySection[name]) {
78
+ // Already present but different specifier
79
+ throw new Error(`Package dependency "${name}" already exists with a different specifier.`);
80
+ }
81
+ else {
82
+ // Add new dependency in alphabetical order
83
+ const entries = Object.entries(dependencySection);
84
+ entries.push([name, specifier]);
85
+ entries.sort((a, b) => a[0].localeCompare(b[0]));
86
+ manifest[type] = Object.fromEntries(entries);
87
+ }
88
+ tree.overwrite(packageJsonPath, JSON.stringify(manifest, null, 2));
89
+ const installPaths = (_a = installTasks.get(context)) !== null && _a !== void 0 ? _a : new Set();
90
+ if (!installPaths.has(packageJsonPath)) {
91
+ context.addTask(new tasks_1.NodePackageInstallTask({ workingDirectory: path.dirname(packageJsonPath) }));
92
+ installPaths.add(packageJsonPath);
93
+ installTasks.set(context, installPaths);
94
+ }
95
+ };
96
+ }
97
+ exports.addDependency = addDependency;
@@ -15,6 +15,7 @@ export interface ModuleOptions {
15
15
  skipImport?: boolean;
16
16
  moduleExt?: string;
17
17
  routingModuleExt?: string;
18
+ standalone?: boolean;
18
19
  }
19
20
  export declare const MODULE_EXT = ".module.ts";
20
21
  export declare const ROUTING_MODULE_EXT = "-routing.module.ts";
@@ -15,8 +15,7 @@ exports.ROUTING_MODULE_EXT = '-routing.module.ts';
15
15
  * Find the module referred by a set of options passed to the schematics.
16
16
  */
17
17
  function findModuleFromOptions(host, options) {
18
- // eslint-disable-next-line no-prototype-builtins
19
- if (options.hasOwnProperty('skipImport') && options.skipImport) {
18
+ if (options.standalone || options.skipImport) {
20
19
  return undefined;
21
20
  }
22
21
  const moduleExt = options.moduleExt || exports.MODULE_EXT;
@@ -8,7 +8,6 @@
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports.generateFromFiles = void 0;
11
- const core_1 = require("@angular-devkit/core");
12
11
  const schematics_1 = require("@angular-devkit/schematics");
13
12
  const parse_name_1 = require("./parse-name");
14
13
  const workspace_1 = require("./workspace");
@@ -24,11 +23,11 @@ function generateFromFiles(options, extraTemplateValues = {}) {
24
23
  const templateSource = (0, schematics_1.apply)((0, schematics_1.url)('./files'), [
25
24
  options.skipTests ? (0, schematics_1.filter)((path) => !path.endsWith('.spec.ts.template')) : (0, schematics_1.noop)(),
26
25
  (0, schematics_1.applyTemplates)({
27
- ...core_1.strings,
26
+ ...schematics_1.strings,
28
27
  ...options,
29
28
  ...extraTemplateValues,
30
29
  }),
31
- (0, schematics_1.move)(parsedPath.path + (options.flat ? '' : '/' + core_1.strings.dasherize(options.name))),
30
+ (0, schematics_1.move)(parsedPath.path + (options.flat ? '' : '/' + schematics_1.strings.dasherize(options.name))),
32
31
  ]);
33
32
  return (0, schematics_1.chain)([(0, schematics_1.mergeWith)(templateSource)]);
34
33
  };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ export { ProjectDefinition, TargetDefinition, WorkspaceDefinition, getWorkspace as readWorkspace, updateWorkspace, writeWorkspace, } from './workspace';
9
+ export { Builders as AngularBuilder } from './workspace-models';
10
+ export { DependencyType, addDependency } from './dependency';
@@ -0,0 +1,21 @@
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
+ exports.addDependency = exports.DependencyType = exports.AngularBuilder = exports.writeWorkspace = exports.updateWorkspace = exports.readWorkspace = void 0;
11
+ // Workspace related rules and types
12
+ var workspace_1 = require("./workspace");
13
+ Object.defineProperty(exports, "readWorkspace", { enumerable: true, get: function () { return workspace_1.getWorkspace; } });
14
+ Object.defineProperty(exports, "updateWorkspace", { enumerable: true, get: function () { return workspace_1.updateWorkspace; } });
15
+ Object.defineProperty(exports, "writeWorkspace", { enumerable: true, get: function () { return workspace_1.writeWorkspace; } });
16
+ var workspace_models_1 = require("./workspace-models");
17
+ Object.defineProperty(exports, "AngularBuilder", { enumerable: true, get: function () { return workspace_models_1.Builders; } });
18
+ // Package dependency related rules and types
19
+ var dependency_1 = require("./dependency");
20
+ Object.defineProperty(exports, "DependencyType", { enumerable: true, get: function () { return dependency_1.DependencyType; } });
21
+ Object.defineProperty(exports, "addDependency", { enumerable: true, get: function () { return dependency_1.addDependency; } });
@@ -14,13 +14,7 @@ class JSONFile {
14
14
  constructor(host, path) {
15
15
  this.host = host;
16
16
  this.path = path;
17
- const buffer = this.host.read(this.path);
18
- if (buffer) {
19
- this.content = buffer.toString();
20
- }
21
- else {
22
- throw new Error(`Could not read '${path}'.`);
23
- }
17
+ this.content = this.host.readText(this.path);
24
18
  }
25
19
  get JsonAst() {
26
20
  if (this._jsonAst) {
@@ -37,11 +37,7 @@ const path_1 = require("path");
37
37
  const ts = __importStar(require("../third_party/github.com/Microsoft/TypeScript/lib/typescript"));
38
38
  const ast_utils_1 = require("../utility/ast-utils");
39
39
  function findBootstrapModuleCall(host, mainPath) {
40
- const mainBuffer = host.read(mainPath);
41
- if (!mainBuffer) {
42
- throw new schematics_1.SchematicsException(`Main file (${mainPath}) not found`);
43
- }
44
- const mainText = mainBuffer.toString('utf-8');
40
+ const mainText = host.readText(mainPath);
45
41
  const source = ts.createSourceFile(mainPath, mainText, ts.ScriptTarget.Latest, true);
46
42
  const allNodes = (0, ast_utils_1.getSourceNodes)(source);
47
43
  let bootstrapCall = null;
@@ -70,11 +66,7 @@ function findBootstrapModulePath(host, mainPath) {
70
66
  throw new schematics_1.SchematicsException('Bootstrap call not found');
71
67
  }
72
68
  const bootstrapModule = bootstrapCall.arguments[0];
73
- const mainBuffer = host.read(mainPath);
74
- if (!mainBuffer) {
75
- throw new schematics_1.SchematicsException(`Client application main file (${mainPath}) not found`);
76
- }
77
- const mainText = mainBuffer.toString('utf-8');
69
+ const mainText = host.readText(mainPath);
78
70
  const source = ts.createSourceFile(mainPath, mainText, ts.ScriptTarget.Latest, true);
79
71
  const allNodes = (0, ast_utils_1.getSourceNodes)(source);
80
72
  const bootstrapModuleRelativePath = allNodes
@@ -8,7 +8,6 @@
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports.parseName = void 0;
11
- // import { relative, Path } from "../../../angular_devkit/core/src/virtual-fs";
12
11
  const core_1 = require("@angular-devkit/core");
13
12
  function parseName(path, name) {
14
13
  const nameWithoutPath = (0, core_1.basename)((0, core_1.normalize)(name));
@@ -8,15 +8,13 @@
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports.validateHtmlSelector = exports.htmlSelectorRe = void 0;
11
- const core_1 = require("@angular-devkit/core");
12
11
  const schematics_1 = require("@angular-devkit/schematics");
13
12
  // Must start with a letter, and must contain only alphanumeric characters or dashes.
14
13
  // When adding a dash the segment after the dash must also start with a letter.
15
14
  exports.htmlSelectorRe = /^[a-zA-Z][.0-9a-zA-Z]*(:?-[a-zA-Z][.0-9a-zA-Z]*)*$/;
16
15
  function validateHtmlSelector(selector) {
17
16
  if (selector && !exports.htmlSelectorRe.test(selector)) {
18
- throw new schematics_1.SchematicsException(core_1.tags.oneLine `Selector (${selector})
19
- is invalid.`);
17
+ throw new schematics_1.SchematicsException(`Selector (${selector}) is invalid.`);
20
18
  }
21
19
  }
22
20
  exports.validateHtmlSelector = validateHtmlSelector;
@@ -9,6 +9,12 @@ export declare enum ProjectType {
9
9
  Application = "application",
10
10
  Library = "library"
11
11
  }
12
+ /**
13
+ * An enum of the official Angular builders.
14
+ * Each enum value provides the fully qualified name of the associated builder.
15
+ * This enum can be used when analyzing the `builder` fields of project configurations from the
16
+ * `angular.json` workspace file.
17
+ */
12
18
  export declare enum Builders {
13
19
  AppShell = "@angular-devkit/build-angular:app-shell",
14
20
  Server = "@angular-devkit/build-angular:server",
@@ -13,6 +13,12 @@ var ProjectType;
13
13
  ProjectType["Application"] = "application";
14
14
  ProjectType["Library"] = "library";
15
15
  })(ProjectType = exports.ProjectType || (exports.ProjectType = {}));
16
+ /**
17
+ * An enum of the official Angular builders.
18
+ * Each enum value provides the fully qualified name of the associated builder.
19
+ * This enum can be used when analyzing the `builder` fields of project configurations from the
20
+ * `angular.json` workspace file.
21
+ */
16
22
  var Builders;
17
23
  (function (Builders) {
18
24
  Builders["AppShell"] = "@angular-devkit/build-angular:app-shell";
@@ -7,9 +7,42 @@
7
7
  */
8
8
  import { json, workspaces } from '@angular-devkit/core';
9
9
  import { Rule, Tree } from '@angular-devkit/schematics';
10
- export declare function updateWorkspace(updater: (workspace: workspaces.WorkspaceDefinition) => void | Rule | PromiseLike<void | Rule>): Rule;
11
- export declare function updateWorkspace(workspace: workspaces.WorkspaceDefinition): Rule;
12
- export declare function getWorkspace(tree: Tree, path?: string): Promise<workspaces.WorkspaceDefinition>;
10
+ export declare type WorkspaceDefinition = workspaces.WorkspaceDefinition;
11
+ export declare type ProjectDefinition = workspaces.ProjectDefinition;
12
+ export declare type TargetDefinition = workspaces.TargetDefinition;
13
+ /**
14
+ * Updates the workspace file (`angular.json`) found within the root of the schematic's tree.
15
+ * The workspace object model can be directly modified within the provided updater function
16
+ * with changes being written to the workspace file after the updater function returns.
17
+ * The spacing and overall layout of the file (including comments) will be maintained where
18
+ * possible when updating the file.
19
+ *
20
+ * @param updater An update function that can be used to modify the object model for the
21
+ * workspace. A {@link WorkspaceDefinition} is provided as the first argument to the function.
22
+ */
23
+ export declare function updateWorkspace(updater: (workspace: WorkspaceDefinition) => void | Rule | PromiseLike<void | Rule>): Rule;
24
+ /**
25
+ * Reads a workspace file (`angular.json`) from the provided {@link Tree} instance.
26
+ *
27
+ * @param tree A schematics {@link Tree} instance used to access the workspace file.
28
+ * @param path The path where a workspace file should be found. If a file is specified, the file
29
+ * path will be used. If a directory is specified, the file `angular.json` will be used from
30
+ * within the specified directory. Defaults to `/angular.json`.
31
+ * @returns A {@link WorkspaceDefinition} representing the workspace found at the specified path.
32
+ */
33
+ export declare function getWorkspace(tree: Tree, path?: string): Promise<WorkspaceDefinition>;
34
+ /**
35
+ * Writes a workspace file (`angular.json`) to the provided {@link Tree} instance.
36
+ * The spacing and overall layout of an exisitng file (including comments) will be maintained where
37
+ * possible when writing the file.
38
+ *
39
+ * @param tree A schematics {@link Tree} instance used to access the workspace file.
40
+ * @param workspace The {@link WorkspaceDefinition} to write.
41
+ * @param path The path where a workspace file should be written. If a file is specified, the file
42
+ * path will be used. If not provided, the definition's underlying file path stored during reading
43
+ * will be used.
44
+ */
45
+ export declare function writeWorkspace(tree: Tree, workspace: WorkspaceDefinition, path?: string): Promise<void>;
13
46
  /**
14
47
  * Build a default project path for generating.
15
48
  * @param project The project which will have its default path generated.
@@ -7,53 +7,89 @@
7
7
  * found in the LICENSE file at https://angular.io/license
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.allTargetOptions = exports.allWorkspaceTargets = exports.createDefaultPath = exports.buildDefaultPath = exports.getWorkspace = exports.updateWorkspace = void 0;
10
+ exports.allTargetOptions = exports.allWorkspaceTargets = exports.createDefaultPath = exports.buildDefaultPath = exports.writeWorkspace = exports.getWorkspace = exports.updateWorkspace = void 0;
11
11
  const core_1 = require("@angular-devkit/core");
12
12
  const schematics_1 = require("@angular-devkit/schematics");
13
13
  const workspace_models_1 = require("./workspace-models");
14
- function createHost(tree) {
15
- return {
16
- async readFile(path) {
17
- const data = tree.read(path);
18
- if (!data) {
19
- throw new Error('File not found.');
20
- }
21
- return core_1.virtualFs.fileBufferToString(data);
22
- },
23
- async writeFile(path, data) {
24
- return tree.overwrite(path, data);
25
- },
26
- async isDirectory(path) {
27
- // approximate a directory check
28
- return !tree.exists(path) && tree.getDir(path).subfiles.length > 0;
29
- },
30
- async isFile(path) {
31
- return tree.exists(path);
32
- },
33
- };
34
- }
35
- function updateWorkspace(updaterOrWorkspace) {
36
- return async (tree) => {
37
- const host = createHost(tree);
38
- if (typeof updaterOrWorkspace === 'function') {
39
- const { workspace } = await core_1.workspaces.readWorkspace('/', host);
40
- const result = await updaterOrWorkspace(workspace);
41
- await core_1.workspaces.writeWorkspace(workspace, host);
42
- return result || schematics_1.noop;
14
+ const DEFAULT_WORKSPACE_PATH = '/angular.json';
15
+ /**
16
+ * A {@link workspaces.WorkspaceHost} backed by a Schematics {@link Tree} instance.
17
+ */
18
+ class TreeWorkspaceHost {
19
+ constructor(tree) {
20
+ this.tree = tree;
21
+ }
22
+ async readFile(path) {
23
+ return this.tree.readText(path);
24
+ }
25
+ async writeFile(path, data) {
26
+ if (this.tree.exists(path)) {
27
+ this.tree.overwrite(path, data);
43
28
  }
44
29
  else {
45
- await core_1.workspaces.writeWorkspace(updaterOrWorkspace, host);
46
- return schematics_1.noop;
30
+ this.tree.create(path, data);
47
31
  }
32
+ }
33
+ async isDirectory(path) {
34
+ // approximate a directory check
35
+ return !this.tree.exists(path) && this.tree.getDir(path).subfiles.length > 0;
36
+ }
37
+ async isFile(path) {
38
+ return this.tree.exists(path);
39
+ }
40
+ }
41
+ /**
42
+ * Updates the workspace file (`angular.json`) found within the root of the schematic's tree.
43
+ * The workspace object model can be directly modified within the provided updater function
44
+ * with changes being written to the workspace file after the updater function returns.
45
+ * The spacing and overall layout of the file (including comments) will be maintained where
46
+ * possible when updating the file.
47
+ *
48
+ * @param updater An update function that can be used to modify the object model for the
49
+ * workspace. A {@link WorkspaceDefinition} is provided as the first argument to the function.
50
+ */
51
+ function updateWorkspace(updater) {
52
+ return async (tree) => {
53
+ const host = new TreeWorkspaceHost(tree);
54
+ const { workspace } = await core_1.workspaces.readWorkspace(DEFAULT_WORKSPACE_PATH, host);
55
+ const result = await updater(workspace);
56
+ await core_1.workspaces.writeWorkspace(workspace, host);
57
+ return result || schematics_1.noop;
48
58
  };
49
59
  }
50
60
  exports.updateWorkspace = updateWorkspace;
51
- async function getWorkspace(tree, path = '/') {
52
- const host = createHost(tree);
61
+ // TODO: This should be renamed `readWorkspace` once deep imports are restricted (already exported from `utility` with that name)
62
+ /**
63
+ * Reads a workspace file (`angular.json`) from the provided {@link Tree} instance.
64
+ *
65
+ * @param tree A schematics {@link Tree} instance used to access the workspace file.
66
+ * @param path The path where a workspace file should be found. If a file is specified, the file
67
+ * path will be used. If a directory is specified, the file `angular.json` will be used from
68
+ * within the specified directory. Defaults to `/angular.json`.
69
+ * @returns A {@link WorkspaceDefinition} representing the workspace found at the specified path.
70
+ */
71
+ async function getWorkspace(tree, path = DEFAULT_WORKSPACE_PATH) {
72
+ const host = new TreeWorkspaceHost(tree);
53
73
  const { workspace } = await core_1.workspaces.readWorkspace(path, host);
54
74
  return workspace;
55
75
  }
56
76
  exports.getWorkspace = getWorkspace;
77
+ /**
78
+ * Writes a workspace file (`angular.json`) to the provided {@link Tree} instance.
79
+ * The spacing and overall layout of an exisitng file (including comments) will be maintained where
80
+ * possible when writing the file.
81
+ *
82
+ * @param tree A schematics {@link Tree} instance used to access the workspace file.
83
+ * @param workspace The {@link WorkspaceDefinition} to write.
84
+ * @param path The path where a workspace file should be written. If a file is specified, the file
85
+ * path will be used. If not provided, the definition's underlying file path stored during reading
86
+ * will be used.
87
+ */
88
+ async function writeWorkspace(tree, workspace, path) {
89
+ const host = new TreeWorkspaceHost(tree);
90
+ return core_1.workspaces.writeWorkspace(workspace, host, path);
91
+ }
92
+ exports.writeWorkspace = writeWorkspace;
57
93
  /**
58
94
  * Build a default project path for generating.
59
95
  * @param project The project which will have its default path generated.
@@ -46,7 +46,7 @@ function addSnippet(options) {
46
46
  }
47
47
  `;
48
48
  // Append the worker creation snippet.
49
- const originalContent = host.read(siblingModulePath);
49
+ const originalContent = host.readText(siblingModulePath);
50
50
  host.overwrite(siblingModulePath, originalContent + '\n' + workerCreationSnippet);
51
51
  return host;
52
52
  };
@@ -72,7 +72,7 @@ function default_1(options) {
72
72
  options.name = parsedPath.name;
73
73
  options.path = parsedPath.path;
74
74
  const templateSourceWorkerCode = (0, schematics_1.apply)((0, schematics_1.url)('./files/worker'), [
75
- (0, schematics_1.applyTemplates)({ ...options, ...core_1.strings }),
75
+ (0, schematics_1.applyTemplates)({ ...options, ...schematics_1.strings }),
76
76
  (0, schematics_1.move)(parsedPath.path),
77
77
  ]);
78
78
  const root = project.root || '';
@@ -7,14 +7,13 @@
7
7
  * found in the LICENSE file at https://angular.io/license
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
- const core_1 = require("@angular-devkit/core");
11
10
  const schematics_1 = require("@angular-devkit/schematics");
12
11
  const latest_versions_1 = require("../utility/latest-versions");
13
12
  function default_1(options) {
14
13
  return (0, schematics_1.mergeWith)((0, schematics_1.apply)((0, schematics_1.url)('./files'), [
15
14
  options.minimal ? (0, schematics_1.filter)((path) => !path.endsWith('editorconfig.template')) : (0, schematics_1.noop)(),
16
15
  (0, schematics_1.applyTemplates)({
17
- utils: core_1.strings,
16
+ utils: schematics_1.strings,
18
17
  ...options,
19
18
  'dot': '.',
20
19
  latestVersions: latest_versions_1.latestVersions,