Skip to content

Commit

Permalink
Deprecate versionInPackageJson parameter (#2572)
Browse files Browse the repository at this point in the history
Closes SAP/cloud-sdk-backlog#161.

Co-authored-by: Florian Richter <[email protected]>
Co-authored-by: Marika Marszalkowski <[email protected]>
  • Loading branch information
3 people authored Jun 17, 2022
1 parent b0f629d commit 069aa16
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .changeset/angry-llamas-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sap-cloud-sdk/generator': minor
---

[Compatibility Note] Deprecate generator option `versionInPackageJson`. If you need to set the version, use the new `include` option to add your own `package.json` file instead.
5 changes: 5 additions & 0 deletions .changeset/late-buses-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sap-cloud-sdk/generator': minor
---

[Compatibility Note] The hidden generator option `additionalFiles` is renamed to `include`.
5 changes: 5 additions & 0 deletions .changeset/tender-fireants-stare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sap-cloud-sdk/generator': minor
---

[New Functionality] New generator option `include` which allows to add files to generated packages.
27 changes: 22 additions & 5 deletions packages/generator/src/generator-options.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { PathLike } from 'fs';
import { resolve } from 'path';
import { Options } from 'yargs';
import { createLogger } from '@sap-cloud-sdk/util';

const logger = createLogger('generator-options');

/**
* Options that can be used to configure the generation when using the generator programmatically.
Expand All @@ -11,7 +14,7 @@ export interface GeneratorOptions {
serviceMapping?: PathLike;
useSwagger: boolean;
writeReadme: boolean;
additionalFiles?: string;
include?: string;
forceOverwrite: boolean;
clearOutputDir: boolean;
generateNpmrc: boolean;
Expand All @@ -24,6 +27,7 @@ export interface GeneratorOptions {
sdkAfterVersionScript: boolean;
s4hanaCloud: boolean;
generateCSN: boolean;
packageVersion?: string;
}
/**
* @internal
Expand Down Expand Up @@ -83,13 +87,12 @@ export const generatorOptionsCli: KeysToOptions = {
default: false,
hidden: true
},
additionalFiles: {
include: {
describe:
'Glob describing additional files to be added to the each generated service directory - relative to the inputDir.',
type: 'string',
coerce: coercePathArg,
normalize: true,
hidden: true
normalize: true
},
forceOverwrite: {
describe:
Expand Down Expand Up @@ -118,7 +121,15 @@ export const generatorOptionsCli: KeysToOptions = {
versionInPackageJson: {
describe:
'By default, when generating package.json file, the generator will set a version by using the generator version. It can also be set to a specific version.',
type: 'string'
type: 'string',
deprecated:
"Since v2.6.0. Use the 'include' option to add your own package.json file instead.",
coerce: (input: string): string => {
logger.warn(
"The option 'versionInPackageJson' is deprecated since v2.6.0. Use the 'include' option to add your own package.json file instead."
);
return input;
}
},
licenseInPackageJson: {
describe:
Expand Down Expand Up @@ -151,6 +162,12 @@ export const generatorOptionsCli: KeysToOptions = {
default: false,
hidden: true
},
packageVersion: {
describe: 'Version of the generated package.',
type: 'string',
default: '1.0.0',
hidden: true
},
s4hanaCloud: {
describe:
'When set to true, the description of the generated packages will be specific to S/4HANA Cloud.',
Expand Down
4 changes: 2 additions & 2 deletions packages/generator/src/generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('generator', () => {
inputDir: pathTestService,
outputDir: outPutPath,
forceOverwrite: true,
additionalFiles: '../../../*.md'
include: '../../../*.md'
})
);

Expand Down Expand Up @@ -202,7 +202,7 @@ describe('generator', () => {
outputDir: outPutPath,
forceOverwrite: true,
generateJs: true,
additionalFiles: '../../../*.md'
include: '../../../*.md'
})
);

Expand Down
13 changes: 5 additions & 8 deletions packages/generator/src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,24 +191,21 @@ async function generateFilesWithoutTsMorph(
const promises = services.flatMap(service => [
generateEntityApis(service, options),
generateServiceFile(service, options),
generateAdditionalFiles(service, options)
generateIncludes(service, options)
]);
await Promise.all(promises);
}

async function generateAdditionalFiles(
async function generateIncludes(
service: VdmServiceMetadata,
options: GeneratorOptions
): Promise<void> {
if (options.additionalFiles) {
const additionalFilesDir = resolve(
options.inputDir.toString(),
options.additionalFiles
)
if (options.include) {
const includeDir = resolve(options.inputDir.toString(), options.include)
.split(sep)
.join(posix.sep);
const serviceDir = resolvePath(service.directoryName, options);
const files = new GlobSync(additionalFilesDir).found;
const files = new GlobSync(includeDir).found;
await copyFiles(files, serviceDir, options.forceOverwrite);
}
}
Expand Down
2 changes: 1 addition & 1 deletion test-packages/e2e-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ For testing if two versions works together do the following in the e2e folder:

```bash
rm -r node_modules/ && yarn install --ignore-engines //contains state of pm2
rm -r sqlite.db && yarn deploy && yarn stop && yarn start //recreate DB
rm sqlite.db && yarn deploy && yarn stop && yarn start //recreate DB
//execute your tests
```
19 changes: 19 additions & 0 deletions test-packages/e2e-tests/test/generator-cli.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,23 @@ describe('generator-cli', () => {
expect(entities).toContain('TestEntity.ts');
expect(entities).toContain('package.json');
}, 60000);

it('should set version when versionInPackageJson option is used', async () => {
const process = await execa('npx', [
'ts-node',
pathToGenerator,
'-c',
path.resolve(__dirname, 'generator.config.json'),
'--versionInPackageJson=42.23'
]);

const actualPackageJson = JSON.parse(
fs.readFileSync(`${outputDir}/test-service/package.json`).toString()
);
expect(actualPackageJson.version).toEqual('42.23');

expect(process.stdout).toMatch(
/The option 'versionInPackageJson' is deprecated since v2.6.0./
);
}, 60000);
});
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('odata negative tests', () => {
),
'-o',
join(testDir, 'faulty-typescript'),
'--additionalFiles',
'--include',
resolve(
testResourcesDir,
'faulty-typescript',
Expand Down

0 comments on commit 069aa16

Please sign in to comment.