Skip to content

Commit

Permalink
feat: allow config via package.json for vsce package/publish
Browse files Browse the repository at this point in the history
Closes: #548
  • Loading branch information
joaomoreno committed Nov 5, 2021
1 parent afa459f commit 7182692
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ export interface Manifest {
devDependencies?: { [name: string]: string };
private?: boolean;

// vsce
vsce?: any;

// not supported (npm)
// files?: string[];
// bin
Expand Down
2 changes: 2 additions & 0 deletions src/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1623,6 +1623,8 @@ export async function pack(options: IPackageOptions = {}): Promise<IPackageResul
export async function packageCommand(options: IPackageOptions = {}): Promise<any> {
const cwd = options.cwd || process.cwd();
const manifest = await readManifest(cwd);
util.patchOptionsWithManifest(options, manifest);

await prepublish(cwd, manifest, options.useYarn);
await versionBump(options);

Expand Down
4 changes: 3 additions & 1 deletion src/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ExtensionQueryFlags, PublishedExtension } from 'azure-devops-node-api/i
import { pack, readManifest, versionBump, prepublish } from './package';
import * as tmp from 'tmp';
import { getPublisher } from './store';
import { getGalleryAPI, read, getPublishedUrl, log, getHubUrl } from './util';
import { getGalleryAPI, read, getPublishedUrl, log, getHubUrl, patchOptionsWithManifest } from './util';
import { Manifest } from './manifest';
import { readVSIXPackage } from './zip';

Expand Down Expand Up @@ -54,6 +54,8 @@ export async function publish(options: IPublishOptions = {}): Promise<any> {
} else {
const cwd = options.cwd || process.cwd();
const manifest = await readManifest(cwd);
patchOptionsWithManifest(options, manifest);

await prepublish(cwd, manifest, options.useYarn);
await versionBump(options);

Expand Down
15 changes: 15 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { IGalleryApi, GalleryApi } from 'azure-devops-node-api/GalleryApi';
import chalk from 'chalk';
import { PublicGalleryAPI } from './publicgalleryapi';
import { ISecurityRolesApi } from 'azure-devops-node-api/SecurityRolesApi';
import { Manifest } from './manifest';

const __read = promisify<_read.Options, string>(_read);
export function read(prompt: string, options: _read.Options = {}): Promise<string> {
Expand Down Expand Up @@ -146,3 +147,17 @@ export const log = {
warn: _log.bind(null, LogMessageType.WARNING) as LogFn,
error: _log.bind(null, LogMessageType.ERROR) as LogFn,
};

export function patchOptionsWithManifest(options: any, manifest: Manifest): void {
if (!manifest.vsce) {
return;
}

for (const key of Object.keys(manifest.vsce)) {
const optionsKey = key === 'yarn' ? 'useYarn' : key;

if (options[optionsKey] === undefined) {
options[optionsKey] = manifest.vsce[key];
}
}
}

0 comments on commit 7182692

Please sign in to comment.