Skip to content

Commit

Permalink
[cascading] from release/9.4.0-rc to main (#992)
Browse files Browse the repository at this point in the history
<!--
{"currentBranch":"release/9.4.0-rc","targetBranch":"main","bypassReviewers":true,"isConflicting":false}
-->

## Cascading from release/9.4.0-rc to main

The configuration requests the cascading to bypass reviewer in case of
CI success.
To not bypass the reviewing process, please check the following
checkbox:

- [ ] <!-- !cancel bypass! --> 🚫 stop reviewing process
bypass for this Pull Request

---

<small>This PR has been generated with ❤️ by the
[Otter](https://github.com/AmadeusITGroup/otter) cascading tool.</small>
  • Loading branch information
matthieu-crouzet authored Nov 2, 2023
2 parents f51438d + 65373da commit e0bd14b
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -498,11 +498,11 @@ public HeaderJsonMimeType() {

@Override
public String formatFragment(String fragment) {
if (fragment == "") {
if (fragment == null || fragment.equals("")) {
return "application/json";
}
String[] mimeTypes = fragment.split(", ");
if (mimeTypes.length < 1 || (mimeTypes.length == 1 && mimeTypes[0] == "")) {
if (mimeTypes.length < 1 || (mimeTypes.length == 1 && mimeTypes[0].equals(""))) {
return "application/json";
}
return HeaderJsonMimeType.getFirstJsonMimeType(mimeTypes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ export function updateApiDependencies(options: {projectName?: string | undefined

insertImportToModuleFile('appendPreconnect', '@o3r/apis-manager', false);

insertBeforeModule('appendPreconnect(\'https://YOUR_API_ENDPOINT\');');
insertBeforeModule('const PROXY_SERVER = \'https://YOUR_API_ENDPOINT\';');

insertBeforeModule('appendPreconnect(PROXY_SERVER);');

addImportToModuleFile('ApiManagerModule', '@o3r/apis-manager');

insertBeforeModule('const PROXY_SERVER = \'https://YOUR_API_ENDPOINT\';');
insertBeforeModule(`
export function apiManagerFactory(): ApiManager {
const apiClient = new ApiFetchClient({
Expand Down
2 changes: 1 addition & 1 deletion packages/@o3r/create/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ const isNgNewOptions = (arg: string) => {
};

const createNgProject = () => {
const { error } = spawnSync(process.execPath, [binPath, 'new', ...args.filter(isNgNewOptions)], {
const { error } = spawnSync(process.execPath, [binPath, 'new', ...args.filter(isNgNewOptions), '--skip-install'], {
stdio: 'inherit'
});

Expand Down
2 changes: 2 additions & 0 deletions packages/@o3r/workspace/schematics/application/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { PackageJson } from 'type-fest';
import { RunSchematicTask } from '@angular-devkit/schematics/tasks';
import { type Schema as ApplicationOptions } from '@schematics/angular/application/schema';
import { Style } from '@schematics/angular/application/schema';
import { updateProjectTsConfig } from '../rule-factories/index';

/**
* Add an Otter application to a monorepo
Expand Down Expand Up @@ -69,6 +70,7 @@ export function generateApplication(options: NgGenerateApplicationSchema): Rule
projectRoot,
style: Style.Scss}),
addProjectSpecificFiles(targetPath, rootDependencies),
updateProjectTsConfig(targetPath, 'tsconfig.app.json'),
(_, c) => {
c.addTask(new RunSchematicTask('@o3r/core:ng-add', extendedOptions));
}
Expand Down
2 changes: 1 addition & 1 deletion packages/@o3r/workspace/schematics/library/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('New module generator', () => {
expect(spy).toHaveBeenNthCalledWith(3, '@o3r/core', 'ng-add-create', expect.anything());
expect(tree.exists('/packages-test/my-new-module/tsconfig.json')).toBe(true);
expect(tree.exists('/packages-test/my-new-module/project.json')).toBe(false);
expect(JSON.parse(tree.readContent('/tsconfig.base.json')).compilerOptions.paths['@my/new-module']).toContain('packages-test/my-new-module/src/public_api');
expect(JSON.parse(tree.readContent('/tsconfig.base.json')).compilerOptions.paths['@my/new-module']).toContain('packages-test/my-new-module/src/public-api');
expect(JSON.parse(tree.readContent('/tsconfig.build.json')).compilerOptions.paths['@my/new-module'][0]).toBe('packages-test/my-new-module/dist');
expect(tree.files.length).toBeGreaterThanOrEqual(9);
});
Expand Down
34 changes: 7 additions & 27 deletions packages/@o3r/workspace/schematics/library/rules/rules.ng.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { PackageJson, TsConfigJson } from 'type-fest';
import type { NgGenerateModuleSchema } from '../schema';
import { findConfigFileRelativePath } from '@o3r/schematics';
import * as ts from 'typescript';
import { apply, chain, externalSchematic, MergeStrategy, mergeWith, move, renameTemplateFiles, Rule, template, url } from '@angular-devkit/schematics';
import * as path from 'node:path';
import { readFileSync } from 'node:fs';
import { updateNgPackagrFactory, updatePackageDependenciesFactory } from './shared';
import { updateProjectTsConfig } from '../../rule-factories/index';

/**
* generate the rules to adapt the library generated by ng cli
Expand Down Expand Up @@ -54,29 +54,6 @@ export function ngGenerateModule(options: NgGenerateModuleSchema & { targetPath:
])(tree, context);
};

/**
* Update the tsconfig generated by the Angular library generator
* @param tree File tree
* @param context Context of the schematics
*/
const updateLibTsconfig: Rule = (tree, context) => {
const tsconfigPath = path.posix.join(options.path || '', options.name, 'tsconfig.lib.json');
if (!tree.exists(tsconfigPath)) {
context.logger.warn(`The file ${tsconfigPath} was not found, the update will not be applied`);
return tree;
}

const tsconfig = ts.parseConfigFileTextToJson(tsconfigPath, tree.readText(tsconfigPath));
if (!tsconfig || !tsconfig.config) {
context.logger.error(`Error parsing ${tsconfigPath}, the update will not be applied`, tsconfig?.error as any);
return tree;
}

tsconfig.config.extends = path.posix.resolve(path.relative(options.path || '.', '.'), 'tsconfig.base.json');
tree.overwrite(tsconfigPath, JSON.stringify(tsconfig, null, 2));
return tree;
};

/**
* Update the root tsconfig files mappings
* @param tree File tree
Expand All @@ -90,7 +67,10 @@ export function ngGenerateModule(options: NgGenerateModuleSchema & { targetPath:
if (configFile?.compilerOptions?.paths) {
configFile.compilerOptions.paths = Object.fromEntries(
Object.entries(configFile.compilerOptions.paths).filter(([pathName, _]) => pathName !== options.name));
configFile.compilerOptions.paths[options.packageJsonName] = [path.posix.join(relativeTargetPath, 'src', 'public_api')];
configFile.compilerOptions.paths[options.packageJsonName] = [
path.posix.join(relativeTargetPath, 'dist'),
path.posix.join(relativeTargetPath, 'src', 'public-api')
];
tree.overwrite(tsconfigBase, JSON.stringify(configFile, null, 2));
} else {
context.logger.warn(`${tsconfigBase} does not contain path mapping, the edition will be skipped`);
Expand All @@ -106,7 +86,7 @@ export function ngGenerateModule(options: NgGenerateModuleSchema & { targetPath:
Object.entries(configFile.compilerOptions.paths).filter(([pathName, _]) => pathName !== options.name));
configFile.compilerOptions.paths[options.packageJsonName] = [
path.posix.join(relativeTargetPath, 'dist'),
path.posix.join(relativeTargetPath, 'src', 'public_api')
path.posix.join(relativeTargetPath, 'src', 'public-api')
];
tree.overwrite(tsconfigBuild, JSON.stringify(configFile, null, 2));
} else {
Expand All @@ -123,7 +103,7 @@ export function ngGenerateModule(options: NgGenerateModuleSchema & { targetPath:
prefix: options.prefix
})(t, c),
updateNgTemplate,
updateLibTsconfig,
updateProjectTsConfig(options.targetPath, 'tsconfig.lib.json', {updateInputFiles: true}),
updateTsConfigFiles
])(tree, context);
};
Expand Down
1 change: 1 addition & 0 deletions packages/@o3r/workspace/schematics/library/rules/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export function updateNgPackagrFactory(targetPath: string): Rule {
return (tree) => {
const ngPackagr = tree.readJson(path.posix.join(targetPath, 'ng-package.json')) as any;
ngPackagr.$schema = 'https://raw.githubusercontent.com/ng-packagr/ng-packagr/master/src/ng-package.schema.json';
ngPackagr.dest = './dist';
tree.overwrite(path.posix.join(targetPath, 'ng-package.json'), JSON.stringify(ngPackagr, null, 2));
return tree;
};
Expand Down
1 change: 1 addition & 0 deletions packages/@o3r/workspace/schematics/rule-factories/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './project-configs';
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import * as path from 'node:path';
import * as ts from 'typescript';
import { findConfigFileRelativePath } from '@o3r/schematics';
import type { Rule } from '@angular-devkit/schematics';

/**
* Update the tsconfig generated by the Angular generators
* * extends the base tsconfig
* * force the outDir to ./dist
* * update input compiler files if needed
* @param targetPath
* @param tsconfigName
* @param options
*/
export function updateProjectTsConfig(targetPath: string, tsconfigName: string, options = {updateInputFiles: false}): Rule {
return (tree, context) => {
const tsconfigPath = path.posix.join(targetPath, tsconfigName);
if (!tree.exists(tsconfigPath)) {
context.logger.warn(`The file ${tsconfigPath} was not found, the update will not be applied`);
return tree;
}

const tsconfig = ts.parseConfigFileTextToJson(tsconfigPath, tree.readText(tsconfigPath));
if (!tsconfig || !tsconfig.config) {
context.logger.error(`Error parsing ${tsconfigPath}, the update will not be applied`, tsconfig?.error as any);
return tree;
}

if (options?.updateInputFiles) {
tsconfig.config = Object.fromEntries(Object.entries(tsconfig.config).filter(([propName, _]) => propName !== 'files'));
tsconfig.config.include = ['./src/**/*.ts'];
}
const baseTsConfig = findConfigFileRelativePath(tree, ['tsconfig.base.json', 'tsconfig.json'], targetPath);
if (baseTsConfig) {
tsconfig.config.extends = baseTsConfig;
}

tsconfig.config.compilerOptions ||= {};
tsconfig.config.compilerOptions.outDir = './dist';
tree.overwrite(tsconfigPath, JSON.stringify(tsconfig.config, null, 2));
return tree;
};
}

Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ export function updateTsConfig(targetPath: string, projectName: string, scope: s
configWithPath.content.compilerOptions ||= {};
configWithPath.content.compilerOptions.paths ||= {};
configWithPath.content.compilerOptions.paths[`${scope ? `@${scope}/` : ''}${projectName}`] = [
`${relativeTargetPath}/dist`,
`${relativeTargetPath}/src/index`
];
configWithPath.content.compilerOptions.paths[`${scope ? `@${scope}/` : ''}${projectName}/*`] = [
`${relativeTargetPath}/dist/*`,
`${relativeTargetPath}/src/*`
];

Expand Down

0 comments on commit e0bd14b

Please sign in to comment.