diff --git a/packages/@o3r/create/src/index.it.spec.ts b/packages/@o3r/create/src/index.it.spec.ts index 3cb34d2e73..d333ecdd3e 100644 --- a/packages/@o3r/create/src/index.it.spec.ts +++ b/packages/@o3r/create/src/index.it.spec.ts @@ -90,7 +90,7 @@ describe('Create new otter project command', () => { expect(() => packageManagerInstall(execInAppOptions)).not.toThrow(); const appName = 'test-application'; - expect(() => packageManagerExec({ script: 'ng', args: ['g', 'application', appName, '--exact-o3r-version'] }, execInAppOptions)).not.toThrow(); + expect(() => packageManagerExec({ script: 'ng', args: ['g', 'application', appName] }, execInAppOptions)).not.toThrow(); expect(existsSync(path.join(inProjectPath, 'project'))).toBe(false); expect(() => packageManagerRunOnProject(appName, true, { script: 'build' }, execInAppOptions)).not.toThrow(); diff --git a/packages/@o3r/schematics/src/rule-factories/index.ts b/packages/@o3r/schematics/src/rule-factories/index.ts index 3374e66fdc..89473ccd93 100644 --- a/packages/@o3r/schematics/src/rule-factories/index.ts +++ b/packages/@o3r/schematics/src/rule-factories/index.ts @@ -4,6 +4,7 @@ export * from './dev-tools/index'; export * from './eslint-fix/index'; export * from './get-test-frameworks/index'; export * from './ng-add/index'; +export * from './options/index'; export * from './remove-packages/index'; export * from './update-imports/index'; export * from './vscode-extensions/index'; diff --git a/packages/@o3r/schematics/src/rule-factories/options/index.ts b/packages/@o3r/schematics/src/rule-factories/options/index.ts new file mode 100644 index 0000000000..39d1b5d8bb --- /dev/null +++ b/packages/@o3r/schematics/src/rule-factories/options/index.ts @@ -0,0 +1,40 @@ +import type { + Rule, +} from '@angular-devkit/schematics'; +import { + getDefaultOptionsForSchematic, + getWorkspaceConfig, +} from '../../utility'; + +/** + * Factory of the schematic to wrap + * @param options Options of the factory + */ +type SchematicWrapperFn> = (options: S) => Rule; + +/** + * Wrapper method of a schematic to retrieve options from workspace and merge it with the one from the run of the schematic + * @param schematicFn + */ +export function createSchematicWithOptionsFromWorkspace>(schematicFn: SchematicWrapperFn): SchematicWrapperFn { + return (options) => (tree, context) => { + const workspace = getWorkspaceConfig(tree); + const workspaceOptions = getDefaultOptionsForSchematic( + workspace, + context.schematic.description.collection.name, + context.schematic.description.name, + { projectName: undefined, ...options } + ); + const schematicOptionsWithoutUndefined = Object.entries(options).reduce((acc: Record, [key, value]) => { + if (typeof value !== 'undefined') { + acc[key] = value; + } + return acc; + }, {}) as S; + const schematicOptions = { + ...workspaceOptions, + ...schematicOptionsWithoutUndefined + }; + return schematicFn(schematicOptions satisfies S); + }; +} diff --git a/packages/@o3r/schematics/src/utility/collection.spec.ts b/packages/@o3r/schematics/src/utility/collection.spec.ts index 60df40d5d6..e08cfbd320 100644 --- a/packages/@o3r/schematics/src/utility/collection.spec.ts +++ b/packages/@o3r/schematics/src/utility/collection.spec.ts @@ -2,13 +2,14 @@ import type { WorkspaceSchema, } from '../interfaces'; import { - getSchematicOptions, + getDefaultOptionsForSchematic, } from './collection'; const angularJsonGenericNgAdd: WorkspaceSchema = { projects: {}, version: 1, - schematics: { '@o3r/components:component': { path: '' }, + schematics: { + '@o3r/components:component': { path: '' }, '@o3r/services:service': { path: '' }, '@o3r/store:store': { path: '' }, '@o3r/core:schematics': { path: '' }, @@ -20,7 +21,8 @@ const angularJsonGenericNgAdd: WorkspaceSchema = { const angularJsonSpecificNgAdd: WorkspaceSchema = { projects: {}, version: 1, - schematics: { '@o3r/components:component': { path: '' }, + schematics: { + '@o3r/components:component': { path: '' }, '@o3r/services:service': { path: '' }, '@o3r/store:store': { path: '' }, '@o3r/core:schematics': { path: '' }, @@ -33,7 +35,8 @@ const angularJsonSpecificNgAdd: WorkspaceSchema = { const angularJsonNoGeneric: WorkspaceSchema = { projects: {}, version: 1, - schematics: { '@o3r/components:component': { path: '' }, + schematics: { + '@o3r/components:component': { path: '' }, '@o3r/services:service': { path: '' }, '@o3r/store:store': { path: '' }, '@o3r/core:schematics': { path: '' }, @@ -42,32 +45,21 @@ const angularJsonNoGeneric: WorkspaceSchema = { } as any }; -const createFakeContext = (collection: string, name: string): any => ({ - schematic: { - description: { - collection: { - name: collection - }, - name - } - } -}); - describe('Get schematics options', () => { it('should return the ng-add generic options followed by overall generic options', () => { - const options = getSchematicOptions(angularJsonGenericNgAdd, createFakeContext('@o3r/core', 'ng-add')); + const options = getDefaultOptionsForSchematic(angularJsonGenericNgAdd, '@o3r/core', 'ng-add'); expect(Object.keys(options)[0]).toBe('enableMetadataExtract'); expect(Object.keys(options)[1]).toBe('libsDir'); expect(Object.keys(options).length).toBe(3); }); it('should return the generic options when no matches for schematics name', () => { - const options = getSchematicOptions(angularJsonGenericNgAdd, createFakeContext('@o3r/core', 'dummy')); + const options = getDefaultOptionsForSchematic(angularJsonGenericNgAdd, '@o3r/core', 'dummy'); expect(options).toEqual(angularJsonGenericNgAdd.schematics['*:*']); }); it('should return the specific o3r/core ng add, followed by ng-add generic options, followed by overall generic options', () => { - const options = getSchematicOptions(angularJsonSpecificNgAdd, createFakeContext('@o3r/core', 'ng-add')); + const options = getDefaultOptionsForSchematic(angularJsonSpecificNgAdd, '@o3r/core', 'ng-add'); expect(Object.keys(options)[0]).toBe('projectName'); expect(Object.keys(options)[1]).toBe('enableMetadataExtract'); expect(Object.keys(options)[2]).toBe('libsDir'); @@ -78,14 +70,15 @@ describe('Get schematics options', () => { }); it('should return closest matching when no generic options present', () => { - const options = getSchematicOptions(angularJsonNoGeneric, createFakeContext('@o3r/core', 'ng-add')); + const options = getDefaultOptionsForSchematic(angularJsonNoGeneric, '@o3r/core', 'ng-add'); expect(Object.keys(options)[0]).toBe('projectName'); expect(Object.keys(options)[1]).toBe('enableMetadataExtract'); expect(Object.keys(options).length).toBe(2); }); - it('should return undefined when no generic options present and no matching', () => { - const options = getSchematicOptions(angularJsonNoGeneric, createFakeContext('@o3r/core', 'dummy')); - expect(options).toBeUndefined(); + it('should return empty object when no generic options present and no matching', () => { + const options = getDefaultOptionsForSchematic(angularJsonNoGeneric, '@o3r/core', 'dummy'); + expect(options).toBeDefined(); + expect(Object.keys(options).length).toBe(0); }); }); diff --git a/packages/@o3r/workspace/schematics/application/index.ts b/packages/@o3r/workspace/schematics/application/index.ts index daa643b217..f1f94315e6 100644 --- a/packages/@o3r/workspace/schematics/application/index.ts +++ b/packages/@o3r/workspace/schematics/application/index.ts @@ -16,6 +16,7 @@ import { } from '@angular-devkit/schematics'; import { createSchematicWithMetricsIfInstalled, + createSchematicWithOptionsFromWorkspace, type DependencyToAdd, enforceTildeRange, getPackagesBaseRootFolder, @@ -133,4 +134,4 @@ function generateApplicationFn(options: NgGenerateApplicationSchema): Rule { * Add an Otter application to a monorepo * @param options Schematic options */ -export const generateApplication = createSchematicWithMetricsIfInstalled(generateApplicationFn); +export const generateApplication = createSchematicWithOptionsFromWorkspace(createSchematicWithMetricsIfInstalled(generateApplicationFn)); diff --git a/packages/@o3r/workspace/schematics/library/index.ts b/packages/@o3r/workspace/schematics/library/index.ts index 1d8935c9f0..42a8731626 100644 --- a/packages/@o3r/workspace/schematics/library/index.ts +++ b/packages/@o3r/workspace/schematics/library/index.ts @@ -12,6 +12,7 @@ import { import { applyEsLintFix, createSchematicWithMetricsIfInstalled, + createSchematicWithOptionsFromWorkspace, type DependencyToAdd, getPackagesBaseRootFolder, getWorkspaceConfig, @@ -88,4 +89,4 @@ function generateModuleFn(options: NgGenerateModuleSchema): Rule { * Add an Otter compatible module to a monorepo * @param options Schematic options */ -export const generateModule = createSchematicWithMetricsIfInstalled(generateModuleFn); +export const generateModule = createSchematicWithOptionsFromWorkspace(createSchematicWithMetricsIfInstalled(generateModuleFn)); diff --git a/packages/@o3r/workspace/schematics/ng-add/index.ts b/packages/@o3r/workspace/schematics/ng-add/index.ts index 483365676e..d6d5663142 100644 --- a/packages/@o3r/workspace/schematics/ng-add/index.ts +++ b/packages/@o3r/workspace/schematics/ng-add/index.ts @@ -11,6 +11,7 @@ import { } from '@angular-devkit/schematics/tasks'; import { createSchematicWithMetricsIfInstalled, + createSchematicWithOptionsFromWorkspace, getPackageManagerExecutor, getWorkspaceConfig, registerPackageCollectionSchematics, @@ -67,4 +68,4 @@ function ngAddFn(options: NgAddSchematicsSchema): Rule { * Add Otter library to an Angular Project * @param options */ -export const ngAdd = createSchematicWithMetricsIfInstalled(ngAddFn); +export const ngAdd = createSchematicWithOptionsFromWorkspace(createSchematicWithMetricsIfInstalled(ngAddFn)); diff --git a/packages/@o3r/workspace/schematics/sdk/index.ts b/packages/@o3r/workspace/schematics/sdk/index.ts index 973fbbb81a..9b8664d222 100644 --- a/packages/@o3r/workspace/schematics/sdk/index.ts +++ b/packages/@o3r/workspace/schematics/sdk/index.ts @@ -24,6 +24,7 @@ import { } from '@angular-devkit/schematics/tasks'; import { createSchematicWithMetricsIfInstalled, + createSchematicWithOptionsFromWorkspace, getPackageManager, getPackagesBaseRootFolder, getWorkspaceConfig, @@ -131,4 +132,4 @@ function generateSdkFn(options: NgGenerateSdkSchema): Rule { * Add an Otter compatible SDK to a monorepo * @param options Schematic options */ -export const generateSdk = createSchematicWithMetricsIfInstalled(generateSdkFn); +export const generateSdk = createSchematicWithOptionsFromWorkspace(createSchematicWithMetricsIfInstalled(generateSdkFn)); diff --git a/tools/github-actions/new-version/packaged-action/LICENSE.txt b/tools/github-actions/new-version/packaged-action/LICENSE.txt index 7ee631dd7c..4ec329636a 100644 --- a/tools/github-actions/new-version/packaged-action/LICENSE.txt +++ b/tools/github-actions/new-version/packaged-action/LICENSE.txt @@ -94,6 +94,33 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @o3r/new-version +Copyright Amadeus SAS + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this +list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation and/or +other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its contributors +may be used to endorse or promote products derived from this software without +specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + @octokit/auth-token MIT diff --git a/tools/github-actions/release/packaged-action/index.cjs b/tools/github-actions/release/packaged-action/index.cjs old mode 100755 new mode 100644