Skip to content

Commit 54aa891

Browse files
clydinfilipesilva
authored andcommitted
refactor(@angular-devkit/build-angular): separate extract format normalization
This separates the option normalization for the i18n format to a separate function to reduce the size of the main builder function.
1 parent bbbda81 commit 54aa891

File tree

1 file changed

+29
-20
lines changed
  • packages/angular_devkit/build_angular/src/extract-i18n

1 file changed

+29
-20
lines changed

packages/angular_devkit/build_angular/src/extract-i18n/index.ts

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,32 @@ async function getSerializer(format: Format, sourceLocale: string, basePath: str
6868
}
6969
}
7070

71+
function normalizeFormatOption(options: ExtractI18nBuilderOptions) {
72+
let format;
73+
if (options.i18nFormat !== Format.Xlf) {
74+
format = options.i18nFormat;
75+
} else {
76+
format = options.format;
77+
}
78+
79+
switch (format) {
80+
case Format.Xlf:
81+
case Format.Xlif:
82+
case Format.Xliff:
83+
format = Format.Xlf;
84+
break;
85+
case Format.Xlf2:
86+
case Format.Xliff2:
87+
format = Format.Xlf2;
88+
break;
89+
case undefined:
90+
format = Format.Xlf;
91+
break;
92+
}
93+
94+
return format;
95+
}
96+
7197
class NoEmitPlugin {
7298
apply(compiler: webpack.Compiler): void {
7399
compiler.hooks.shouldEmit.tap('angular-no-emit', () => false);
@@ -90,24 +116,7 @@ export async function execute(
90116
await context.getBuilderNameForTarget(browserTarget),
91117
);
92118

93-
if (options.i18nFormat !== Format.Xlf) {
94-
options.format = options.i18nFormat;
95-
}
96-
97-
switch (options.format) {
98-
case Format.Xlf:
99-
case Format.Xlif:
100-
case Format.Xliff:
101-
options.format = Format.Xlf;
102-
break;
103-
case Format.Xlf2:
104-
case Format.Xliff2:
105-
options.format = Format.Xlf2;
106-
break;
107-
case undefined:
108-
options.format = Format.Xlf;
109-
break;
110-
}
119+
const format = normalizeFormatOption(options);
111120

112121
// We need to determine the outFile name so that AngularCompiler can retrieve it.
113122
let outFile = options.outFile || getI18nOutfile(options.format);
@@ -142,7 +151,7 @@ export async function execute(
142151
},
143152
buildOptimizer: false,
144153
i18nLocale: options.i18nLocale || i18n.sourceLocale,
145-
i18nFormat: options.format,
154+
i18nFormat: format,
146155
i18nFile: outFile,
147156
aot: true,
148157
progress: options.progress,
@@ -245,7 +254,7 @@ export async function execute(
245254

246255
// Serialize all extracted messages
247256
const serializer = await getSerializer(
248-
options.format,
257+
format,
249258
i18n.sourceLocale,
250259
config.context || projectRoot,
251260
useLegacyIds,

0 commit comments

Comments
 (0)