Skip to content

Commit 35e3475

Browse files
Merge branch 'master' into facade-exports
2 parents 7e959aa + 6b92372 commit 35e3475

File tree

13 files changed

+78
-56
lines changed

13 files changed

+78
-56
lines changed

.eslintrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"no-useless-constructor": "error",
6060
"no-useless-return": "error",
6161
"no-warning-comments": "error",
62+
"one-var": ["error", "never"],
6263
"prefer-promise-reject-errors": "error",
6364
"require-await": "error",
6465
"symbol-description": "error"

src/cli/domain/get-components-by-dir.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { Component } from '../../types';
55
export default function getComponentsByDir() {
66
return (componentsDir: string, callback: Callback<string[]>): void => {
77
const isOcComponent = function (file: string) {
8-
const filePath = path.resolve(componentsDir, file),
9-
packagePath = path.join(filePath, 'package.json');
8+
const filePath = path.resolve(componentsDir, file);
9+
const packagePath = path.join(filePath, 'package.json');
1010
let content: Component;
1111

1212
try {

src/cli/domain/package-components.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const packageComponents =
6060
compiler: true,
6161
componentPath
6262
});
63-
ocTemplate.compile!(compileOptions, callback);
63+
ocTemplate.compile(compileOptions, callback);
6464
} catch (err) {
6565
return callback(err as any, undefined as any);
6666
}

src/cli/domain/registry.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import * as urlParser from '../domain/url-parser';
1010
import { RegistryCli } from '../../types';
1111

1212
const getOcVersion = (): string => {
13-
const ocPackagePath = path.join(__dirname, '../../../package.json'),
14-
ocInfo = fs.readJsonSync(ocPackagePath);
13+
const ocPackagePath = path.join(__dirname, '../../../package.json');
14+
const ocInfo = fs.readJsonSync(ocPackagePath);
1515

1616
return ocInfo.version;
1717
};

src/cli/domain/url-parser.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,19 @@ export function parse(parsed: {
2020
requestVersion: string;
2121
href: string;
2222
}): UrlParsed {
23-
const requestedVersion = parsed.requestVersion,
24-
href = url.parse(parsed.href),
25-
relativePath = removeFinalSlashes(href.pathname || ''),
26-
withoutVersion = removeFinalSlashes(
27-
relativePath.replace(requestedVersion, '')
28-
),
29-
componentName = withoutVersion.substr(withoutVersion.lastIndexOf('/') + 1),
30-
withoutComponent = removeFinalSlashes(
31-
withoutVersion.replace(componentName, '')
32-
),
33-
registryUrl = href.protocol + '//' + href.host + withoutComponent + '/';
23+
const requestedVersion = parsed.requestVersion;
24+
const href = url.parse(parsed.href);
25+
const relativePath = removeFinalSlashes(href.pathname || '');
26+
const withoutVersion = removeFinalSlashes(
27+
relativePath.replace(requestedVersion, '')
28+
);
29+
const componentName = withoutVersion.substr(
30+
withoutVersion.lastIndexOf('/') + 1
31+
);
32+
const withoutComponent = removeFinalSlashes(
33+
withoutVersion.replace(componentName, '')
34+
);
35+
const registryUrl = href.protocol + '//' + href.host + withoutComponent + '/';
3436

3537
return {
3638
clientHref: registryUrl + 'oc-client/client.js',

src/cli/facade/package.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ const cliPackage =
1414
},
1515
callback: Callback<Component, string>
1616
): void => {
17-
const componentPath = opts.componentPath,
18-
useComponentDependencies = opts.useComponentDependencies,
19-
packageDir = path.resolve(componentPath, '_package'),
20-
compressedPackagePath = path.resolve(componentPath, 'package.tar.gz');
17+
const componentPath = opts.componentPath;
18+
const useComponentDependencies = opts.useComponentDependencies;
19+
const packageDir = path.resolve(componentPath, '_package');
20+
const compressedPackagePath = path.resolve(componentPath, 'package.tar.gz');
2121

2222
logger.warn(strings.messages.cli.PACKAGING(packageDir));
2323
handleDependencies(

src/cli/facade/publish.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ const publish =
2929
},
3030
callback: (err?: Error | string) => void
3131
): void => {
32-
const componentPath = opts.componentPath,
33-
skipPackage = opts.skipPackage,
34-
packageDir = path.resolve(componentPath, '_package'),
35-
compressedPackagePath = path.resolve(componentPath, 'package.tar.gz');
32+
const componentPath = opts.componentPath;
33+
const skipPackage = opts.skipPackage;
34+
const packageDir = path.resolve(componentPath, '_package');
35+
const compressedPackagePath = path.resolve(componentPath, 'package.tar.gz');
3636

3737
let errorMessage;
3838

@@ -115,9 +115,10 @@ const publish =
115115
});
116116
} else if ((err as any).code === 'cli_version_not_valid') {
117117
const upgradeCommand = strings.commands.cli.UPGRADE(
118-
(err as any).details.suggestedVersion
119-
),
120-
errorDetails = strings.errors.cli.OC_CLI_VERSION_NEEDS_UPGRADE(
118+
(err as any).details.suggestedVersion
119+
);
120+
const errorDetails =
121+
strings.errors.cli.OC_CLI_VERSION_NEEDS_UPGRADE(
121122
colors.blue(upgradeCommand)
122123
);
123124

@@ -156,8 +157,8 @@ const publish =
156157
async.eachSeries(
157158
registryLocations,
158159
(registryUrl, next) => {
159-
const registryNormalised = registryUrl.replace(/\/$/, ''),
160-
componentRoute = `${registryNormalised}/${component.name}/${component.version}`;
160+
const registryNormalised = registryUrl.replace(/\/$/, '');
161+
const componentRoute = `${registryNormalised}/${component.name}/${component.version}`;
161162
putComponentToRegistry(
162163
{ route: componentRoute, path: compressedPackagePath },
163164
next as any

src/cli/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,10 @@ function processCommand(
104104
}
105105

106106
if (command.example) {
107-
yargs.example(command.example.cmd, command.example.description!);
107+
yargs.example(
108+
command.example.cmd,
109+
command.example.description || command.description
110+
);
108111
}
109112

110113
return yargs;

src/registry/domain/validators/uploaded-package.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
type ValidationResponse =
22
| {
33
isValid: true;
4+
files:
5+
| Express.Multer.File[]
6+
| {
7+
[fieldname: string]: Express.Multer.File[];
8+
};
49
}
510
| {
611
isValid: false;
@@ -40,5 +45,5 @@ export default function uploadedPackage(
4045
return returnError('not_valid');
4146
}
4247

43-
return { isValid: true };
48+
return { isValid: true, files: input };
4449
}

src/registry/routes/helpers/apply-default-values.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
import { OcParameter } from '../../../types';
22

3+
interface OptionalParameterWithDefault extends OcParameter {
4+
mandatory: false;
5+
default: Exclude<OcParameter['default'], undefined>;
6+
}
7+
38
export default function applyDefaultValues(
49
requestParameters: Dictionary<string | number | boolean> = {},
510
expectedParameters: Dictionary<OcParameter> = {}
611
): Dictionary<string | number | boolean> {
712
const optionalParametersWithDefaults = Object.entries(
813
expectedParameters
9-
).filter(([, p]) => !p.mandatory && typeof p.default !== 'undefined');
14+
).filter(
15+
(params): params is [string, OptionalParameterWithDefault] =>
16+
!params[1].mandatory && typeof params[1].default !== 'undefined'
17+
);
1018

1119
optionalParametersWithDefaults.forEach(
1220
([expectedParameterName, expectedParameter]) => {
1321
const param = requestParameters[expectedParameterName];
1422
if (param === null || param === undefined) {
15-
requestParameters[expectedParameterName] = expectedParameter.default!;
23+
requestParameters[expectedParameterName] = expectedParameter.default;
1624
}
1725
}
1826
);

0 commit comments

Comments
 (0)