Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cascading] from release/11.1 to release/11.2.0-rc #2172

Open
wants to merge 3 commits into
base: release/11.2.0-rc
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions packages/@o3r/design/builders/generate-css/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { GenerateCssSchematicsSchema } from './schema';
import { BuilderOutput, createBuilder } from '@angular-devkit/architect';
import type { BuilderWrapper } from '@o3r/telemetry';
import {
getCssTokenDefinitionRenderer,
getCssTokenValueRenderer,
Expand All @@ -17,11 +18,20 @@ import { sync } from 'globby';
import { EOL } from 'node:os';
import { readFile, writeFile } from 'node:fs/promises';

const createBuilderWithMetricsIfInstalled: BuilderWrapper = (builderFn) => async (opts, ctx) => {
let wrapper: BuilderWrapper = (fn) => fn;
try {
const { createBuilderWithMetrics } = await import('@o3r/telemetry');
wrapper = createBuilderWithMetrics;
} catch {}
return wrapper(builderFn)(opts, ctx);
};

/**
* Generate CSS from Design Token files
* @param options
*/
export default createBuilder<GenerateCssSchematicsSchema>(async (options, context): Promise<BuilderOutput> => {
export default createBuilder<GenerateCssSchematicsSchema>(createBuilderWithMetricsIfInstalled(async (options, context): Promise<BuilderOutput> => {
const templateFilePaths = options.templateFile
&& (typeof options.templateFile === 'string' ? [options.templateFile] : options.templateFile).map((templateFile) => resolve(context.workspaceRoot, templateFile))
|| undefined;
Expand Down Expand Up @@ -170,4 +180,4 @@ export default createBuilder<GenerateCssSchematicsSchema>(async (options, contex
return { success: false, error: String(err) };
}
}
});
}));
15 changes: 13 additions & 2 deletions packages/@o3r/design/builders/generate-jsonschema/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { GenerateJsonSchemaSchematicsSchema } from './schema';
import { BuilderOutput, createBuilder } from '@angular-devkit/architect';
import type { BuilderWrapper } from '@o3r/telemetry';
import {
getJsonSchemaStyleContentUpdater,
getJsonSchemaTokenDefinitionRenderer,
Expand All @@ -10,11 +11,21 @@ import type { DesignTokenVariableSet, DesignTokenVariableStructure } from '../..
import { resolve } from 'node:path';
import * as globby from 'globby';


const createBuilderWithMetricsIfInstalled: BuilderWrapper = (builderFn) => async (opts, ctx) => {
let wrapper: BuilderWrapper = (fn) => fn;
try {
const { createBuilderWithMetrics } = await import('@o3r/telemetry');
wrapper = createBuilderWithMetrics;
} catch {}
return wrapper(builderFn)(opts, ctx);
};

/**
* Generate Json Schema from Design Token files
* @param options
*/
export default createBuilder<GenerateJsonSchemaSchematicsSchema>(async (options, context): Promise<BuilderOutput> => {
export default createBuilder<GenerateJsonSchemaSchematicsSchema>(createBuilderWithMetricsIfInstalled(async (options, context): Promise<BuilderOutput> => {
const designTokenFilePatterns = Array.isArray(options.designTokenFilePatterns) ? options.designTokenFilePatterns : [options.designTokenFilePatterns];

const execute = async (): Promise<BuilderOutput> => {
Expand Down Expand Up @@ -80,4 +91,4 @@ export default createBuilder<GenerateJsonSchemaSchematicsSchema>(async (options,
return { success: false, error: String(err) };
}
}
});
}));
5 changes: 5 additions & 0 deletions packages/@o3r/design/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"@o3r/core": "workspace:^",
"@o3r/schematics": "workspace:^",
"@o3r/styling": "workspace:^",
"@o3r/telemetry": "workspace:^",
"chokidar": "^3.5.2",
"globby": "^11.1.0",
"sass": "~1.77.0"
Expand All @@ -70,6 +71,9 @@
"@o3r/styling": {
"optional": true
},
"@o3r/telemetry": {
"optional": true
},
"chokidar": {
"optional": true
},
Expand Down Expand Up @@ -106,6 +110,7 @@
"@o3r/eslint-plugin": "workspace:^",
"@o3r/schematics": "workspace:^",
"@o3r/styling": "workspace:^",
"@o3r/telemetry": "workspace:^",
"@o3r/test-helpers": "workspace:^",
"@schematics/angular": "~18.2.0",
"@stylistic/eslint-plugin-ts": "~2.4.0",
Expand Down
22 changes: 20 additions & 2 deletions packages/@o3r/design/schematics/extract-token/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import type { Rule } from '@angular-devkit/schematics';
import type { ExtractTokenSchematicsSchema } from './schema';
import type { createSchematicWithMetricsIfInstalled } from '@o3r/schematics';
import { posix, resolve } from 'node:path';
import { AUTO_GENERATED_END, AUTO_GENERATED_START, DesignToken, DesignTokenGroup, DesignTokenNode } from '../../src/public_api';
import type { ExtractTokenSchematicsSchema } from './schema';

const patternToDetect = 'o3r.var';

/**
* Extract the token from o3r mixin sass file
* @param options
*/
export function extractToken(options: ExtractTokenSchematicsSchema): Rule {
function extractTokenFn(options: ExtractTokenSchematicsSchema): Rule {

const updateFileContent = (content: string): string => {
const start = content.indexOf(patternToDetect);
Expand Down Expand Up @@ -104,3 +105,20 @@ export function extractToken(options: ExtractTokenSchematicsSchema): Rule {
}
};
}

/**
* Extract the token from o3r mixin sass file
* @param options
*/
export const extractToken = (options: ExtractTokenSchematicsSchema) => async () => {
let createSchematicWithMetrics: typeof createSchematicWithMetricsIfInstalled | undefined;
try {
({ createSchematicWithMetricsIfInstalled: createSchematicWithMetrics } = await import('@o3r/schematics'));
} catch {
// No @o3r/schematics detected
}
if (!createSchematicWithMetrics) {
return extractTokenFn(options);
}
return createSchematicWithMetrics(extractTokenFn)(options);
};
23 changes: 21 additions & 2 deletions packages/@o3r/design/schematics/generate-css/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { GenerateCssSchematicsSchema } from './schema';
import type { Rule } from '@angular-devkit/schematics';
import { globInTree } from '@o3r/schematics';
import type { createSchematicWithMetricsIfInstalled } from '@o3r/schematics';
import { parseDesignTokenFile, renderDesignTokens } from '@o3r/design';
import type { DesignTokenRendererOptions, DesignTokenVariableSet, DesignTokenVariableStructure } from '@o3r/design';

/**
* Generate CSS from Design Token files
* @param options
*/
export function generateCss(options: GenerateCssSchematicsSchema): Rule {
function generateCssFn(options: GenerateCssSchematicsSchema): Rule {
return async (tree, context) => {
const writeFile = (filePath: string, content: string) => tree.exists(filePath) ? tree.overwrite(filePath, content) : tree.create(filePath, content);
const readFile = tree.readText;
Expand All @@ -29,6 +29,8 @@ export function generateCss(options: GenerateCssSchematicsSchema): Rule {
logger: context.logger
};

const { globInTree } = await import('@o3r/schematics');

const files = globInTree(tree, Array.isArray(options.designTokenFilePatterns) ? options.designTokenFilePatterns : [options.designTokenFilePatterns]);

const duplicatedToken: DesignTokenVariableStructure[] = [];
Expand All @@ -48,3 +50,20 @@ export function generateCss(options: GenerateCssSchematicsSchema): Rule {
await renderDesignTokens(tokens, renderDesignTokenOptions);
};
}

/**
* Generate CSS from Design Token files
* @param options
*/
export const generateCss = (options: GenerateCssSchematicsSchema) => async () => {
let createSchematicWithMetrics: typeof createSchematicWithMetricsIfInstalled | undefined;
try {
({ createSchematicWithMetricsIfInstalled: createSchematicWithMetrics } = await import('@o3r/schematics'));
} catch {
// No @o3r/schematics detected
}
if (!createSchematicWithMetrics) {
return generateCssFn(options);
}
return createSchematicWithMetrics(generateCssFn)(options);
};
2 changes: 1 addition & 1 deletion packages/@o3r/design/schematics/ng-add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const packageJsonPath = path.resolve(__dirname, '..', '..', 'package.json');

const reportMissingSchematicsDep = (logger: { error: (message: string) => any }) => (reason: any) => {
logger.error(`[ERROR]: Adding @o3r/design has failed.
You need to install '@o3r/schematics' to be able to use the o3r apis-manager package. Please run 'ng add @o3r/schematics'.`);
You need to install '@o3r/schematics' to be able to use the o3r design package. Please run 'ng add @o3r/schematics'.`);
throw reason;
};

Expand Down
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7335,6 +7335,7 @@ __metadata:
"@o3r/eslint-plugin": "workspace:^"
"@o3r/schematics": "workspace:^"
"@o3r/styling": "workspace:^"
"@o3r/telemetry": "workspace:^"
"@o3r/test-helpers": "workspace:^"
"@schematics/angular": "npm:~18.2.0"
"@stylistic/eslint-plugin-ts": "npm:~2.4.0"
Expand Down Expand Up @@ -7375,6 +7376,7 @@ __metadata:
"@o3r/core": "workspace:^"
"@o3r/schematics": "workspace:^"
"@o3r/styling": "workspace:^"
"@o3r/telemetry": "workspace:^"
chokidar: ^3.5.2
globby: ^11.1.0
sass: ~1.77.0
Expand All @@ -7385,6 +7387,8 @@ __metadata:
optional: true
"@o3r/styling":
optional: true
"@o3r/telemetry":
optional: true
chokidar:
optional: true
globby:
Expand Down
Loading