diff --git a/packages/@o3r/localization/builders/helpers/localization.generator.ts b/packages/@o3r/localization/builders/helpers/localization.generator.ts index 821b73d18d..e30aa7cbc0 100644 --- a/packages/@o3r/localization/builders/helpers/localization.generator.ts +++ b/packages/@o3r/localization/builders/helpers/localization.generator.ts @@ -6,6 +6,7 @@ import * as fs from 'node:fs'; import * as glob from 'globby'; import * as path from 'node:path'; import * as ts from 'typescript'; +import type { LocalizationExtractorBuilderSchema } from '../localization-extractor/schema'; /** List of Angular decorator to look for */ const ANGULAR_ANNOTATION = ['Component', 'Injectable', 'Pipe']; @@ -59,7 +60,7 @@ export class LocalizationExtractor { private logger: logging.LoggerApi; - constructor(tsconfigPath: string, logger: logging.LoggerApi) { + constructor(tsconfigPath: string, logger: logging.LoggerApi, private options?: Partial) { this.tsconfigPath = tsconfigPath; this.logger = logger; } @@ -121,6 +122,7 @@ export class LocalizationExtractor { } return res; }) + .filter(({ref}) => (this.options?.libraries || []).every((lib) => !ref.startsWith(lib))) .map(({ref}) => { if (!ref.startsWith('.')) { try { diff --git a/packages/@o3r/localization/builders/localization-extractor/index.ts b/packages/@o3r/localization/builders/localization-extractor/index.ts index b8c681fd39..a483e942ba 100644 --- a/packages/@o3r/localization/builders/localization-extractor/index.ts +++ b/packages/@o3r/localization/builders/localization-extractor/index.ts @@ -13,7 +13,7 @@ export * from './schema'; export default createBuilder(async (options, context): Promise => { context.reportRunning(); - const localizationExtractor = new LocalizationExtractor(path.resolve(context.workspaceRoot, options.tsConfig), context.logger); + const localizationExtractor = new LocalizationExtractor(path.resolve(context.workspaceRoot, options.tsConfig), context.logger, options); const cache: { libs: LibraryMetadataMap; locs: LocalizationFileMap } = {libs: {}, locs: {}}; const execute = async (isFirstLoad = true, files?: { libs?: string[]; locs?: string[]; extraFiles?: string[] }): Promise => { @@ -28,7 +28,7 @@ export default createBuilder(async (options, cache.locs = await localizationExtractor.extractLocalizationFromTsConfig(files && files.extraFiles); context.reportProgress(STEP_NUMBER, stepValue++, 'Load metadata'); - cache.libs = files && files.libs ? await localizationExtractor.getMetadataFromLibraries(files.libs) : {}; + cache.libs = options.isApplication && files && files.libs ? await localizationExtractor.getMetadataFromLibraries(files.libs) : {}; // Load specific files that have changed } else { @@ -46,7 +46,7 @@ export default createBuilder(async (options, ...newLocs }; } - if (files && files.libs) { + if (options.isApplication && files && files.libs) { context.reportProgress(STEP_NUMBER, stepValue++, 'reload library metadata'); const newLibs = await localizationExtractor.getMetadataFromFiles(files.libs); cache.libs = { @@ -139,7 +139,6 @@ export default createBuilder(async (options, await currentProcess; - /** SCSS file watcher */ const watcher = chokidar.watch([...Object.keys(cache.locs), ...(options.extraFilePatterns || [])], {ignoreInitial: true}); const metadataWatcher = chokidar.watch(Object.keys(cache.libs), {ignoreInitial: true}); const { include, exclude, cwd } = localizationExtractor.getPatternsFromTsConfig(); diff --git a/packages/@o3r/localization/builders/localization-extractor/schema.json b/packages/@o3r/localization/builders/localization-extractor/schema.json index 0d351a048b..b6bd91c636 100644 --- a/packages/@o3r/localization/builders/localization-extractor/schema.json +++ b/packages/@o3r/localization/builders/localization-extractor/schema.json @@ -50,6 +50,11 @@ "type": "boolean", "description": "Sort metadata alphabetically by keys", "default": false + }, + "isApplication": { + "type": "boolean", + "default": true, + "description": "If true, metadata from libraries are added" } }, "additionalProperties": false, diff --git a/packages/@o3r/localization/builders/localization-extractor/schema.ts b/packages/@o3r/localization/builders/localization-extractor/schema.ts index ab613bf083..d54c761afd 100644 --- a/packages/@o3r/localization/builders/localization-extractor/schema.ts +++ b/packages/@o3r/localization/builders/localization-extractor/schema.ts @@ -25,4 +25,7 @@ export interface LocalizationExtractorBuilderSchema extends JsonObject { /** If true, metadata objects are sorted by keys */ sortKeys: boolean; + + /** If true, metadata from libraries are added */ + isApplication: boolean; }