diff --git a/packages/@o3r/design/builders/generate-css/index.ts b/packages/@o3r/design/builders/generate-css/index.ts index 3028236d0c..145e3509e5 100644 --- a/packages/@o3r/design/builders/generate-css/index.ts +++ b/packages/@o3r/design/builders/generate-css/index.ts @@ -16,6 +16,7 @@ import { resolve } from 'node:path'; import { sync } from 'globby'; import { EOL } from 'node:os'; import { readFile, writeFile } from 'node:fs/promises'; +import { existsSync } from 'node:fs'; /** * Generate CSS from Design Token files @@ -23,7 +24,7 @@ import { readFile, writeFile } from 'node:fs/promises'; */ export default createBuilder(async (options, context): Promise => { const templateFilePaths = options.templateFile - && (typeof options.templateFile === 'string' ? [options.templateFile] : options.templateFile).map((templateFile) => resolve(context.workspaceRoot, templateFile)) + && (typeof options.templateFile === 'string' ? [options.templateFile] : options.templateFile) || undefined; const designTokenFilePatterns = Array.isArray(options.designTokenFilePatterns) ? options.designTokenFilePatterns : [options.designTokenFilePatterns]; const determineFileToUpdate = options.output ? () => resolve(context.workspaceRoot, options.output!) : @@ -85,7 +86,17 @@ export default createBuilder(async (options, contex if (templateFilePaths) { const templateFiles = await Promise.all( templateFilePaths - .map(async (templateFile) => JSON.parse(await readFile(templateFile, { encoding: 'utf8' })) as DesignTokenGroupTemplate) + .map(async (templateFile) => { + let templateFilePath = resolve(context.workspaceRoot, templateFile); + if (!existsSync(templateFilePath)) { + try { + templateFilePath = require.resolve(templateFile); + } catch { + context.logger.error(`Cannot resolve the template file at '${templateFile}'`); + } + } + return JSON.parse(await readFile(templateFilePath, { encoding: 'utf8' })) as DesignTokenGroupTemplate; + }) ); template = templateFiles.reduce((acc, cur) => mergeDesignTokenTemplates(acc, cur), {}); } diff --git a/packages/@o3r/design/src/core/design-token/design-token-specification.interface.ts b/packages/@o3r/design/src/core/design-token/design-token-specification.interface.ts index 871de71d19..c76bb01070 100644 --- a/packages/@o3r/design/src/core/design-token/design-token-specification.interface.ts +++ b/packages/@o3r/design/src/core/design-token/design-token-specification.interface.ts @@ -238,7 +238,7 @@ export type DesignTokenGroup = - DesignTokenGroupCommonFields & { [x: string]: DesignTokenGroupTemplate | G | string | boolean | undefined }; + DesignTokenGroupCommonFields & { [x: string]: DesignTokenGroupTemplate | G | string | boolean | undefined }; /** Context of the Design Token specification document */ export type DesignTokenContext = {