Skip to content

Commit

Permalink
Add support for --repo option
Browse files Browse the repository at this point in the history
This overrides the `repo` option in the config files and the automatic detection from the `repository` field in the `package.json` file. This allows lerna-changelog to be used outside of lerna and Node.js projects.
  • Loading branch information
Turbo87 committed Aug 7, 2021
1 parent 3c330cf commit 14d7ec1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ export async function run() {
desc: "Infer the name of the next version from package metadata",
default: false,
},
repo: {
type: "string",
desc: "`<USER|ORG>/<PROJECT>` of the GitHub project",
defaultDescription: "inferred from the `package.json` file",
},
})
.example(
"lerna-changelog",
Expand All @@ -64,6 +69,7 @@ export async function run() {
try {
let config = loadConfig({
nextVersionFromMetadata: argv["next-version-from-metadata"],
repo: argv.repo,
});

if (argv["next-version"] !== NEXT_VERSION_DEFAULT) {
Expand Down
6 changes: 6 additions & 0 deletions src/configuration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ describe("Configuration", function() {
it("throws ConfigurationError if neither 'package.json' nor 'lerna.json' exist", function() {
expect(() => fromPath(tmpDir)).toThrowError(ConfigurationError);
});

it("uses passed in `repo` option", function() {
const result = fromPath(tmpDir, { repo: "foo/bar" });
expect(result.nextVersion).toEqual(undefined);
expect(result.repo).toEqual("foo/bar");
});
});

describe("findRepoFromPkg", function() {
Expand Down
5 changes: 5 additions & 0 deletions src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface Configuration {
}

export interface ConfigLoaderOptions {
repo?: string;
nextVersionFromMetadata?: boolean;
}

Expand All @@ -29,6 +30,10 @@ export function fromPath(rootPath: string, options: ConfigLoaderOptions = {}): C
// Step 1: load partial config from `package.json` or `lerna.json`
let config = fromPackageConfig(rootPath) || fromLernaConfig(rootPath) || {};

if (options.repo) {
config.repo = options.repo;
}

// Step 2: fill partial config with defaults
let { repo, nextVersion, labels, cacheDir, ignoreCommitters } = config;

Expand Down

0 comments on commit 14d7ec1

Please sign in to comment.