Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ Generate and publish an SDK to a package registry and/or source repository
```
USAGE
$ apimatic sdk publish [-p <value>] [-v <value>] [-d <value>] [-l csharp|java|php|python|ruby|typescript] [-f]
[-i <value>] [--publish-type package|sourcecode...] [--dry-run]
[-i <value>] [--publish-type package|sourcecode...] [--dry-run] [--codegen-version v3|v4] [--stability stable|beta]

FLAGS
-d, --destination=<value> [default: <input>/sdk] path where the sdk will be generated.
Expand All @@ -488,10 +488,14 @@ FLAGS
<options: csharp|java|php|python|ruby|typescript>
-p, --profile-id=<value> Id of the publishing profile to use.
-v, --version=<value> Semantic version of the SDK to publish (e.g. 1.0.0).
--codegen-version=<option> [default: v3] Version of the code generator to use
<options: v3|v4>
--dry-run Generate the SDK locally for review without publishing.
--publish-type=<option>... One or more publishing targets: 'package' for a package registry, 'sourcecode' for a
git repository.
<options: package|sourcecode>
--stability=<option> [default: stable] Stability level of the generated SDK
<options: stable|beta>

DESCRIPTION
Generate and publish an SDK to a package registry and/or source repository
Expand All @@ -508,6 +512,8 @@ EXAMPLES
apimatic sdk publish --profile-id=b2c3d4e5f6a1b2c3d4e5f6a1 --language=java --version=2.0.0 --publish-type=sourcecode

apimatic sdk publish --profile-id=c3d4e5f6a1b2c3d4e5f6a1b2 --language=python --version=1.0.0 --publish-type=package --dry-run

apimatic sdk publish --profile-id=d4e5f6a1b2c3d4e5f6a1b2c3 --language=csharp --version=1.0.0 --publish-type=package --codegen-version=v4 --stability=beta
```

