Skip to content

Commit 16f35b3

Browse files
committed
Add githubBranch flag to control the branch for GitHub relative links
1 parent 638e34f commit 16f35b3

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

src/main.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,25 +70,27 @@ module.exports = function (argv: string[]): void {
7070
.command('package')
7171
.description('Packages an extension')
7272
.option('-o, --out [path]', 'Output .vsix extension file to [path] location')
73+
.option('--githubBranch [branch]', 'The GitHub branch used to infer relative links in README.md. Can be overriden by --baseContentUrl and --baseImagesUrl.')
7374
.option('--baseContentUrl [url]', 'Prepend all relative links in README.md with this url.')
7475
.option('--baseImagesUrl [url]', 'Prepend all relative image links in README.md with this url.')
7576
.option('--yarn', 'Use yarn instead of npm')
7677
.option('--ignoreFile [path]', 'Indicate alternative .vscodeignore')
7778
.option('--noGitHubIssueLinking', 'Prevent automatic expansion of GitHub-style issue syntax into links')
78-
.action(({ out, baseContentUrl, baseImagesUrl, yarn, ignoreFile, noGitHubIssueLinking }) => main(packageCommand({ packagePath: out, baseContentUrl, baseImagesUrl, useYarn: yarn, ignoreFile, expandGitHubIssueLinks: noGitHubIssueLinking })));
79+
.action(({ out, githubBranch, baseContentUrl, baseImagesUrl, yarn, ignoreFile, noGitHubIssueLinking }) => main(packageCommand({ packagePath: out, githubBranch, baseContentUrl, baseImagesUrl, useYarn: yarn, ignoreFile, expandGitHubIssueLinks: noGitHubIssueLinking })));
7980

8081
program
8182
.command('publish [<version>]')
8283
.description('Publishes an extension')
8384
.option('-p, --pat <token>', 'Personal Access Token', process.env['VSCE_PAT'])
8485
.option('-m, --message <commit message>', 'Commit message used when calling `npm version`.')
8586
.option('--packagePath [path]', 'Publish the VSIX package located at the specified path.')
87+
.option('--githubBranch [branch]', 'The GitHub branch used to infer relative links in README.md. Can be overriden by --baseContentUrl and --baseImagesUrl.')
8688
.option('--baseContentUrl [url]', 'Prepend all relative links in README.md with this url.')
8789
.option('--baseImagesUrl [url]', 'Prepend all relative image links in README.md with this url.')
8890
.option('--yarn', 'Use yarn instead of npm while packing extension files')
8991
.option('--noVerify')
9092
.option('--ignoreFile [path]', 'Indicate alternative .vscodeignore')
91-
.action((version, { pat, message, packagePath, baseContentUrl, baseImagesUrl, yarn, noVerify, ignoreFile }) => main(publish({ pat, commitMessage: message, version, packagePath, baseContentUrl, baseImagesUrl, useYarn: yarn, noVerify, ignoreFile })));
93+
.action((version, { pat, message, packagePath, githubBranch, baseContentUrl, baseImagesUrl, yarn, noVerify, ignoreFile }) => main(publish({ pat, commitMessage: message, version, packagePath, githubBranch, baseContentUrl, baseImagesUrl, useYarn: yarn, noVerify, ignoreFile })));
9294

9395
program
9496
.command('unpublish [<extensionid>]')

src/package.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export interface IAsset {
5959
export interface IPackageOptions {
6060
cwd?: string;
6161
packagePath?: string;
62+
githubBranch?: string;
6263
baseContentUrl?: string;
6364
baseImagesUrl?: string;
6465
useYarn?: boolean;
@@ -365,7 +366,7 @@ export class MarkdownProcessor extends BaseProcessor {
365366
constructor(manifest: Manifest, private name: string, private regexp: RegExp, private assetType: string, options: IPackageOptions = {}) {
366367
super(manifest);
367368

368-
const guess = this.guessBaseUrls();
369+
const guess = this.guessBaseUrls(options.githubBranch);
369370

370371
this.baseContentUrl = options.baseContentUrl || (guess && guess.content);
371372
this.baseImagesUrl = options.baseImagesUrl || options.baseContentUrl || (guess && guess.images);
@@ -492,7 +493,7 @@ export class MarkdownProcessor extends BaseProcessor {
492493
}
493494

494495
// GitHub heuristics
495-
private guessBaseUrls(): { content: string; images: string; repository: string } {
496+
private guessBaseUrls(githubBranch: string | undefined): { content: string; images: string; repository: string } {
496497
let repository = null;
497498

498499
if (typeof this.manifest.repository === 'string') {
@@ -514,10 +515,11 @@ export class MarkdownProcessor extends BaseProcessor {
514515

515516
const account = match[1];
516517
const repositoryName = match[2].replace(/\.git$/i, '');
518+
const branchName = githubBranch ? githubBranch : 'master';
517519

518520
return {
519-
content: `https://github.com/${account}/${repositoryName}/blob/master`,
520-
images: `https://github.com/${account}/${repositoryName}/raw/master`,
521+
content: `https://github.com/${account}/${repositoryName}/blob/${branchName}`,
522+
images: `https://github.com/${account}/${repositoryName}/raw/${branchName}`,
521523
repository: `https://github.com/${account}/${repositoryName}`
522524
};
523525
}

src/publish.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export interface IPublishOptions {
9292
commitMessage?: string;
9393
cwd?: string;
9494
pat?: string;
95+
githubBranch?: string;
9596
baseContentUrl?: string;
9697
baseImagesUrl?: string;
9798
useYarn?: boolean;
@@ -156,14 +157,15 @@ export function publish(options: IPublishOptions = {}): Promise<any> {
156157
.then(manifest => ({ manifest, packagePath: options.packagePath }));
157158
} else {
158159
const cwd = options.cwd;
160+
const githubBranch = options.githubBranch;
159161
const baseContentUrl = options.baseContentUrl;
160162
const baseImagesUrl = options.baseImagesUrl;
161163
const useYarn = options.useYarn;
162164
const ignoreFile = options.ignoreFile;
163165

164166
promise = versionBump(options.cwd, options.version, options.commitMessage)
165167
.then(() => tmpName())
166-
.then(packagePath => pack({ packagePath, cwd, baseContentUrl, baseImagesUrl, useYarn, ignoreFile }));
168+
.then(packagePath => pack({ packagePath, cwd, githubBranch, baseContentUrl, baseImagesUrl, useYarn, ignoreFile }));
167169
}
168170

169171
return promise.then(({ manifest, packagePath }) => {

0 commit comments

Comments
 (0)