Skip to content

Commit

Permalink
fix(design): avoid failure on non-otter packages
Browse files Browse the repository at this point in the history
  • Loading branch information
kpanot committed Sep 6, 2024
1 parent 9c654c1 commit 10f2521
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions packages/@o3r/design/schematics/ng-add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ import * as path from 'node:path';

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'.`);
throw reason;
};

/**
* Add Otter design to an Angular Project
* @param options
Expand Down Expand Up @@ -50,6 +44,17 @@ export function ngAddFn(options: NgAddSchematicsSchema): Rule {
* @param options
*/
export const ngAdd = (options: NgAddSchematicsSchema): Rule => async (_, { logger }) => {
const { createSchematicWithMetricsIfInstalled } = await import('@o3r/schematics').catch(reportMissingSchematicsDep(logger));
return createSchematicWithMetricsIfInstalled(ngAddFn)(options);
const missingSchematicDependencyMessage = 'Missing @o3r/schematics';
try {
const { createSchematicWithMetricsIfInstalled } = await import('@o3r/schematics').catch(() => { throw new Error(missingSchematicDependencyMessage); });
return createSchematicWithMetricsIfInstalled(ngAddFn)(options);
} catch (err) {
if (err instanceof Error && err.message === missingSchematicDependencyMessage) {
logger.warn(`[WARNING]: The run of the ng-add schematics of @o3r/design has failed, the setup of default features will not be done.
The failure is due to miss of the package '@o3r/schematics'.
To get benefit of the setup scripts, please run 'ng add @o3r/schematics' before.`);
} else {
throw err;
}
}
};

0 comments on commit 10f2521

Please sign in to comment.