Add githubBranch flag to control the branch for GitHub relative links
This commit is contained in:
parent
638e34f818
commit
16f35b3485
3 changed files with 13 additions and 7 deletions
|
@ -70,12 +70,13 @@ module.exports = function (argv: string[]): void {
|
|||
.command('package')
|
||||
.description('Packages an extension')
|
||||
.option('-o, --out [path]', 'Output .vsix extension file to [path] location')
|
||||
.option('--githubBranch [branch]', 'The GitHub branch used to infer relative links in README.md. Can be overriden by --baseContentUrl and --baseImagesUrl.')
|
||||
.option('--baseContentUrl [url]', 'Prepend all relative links in README.md with this url.')
|
||||
.option('--baseImagesUrl [url]', 'Prepend all relative image links in README.md with this url.')
|
||||
.option('--yarn', 'Use yarn instead of npm')
|
||||
.option('--ignoreFile [path]', 'Indicate alternative .vscodeignore')
|
||||
.option('--noGitHubIssueLinking', 'Prevent automatic expansion of GitHub-style issue syntax into links')
|
||||
.action(({ out, baseContentUrl, baseImagesUrl, yarn, ignoreFile, noGitHubIssueLinking }) => main(packageCommand({ packagePath: out, baseContentUrl, baseImagesUrl, useYarn: yarn, ignoreFile, expandGitHubIssueLinks: noGitHubIssueLinking })));
|
||||
.action(({ out, githubBranch, baseContentUrl, baseImagesUrl, yarn, ignoreFile, noGitHubIssueLinking }) => main(packageCommand({ packagePath: out, githubBranch, baseContentUrl, baseImagesUrl, useYarn: yarn, ignoreFile, expandGitHubIssueLinks: noGitHubIssueLinking })));
|
||||
|
||||
program
|
||||
.command('publish [<version>]')
|
||||
|
@ -83,12 +84,13 @@ module.exports = function (argv: string[]): void {
|
|||
.option('-p, --pat <token>', 'Personal Access Token', process.env['VSCE_PAT'])
|
||||
.option('-m, --message <commit message>', 'Commit message used when calling `npm version`.')
|
||||
.option('--packagePath [path]', 'Publish the VSIX package located at the specified path.')
|
||||
.option('--githubBranch [branch]', 'The GitHub branch used to infer relative links in README.md. Can be overriden by --baseContentUrl and --baseImagesUrl.')
|
||||
.option('--baseContentUrl [url]', 'Prepend all relative links in README.md with this url.')
|
||||
.option('--baseImagesUrl [url]', 'Prepend all relative image links in README.md with this url.')
|
||||
.option('--yarn', 'Use yarn instead of npm while packing extension files')
|
||||
.option('--noVerify')
|
||||
.option('--ignoreFile [path]', 'Indicate alternative .vscodeignore')
|
||||
.action((version, { pat, message, packagePath, baseContentUrl, baseImagesUrl, yarn, noVerify, ignoreFile }) => main(publish({ pat, commitMessage: message, version, packagePath, baseContentUrl, baseImagesUrl, useYarn: yarn, noVerify, ignoreFile })));
|
||||
.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 })));
|
||||
|
||||
program
|
||||
.command('unpublish [<extensionid>]')
|
||||
|
|
|
@ -59,6 +59,7 @@ export interface IAsset {
|
|||
export interface IPackageOptions {
|
||||
cwd?: string;
|
||||
packagePath?: string;
|
||||
githubBranch?: string;
|
||||
baseContentUrl?: string;
|
||||
baseImagesUrl?: string;
|
||||
useYarn?: boolean;
|
||||
|
@ -365,7 +366,7 @@ export class MarkdownProcessor extends BaseProcessor {
|
|||
constructor(manifest: Manifest, private name: string, private regexp: RegExp, private assetType: string, options: IPackageOptions = {}) {
|
||||
super(manifest);
|
||||
|
||||
const guess = this.guessBaseUrls();
|
||||
const guess = this.guessBaseUrls(options.githubBranch);
|
||||
|
||||
this.baseContentUrl = options.baseContentUrl || (guess && guess.content);
|
||||
this.baseImagesUrl = options.baseImagesUrl || options.baseContentUrl || (guess && guess.images);
|
||||
|
@ -492,7 +493,7 @@ export class MarkdownProcessor extends BaseProcessor {
|
|||
}
|
||||
|
||||
// GitHub heuristics
|
||||
private guessBaseUrls(): { content: string; images: string; repository: string } {
|
||||
private guessBaseUrls(githubBranch: string | undefined): { content: string; images: string; repository: string } {
|
||||
let repository = null;
|
||||
|
||||
if (typeof this.manifest.repository === 'string') {
|
||||
|
@ -514,10 +515,11 @@ export class MarkdownProcessor extends BaseProcessor {
|
|||
|
||||
const account = match[1];
|
||||
const repositoryName = match[2].replace(/\.git$/i, '');
|
||||
const branchName = githubBranch ? githubBranch : 'master';
|
||||
|
||||
return {
|
||||
content: `https://github.com/${account}/${repositoryName}/blob/master`,
|
||||
images: `https://github.com/${account}/${repositoryName}/raw/master`,
|
||||
content: `https://github.com/${account}/${repositoryName}/blob/${branchName}`,
|
||||
images: `https://github.com/${account}/${repositoryName}/raw/${branchName}`,
|
||||
repository: `https://github.com/${account}/${repositoryName}`
|
||||
};
|
||||
}
|
||||
|
|
|
@ -92,6 +92,7 @@ export interface IPublishOptions {
|
|||
commitMessage?: string;
|
||||
cwd?: string;
|
||||
pat?: string;
|
||||
githubBranch?: string;
|
||||
baseContentUrl?: string;
|
||||
baseImagesUrl?: string;
|
||||
useYarn?: boolean;
|
||||
|
@ -156,6 +157,7 @@ export function publish(options: IPublishOptions = {}): Promise<any> {
|
|||
.then(manifest => ({ manifest, packagePath: options.packagePath }));
|
||||
} else {
|
||||
const cwd = options.cwd;
|
||||
const githubBranch = options.githubBranch;
|
||||
const baseContentUrl = options.baseContentUrl;
|
||||
const baseImagesUrl = options.baseImagesUrl;
|
||||
const useYarn = options.useYarn;
|
||||
|
@ -163,7 +165,7 @@ export function publish(options: IPublishOptions = {}): Promise<any> {
|
|||
|
||||
promise = versionBump(options.cwd, options.version, options.commitMessage)
|
||||
.then(() => tmpName())
|
||||
.then(packagePath => pack({ packagePath, cwd, baseContentUrl, baseImagesUrl, useYarn, ignoreFile }));
|
||||
.then(packagePath => pack({ packagePath, cwd, githubBranch, baseContentUrl, baseImagesUrl, useYarn, ignoreFile }));
|
||||
}
|
||||
|
||||
return promise.then(({ manifest, packagePath }) => {
|
||||
|
|
Loading…
Add table
Reference in a new issue