Skip to content

Commit 13202cb

Browse files
Merge pull request #1277 from opencomponents/registries-option-on-publish
[CLI-FEATURE] add registries options for oc publish
2 parents 43d7c46 + 223ffe5 commit 13202cb

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

src/cli/commands.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ export default {
133133
boolean: true,
134134
description: 'Skip packaging step',
135135
default: false
136+
},
137+
registries: {
138+
array: true,
139+
description:
140+
'List of registries to publish to. This setting will take precedence over oc.json file'
136141
}
137142
},
138143
description: 'Publish a component',

src/cli/facade/publish.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const publish =
2626
skipPackage?: boolean;
2727
username?: string;
2828
password?: string;
29+
registries?: string[];
2930
},
3031
callback: (err?: Error | string) => void
3132
): void => {
@@ -91,6 +92,14 @@ const publish =
9192
});
9293
};
9394

95+
const getRegistries = (
96+
cb: (err: string | null, registryLocations: string[]) => void
97+
): void => {
98+
if (opts.registries) return cb(null, opts.registries);
99+
100+
registry.get(cb);
101+
};
102+
94103
const putComponentToRegistry = (
95104
options: {
96105
route: string;
@@ -181,7 +190,7 @@ const publish =
181190
);
182191
};
183192

184-
registry.get((err: string | null, registryLocations: string[]) => {
193+
getRegistries((err: string | null, registryLocations: string[]) => {
185194
if (err) {
186195
logger.err(err);
187196
return callback(err);

test/unit/cli-facade-publish.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('cli : facade : publish', () => {
2020

2121
const execute = function (
2222
cb,
23-
{ creds = {}, skipPackage = false, fs = {} } = {}
23+
{ creds = {}, skipPackage = false, fs = {}, registries } = {}
2424
) {
2525
logSpy.err = sinon.stub();
2626
logSpy.log = sinon.stub();
@@ -47,7 +47,8 @@ describe('cli : facade : publish', () => {
4747
componentPath: 'test/fixtures/components/hello-world/',
4848
username: creds.username,
4949
password: creds.password,
50-
skipPackage
50+
skipPackage,
51+
registries
5152
},
5253
() => {
5354
cb();
@@ -101,6 +102,20 @@ describe('cli : facade : publish', () => {
101102
});
102103
});
103104

105+
it('should take precedence over the registries set through oc.json', done => {
106+
sinon.stub(registry, 'putComponent').yields(null, 'ok');
107+
execute(
108+
() => {
109+
registry.putComponent.restore();
110+
111+
expect(logSpy.ok.args[0][0]).to.include('http://www.newapi.com');
112+
expect(logSpy.ok.args[1][0]).to.include('http://www.newapi2.com');
113+
done();
114+
},
115+
{ registries: ['http://www.newapi.com', 'http://www.newapi2.com'] }
116+
);
117+
});
118+
104119
describe('when packaging', () => {
105120
describe('when a component is not valid', () => {
106121
beforeEach(done => {

0 commit comments

Comments
 (0)