Skip to content

Commit 7120981

Browse files
caroso1222hansl
authored andcommitted
refactor(@angular-devkit/core): expose string utils as a scoped namespace
1 parent 318b40c commit 7120981

File tree

17 files changed

+63
-202
lines changed

17 files changed

+63
-202
lines changed

packages/angular_devkit/core/src/utils/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88
import * as tags from './literals';
9+
import * as strings from './strings';
10+
911
export * from './object';
10-
export * from './strings';
1112
export * from './template';
1213
export * from './priority-queue';
1314

14-
export { tags };
15+
export { tags, strings };

packages/schematics/angular/application/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8+
import { strings } from '@angular-devkit/core';
89
import {
910
MergeStrategy,
1011
Rule,
@@ -22,7 +23,6 @@ import {
2223
url,
2324
} from '@angular-devkit/schematics';
2425
import * as ts from 'typescript';
25-
import * as stringUtils from '../strings';
2626
import { addBootstrapToModule, addImportToModule } from '../utility/ast-utils';
2727
import { InsertChange } from '../utility/change';
2828
import { Schema as ApplicationOptions } from './schema';
@@ -97,7 +97,7 @@ export default function (options: ApplicationOptions): Rule {
9797
options.skipGit ? filter(path => !path.endsWith('/__dot__gitignore')) : noop(),
9898
options.serviceWorker ? noop() : filter(path => !path.endsWith('/ngsw-config.json')),
9999
template({
100-
utils: stringUtils,
100+
utils: strings,
101101
...options,
102102
'dot': '.',
103103
sourcedir: sourceDir,
@@ -128,7 +128,7 @@ export default function (options: ApplicationOptions): Rule {
128128
componentOptions.inlineTemplate ? filter(path => !path.endsWith('.html')) : noop(),
129129
!componentOptions.spec ? filter(path => !path.endsWith('.spec.ts')) : noop(),
130130
template({
131-
utils: stringUtils,
131+
utils: strings,
132132
...options as any, // tslint:disable-line:no-any
133133
selector: appRootSelector,
134134
...componentOptions,

packages/schematics/angular/class/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import { normalize } from '@angular-devkit/core';
8+
import { normalize, strings } from '@angular-devkit/core';
99
import {
1010
Rule,
1111
SchematicsException,
@@ -19,7 +19,6 @@ import {
1919
template,
2020
url,
2121
} from '@angular-devkit/schematics';
22-
import * as stringUtils from '../strings';
2322
import { Schema as ClassOptions } from './schema';
2423

2524

@@ -34,7 +33,7 @@ export default function (options: ClassOptions): Rule {
3433
const templateSource = apply(url('./files'), [
3534
options.spec ? noop() : filter(path => !path.endsWith('.spec.ts')),
3635
template({
37-
...stringUtils,
36+
...strings,
3837
...options,
3938
}),
4039
move(sourceDir),

packages/schematics/angular/component/index.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import { normalize } from '@angular-devkit/core';
8+
import { normalize, strings } from '@angular-devkit/core';
99
import {
1010
Rule,
1111
SchematicContext,
@@ -22,7 +22,6 @@ import {
2222
url,
2323
} from '@angular-devkit/schematics';
2424
import * as ts from 'typescript';
25-
import * as stringUtils from '../strings';
2625
import { addDeclarationToModule, addExportToModule } from '../utility/ast-utils';
2726
import { InsertChange } from '../utility/change';
2827
import { buildRelativePath, findModuleFromOptions } from '../utility/find-module';
@@ -44,11 +43,11 @@ function addDeclarationToNgModule(options: ComponentOptions): Rule {
4443
const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);
4544

4645
const componentPath = `/${options.sourceDir}/${options.path}/`
47-
+ (options.flat ? '' : stringUtils.dasherize(options.name) + '/')
48-
+ stringUtils.dasherize(options.name)
46+
+ (options.flat ? '' : strings.dasherize(options.name) + '/')
47+
+ strings.dasherize(options.name)
4948
+ '.component';
5049
const relativePath = buildRelativePath(modulePath, componentPath);
51-
const classifiedName = stringUtils.classify(`${options.name}Component`);
50+
const classifiedName = strings.classify(`${options.name}Component`);
5251
const declarationChanges = addDeclarationToModule(source,
5352
modulePath,
5453
classifiedName,
@@ -73,7 +72,7 @@ function addDeclarationToNgModule(options: ComponentOptions): Rule {
7372

7473
const exportRecorder = host.beginUpdate(modulePath);
7574
const exportChanges = addExportToModule(source, modulePath,
76-
stringUtils.classify(`${options.name}Component`),
75+
strings.classify(`${options.name}Component`),
7776
relativePath);
7877

7978
for (const change of exportChanges) {
@@ -91,7 +90,7 @@ function addDeclarationToNgModule(options: ComponentOptions): Rule {
9190

9291

9392
function buildSelector(options: ComponentOptions) {
94-
let selector = stringUtils.dasherize(options.name);
93+
let selector = strings.dasherize(options.name);
9594
if (options.prefix) {
9695
selector = `${options.prefix}-${selector}`;
9796
}
@@ -116,7 +115,7 @@ export default function(options: ComponentOptions): Rule {
116115
options.inlineStyle ? filter(path => !path.endsWith('.__styleext__')) : noop(),
117116
options.inlineTemplate ? filter(path => !path.endsWith('.html')) : noop(),
118117
template({
119-
...stringUtils,
118+
...strings,
120119
'if-flat': (s: string) => options.flat ? '' : s,
121120
...options,
122121
}),

packages/schematics/angular/directive/index.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import { normalize } from '@angular-devkit/core';
8+
import { normalize, strings } from '@angular-devkit/core';
99
import {
1010
Rule,
1111
SchematicContext,
@@ -22,7 +22,6 @@ import {
2222
url,
2323
} from '@angular-devkit/schematics';
2424
import * as ts from 'typescript';
25-
import * as stringUtils from '../strings';
2625
import { addDeclarationToModule, addExportToModule } from '../utility/ast-utils';
2726
import { InsertChange } from '../utility/change';
2827
import { buildRelativePath, findModuleFromOptions } from '../utility/find-module';
@@ -44,11 +43,11 @@ function addDeclarationToNgModule(options: DirectiveOptions): Rule {
4443
const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);
4544

4645
const directivePath = `/${options.sourceDir}/${options.path}/`
47-
+ (options.flat ? '' : stringUtils.dasherize(options.name) + '/')
48-
+ stringUtils.dasherize(options.name)
46+
+ (options.flat ? '' : strings.dasherize(options.name) + '/')
47+
+ strings.dasherize(options.name)
4948
+ '.directive';
5049
const relativePath = buildRelativePath(modulePath, directivePath);
51-
const classifiedName = stringUtils.classify(`${options.name}Directive`);
50+
const classifiedName = strings.classify(`${options.name}Directive`);
5251
const declarationChanges = addDeclarationToModule(source,
5352
modulePath,
5453
classifiedName,
@@ -72,7 +71,7 @@ function addDeclarationToNgModule(options: DirectiveOptions): Rule {
7271

7372
const exportRecorder = host.beginUpdate(modulePath);
7473
const exportChanges = addExportToModule(source, modulePath,
75-
stringUtils.classify(`${options.name}Directive`),
74+
strings.classify(`${options.name}Directive`),
7675
relativePath);
7776

7877
for (const change of exportChanges) {
@@ -94,7 +93,7 @@ function buildSelector(options: DirectiveOptions) {
9493
selector = `${options.prefix}-${selector}`;
9594
}
9695

97-
return stringUtils.camelize(selector);
96+
return strings.camelize(selector);
9897
}
9998

10099
export default function (options: DirectiveOptions): Rule {
@@ -110,7 +109,7 @@ export default function (options: DirectiveOptions): Rule {
110109
const templateSource = apply(url('./files'), [
111110
options.spec ? noop() : filter(path => !path.endsWith('.spec.ts')),
112111
template({
113-
...stringUtils,
112+
...strings,
114113
'if-flat': (s: string) => options.flat ? '' : s,
115114
...options,
116115
}),

packages/schematics/angular/enum/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import { normalize } from '@angular-devkit/core';
8+
import { normalize, strings } from '@angular-devkit/core';
99
import {
1010
Rule,
1111
SchematicsException,
@@ -17,7 +17,6 @@ import {
1717
template,
1818
url,
1919
} from '@angular-devkit/schematics';
20-
import * as stringUtils from '../strings';
2120
import { Schema as EnumOptions } from './schema';
2221

2322

@@ -30,7 +29,7 @@ export default function (options: EnumOptions): Rule {
3029

3130
const templateSource = apply(url('./files'), [
3231
template({
33-
...stringUtils,
32+
...strings,
3433
...options,
3534
}),
3635
move(sourceDir),

packages/schematics/angular/guard/index.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import { normalize } from '@angular-devkit/core';
8+
import { normalize, strings } from '@angular-devkit/core';
99
import {
1010
Rule,
1111
SchematicContext,
@@ -22,7 +22,6 @@ import {
2222
url,
2323
} from '@angular-devkit/schematics';
2424
import * as ts from 'typescript';
25-
import * as stringUtils from '../strings';
2625
import { addProviderToModule } from '../utility/ast-utils';
2726
import { InsertChange } from '../utility/change';
2827
import { buildRelativePath, findModuleFromOptions } from '../utility/find-module';
@@ -45,12 +44,12 @@ function addDeclarationToNgModule(options: GuardOptions): Rule {
4544
const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);
4645

4746
const guardPath = `/${options.sourceDir}/${options.path}/`
48-
+ (options.flat ? '' : stringUtils.dasherize(options.name) + '/')
49-
+ stringUtils.dasherize(options.name)
47+
+ (options.flat ? '' : strings.dasherize(options.name) + '/')
48+
+ strings.dasherize(options.name)
5049
+ '.guard';
5150
const relativePath = buildRelativePath(modulePath, guardPath);
5251
const changes = addProviderToModule(source, modulePath,
53-
stringUtils.classify(`${options.name}Guard`),
52+
strings.classify(`${options.name}Guard`),
5453
relativePath);
5554
const recorder = host.beginUpdate(modulePath);
5655
for (const change of changes) {
@@ -79,7 +78,7 @@ export default function (options: GuardOptions): Rule {
7978
const templateSource = apply(url('./files'), [
8079
options.spec ? noop() : filter(path => !path.endsWith('.spec.ts')),
8180
template({
82-
...stringUtils,
81+
...strings,
8382
...options,
8483
}),
8584
move(sourceDir),

packages/schematics/angular/interface/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import { normalize } from '@angular-devkit/core';
8+
import { normalize, strings } from '@angular-devkit/core';
99
import {
1010
Rule,
1111
SchematicsException,
@@ -17,7 +17,6 @@ import {
1717
template,
1818
url,
1919
} from '@angular-devkit/schematics';
20-
import * as stringUtils from '../strings';
2120
import { Schema as InterfaceOptions } from './schema';
2221

2322

@@ -32,7 +31,7 @@ export default function (options: InterfaceOptions): Rule {
3231

3332
const templateSource = apply(url('./files'), [
3433
template({
35-
...stringUtils,
34+
...strings,
3635
...options,
3736
}),
3837
move(sourceDir),

packages/schematics/angular/module/index.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import { basename, dirname, normalize, relative } from '@angular-devkit/core';
8+
import { basename, dirname, normalize, relative, strings } from '@angular-devkit/core';
99
import {
1010
Rule,
1111
SchematicContext,
@@ -22,7 +22,6 @@ import {
2222
url,
2323
} from '@angular-devkit/schematics';
2424
import * as ts from 'typescript';
25-
import * as stringUtils from '../strings';
2625
import { addImportToModule } from '../utility/ast-utils';
2726
import { InsertChange } from '../utility/change';
2827
import { findModuleFromOptions } from '../utility/find-module';
@@ -46,15 +45,15 @@ function addDeclarationToNgModule(options: ModuleOptions): Rule {
4645

4746
const importModulePath = normalize(
4847
`/${options.sourceDir}/${options.path}/`
49-
+ (options.flat ? '' : stringUtils.dasherize(options.name) + '/')
50-
+ stringUtils.dasherize(options.name)
48+
+ (options.flat ? '' : strings.dasherize(options.name) + '/')
49+
+ strings.dasherize(options.name)
5150
+ '.module',
5251
);
5352
const relativeDir = relative(dirname(modulePath), dirname(importModulePath));
5453
const relativePath = (relativeDir.startsWith('.') ? relativeDir : './' + relativeDir)
5554
+ '/' + basename(importModulePath);
5655
const changes = addImportToModule(source, modulePath,
57-
stringUtils.classify(`${options.name}Module`),
56+
strings.classify(`${options.name}Module`),
5857
relativePath);
5958

6059
const recorder = host.beginUpdate(modulePath);
@@ -85,7 +84,7 @@ export default function (options: ModuleOptions): Rule {
8584
options.spec ? noop() : filter(path => !path.endsWith('.spec.ts')),
8685
options.routing ? noop() : filter(path => !path.endsWith('-routing.module.ts')),
8786
template({
88-
...stringUtils,
87+
...strings,
8988
'if-flat': (s: string) => options.flat ? '' : s,
9089
...options,
9190
}),

packages/schematics/angular/pipe/index.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import { normalize } from '@angular-devkit/core';
8+
import { normalize, strings } from '@angular-devkit/core';
99
import {
1010
Rule,
1111
SchematicContext,
@@ -22,7 +22,6 @@ import {
2222
url,
2323
} from '@angular-devkit/schematics';
2424
import * as ts from 'typescript';
25-
import * as stringUtils from '../strings';
2625
import { addDeclarationToModule, addExportToModule } from '../utility/ast-utils';
2726
import { InsertChange } from '../utility/change';
2827
import { buildRelativePath, findModuleFromOptions } from '../utility/find-module';
@@ -44,12 +43,12 @@ function addDeclarationToNgModule(options: PipeOptions): Rule {
4443
const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);
4544

4645
const pipePath = `/${options.sourceDir}/${options.path}/`
47-
+ (options.flat ? '' : stringUtils.dasherize(options.name) + '/')
48-
+ stringUtils.dasherize(options.name)
46+
+ (options.flat ? '' : strings.dasherize(options.name) + '/')
47+
+ strings.dasherize(options.name)
4948
+ '.pipe';
5049
const relativePath = buildRelativePath(modulePath, pipePath);
5150
const changes = addDeclarationToModule(source, modulePath,
52-
stringUtils.classify(`${options.name}Pipe`),
51+
strings.classify(`${options.name}Pipe`),
5352
relativePath);
5453
const recorder = host.beginUpdate(modulePath);
5554
for (const change of changes) {
@@ -69,7 +68,7 @@ function addDeclarationToNgModule(options: PipeOptions): Rule {
6968

7069
const exportRecorder = host.beginUpdate(modulePath);
7170
const exportChanges = addExportToModule(source, modulePath,
72-
stringUtils.classify(`${options.name}Pipe`),
71+
strings.classify(`${options.name}Pipe`),
7372
relativePath);
7473

7574
for (const change of exportChanges) {
@@ -97,7 +96,7 @@ export default function (options: PipeOptions): Rule {
9796
const templateSource = apply(url('./files'), [
9897
options.spec ? noop() : filter(path => !path.endsWith('.spec.ts')),
9998
template({
100-
...stringUtils,
99+
...strings,
101100
'if-flat': (s: string) => options.flat ? '' : s,
102101
...options,
103102
}),

0 commit comments

Comments
 (0)