-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: migrate schematics import to dynamic (#1469)
## Proposed change Migrate schematics import to dynamic ## Related issues - 🚀 Feature #1429 <!-- Please make sure to follow the contributing guidelines on https://github.com/amadeus-digital/Otter/blob/main/CONTRIBUTING.md -->
- Loading branch information
Showing
38 changed files
with
1,013 additions
and
880 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
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
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 |
---|---|---|
@@ -1,25 +1,33 @@ | ||
import type { Rule } from '@angular-devkit/schematics'; | ||
import { createSchematicWithMetricsIfInstalled, getPackageInstallConfig, setupDependencies } from '@o3r/schematics'; | ||
import type { NgAddSchematicsSchema } from './schema'; | ||
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/analytics has failed. | ||
If the error is related to missing @o3r dependencies you need to install '@o3r/core'. Please run 'ng add @o3r/core'. | ||
Otherwise, use the error message as guidance.`); | ||
throw reason; | ||
}; | ||
|
||
/** | ||
* Add Otter analytics to an Angular Project | ||
* @param options | ||
*/ | ||
function ngAddFn(options: NgAddSchematicsSchema): Rule { | ||
/* ng add rules */ | ||
return (tree) => { | ||
return async (tree) => { | ||
const { getPackageInstallConfig, setupDependencies } = await import('@o3r/schematics'); | ||
return setupDependencies({ | ||
projectName: options.projectName, | ||
dependencies: getPackageInstallConfig(packageJsonPath, tree, options.projectName, false, !!options.exactO3rVersion) | ||
}); | ||
}; | ||
} | ||
|
||
/** | ||
* Add Otter analytics to an Angular Project | ||
*/ | ||
export const ngAdd = createSchematicWithMetricsIfInstalled(ngAddFn); | ||
|
||
export const ngAdd = (options: NgAddSchematicsSchema): Rule => async (_, {logger}) => { | ||
const { createSchematicWithMetricsIfInstalled } = await import('@o3r/schematics').catch(reportMissingSchematicsDep(logger)); | ||
return createSchematicWithMetricsIfInstalled(ngAddFn)(options); | ||
}; |
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 |
---|---|---|
@@ -1,60 +1,59 @@ | ||
import { chain, noop, Rule, SchematicContext, Tree } from '@angular-devkit/schematics'; | ||
import { createSchematicWithMetricsIfInstalled, getPackageInstallConfig } from '@o3r/schematics'; | ||
import { chain, noop, type Rule } from '@angular-devkit/schematics'; | ||
import * as path from 'node:path'; | ||
import type { NgAddSchematicsSchema } from './schema'; | ||
|
||
const reportMissingSchematicsDep = (logger: { error: (message: string) => any }) => (reason: any) => { | ||
logger.error(`[ERROR]: Adding @o3r/apis-manager 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 apis manager to an Angular Project | ||
* @param options | ||
*/ | ||
function ngAddFn(options: NgAddSchematicsSchema): Rule { | ||
return async (tree: Tree, context: SchematicContext) => { | ||
try { | ||
const { setupDependencies, getO3rPeerDeps, applyEsLintFix, getWorkspaceConfig, getProjectNewDependenciesTypes } = await import('@o3r/schematics'); | ||
const { updateApiDependencies } = await import('../helpers/update-api-deps'); | ||
const packageJsonPath = path.resolve(__dirname, '..', '..', 'package.json'); | ||
const depsInfo = getO3rPeerDeps(packageJsonPath); | ||
const rulesToExecute: Rule[] = []; | ||
const workspaceProject = options.projectName ? getWorkspaceConfig(tree)?.projects[options.projectName] : undefined; | ||
const projectType = workspaceProject?.projectType || 'application'; | ||
if (projectType === 'application') { | ||
rulesToExecute.push(updateApiDependencies(options)); | ||
} | ||
|
||
const dependencies = depsInfo.o3rPeerDeps.reduce((acc, dep) => { | ||
acc[dep] = { | ||
inManifest: [{ | ||
range: `${options.exactO3rVersion ? '' : '~'}${depsInfo.packageVersion}`, | ||
types: getProjectNewDependenciesTypes(workspaceProject) | ||
}], | ||
ngAddOptions: { exactO3rVersion: options.exactO3rVersion } | ||
}; | ||
return acc; | ||
}, getPackageInstallConfig(packageJsonPath, tree, options.projectName, false, !!options.exactO3rVersion)); | ||
|
||
return () => chain([ | ||
...rulesToExecute, | ||
options.skipLinter ? noop : applyEsLintFix(), | ||
setupDependencies({ | ||
projectName: options.projectName, | ||
dependencies, | ||
ngAddToRun: depsInfo.o3rPeerDeps | ||
}) | ||
])(tree, context); | ||
|
||
} catch (e) { | ||
// o3r apis-manager needs o3r/schematics as peer dep. | ||
context.logger.error(`[ERROR]: Adding @o3r/apis-manager 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 (e); | ||
return async (tree) => { | ||
const { getPackageInstallConfig } = await import('@o3r/schematics'); | ||
const { setupDependencies, getO3rPeerDeps, applyEsLintFix, getWorkspaceConfig, getProjectNewDependenciesTypes } = await import('@o3r/schematics'); | ||
const { updateApiDependencies } = await import('../helpers/update-api-deps'); | ||
const packageJsonPath = path.resolve(__dirname, '..', '..', 'package.json'); | ||
const depsInfo = getO3rPeerDeps(packageJsonPath); | ||
const rulesToExecute: Rule[] = []; | ||
const workspaceProject = options.projectName ? getWorkspaceConfig(tree)?.projects[options.projectName] : undefined; | ||
const projectType = workspaceProject?.projectType || 'application'; | ||
if (projectType === 'application') { | ||
rulesToExecute.push(updateApiDependencies(options)); | ||
} | ||
}; | ||
|
||
const dependencies = depsInfo.o3rPeerDeps.reduce((acc, dep) => { | ||
acc[dep] = { | ||
inManifest: [{ | ||
range: `${options.exactO3rVersion ? '' : '~'}${depsInfo.packageVersion}`, | ||
types: getProjectNewDependenciesTypes(workspaceProject) | ||
}], | ||
ngAddOptions: { exactO3rVersion: options.exactO3rVersion } | ||
}; | ||
return acc; | ||
}, getPackageInstallConfig(packageJsonPath, tree, options.projectName, false, !!options.exactO3rVersion)); | ||
|
||
return () => chain([ | ||
...rulesToExecute, | ||
options.skipLinter ? noop : applyEsLintFix(), | ||
setupDependencies({ | ||
projectName: options.projectName, | ||
dependencies, | ||
ngAddToRun: depsInfo.o3rPeerDeps | ||
}) | ||
]); | ||
}; | ||
} | ||
|
||
/** | ||
* Add Otter apis manager to an Angular Project | ||
* @param options | ||
*/ | ||
export const ngAdd = createSchematicWithMetricsIfInstalled(ngAddFn); | ||
export const ngAdd = (options: NgAddSchematicsSchema): Rule => async (_, { logger }) => { | ||
const { createSchematicWithMetricsIfInstalled } = await import('@o3r/schematics').catch(reportMissingSchematicsDep(logger)); | ||
return createSchematicWithMetricsIfInstalled(ngAddFn)(options); | ||
}; |
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
Oops, something went wrong.