_See code: [src/commands/sdk/publish.ts](https://github.com/apimatic/apimatic-cli/blob/beta/src/commands/sdk/publish.ts)_
Expand Down
12 changes: 7 additions & 5 deletions src/actions/sdk/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { SdkContext } from '../../types/sdk-context.js';
import { SdkGeneratePrompts } from '../../prompts/sdk/generate.js';
import { CommandMetadata } from '../../types/common/command-metadata.js';
import { TempContext } from '../../types/temp-context.js';
import { CodeGenerationVersion, Language, Stability } from '../../types/sdk/generate.js';
import { CodegenOption, Language } from '../../types/sdk/generate.js';
import { MergeSourceTreeAction } from './merge-source-tree.js';
import { BuildContext } from '../../types/build-context.js';
import { SemVersion } from '../../types/publish/version.js';
Expand All @@ -32,12 +32,14 @@ export class GenerateAction {
zipSdk: boolean,
skipChanges: boolean,
trackChanges: boolean,
codeGenVersion: CodeGenerationVersion,
stability: Stability,
codegenOption: CodegenOption,
stabilityWasProvided: boolean,
apiVersion?: string,
packageVersion?: SemVersion,
packageSettingsDirectory?: DirectoryPath
): Promise<ActionResult<{ sourceTreeTrackingInitiated: boolean; conflictsResolved: boolean }>> => {
this.prompts.warnIfStabilityIgnored(codegenOption, stabilityWasProvided);

if (buildDirectory.isEqual(destinationSdkDirectory)) {
this.prompts.sameBuildAndSdkDir(buildDirectory);
return ActionResult.failed();
Expand Down Expand Up @@ -106,14 +108,14 @@ export class GenerateAction {
const tempContext = new TempContext(tempDirectory);
const buildZipPath = await buildContext.getBuildZipPath(tempDirectory, packageSettingsDirectory);

if (codeGenVersion === CodeGenerationVersion.V4) {
if (codegenOption.isV4()) {
this.prompts.sdkCustomizationsNotSupportedForV4();

const response = await this.prompts.generateV4SDK(
this.portalService.generateV4Sdk(
buildZipPath,
language,
stability,
codegenOption.stabilityLevel(),
this.configDir,
this.commandMetadata,
this.authKey
Expand Down
13 changes: 8 additions & 5 deletions src/actions/sdk/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { PublishType } from '../../types/publish-api/publishing-profile-item.js'
import { PublishingInfo } from '../../types/publish-api/publishing-info.js';
import { ProfileId } from '../../types/publish/profile-id.js';
import { SemVersion } from '../../types/publish/version.js';
import { CodeGenerationVersion, Language, Stability } from '../../types/sdk/generate.js';
import { CodegenOption, Language } from '../../types/sdk/generate.js';
import { PublishingProfile } from '../../types/publish/publishing-profile.js';
import { PackageSettingsContext } from '../../types/package-settings-context.js';
import { TempContext } from '../../types/temp-context.js';
Expand All @@ -34,6 +34,9 @@ export class SdkPublishAction {
semVersion: SemVersion,
publishingProfile: PublishingProfile,
dryRun: boolean,
codegenOption: CodegenOption,
stabilityWasProvided: boolean,
publishingSummary: string,
onPublishSdkError: (errorMessage: string) => void
): Promise<ActionResult> => {
const publishResult = await withDirPath(async (tempDirectory): Promise<ActionResult<PublishingInfo>> => {
Expand All @@ -55,8 +58,8 @@ export class SdkPublishAction {
false,
false,
false,
CodeGenerationVersion.V3,
Stability.STABLE,
codegenOption,
stabilityWasProvided,
undefined,
semVersion,
packageSettingsDirectory
Expand All @@ -71,7 +74,7 @@ export class SdkPublishAction {
const sdkLanguageDirectory = outputDirectory.join(language);

if (dryRun) {
this.prompts.dryRunNotice(publishingProfile, language, semVersion, publishType);
this.prompts.dryRunNotice(publishingSummary);
const readmeFilePath = new FilePath(sdkLanguageDirectory, new FileName('README.md'));
await this.launcherService.openDirectoryInEditorOrFileExplorer(sdkLanguageDirectory, readmeFilePath);
return ActionResult.success();
Expand Down Expand Up @@ -114,7 +117,7 @@ export class SdkPublishAction {
}

const publishingInfo = publishResult.getValue();
this.prompts.publishingRunningNotice(publishingProfile, language, semVersion, publishType);
this.prompts.publishingRunningNotice(publishingSummary);
this.prompts.publishingLogsMessage(publishingInfo.publishingLogUrl);

const publishingOutcome = await this.prompts.pollPublishingStatus(() =>
Expand Down
23 changes: 22 additions & 1 deletion src/actions/sdk/publish/interactive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { DirectoryPath } from '../../../types/file/directoryPath.js';
import { PublishType } from '../../../types/publish-api/publishing-profile-item.js';
import { PublishingProfile } from '../../../types/publish/publishing-profile.js';
import { PublishingProfiles } from '../../../types/publish/publishing-profiles.js';
import { getCodegenOptions } from '../../../types/sdk/generate.js';
import { formatPublishingDetails } from '../../../prompts/sdk/publish.js';
import { ActionResult } from '../../action-result.js';
import { SdkPublishAction } from '../publish.js';
import { BuildContext } from '../../../types/build-context.js';
Expand Down Expand Up @@ -78,6 +80,14 @@ export class SdkPublishInteractiveAction {
return ActionResult.cancelled();
}

const codegenOptions = getCodegenOptions(language);
const codegenOption = codegenOptions.length === 1 ? codegenOptions[0]
: await this.prompts.selectCodegenVersion(codegenOptions);
if (!codegenOption) {
this.prompts.noCodegenVersionSelected();
return ActionResult.cancelled();
}

const version = await this.prompts.inputVersion();
if (!version) {
this.prompts.noVersionSpecified();
Expand All @@ -86,7 +96,15 @@ export class SdkPublishInteractiveAction {

const publishTypes = publishingProfile.getPublishTypesForLanguage(language);

this.prompts.publishingSummary(publishingProfile, language, version, publishTypes);
const publishingSummary = formatPublishingDetails({
profile: publishingProfile,
language,
version,
publishType: publishTypes,
codegenOption: codegenOptions.length === 1 ? undefined : codegenOption
});

this.prompts.publishingSummary(publishingSummary);

const confirmed = await this.prompts.confirmPublishing();
if (!confirmed) {
Expand All @@ -109,6 +127,9 @@ export class SdkPublishInteractiveAction {
version,
publishingProfile,
false,
codegenOption,
false,
publishingSummary,
onPublishSdkError
);
if (publishResult.isFailed()) {
Expand Down
15 changes: 14 additions & 1 deletion src/actions/sdk/publish/non-interactive.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { PublishingApiService } from '../../../infrastructure/services/publishing-api-service.js';
import { SdkPublishNonInteractivePrompts } from '../../../prompts/sdk/publish/non-interactive.js';
import { formatPublishingDetails } from '../../../prompts/sdk/publish.js';
import { CommandMetadata } from '../../../types/common/command-metadata.js';
import { DirectoryPath } from '../../../types/file/directoryPath.js';
import { PublishingProfileItem, PublishType } from '../../../types/publish-api/publishing-profile-item.js';
import { PublishingProfile } from '../../../types/publish/publishing-profile.js';
import { Language } from '../../../types/sdk/generate.js';
import { CodegenOption, Language } from '../../../types/sdk/generate.js';
import { ActionResult } from '../../action-result.js';
import { getDownloadsDirectory } from '../../../infrastructure/os-extensions.js';
import { SemVersion } from '../../../types/publish/version.js';
Expand All @@ -27,6 +28,8 @@ export class SdkPublishNonInteractiveAction {
publishTypes: PublishType[],
force: boolean,
dryRun: boolean,
codegenOption: CodegenOption,
stabilityWasProvided: boolean,
onPublishSdkError: (errorMessage: string) => void,
profileId?: string,
version?: string
Expand Down Expand Up @@ -102,6 +105,13 @@ export class SdkPublishNonInteractiveAction {
}

const semVersion = semVersionResult.value;
const publishingSummary = formatPublishingDetails({
profile: publishingProfile,
language,
version: semVersion,
publishType: publishTypes,
codegenOption
});
const outputDir = dryRun ? await this.fileService.getAvailableDirectoryPath(getDownloadsDirectory('apimatic-sdk')) : sdkDirectory;
const publishResult = await new SdkPublishAction(this.configDir, this.commandMetadata).execute(
buildDirectory,
Expand All @@ -113,6 +123,9 @@ export class SdkPublishNonInteractiveAction {
semVersion,
publishingProfile,
dryRun,
codegenOption,
stabilityWasProvided,
publishingSummary,
onPublishSdkError
);
if (publishResult.isFailed()) {
Expand Down
8 changes: 4 additions & 4 deletions src/actions/sdk/quickstart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { ValidateAction } from '../api/validate.js';
import { FileDownloadService } from '../../infrastructure/services/file-download-service.js';
import { FileService } from '../../infrastructure/file-service.js';
import { GenerateAction } from './generate.js';
import { CodeGenerationVersion, Language, mapLanguages, Stability } from '../../types/sdk/generate.js';
import { CodegenOption, Language, mapLanguages } from '../../types/sdk/generate.js';
import { LauncherService } from '../../infrastructure/launcher-service.js';
import { ZipService } from '../../infrastructure/zip-service.js';
import { FileName } from '../../types/file/fileName.js';
Expand Down Expand Up @@ -200,9 +200,9 @@ export class SdkQuickstartAction {
true,
false,
false,
false,
CodeGenerationVersion.V3,
Stability.STABLE);
false,
CodegenOption.v3,
false);
if (result.isFailed()) {
return ActionResult.failed();
}
Expand Down
25 changes: 13 additions & 12 deletions src/commands/sdk/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Command, Flags } from "@oclif/core";
import { DirectoryPath } from "../../types/file/directoryPath.js";
import { FlagsProvider } from "../../types/flags-provider.js";
import { GenerateAction } from "../../actions/sdk/generate.js";
import { CodeGenerationVersion, Language, Stability } from "../../types/sdk/generate.js";
import { CodeGenerationVersion, CodegenOption, Language, Stability } from "../../types/sdk/generate.js";
import { CommandMetadata } from "../../types/common/command-metadata.js";
import { format, intro, outro } from "../../prompts/format.js";
import { SdkChangesTrackedEvent } from "../../types/events/sdk-changes-tracked.js";
Expand Down Expand Up @@ -68,18 +68,19 @@ Supports multiple programming languages including Java, C#, Python, JavaScript,

async run() {
const {
flags: { language,
input,
destination,
force,
zip: zipSdk,
"auth-key": authKey,
"skip-changes": skipChanges,
flags: { language,
input,
destination,
force,
zip: zipSdk,
"auth-key": authKey,
"skip-changes": skipChanges,
"track-changes": trackChanges,
"api-version": apiVersion,
"api-version": apiVersion,
"codegen-version": codegenVersion,
stability
}
},
metadata
} = await this.parse(SdkGenerate);

const workingDirectory = DirectoryPath.createInput(input);
Expand All @@ -102,8 +103,8 @@ Supports multiple programming languages including Java, C#, Python, JavaScript,
zipSdk,
skipChanges,
trackChanges,
codegenVersion as CodeGenerationVersion,
stability as Stability,
CodegenOption.create(codegenVersion as CodeGenerationVersion, stability as Stability),
metadata.flags.stability?.setFromDefault !== true,
apiVersion
);
outro(result);
Expand Down
34 changes: 29 additions & 5 deletions src/commands/sdk/publish.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Command, Flags } from '@oclif/core';
import { DirectoryPath } from '../../types/file/directoryPath.js';
import { FlagsProvider } from '../../types/flags-provider.js';
import { Language } from '../../types/sdk/generate.js';
import { CodeGenerationVersion, CodegenOption, Language, Stability } from '../../types/sdk/generate.js';
import { CommandMetadata } from '../../types/common/command-metadata.js';
import { format, intro, outro } from '../../prompts/format.js';
import { PublishType } from '../../types/publish-api/publishing-profile-item.js';
Expand Down Expand Up @@ -46,6 +46,16 @@ export default class SdkPublish extends Command {
'dry-run': Flags.boolean({
default: false,
description: 'Generate the SDK locally for review without publishing.'
}),
'codegen-version': Flags.string({
description: 'Version of the code generator to use',
options: Object.values(CodeGenerationVersion).map((v) => v.valueOf()),
default: CodeGenerationVersion.V3
}),
'stability': Flags.string({
description: 'Stability level of the generated SDK',
options: Object.values(Stability).map((s) => s.valueOf()),
default: Stability.STABLE
})
};

Expand All @@ -65,7 +75,14 @@ export default class SdkPublish extends Command {
`${SdkPublish.cmdTxt} ${format.flag('profile-id', 'c3d4e5f6a1b2c3d4e5f6a1b2')} ${format.flag('language', 'python')} ${format.flag(
'version',
'1.0.0'
)} ${format.flag('publish-type', PublishType.PackagePublishing)} ${format.flag('dry-run')}`
)} ${format.flag('publish-type', PublishType.PackagePublishing)} ${format.flag('dry-run')}`,
`${SdkPublish.cmdTxt} ${format.flag('profile-id', 'd4e5f6a1b2c3d4e5f6a1b2c3')} ${format.flag(
'language',
'csharp'
)} ${format.flag('version', '1.0.0')} ${format.flag(
'publish-type',
PublishType.PackagePublishing
)} ${format.flag('codegen-version', 'v4')} ${format.flag('stability', 'beta')}`
];

async run() {
Expand All @@ -78,8 +95,11 @@ export default class SdkPublish extends Command {
force,
input,
'publish-type': publishType,
'dry-run': dryRun
}
'dry-run': dryRun,
'codegen-version': codegenVersion,
stability
},
metadata
} = await this.parse(SdkPublish);

const publishTypes = [...new Set(publishType)] as PublishType[];
Expand Down Expand Up @@ -108,7 +128,9 @@ export default class SdkPublish extends Command {
version,
language,
...(force && { force }),
'publish-type': publishTypes
'publish-type': publishTypes,
'codegen-version': codegenVersion,
stability
}),
commandMetadata.shell
);
Expand All @@ -126,6 +148,8 @@ export default class SdkPublish extends Command {
publishTypes,
force,
dryRun,
CodegenOption.create(codegenVersion as CodeGenerationVersion, stability as Stability),
metadata.flags.stability?.setFromDefault !== true,
onPublishSdkError,
profileId,
version,
Expand Down
10 changes: 10 additions & 0 deletions src/prompts/sdk/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,18 @@ import { Result } from "neverthrow";
import { withSpinner } from "../prompt.js";
import { ServiceError } from "../../infrastructure/service-error.js";
import { GeneratedSdkResult } from "../../infrastructure/services/portal-service.js";
import { CodeGenerationVersion, CodegenOption } from "../../types/sdk/generate.js";

export class SdkGeneratePrompts {
public warnIfStabilityIgnored(codegenOption: CodegenOption, stabilityWasProvided: boolean) {
if (stabilityWasProvided && codegenOption.isV3()) {
log.warn(
`${f.flag("stability")} has no effect with ${f.flag("codegen-version", CodeGenerationVersion.V3)}. ` +
`The V3 code generator always produces a stable SDK.`
);
}
}

public async overwriteSdk(directory: DirectoryPath): Promise<boolean> {
const overwrite = await confirm({
message: `The destination ${f.path(directory)} is not empty, do you want to overwrite?`,
Expand Down
Loading
Loading