Skip to content

Commit

Permalink
Merge pull request #1277 from opencomponents/registries-option-on-pub…
Browse files Browse the repository at this point in the history
…lish

[CLI-FEATURE] add registries options for oc publish
  • Loading branch information
ricardo-devis-agullo authored Nov 16, 2021
2 parents 43d7c46 + 223ffe5 commit 13202cb
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/cli/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ export default {
boolean: true,
description: 'Skip packaging step',
default: false
},
registries: {
array: true,
description:
'List of registries to publish to. This setting will take precedence over oc.json file'
}
},
description: 'Publish a component',
Expand Down
11 changes: 10 additions & 1 deletion src/cli/facade/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const publish =
skipPackage?: boolean;
username?: string;
password?: string;
registries?: string[];
},
callback: (err?: Error | string) => void
): void => {
Expand Down Expand Up @@ -91,6 +92,14 @@ const publish =
});
};

const getRegistries = (
cb: (err: string | null, registryLocations: string[]) => void
): void => {
if (opts.registries) return cb(null, opts.registries);

registry.get(cb);
};

const putComponentToRegistry = (
options: {
route: string;
Expand Down Expand Up @@ -181,7 +190,7 @@ const publish =
);
};

registry.get((err: string | null, registryLocations: string[]) => {
getRegistries((err: string | null, registryLocations: string[]) => {
if (err) {
logger.err(err);
return callback(err);
Expand Down
19 changes: 17 additions & 2 deletions test/unit/cli-facade-publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('cli : facade : publish', () => {

const execute = function (
cb,
{ creds = {}, skipPackage = false, fs = {} } = {}
{ creds = {}, skipPackage = false, fs = {}, registries } = {}
) {
logSpy.err = sinon.stub();
logSpy.log = sinon.stub();
Expand All @@ -47,7 +47,8 @@ describe('cli : facade : publish', () => {
componentPath: 'test/fixtures/components/hello-world/',
username: creds.username,
password: creds.password,
skipPackage
skipPackage,
registries
},
() => {
cb();
Expand Down Expand Up @@ -101,6 +102,20 @@ describe('cli : facade : publish', () => {
});
});

it('should take precedence over the registries set through oc.json', done => {
sinon.stub(registry, 'putComponent').yields(null, 'ok');
execute(
() => {
registry.putComponent.restore();

expect(logSpy.ok.args[0][0]).to.include('http://www.newapi.com');
expect(logSpy.ok.args[1][0]).to.include('http://www.newapi2.com');
done();
},
{ registries: ['http://www.newapi.com', 'http://www.newapi2.com'] }
);
});

describe('when packaging', () => {
describe('when a component is not valid', () => {
beforeEach(done => {
Expand Down

0 comments on commit 13202cb

Please sign in to comment.