-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[cascading] from release/10.3 to release/10.4.0-rc (#1838)
<!-- {"currentBranch":"release/10.3","targetBranch":"release/10.4.0-rc","bypassReviewers":false,"isConflicting":false} --> ## Cascading from release/10.3 to release/10.4.0-rc --- :heavy_exclamation_mark: The pull request is conflicting with the target branch. You can fix the issue locally with the following commands: <details open> <summary>Using <b>gh CLI</b></summary> ```shell gh pr checkout 1838 git pull --ff origin release/10.4.0-rc ``` and update this Pull Request with ```shell gh pr push 1838 ``` </details> <details> <summary>Using <b>git</b> only</summary> ```shell git fetch origin git checkout origin/cascading/10.3.0-10.4.0-rc git pull --ff origin release/10.4.0-rc ``` and update this Pull Request with ```shell git push origin HEAD:cascading/10.3.0-10.4.0-rc ``` </details> --- <small>This Pull Request has been generated with :heart: by the [Otter](https://github.com/AmadeusITGroup/otter) cascading tool.</small>
- Loading branch information
Showing
7 changed files
with
115 additions
and
7 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
74 changes: 74 additions & 0 deletions
74
packages/@ama-sdk/schematics/schematics/ng-update/typescript/v10.3/update-openapiversion.ts
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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import type {Rule} from '@angular-devkit/schematics'; | ||
import * as semver from 'semver'; | ||
import {getWorkspaceConfig, globInTree} from '@o3r/schematics'; | ||
import {chain} from '@angular-devkit/schematics'; | ||
|
||
/** | ||
* Update open api version used in the project to match with the one used in @ama-sdk/schematics:typescript-core | ||
*/ | ||
export const updateOpenApiVersionInProject = (): Rule => { | ||
const overwriteOpenApiVersion = (pathOfWorkspace: string): Rule => { | ||
return (tree, context) => { | ||
const packageJson = tree.readText(`${pathOfWorkspace}/package.json`); | ||
const amaSdkTypescriptUsage = packageJson.match(/@ama-sdk\/schematics:typescript-core.*",?$/mg); | ||
if (!amaSdkTypescriptUsage) { | ||
context.logger.info(`Skipping ng-update for ${pathOfWorkspace} as it does not use @ama-sdk/schematics:typescript-core`); | ||
return tree; | ||
} | ||
const openapitoolsPaths: string[] = []; | ||
amaSdkTypescriptUsage.forEach((script) => { | ||
const openapiToolsPath = new RegExp(/@ama-sdk\/schematics:typescript-core.* --spec-config-path(?:=|\s+)["']?(?:\.\/)?([a-zA-Z-/.0-9_]*\.json)/).exec(script); | ||
if (openapiToolsPath?.length === 2) { | ||
openapitoolsPaths.push(`${pathOfWorkspace}/${openapiToolsPath[1]}`); | ||
} | ||
}); | ||
if (amaSdkTypescriptUsage.length > openapitoolsPaths.length) { | ||
openapitoolsPaths.push(`${pathOfWorkspace}/openapitools.json`); | ||
} | ||
(openapitoolsPaths || []).forEach((path) => { | ||
if (!tree.exists(path)) { | ||
context.logger.warn(`Missing ${path} file described in the package json.`); | ||
return; | ||
} | ||
const openApiToolsConfig = tree.readJson(path) as any; | ||
openApiToolsConfig['generator-cli'] ||= {}; | ||
if (!openApiToolsConfig['generator-cli'].version || !semver.satisfies(openApiToolsConfig['generator-cli'].version, '~7.4.0')) { | ||
context.logger.info(`The following file will be updated to target open api tools version 7.4: ${path}`); | ||
openApiToolsConfig['generator-cli'].version = '7.4.0'; | ||
tree.overwrite(path, JSON.stringify(openApiToolsConfig, null, 2)); | ||
} | ||
} | ||
); | ||
return tree; | ||
}; | ||
}; | ||
|
||
return (tree, context) => { | ||
const pathsPackageJson = ['.']; | ||
if (!tree.exists('package.json')) { | ||
context.logger.error('Could not find a package.json file, make sure to run the ng-update at the root of typescript project'); | ||
} | ||
const cwdPackageJson = tree.readJson('package.json') as any; | ||
if (tree.exists('angular.json')) { | ||
const workspaceConfig = getWorkspaceConfig(tree); | ||
pathsPackageJson.push(...Object.values(workspaceConfig?.projects || {}).map((project) => project.root)); | ||
} else if (cwdPackageJson.workspaces) { | ||
context.logger.info('Workspaces detected outside an angular project, running the update on the workspaces'); | ||
pathsPackageJson.push(...cwdPackageJson.workspaces.reduce((paths: string[], workspace: string) => { | ||
if (workspace.includes('*')) { | ||
paths.push( | ||
...globInTree(tree, [`**/${workspace}/package.json`]).map((path) => path.replace('/package.json', '')) | ||
); | ||
} else { | ||
paths.push(workspace); | ||
} | ||
return paths; | ||
}, [])); | ||
} | ||
return chain( | ||
pathsPackageJson.map((pathPackageJson) => | ||
overwriteOpenApiVersion(pathPackageJson.at(pathPackageJson.length - 1) === '/' ? pathPackageJson.trim() : pathPackageJson) | ||
) | ||
); | ||
}; | ||
}; |
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