Skip to content

Commit

Permalink
feat: support pricing model in the manifest file (#749)
Browse files Browse the repository at this point in the history
* feat: support pricing model in the manifest file

* feat: make pricing value case insensitive

* Revert "feat: make pricing value case insensitive"

This reverts commit 29d1fb4.
  • Loading branch information
prashantvc authored Oct 21, 2022
1 parent 2589114 commit 1dcedef
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export interface Manifest {
dependencies?: { [name: string]: string };
devDependencies?: { [name: string]: string };
private?: boolean;
pricing?: string;

// vsce
vsce?: any;
Expand Down
8 changes: 8 additions & 0 deletions src/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ export interface VSIX {
localizedLanguages: string;
preRelease: boolean;
sponsorLink: string;
pricing: string;
}

export class BaseProcessor implements IProcessor {
Expand Down Expand Up @@ -475,6 +476,7 @@ export class ManifestProcessor extends BaseProcessor {
target,
engine: manifest.engines['vscode'],
description: manifest.description ?? '',
pricing: manifest.pricing ?? 'Free',
categories: (manifest.categories ?? []).join(','),
flags: flags.join(' '),
links: {
Expand Down Expand Up @@ -1191,6 +1193,10 @@ export function validateManifest(manifest: Manifest): Manifest {
throw new Error('Manifest missing field: version');
}

if (manifest.pricing && !['Free', 'Trial'].includes(manifest.pricing)) {
throw new Error('Pricing should be Free or Trial');
}

validateVersion(manifest.version);

if (!manifest.engines) {
Expand Down Expand Up @@ -1404,6 +1410,8 @@ export async function toVsixManifest(vsix: VSIX): Promise<string> {
: ''
}
<Property Id="Microsoft.VisualStudio.Services.GitHubFlavoredMarkdown" Value="${escape(vsix.githubMarkdown)}" />
<Property Id="Microsoft.VisualStudio.Services.Content.Pricing" Value="${escape(vsix.pricing)}"/>
${
vsix.enableMarketplaceQnA !== undefined
? `<Property Id="Microsoft.VisualStudio.Services.EnableMarketplaceQnA" Value="${escape(
Expand Down
14 changes: 14 additions & 0 deletions src/test/package.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,13 @@ describe('validateManifest', () => {
validateManifest(createManifest({ sponsor: { url: 'https://foo.bar' } }));
validateManifest(createManifest({ sponsor: { url: 'http://www.foo.com' } }));
});

it('should validate pricing', () => {
assert.throws(() => validateManifest(createManifest({ pricing: 'Paid' })));
validateManifest(createManifest({ pricing: 'Trial' }));
validateManifest(createManifest({ pricing: 'Free' }));
validateManifest(createManifest());
});
});

describe('toVsixManifest', () => {
Expand Down Expand Up @@ -1724,6 +1731,13 @@ describe('toVsixManifest', () => {

throw new Error('Should not reach here');
});

it('should identify trial version of an extension', async () => {
const manifest = createManifest({ pricing: 'Trial' });
var raw = await _toVsixManifest(manifest, []);
const xmlManifest = await parseXmlManifest(raw);
assertProperty(xmlManifest, 'Microsoft.VisualStudio.Services.Content.Pricing', 'Trial');
});
});

describe('qna', () => {
Expand Down

0 comments on commit 1dcedef

Please sign in to comment.