Skip to content

Commit

Permalink
feat: support --readme-path and --changelog-path (#919)
Browse files Browse the repository at this point in the history
fixes #905
  • Loading branch information
joaomoreno authored Dec 15, 2023
1 parent 302f02c commit 916fd91
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 5 deletions.
12 changes: 12 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ module.exports = function (argv: string[]): void {
.option('-o, --out <path>', 'Output .vsix extension file to <path> location (defaults to <name>-<version>.vsix)')
.option('-t, --target <target>', `Target architecture. Valid targets: ${ValidTargets}`)
.option('--ignore-other-target-folders', `Ignore other target folders. Valid only when --target <target> is provided.`)
.option('--readme-path <path>', 'Path to README file (defaults to README.md)')
.option('--changelog-path <path>', 'Path to CHANGELOG file (defaults to CHANGELOG.md)')
.option('-m, --message <commit message>', 'Commit message used when calling `npm version`.')
.option(
'--no-git-tag-version',
Expand Down Expand Up @@ -122,6 +124,8 @@ module.exports = function (argv: string[]): void {
out,
target,
ignoreOtherTargetFolders,
readmePath,
changelogPath,
message,
gitTagVersion,
updatePackageJson,
Expand All @@ -147,6 +151,8 @@ module.exports = function (argv: string[]): void {
version,
target,
ignoreOtherTargetFolders,
readmePath,
changelogPath,
commitMessage: message,
gitTagVersion,
updatePackageJson,
Expand Down Expand Up @@ -178,6 +184,8 @@ module.exports = function (argv: string[]): void {
)
.option('-t, --target <targets...>', `Target architectures. Valid targets: ${ValidTargets}`)
.option('--ignore-other-target-folders', `Ignore other target folders. Valid only when --target <target> is provided.`)
.option('--readme-path <path>', 'Path to README file (defaults to README.md)')
.option('--changelog-path <path>', 'Path to CHANGELOG file (defaults to CHANGELOG.md)')
.option('-m, --message <commit message>', 'Commit message used when calling `npm version`.')
.option(
'--no-git-tag-version',
Expand Down Expand Up @@ -216,6 +224,8 @@ module.exports = function (argv: string[]): void {
pat,
target,
ignoreOtherTargetFolders,
readmePath,
changelogPath,
message,
gitTagVersion,
updatePackageJson,
Expand Down Expand Up @@ -243,6 +253,8 @@ module.exports = function (argv: string[]): void {
version,
targets: target,
ignoreOtherTargetFolders,
readmePath,
changelogPath,
commitMessage: message,
gitTagVersion,
updatePackageJson,
Expand Down
23 changes: 18 additions & 5 deletions src/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ export interface IPackageOptions {
*/
readonly cwd?: string;

readonly readmePath?: string;
readonly changelogPath?: string;

/**
* GitHub branch used to publish the package. Used to automatically infer
* the base content and images URI.
Expand Down Expand Up @@ -693,7 +696,9 @@ export class TagsProcessor extends BaseProcessor {
}
}

export class MarkdownProcessor extends BaseProcessor {
export abstract class MarkdownProcessor extends BaseProcessor {

private regexp: RegExp;
private baseContentUrl: string | undefined;
private baseImagesUrl: string | undefined;
private rewriteRelativeLinks: boolean;
Expand All @@ -706,14 +711,15 @@ export class MarkdownProcessor extends BaseProcessor {
constructor(
manifest: Manifest,
private name: string,
private regexp: RegExp,
filePath: string,
private assetType: string,
options: IPackageOptions = {}
) {
super(manifest);

const guess = this.guessBaseUrls(options.githubBranch || options.gitlabBranch);
this.regexp = new RegExp(`^extension/${filePath}$`, 'i');

const guess = this.guessBaseUrls(options.githubBranch || options.gitlabBranch);
this.baseContentUrl = options.baseContentUrl || (guess && guess.content);
this.baseImagesUrl = options.baseImagesUrl || options.baseContentUrl || (guess && guess.images);
this.rewriteRelativeLinks = options.rewriteRelativeLinks ?? true;
Expand Down Expand Up @@ -923,15 +929,22 @@ export class MarkdownProcessor extends BaseProcessor {

export class ReadmeProcessor extends MarkdownProcessor {
constructor(manifest: Manifest, options: IPackageOptions = {}) {
super(manifest, 'README.md', /^extension\/readme.md$/i, 'Microsoft.VisualStudio.Services.Content.Details', options);
super(
manifest,
'README.md',
options.readmePath ?? 'readme.md',
'Microsoft.VisualStudio.Services.Content.Details',
options
);
}
}

export class ChangelogProcessor extends MarkdownProcessor {
constructor(manifest: Manifest, options: IPackageOptions = {}) {
super(
manifest,
'CHANGELOG.md',
/^extension\/changelog.md$/i,
options.changelogPath ?? 'changelog.md',
'Microsoft.VisualStudio.Services.Content.Changelog',
options
);
Expand Down
2 changes: 2 additions & 0 deletions src/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export interface IPublishOptions {
* Defaults to `process.cwd()`.
*/
readonly cwd?: string;
readonly readmePath?: string;
readonly changelogPath?: string;
readonly githubBranch?: string;
readonly gitlabBranch?: string;

Expand Down
46 changes: 46 additions & 0 deletions src/test/package.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,29 @@ describe('toVsixManifest', () => {
});
});

it('should handle readmePath', () => {
const manifest = {
name: 'test',
publisher: 'mocha',
version: '0.0.1',
description: 'test extension',
engines: Object.create(null),
};

const files = [{ path: 'extension/foo/readme-foo.md', contents: Buffer.from('') }];

return _toVsixManifest(manifest, files, { readmePath: 'foo/readme-foo.md' })
.then(xml => parseXmlManifest(xml))
.then(result => {
assert.strictEqual(result.PackageManifest.Assets[0].Asset.length, 2);
assert.strictEqual(
result.PackageManifest.Assets[0].Asset[1].$.Type,
'Microsoft.VisualStudio.Services.Content.Details'
);
assert.strictEqual(result.PackageManifest.Assets[0].Asset[1].$.Path, 'extension/foo/readme-foo.md');
});
});

it('should treat CHANGELOG.md as asset', () => {
const manifest = {
name: 'test',
Expand All @@ -696,6 +719,29 @@ describe('toVsixManifest', () => {
});
});

it('should handle changelogPath', () => {
const manifest = {
name: 'test',
publisher: 'mocha',
version: '0.0.1',
description: 'test extension',
engines: Object.create(null),
};

const files = [{ path: 'extension/foo/changelog-foo.md', contents: Buffer.from('') }];

return _toVsixManifest(manifest, files, { changelogPath: 'foo/changelog-foo.md' })
.then(xml => parseXmlManifest(xml))
.then(result => {
assert.strictEqual(result.PackageManifest.Assets[0].Asset.length, 2);
assert.strictEqual(
result.PackageManifest.Assets[0].Asset[1].$.Type,
'Microsoft.VisualStudio.Services.Content.Changelog'
);
assert.strictEqual(result.PackageManifest.Assets[0].Asset[1].$.Path, 'extension/foo/changelog-foo.md');
});
});

it('should respect display name', () => {
const manifest = {
name: 'test',
Expand Down

0 comments on commit 916fd91

Please sign in to comment.