-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(angular): add the extract-i18n executor (#21802)
- Loading branch information
1 parent
b625a79
commit 343c0f6
Showing
12 changed files
with
275 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
docs/generated/packages/angular/executors/extract-i18n.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
{ | ||
"name": "extract-i18n", | ||
"implementation": "/packages/angular/src/executors/extract-i18n/extract-i18n.impl.ts", | ||
"schema": { | ||
"$schema": "http://json-schema.org/draft-07/schema", | ||
"title": "Schema for Nx extract-i18n Executor", | ||
"description": "Extracts i18n messages from source code.", | ||
"outputCapture": "direct-nodejs", | ||
"type": "object", | ||
"properties": { | ||
"buildTarget": { | ||
"type": "string", | ||
"description": "A builder target to extract i18n messages in the format of `project:target[:configuration]`. You can also pass in more than one configuration name as a comma-separated list. Example: `project:target:production,staging`.", | ||
"pattern": "^[^:\\s]+:[^:\\s]+(:[^\\s]+)?$" | ||
}, | ||
"format": { | ||
"type": "string", | ||
"description": "Output format for the generated file.", | ||
"default": "xlf", | ||
"enum": [ | ||
"xmb", | ||
"xlf", | ||
"xlif", | ||
"xliff", | ||
"xlf2", | ||
"xliff2", | ||
"json", | ||
"arb", | ||
"legacy-migrate" | ||
] | ||
}, | ||
"progress": { | ||
"type": "boolean", | ||
"description": "Log progress to the console.", | ||
"default": true | ||
}, | ||
"outputPath": { | ||
"type": "string", | ||
"description": "Path where output will be placed." | ||
}, | ||
"outFile": { | ||
"type": "string", | ||
"description": "Name of the file to output." | ||
} | ||
}, | ||
"additionalProperties": false, | ||
"required": ["buildTarget"], | ||
"presets": [] | ||
}, | ||
"description": "Extracts i18n messages from source code.", | ||
"aliases": [], | ||
"hidden": false, | ||
"path": "/packages/angular/src/executors/extract-i18n/schema.json", | ||
"type": "executor" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
packages/angular/src/executors/extract-i18n/extract-i18n.impl.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import type { ExtractI18nBuilderOptions } from '@angular-devkit/build-angular'; | ||
import { parseTargetString, type ExecutorContext } from '@nx/devkit'; | ||
import { createBuilderContext } from 'nx/src/adapter/ngcli-adapter'; | ||
import { readCachedProjectConfiguration } from 'nx/src/project-graph/project-graph'; | ||
import { getInstalledAngularVersionInfo } from '../utilities/angular-version-utils'; | ||
import { patchBuilderContext } from '../utilities/patch-builder-context'; | ||
import type { ExtractI18nExecutorOptions } from './schema'; | ||
|
||
export default async function* extractI18nExecutor( | ||
options: ExtractI18nExecutorOptions, | ||
context: ExecutorContext | ||
) { | ||
const parsedBuildTarget = parseTargetString(options.buildTarget, context); | ||
const browserTargetProjectConfiguration = readCachedProjectConfiguration( | ||
parsedBuildTarget.project | ||
); | ||
|
||
const buildTarget = | ||
browserTargetProjectConfiguration.targets[parsedBuildTarget.target]; | ||
|
||
const isUsingEsbuildBuilder = [ | ||
'@angular-devkit/build-angular:application', | ||
'@angular-devkit/build-angular:browser-esbuild', | ||
'@nx/angular:application', | ||
'@nx/angular:browser-esbuild', | ||
].includes(buildTarget.executor); | ||
|
||
const builderContext = await createBuilderContext( | ||
{ | ||
builderName: 'extrct-i18n', | ||
description: 'Extracts i18n messages from source code.', | ||
optionSchema: await import('./schema.json'), | ||
}, | ||
context | ||
); | ||
|
||
/** | ||
* The Angular CLI extract-i18n builder make some decisions based on the build | ||
* target builder but it only considers `@angular-devkit/build-angular:*` | ||
* builders. Since we are using a custom builder, we patch the context to | ||
* handle `@nx/angular:*` executors. | ||
*/ | ||
patchBuilderContext(builderContext, isUsingEsbuildBuilder, parsedBuildTarget); | ||
|
||
const { executeExtractI18nBuilder } = await import( | ||
'@angular-devkit/build-angular' | ||
); | ||
const delegateBuilderOptions = getDelegateBuilderOptions(options); | ||
|
||
return await executeExtractI18nBuilder( | ||
delegateBuilderOptions, | ||
builderContext | ||
); | ||
} | ||
|
||
function getDelegateBuilderOptions( | ||
options: ExtractI18nExecutorOptions | ||
): ExtractI18nBuilderOptions { | ||
const delegateBuilderOptions: ExtractI18nBuilderOptions = { ...options }; | ||
|
||
const { major: angularMajorVersion } = getInstalledAngularVersionInfo(); | ||
if (angularMajorVersion <= 17) { | ||
delegateBuilderOptions.browserTarget = delegateBuilderOptions.buildTarget; | ||
delete delegateBuilderOptions.buildTarget; | ||
} | ||
|
||
return delegateBuilderOptions; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import type { ExtractI18nBuilderOptions } from '@angular-devkit/build-angular'; | ||
|
||
export type ExtractI18nExecutorOptions = Omit< | ||
ExtractI18nBuilderOptions, | ||
'browserTarget' | ||
> & { | ||
buildTarget: string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema", | ||
"title": "Schema for Nx extract-i18n Executor", | ||
"description": "Extracts i18n messages from source code.", | ||
"outputCapture": "direct-nodejs", | ||
"type": "object", | ||
"properties": { | ||
"buildTarget": { | ||
"type": "string", | ||
"description": "A builder target to extract i18n messages in the format of `project:target[:configuration]`. You can also pass in more than one configuration name as a comma-separated list. Example: `project:target:production,staging`.", | ||
"pattern": "^[^:\\s]+:[^:\\s]+(:[^\\s]+)?$" | ||
}, | ||
"format": { | ||
"type": "string", | ||
"description": "Output format for the generated file.", | ||
"default": "xlf", | ||
"enum": [ | ||
"xmb", | ||
"xlf", | ||
"xlif", | ||
"xliff", | ||
"xlf2", | ||
"xliff2", | ||
"json", | ||
"arb", | ||
"legacy-migrate" | ||
] | ||
}, | ||
"progress": { | ||
"type": "boolean", | ||
"description": "Log progress to the console.", | ||
"default": true | ||
}, | ||
"outputPath": { | ||
"type": "string", | ||
"description": "Path where output will be placed." | ||
}, | ||
"outFile": { | ||
"type": "string", | ||
"description": "Name of the file to output." | ||
} | ||
}, | ||
"additionalProperties": false, | ||
"required": ["buildTarget"] | ||
} |
Oops, something went wrong.