Skip to content

Commit f41803b

Browse files
add registries options for oc publish
1 parent 94e70f3 commit f41803b

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
@@ -128,6 +128,11 @@ export default {
128128
boolean: true,
129129
description: 'Skip packaging step',
130130
default: false
131+
},
132+
registries: {
133+
array: true,
134+
description:
135+
'registries to publish, overriding your configuration in oc.json'
131136
}
132137
},
133138
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 => {
@@ -85,6 +86,14 @@ const publish =
8586
});
8687
};
8788

89+
const getRegistries = (
90+
cb: (err: string | null, registryLocations: string[]) => void
91+
): void => {
92+
if (opts.registries) return cb(null, opts.registries);
93+
94+
registry.get(cb);
95+
};
96+
8897
const putComponentToRegistry = (
8998
options: {
9099
route: string;
@@ -175,7 +184,7 @@ const publish =
175184
);
176185
};
177186

178-
registry.get((err: string | null, registryLocations: string[]) => {
187+
getRegistries((err: string | null, registryLocations: string[]) => {
179188
if (err) {
180189
logger.err(err);
181190
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 the registries set through options', 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)