oc 0.49.6 → 0.49.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -0
- package/README.md +2 -15
- package/dist/cli/commands.d.ts +163 -163
- package/dist/cli/commands.js +162 -162
- package/dist/cli/domain/clean.d.ts +2 -2
- package/dist/cli/domain/clean.js +24 -27
- package/dist/cli/domain/get-components-by-dir.d.ts +1 -1
- package/dist/cli/domain/get-components-by-dir.js +41 -48
- package/dist/cli/domain/get-mocked-plugins.d.ts +10 -10
- package/dist/cli/domain/get-mocked-plugins.js +89 -87
- package/dist/cli/domain/handle-dependencies/ensure-compiler-is-declared-as-devDependency.d.ts +6 -6
- package/dist/cli/domain/handle-dependencies/ensure-compiler-is-declared-as-devDependency.js +16 -17
- package/dist/cli/domain/handle-dependencies/get-compiler.d.ts +10 -10
- package/dist/cli/domain/handle-dependencies/get-compiler.js +28 -28
- package/dist/cli/domain/handle-dependencies/get-missing-dependencies.d.ts +1 -1
- package/dist/cli/domain/handle-dependencies/get-missing-dependencies.js +18 -18
- package/dist/cli/domain/handle-dependencies/index.d.ts +10 -9
- package/dist/cli/domain/handle-dependencies/index.js +70 -64
- package/dist/cli/domain/handle-dependencies/install-compiler.d.ts +8 -8
- package/dist/cli/domain/handle-dependencies/install-compiler.js +54 -47
- package/dist/cli/domain/handle-dependencies/install-missing-dependencies.d.ts +5 -5
- package/dist/cli/domain/handle-dependencies/install-missing-dependencies.js +59 -55
- package/dist/cli/domain/handle-dependencies/link-missing-dependencies.d.ts +6 -6
- package/dist/cli/domain/handle-dependencies/link-missing-dependencies.js +32 -36
- package/dist/cli/domain/handle-dependencies/require-template.d.ts +17 -17
- package/dist/cli/domain/handle-dependencies/require-template.js +34 -34
- package/dist/cli/domain/init-template/index.d.ts +10 -10
- package/dist/cli/domain/init-template/index.js +40 -42
- package/dist/cli/domain/init-template/install-template.d.ts +11 -11
- package/dist/cli/domain/init-template/install-template.js +54 -53
- package/dist/cli/domain/init-template/scaffold.d.ts +11 -11
- package/dist/cli/domain/init-template/scaffold.js +30 -30
- package/dist/cli/domain/local.d.ts +2 -2
- package/dist/cli/domain/local.js +82 -81
- package/dist/cli/domain/mock.d.ts +5 -5
- package/dist/cli/domain/mock.js +33 -33
- package/dist/cli/domain/package-components.d.ts +9 -9
- package/dist/cli/domain/package-components.js +67 -70
- package/dist/cli/domain/registry.d.ts +6 -6
- package/dist/cli/domain/registry.js +136 -149
- package/dist/cli/domain/url-parser.d.ts +14 -14
- package/dist/cli/domain/url-parser.js +31 -31
- package/dist/cli/domain/watch.d.ts +1 -1
- package/dist/cli/domain/watch.js +29 -29
- package/dist/cli/facade/clean.d.ts +16 -10
- package/dist/cli/facade/clean.js +58 -48
- package/dist/cli/facade/dev.d.ts +114 -21
- package/dist/cli/facade/dev.js +176 -190
- package/dist/cli/facade/init.d.ts +18 -11
- package/dist/cli/facade/init.js +39 -37
- package/dist/cli/facade/mock.d.ts +18 -11
- package/dist/cli/facade/mock.js +12 -13
- package/dist/cli/facade/package.d.ts +18 -11
- package/dist/cli/facade/package.js +49 -51
- package/dist/cli/facade/preview.d.ts +14 -9
- package/dist/cli/facade/preview.js +20 -18
- package/dist/cli/facade/publish.d.ts +23 -14
- package/dist/cli/facade/publish.js +145 -165
- package/dist/cli/facade/registry-add.d.ts +14 -9
- package/dist/cli/facade/registry-add.js +18 -17
- package/dist/cli/facade/registry-ls.d.ts +10 -7
- package/dist/cli/facade/registry-ls.js +27 -25
- package/dist/cli/facade/registry-remove.d.ts +14 -9
- package/dist/cli/facade/registry-remove.js +18 -17
- package/dist/cli/facade/registry.d.ts +5 -2
- package/dist/cli/facade/registry.js +9 -6
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.js +91 -93
- package/dist/cli/logger.d.ts +8 -8
- package/dist/cli/logger.js +19 -19
- package/dist/cli/programmatic-api.d.ts +84 -84
- package/dist/cli/programmatic-api.js +66 -66
- package/dist/cli/validate-command.d.ts +2 -2
- package/dist/cli/validate-command.js +18 -18
- package/dist/components/oc-client/_package/package.json +1 -1
- package/dist/components/oc-client/package.json +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +12 -12
- package/dist/oc-cli.d.ts +2 -2
- package/dist/oc-cli.js +3 -3
- package/dist/registry/app-start.d.ts +2 -2
- package/dist/registry/app-start.js +44 -44
- package/dist/registry/domain/authentication.d.ts +7 -8
- package/dist/registry/domain/authentication.js +53 -50
- package/dist/registry/domain/components-cache/components-list.d.ts +8 -7
- package/dist/registry/domain/components-cache/components-list.js +50 -64
- package/dist/registry/domain/components-cache/index.d.ts +7 -6
- package/dist/registry/domain/components-cache/index.js +76 -79
- package/dist/registry/domain/components-details.d.ts +6 -5
- package/dist/registry/domain/components-details.js +64 -75
- package/dist/registry/domain/events-handler.d.ts +40 -40
- package/dist/registry/domain/events-handler.js +37 -37
- package/dist/registry/domain/extract-package.d.ts +8 -8
- package/dist/registry/domain/extract-package.js +26 -29
- package/dist/registry/domain/get-package-json-from-temp-dir.d.ts +2 -2
- package/dist/registry/domain/get-package-json-from-temp-dir.js +11 -11
- package/dist/registry/domain/nested-renderer.d.ts +14 -13
- package/dist/registry/domain/nested-renderer.js +59 -95
- package/dist/registry/domain/options-sanitiser.d.ts +6 -6
- package/dist/registry/domain/options-sanitiser.js +106 -104
- package/dist/registry/domain/plugins-initialiser.d.ts +3 -1
- package/dist/registry/domain/plugins-initialiser.js +95 -99
- package/dist/registry/domain/register-templates.d.ts +5 -5
- package/dist/registry/domain/register-templates.js +30 -30
- package/dist/registry/domain/repository.d.ts +2 -2
- package/dist/registry/domain/repository.js +237 -259
- package/dist/registry/domain/require-wrapper.d.ts +2 -2
- package/dist/registry/domain/require-wrapper.js +33 -34
- package/dist/registry/domain/sanitiser.d.ts +2 -2
- package/dist/registry/domain/sanitiser.js +52 -52
- package/dist/registry/domain/storage-adapter.d.ts +10 -0
- package/dist/registry/domain/storage-adapter.js +55 -0
- package/dist/registry/domain/url-builder.d.ts +10 -10
- package/dist/registry/domain/url-builder.js +60 -60
- package/dist/registry/domain/validators/component-parameters.d.ts +11 -11
- package/dist/registry/domain/validators/component-parameters.js +79 -79
- package/dist/registry/domain/validators/index.d.ts +16 -16
- package/dist/registry/domain/validators/index.js +29 -29
- package/dist/registry/domain/validators/node-version.d.ts +15 -15
- package/dist/registry/domain/validators/node-version.js +40 -40
- package/dist/registry/domain/validators/oc-cli-version.d.ts +15 -15
- package/dist/registry/domain/validators/oc-cli-version.js +34 -34
- package/dist/registry/domain/validators/package-json-validator.d.ts +13 -13
- package/dist/registry/domain/validators/package-json-validator.js +23 -23
- package/dist/registry/domain/validators/plugins-requirements.d.ts +9 -9
- package/dist/registry/domain/validators/plugins-requirements.js +22 -22
- package/dist/registry/domain/validators/registry-configuration.d.ts +9 -9
- package/dist/registry/domain/validators/registry-configuration.js +113 -113
- package/dist/registry/domain/validators/uploaded-package.d.ts +14 -14
- package/dist/registry/domain/validators/uploaded-package.js +25 -25
- package/dist/registry/domain/version-handler.d.ts +2 -2
- package/dist/registry/domain/version-handler.js +22 -22
- package/dist/registry/index.d.ts +48 -48
- package/dist/registry/index.js +107 -120
- package/dist/registry/middleware/base-url-handler.d.ts +2 -2
- package/dist/registry/middleware/base-url-handler.js +12 -12
- package/dist/registry/middleware/cors.d.ts +2 -2
- package/dist/registry/middleware/cors.js +11 -11
- package/dist/registry/middleware/discovery-handler.d.ts +2 -2
- package/dist/registry/middleware/discovery-handler.js +15 -15
- package/dist/registry/middleware/file-uploads.d.ts +2 -2
- package/dist/registry/middleware/file-uploads.js +23 -23
- package/dist/registry/middleware/index.d.ts +7 -3
- package/dist/registry/middleware/index.js +51 -47
- package/dist/registry/middleware/request-handler.d.ts +2 -2
- package/dist/registry/middleware/request-handler.js +30 -30
- package/dist/registry/router.d.ts +3 -3
- package/dist/registry/router.js +56 -58
- package/dist/registry/routes/component-info.d.ts +3 -3
- package/dist/registry/routes/component-info.js +90 -89
- package/dist/registry/routes/component-preview.d.ts +3 -3
- package/dist/registry/routes/component-preview.js +68 -67
- package/dist/registry/routes/component.d.ts +3 -3
- package/dist/registry/routes/component.js +43 -43
- package/dist/registry/routes/components.d.ts +3 -3
- package/dist/registry/routes/components.js +78 -78
- package/dist/registry/routes/dependencies.d.ts +3 -3
- package/dist/registry/routes/dependencies.js +28 -28
- package/dist/registry/routes/helpers/apply-default-values.d.ts +2 -2
- package/dist/registry/routes/helpers/apply-default-values.js +13 -13
- package/dist/registry/routes/helpers/get-available-dependencies.d.ts +8 -8
- package/dist/registry/routes/helpers/get-available-dependencies.js +24 -24
- package/dist/registry/routes/helpers/get-component-fallback.d.ts +17 -22
- package/dist/registry/routes/helpers/get-component-fallback.js +91 -91
- package/dist/registry/routes/helpers/get-component-retrieving-info.d.ts +20 -20
- package/dist/registry/routes/helpers/get-component-retrieving-info.js +24 -24
- package/dist/registry/routes/helpers/get-component.d.ts +33 -33
- package/dist/registry/routes/helpers/get-component.js +406 -405
- package/dist/registry/routes/helpers/get-components-history.d.ts +8 -8
- package/dist/registry/routes/helpers/get-components-history.js +28 -28
- package/dist/registry/routes/helpers/is-url-discoverable.d.ts +3 -3
- package/dist/registry/routes/helpers/is-url-discoverable.js +22 -16
- package/dist/registry/routes/index.d.ts +3 -3
- package/dist/registry/routes/index.js +93 -92
- package/dist/registry/routes/plugins.d.ts +3 -3
- package/dist/registry/routes/plugins.js +17 -17
- package/dist/registry/routes/publish.d.ts +3 -3
- package/dist/registry/routes/publish.js +97 -96
- package/dist/registry/routes/static-redirector.d.ts +3 -3
- package/dist/registry/routes/static-redirector.js +63 -63
- package/dist/registry/views/index.d.ts +2 -2
- package/dist/registry/views/index.js +39 -39
- package/dist/registry/views/info.d.ts +16 -16
- package/dist/registry/views/info.js +44 -41
- package/dist/registry/views/partials/component-author.d.ts +8 -8
- package/dist/registry/views/partials/component-author.js +20 -20
- package/dist/registry/views/partials/component-parameters.d.ts +5 -5
- package/dist/registry/views/partials/component-parameters.js +24 -24
- package/dist/registry/views/partials/component-state.d.ts +5 -5
- package/dist/registry/views/partials/component-state.js +6 -6
- package/dist/registry/views/partials/component-versions.d.ts +5 -5
- package/dist/registry/views/partials/component-versions.js +9 -9
- package/dist/registry/views/partials/components-dependencies.d.ts +2 -2
- package/dist/registry/views/partials/components-dependencies.js +12 -12
- package/dist/registry/views/partials/components-history.d.ts +2 -2
- package/dist/registry/views/partials/components-history.js +10 -10
- package/dist/registry/views/partials/components-list.d.ts +2 -2
- package/dist/registry/views/partials/components-list.js +26 -26
- package/dist/registry/views/partials/components-plugins.d.ts +2 -2
- package/dist/registry/views/partials/components-plugins.js +8 -8
- package/dist/registry/views/partials/components-templates.d.ts +2 -2
- package/dist/registry/views/partials/components-templates.js +14 -14
- package/dist/registry/views/partials/layout.d.ts +8 -8
- package/dist/registry/views/partials/layout.js +11 -11
- package/dist/registry/views/partials/property.d.ts +2 -2
- package/dist/registry/views/partials/property.js +11 -11
- package/dist/registry/views/partials/selected-checkbox.d.ts +4 -4
- package/dist/registry/views/partials/selected-checkbox.js +7 -7
- package/dist/registry/views/preview.d.ts +8 -8
- package/dist/registry/views/preview.js +9 -9
- package/dist/registry/views/static/index.d.ts +2 -2
- package/dist/registry/views/static/index.js +3 -3
- package/dist/registry/views/static/info.d.ts +2 -2
- package/dist/registry/views/static/info.js +15 -4
- package/dist/registry/views/static/style.d.ts +2 -2
- package/dist/registry/views/static/style.js +3 -3
- package/dist/resources/index.d.ts +134 -134
- package/dist/resources/index.js +145 -145
- package/dist/resources/settings.d.ts +17 -17
- package/dist/resources/settings.js +18 -18
- package/dist/types.d.ts +287 -285
- package/dist/types.js +2 -2
- package/dist/utils/clean-require.d.ts +16 -16
- package/dist/utils/clean-require.js +18 -18
- package/dist/utils/date-stringify.d.ts +1 -1
- package/dist/utils/date-stringify.js +22 -22
- package/dist/utils/error-to-string.d.ts +1 -1
- package/dist/utils/error-to-string.js +15 -15
- package/dist/utils/is-template-legacy.d.ts +3 -3
- package/dist/utils/is-template-legacy.js +6 -6
- package/dist/utils/is-template-valid.d.ts +4 -4
- package/dist/utils/is-template-valid.js +12 -12
- package/dist/utils/module-exists.d.ts +1 -1
- package/dist/utils/module-exists.js +15 -15
- package/dist/utils/npm-utils.d.ts +20 -22
- package/dist/utils/npm-utils.js +74 -63
- package/dist/utils/put.d.ts +2 -1
- package/dist/utils/put.js +29 -48
- package/dist/utils/strip-version.d.ts +1 -1
- package/dist/utils/strip-version.js +11 -11
- package/logintervals.md +1 -1
- package/package.json +6 -1
- package/src/cli/domain/clean.ts +10 -20
- package/src/cli/domain/get-components-by-dir.ts +12 -26
- package/src/cli/domain/get-mocked-plugins.ts +32 -26
- package/src/cli/domain/handle-dependencies/ensure-compiler-is-declared-as-devDependency.ts +8 -12
- package/src/cli/domain/handle-dependencies/get-compiler.ts +8 -11
- package/src/cli/domain/handle-dependencies/index.ts +55 -109
- package/src/cli/domain/handle-dependencies/install-compiler.ts +22 -15
- package/src/cli/domain/handle-dependencies/install-missing-dependencies.ts +19 -13
- package/src/cli/domain/handle-dependencies/link-missing-dependencies.ts +8 -16
- package/src/cli/domain/init-template/index.ts +13 -20
- package/src/cli/domain/init-template/install-template.ts +11 -12
- package/src/cli/domain/init-template/scaffold.ts +9 -12
- package/src/cli/domain/local.ts +19 -22
- package/src/cli/domain/mock.ts +32 -36
- package/src/cli/domain/package-components.ts +14 -25
- package/src/cli/domain/registry.ts +80 -116
- package/src/cli/domain/watch.ts +1 -1
- package/src/cli/facade/clean.ts +37 -37
- package/src/cli/facade/dev.ts +159 -182
- package/src/cli/facade/init.ts +36 -38
- package/src/cli/facade/mock.ts +11 -10
- package/src/cli/facade/package.ts +44 -49
- package/src/cli/facade/preview.ts +20 -18
- package/src/cli/facade/publish.ts +134 -172
- package/src/cli/facade/registry-add.ts +16 -15
- package/src/cli/facade/registry-ls.ts +27 -22
- package/src/cli/facade/registry-remove.ts +16 -15
- package/src/cli/facade/registry.ts +7 -5
- package/src/cli/index.ts +3 -5
- package/src/components/oc-client/_package/package.json +1 -1
- package/src/components/oc-client/package.json +1 -1
- package/src/globals.d.ts +38 -0
- package/src/oc-cli.js +0 -0
- package/src/registry/app-start.ts +27 -31
- package/src/registry/domain/authentication.ts +5 -13
- package/src/registry/domain/components-cache/components-list.ts +45 -67
- package/src/registry/domain/components-cache/index.ts +55 -60
- package/src/registry/domain/components-details.ts +49 -75
- package/src/registry/domain/extract-package.ts +19 -27
- package/src/registry/domain/get-package-json-from-temp-dir.ts +3 -4
- package/src/registry/domain/nested-renderer.ts +64 -122
- package/src/registry/domain/options-sanitiser.ts +6 -3
- package/src/registry/domain/plugins-initialiser.ts +45 -49
- package/src/registry/domain/repository.ts +129 -235
- package/src/registry/domain/require-wrapper.ts +1 -2
- package/src/registry/domain/storage-adapter.ts +85 -0
- package/src/registry/index.ts +48 -79
- package/src/registry/middleware/index.ts +10 -2
- package/src/registry/router.ts +2 -10
- package/src/registry/routes/component-info.ts +4 -3
- package/src/registry/routes/component-preview.ts +3 -2
- package/src/registry/routes/components.ts +1 -1
- package/src/registry/routes/helpers/get-component-fallback.ts +3 -9
- package/src/registry/routes/helpers/get-component.ts +11 -9
- package/src/registry/routes/helpers/is-url-discoverable.ts +14 -15
- package/src/registry/routes/index.ts +18 -13
- package/src/registry/routes/publish.ts +31 -34
- package/src/registry/views/info.ts +5 -2
- package/src/registry/views/static/info.ts +12 -1
- package/src/resources/settings.ts +1 -1
- package/src/types.ts +80 -141
- package/src/utils/npm-utils.ts +38 -37
- package/src/utils/put.ts +15 -37
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import colors from 'colors/safe';
|
|
2
2
|
import path from 'path';
|
|
3
|
-
import _ from 'lodash';
|
|
4
3
|
import fs from 'fs-extra';
|
|
5
|
-
import {
|
|
4
|
+
import { Config, Repository } from '../types';
|
|
6
5
|
|
|
7
6
|
const packageInfo = fs.readJsonSync(
|
|
8
7
|
path.join(
|
|
@@ -15,16 +14,16 @@ const packageInfo = fs.readJsonSync(
|
|
|
15
14
|
)
|
|
16
15
|
);
|
|
17
16
|
|
|
18
|
-
export default function appStart(
|
|
17
|
+
export default async function appStart(
|
|
19
18
|
repository: Repository,
|
|
20
|
-
options: Config
|
|
21
|
-
|
|
22
|
-
): void {
|
|
19
|
+
options: Config
|
|
20
|
+
): Promise<void> {
|
|
23
21
|
if (options.local) {
|
|
24
|
-
return
|
|
22
|
+
return;
|
|
25
23
|
}
|
|
26
24
|
|
|
27
|
-
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
26
|
+
const logger = options.verbosity ? console : { log: () => {} };
|
|
28
27
|
|
|
29
28
|
logger.log(
|
|
30
29
|
colors.yellow(
|
|
@@ -32,10 +31,8 @@ export default function appStart(
|
|
|
32
31
|
)
|
|
33
32
|
);
|
|
34
33
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return logger.log(colors.red(err));
|
|
38
|
-
}
|
|
34
|
+
try {
|
|
35
|
+
const componentInfo = await repository.getComponentVersions('oc-client');
|
|
39
36
|
|
|
40
37
|
logger.log(
|
|
41
38
|
colors.yellow(
|
|
@@ -43,7 +40,7 @@ export default function appStart(
|
|
|
43
40
|
)
|
|
44
41
|
);
|
|
45
42
|
|
|
46
|
-
if (!
|
|
43
|
+
if (!componentInfo.includes(packageInfo.version)) {
|
|
47
44
|
logger.log(colors.yellow('Component not found. Publishing it...'));
|
|
48
45
|
|
|
49
46
|
const pkgInfo = {
|
|
@@ -54,25 +51,24 @@ export default function appStart(
|
|
|
54
51
|
packageJson: packageInfo
|
|
55
52
|
};
|
|
56
53
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
callback(err, res);
|
|
71
|
-
}
|
|
72
|
-
);
|
|
54
|
+
try {
|
|
55
|
+
await repository.publishComponent(
|
|
56
|
+
pkgInfo,
|
|
57
|
+
'oc-client',
|
|
58
|
+
packageInfo.version
|
|
59
|
+
);
|
|
60
|
+
logger.log(colors.green('Component published.'));
|
|
61
|
+
} catch (err) {
|
|
62
|
+
logger.log(
|
|
63
|
+
colors.red(`Component not published: ${(err as any).message}`)
|
|
64
|
+
);
|
|
65
|
+
throw err;
|
|
66
|
+
}
|
|
73
67
|
} else {
|
|
74
68
|
logger.log(colors.green('Component is available on library.'));
|
|
75
|
-
callback(null, 'ok');
|
|
76
69
|
}
|
|
77
|
-
})
|
|
70
|
+
} catch (err) {
|
|
71
|
+
logger.log(colors.red(String(err)));
|
|
72
|
+
throw err;
|
|
73
|
+
}
|
|
78
74
|
}
|
|
@@ -2,17 +2,7 @@ import basicAuth from 'basic-auth-connect';
|
|
|
2
2
|
import { RequestHandler } from 'express';
|
|
3
3
|
|
|
4
4
|
import strings from '../../resources/';
|
|
5
|
-
|
|
6
|
-
type Validate<T = unknown> = (config: T) => {
|
|
7
|
-
isValid: boolean;
|
|
8
|
-
message: string;
|
|
9
|
-
};
|
|
10
|
-
type Middleware<T> = (config: T) => any;
|
|
11
|
-
|
|
12
|
-
type Authentication<T = any> = {
|
|
13
|
-
validate: Validate<T>;
|
|
14
|
-
middleware: Middleware<T>;
|
|
15
|
-
};
|
|
5
|
+
import { Authentication, PublishAuthConfig } from '../../types';
|
|
16
6
|
|
|
17
7
|
const basicAuthentication: Authentication<{
|
|
18
8
|
username: string;
|
|
@@ -40,8 +30,10 @@ const builtin: Record<string, Authentication> = {
|
|
|
40
30
|
|
|
41
31
|
let scheme: Authentication;
|
|
42
32
|
|
|
43
|
-
export function validate(authConfig:
|
|
44
|
-
if (
|
|
33
|
+
export function validate(authConfig: PublishAuthConfig) {
|
|
34
|
+
if (typeof authConfig.type !== 'string') {
|
|
35
|
+
scheme = authConfig.type;
|
|
36
|
+
} else if (builtin[authConfig.type]) {
|
|
45
37
|
scheme = builtin[authConfig.type];
|
|
46
38
|
} else {
|
|
47
39
|
const moduleName = `oc-auth-${authConfig.type}`;
|
|
@@ -1,91 +1,69 @@
|
|
|
1
|
-
import async from 'async';
|
|
2
1
|
import semver from 'semver';
|
|
2
|
+
import pLimit from 'p-limit';
|
|
3
3
|
import getUnixUTCTimestamp from 'oc-get-unix-utc-timestamp';
|
|
4
|
-
import {
|
|
4
|
+
import { ComponentsList, Config } from '../../../types';
|
|
5
|
+
import { StorageAdapter } from 'oc-storage-adapters-utils';
|
|
5
6
|
|
|
6
|
-
export default function componentsList(conf: Config, cdn:
|
|
7
|
+
export default function componentsList(conf: Config, cdn: StorageAdapter) {
|
|
7
8
|
const filePath = (): string =>
|
|
8
9
|
`${conf.storage.options.componentsDir}/components.json`;
|
|
9
10
|
|
|
10
11
|
const componentsList = {
|
|
11
|
-
getFromJson: (
|
|
12
|
-
cdn.getJson(filePath(), true, callback),
|
|
12
|
+
getFromJson: (): Promise<ComponentsList> => cdn.getJson(filePath(), true),
|
|
13
13
|
|
|
14
|
-
getFromDirectories: (
|
|
15
|
-
callback: (err: string | null, data: ComponentsList) => void
|
|
16
|
-
) => {
|
|
14
|
+
getFromDirectories: async (): Promise<ComponentsList> => {
|
|
17
15
|
const componentsInfo: Record<string, string[]> = {};
|
|
18
16
|
|
|
19
|
-
const getVersionsForComponent = (
|
|
20
|
-
componentName: string
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
`${conf.storage.options.componentsDir}/${componentName}`,
|
|
25
|
-
(err, versions) => {
|
|
26
|
-
if (err) {
|
|
27
|
-
return cb(err, undefined as any);
|
|
28
|
-
}
|
|
29
|
-
cb(null, versions.sort(semver.compare));
|
|
30
|
-
}
|
|
17
|
+
const getVersionsForComponent = async (
|
|
18
|
+
componentName: string
|
|
19
|
+
): Promise<string[]> => {
|
|
20
|
+
const versions = await cdn.listSubDirectories(
|
|
21
|
+
`${conf.storage.options.componentsDir}/${componentName}`
|
|
31
22
|
);
|
|
32
|
-
};
|
|
33
23
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
(err, components) => {
|
|
37
|
-
if (err) {
|
|
38
|
-
if (err.code === 'dir_not_found') {
|
|
39
|
-
return callback(null, {
|
|
40
|
-
lastEdit: getUnixUTCTimestamp(),
|
|
41
|
-
components: [] as any
|
|
42
|
-
});
|
|
43
|
-
}
|
|
24
|
+
return versions.sort(semver.compare);
|
|
25
|
+
};
|
|
44
26
|
|
|
45
|
-
|
|
46
|
-
|
|
27
|
+
try {
|
|
28
|
+
const components = await cdn.listSubDirectories(
|
|
29
|
+
conf.storage.options.componentsDir
|
|
30
|
+
);
|
|
31
|
+
const limit = pLimit(cdn.maxConcurrentRequests);
|
|
47
32
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
if (errors) {
|
|
54
|
-
return callback(errors as any, undefined as any);
|
|
55
|
-
}
|
|
33
|
+
const versions = await Promise.all(
|
|
34
|
+
components.map(component =>
|
|
35
|
+
limit(() => getVersionsForComponent(component))
|
|
36
|
+
)
|
|
37
|
+
);
|
|
56
38
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
39
|
+
components.forEach((component, i) => {
|
|
40
|
+
componentsInfo[component] = versions[i];
|
|
41
|
+
});
|
|
60
42
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
43
|
+
return {
|
|
44
|
+
lastEdit: getUnixUTCTimestamp(),
|
|
45
|
+
components: componentsInfo
|
|
46
|
+
};
|
|
47
|
+
} catch (err: any) {
|
|
48
|
+
if (err.code === 'dir_not_found') {
|
|
49
|
+
throw {
|
|
50
|
+
lastEdit: getUnixUTCTimestamp(),
|
|
51
|
+
components: [] as any
|
|
52
|
+
};
|
|
67
53
|
}
|
|
68
|
-
|
|
54
|
+
throw err;
|
|
55
|
+
}
|
|
69
56
|
},
|
|
70
57
|
|
|
71
|
-
refresh(
|
|
72
|
-
componentsList.getFromDirectories(
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
componentsList.save(components, err => {
|
|
77
|
-
if (err) {
|
|
78
|
-
return callback(err, undefined as any);
|
|
79
|
-
}
|
|
80
|
-
callback(err, components);
|
|
81
|
-
});
|
|
82
|
-
});
|
|
58
|
+
async refresh(): Promise<ComponentsList> {
|
|
59
|
+
const components = await componentsList.getFromDirectories();
|
|
60
|
+
await componentsList.save(components);
|
|
61
|
+
|
|
62
|
+
return components;
|
|
83
63
|
},
|
|
84
64
|
|
|
85
|
-
save: (
|
|
86
|
-
data
|
|
87
|
-
callback: (err: string | null, data: unknown) => void
|
|
88
|
-
) => cdn.putFileContent(JSON.stringify(data), filePath(), true, callback)
|
|
65
|
+
save: (data: ComponentsList): Promise<unknown> =>
|
|
66
|
+
cdn.putFileContent(JSON.stringify(data), filePath(), true)
|
|
89
67
|
};
|
|
90
68
|
|
|
91
69
|
return componentsList;
|
|
@@ -2,94 +2,89 @@ import _ from 'lodash';
|
|
|
2
2
|
import getComponentsList from './components-list';
|
|
3
3
|
import eventsHandler from '../events-handler';
|
|
4
4
|
import getUnixUTCTimestamp from 'oc-get-unix-utc-timestamp';
|
|
5
|
-
import {
|
|
5
|
+
import { ComponentsList, Config } from '../../../types';
|
|
6
|
+
import { StorageAdapter } from 'oc-storage-adapters-utils';
|
|
6
7
|
|
|
7
|
-
export default function componentsCache(conf: Config, cdn:
|
|
8
|
+
export default function componentsCache(conf: Config, cdn: StorageAdapter) {
|
|
8
9
|
let cachedComponentsList: ComponentsList;
|
|
9
10
|
let refreshLoop: NodeJS.Timeout;
|
|
10
11
|
|
|
11
12
|
const componentsList = getComponentsList(conf, cdn);
|
|
12
13
|
|
|
13
14
|
const poll = () =>
|
|
14
|
-
setTimeout(() => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
eventsHandler.fire('error', {
|
|
18
|
-
code: 'components_list_get',
|
|
19
|
-
message: err
|
|
20
|
-
});
|
|
21
|
-
} else {
|
|
22
|
-
eventsHandler.fire('cache-poll', getUnixUTCTimestamp());
|
|
15
|
+
setTimeout(async () => {
|
|
16
|
+
try {
|
|
17
|
+
const data = await componentsList.getFromJson();
|
|
23
18
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
19
|
+
eventsHandler.fire('cache-poll', getUnixUTCTimestamp());
|
|
20
|
+
|
|
21
|
+
if (data.lastEdit > cachedComponentsList.lastEdit) {
|
|
22
|
+
cachedComponentsList = data;
|
|
27
23
|
}
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
} catch (err: any) {
|
|
25
|
+
eventsHandler.fire('error', {
|
|
26
|
+
code: 'components_list_get',
|
|
27
|
+
message: err?.message || String(err)
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
refreshLoop = poll();
|
|
30
31
|
}, conf.pollingInterval * 1000);
|
|
31
32
|
|
|
32
|
-
const cacheDataAndStartPolling = (
|
|
33
|
-
data: ComponentsList,
|
|
34
|
-
callback: (err: null, data: ComponentsList) => void
|
|
35
|
-
) => {
|
|
33
|
+
const cacheDataAndStartPolling = (data: ComponentsList) => {
|
|
36
34
|
cachedComponentsList = data;
|
|
37
35
|
refreshLoop = poll();
|
|
38
|
-
|
|
36
|
+
|
|
37
|
+
return data;
|
|
39
38
|
};
|
|
40
39
|
|
|
41
|
-
const
|
|
42
|
-
code:
|
|
43
|
-
|
|
44
|
-
callback: (err: any | null, data: any) => void
|
|
45
|
-
) => {
|
|
46
|
-
eventsHandler.fire('error', { code, message });
|
|
47
|
-
return callback(code, undefined as any);
|
|
40
|
+
const throwError = (code: string, message: any) => {
|
|
41
|
+
eventsHandler.fire('error', { code, message: message?.message ?? message });
|
|
42
|
+
throw code;
|
|
48
43
|
};
|
|
49
44
|
|
|
50
45
|
return {
|
|
51
|
-
get(
|
|
46
|
+
get(): ComponentsList {
|
|
52
47
|
if (!cachedComponentsList) {
|
|
53
|
-
return
|
|
48
|
+
return throwError(
|
|
54
49
|
'components_cache_empty',
|
|
55
|
-
`The component's cache was empty
|
|
56
|
-
callback
|
|
50
|
+
`The component's cache was empty`
|
|
57
51
|
);
|
|
58
52
|
}
|
|
59
53
|
|
|
60
|
-
|
|
54
|
+
return cachedComponentsList;
|
|
61
55
|
},
|
|
62
56
|
|
|
63
|
-
load(
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
});
|
|
57
|
+
async load(): Promise<ComponentsList> {
|
|
58
|
+
const dirComponents = await componentsList
|
|
59
|
+
.getFromDirectories()
|
|
60
|
+
.catch(err => throwError('components_list_get', err));
|
|
61
|
+
const jsonComponents = await componentsList
|
|
62
|
+
.getFromJson()
|
|
63
|
+
.catch(() => null);
|
|
64
|
+
|
|
65
|
+
if (
|
|
66
|
+
!jsonComponents ||
|
|
67
|
+
!_.isEqual(dirComponents.components, jsonComponents.components)
|
|
68
|
+
) {
|
|
69
|
+
await componentsList
|
|
70
|
+
.save(dirComponents)
|
|
71
|
+
.catch(err => throwError('components_list_save', err));
|
|
72
|
+
}
|
|
73
|
+
cacheDataAndStartPolling(dirComponents);
|
|
74
|
+
|
|
75
|
+
return dirComponents;
|
|
83
76
|
},
|
|
84
|
-
|
|
77
|
+
|
|
78
|
+
async refresh(): Promise<ComponentsList> {
|
|
85
79
|
clearTimeout(refreshLoop);
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
80
|
+
try {
|
|
81
|
+
const components = await componentsList.refresh();
|
|
82
|
+
cacheDataAndStartPolling(components);
|
|
90
83
|
|
|
91
|
-
|
|
92
|
-
})
|
|
84
|
+
return components;
|
|
85
|
+
} catch (err) {
|
|
86
|
+
return throwError('components_cache_refresh', err);
|
|
87
|
+
}
|
|
93
88
|
}
|
|
94
89
|
};
|
|
95
90
|
}
|
|
@@ -1,39 +1,34 @@
|
|
|
1
|
-
import
|
|
1
|
+
import pLimit from 'p-limit';
|
|
2
2
|
import _ from 'lodash';
|
|
3
3
|
import eventsHandler from './events-handler';
|
|
4
4
|
import getUnixUTCTimestamp from 'oc-get-unix-utc-timestamp';
|
|
5
5
|
import {
|
|
6
|
-
Cdn,
|
|
7
6
|
Component,
|
|
8
7
|
ComponentsDetails,
|
|
9
8
|
ComponentsList,
|
|
10
9
|
Config
|
|
11
10
|
} from '../../types';
|
|
11
|
+
import { StorageAdapter } from 'oc-storage-adapters-utils';
|
|
12
12
|
|
|
13
|
-
export default function componentsDetails(conf: Config, cdn:
|
|
14
|
-
const returnError = (
|
|
15
|
-
code: string,
|
|
16
|
-
message: string | Error,
|
|
17
|
-
callback: (code: string) => void
|
|
18
|
-
) => {
|
|
13
|
+
export default function componentsDetails(conf: Config, cdn: StorageAdapter) {
|
|
14
|
+
const returnError = (code: string, message: string | Error) => {
|
|
19
15
|
eventsHandler.fire('error', {
|
|
20
16
|
code,
|
|
21
17
|
message: (message as Error)?.message ?? message
|
|
22
18
|
});
|
|
23
|
-
|
|
19
|
+
throw code;
|
|
24
20
|
};
|
|
25
21
|
|
|
26
22
|
const filePath = (): string =>
|
|
27
23
|
`${conf.storage.options.componentsDir}/components-details.json`;
|
|
28
24
|
|
|
29
|
-
const getFromJson = (
|
|
30
|
-
|
|
31
|
-
) => cdn.getJson<ComponentsDetails>(filePath(), true, callback);
|
|
25
|
+
const getFromJson = (): Promise<ComponentsDetails> =>
|
|
26
|
+
cdn.getJson(filePath(), true);
|
|
32
27
|
|
|
33
|
-
const getFromDirectories = (
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
) => {
|
|
28
|
+
const getFromDirectories = async (options: {
|
|
29
|
+
componentsList: ComponentsList;
|
|
30
|
+
details?: ComponentsDetails;
|
|
31
|
+
}): Promise<ComponentsDetails> => {
|
|
37
32
|
const details = Object.assign({}, _.cloneDeep(options.details));
|
|
38
33
|
details.components = details.components || {};
|
|
39
34
|
|
|
@@ -47,72 +42,51 @@ export default function componentsDetails(conf: Config, cdn: Cdn) {
|
|
|
47
42
|
});
|
|
48
43
|
});
|
|
49
44
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
({ name, version }
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
publishDate: content.oc.date || 0
|
|
63
|
-
};
|
|
64
|
-
next();
|
|
65
|
-
}
|
|
66
|
-
);
|
|
67
|
-
},
|
|
68
|
-
err =>
|
|
69
|
-
callback(err, {
|
|
70
|
-
lastEdit: getUnixUTCTimestamp(),
|
|
71
|
-
components: details.components
|
|
45
|
+
const limit = pLimit(cdn.maxConcurrentRequests);
|
|
46
|
+
|
|
47
|
+
await Promise.all(
|
|
48
|
+
missing.map(({ name, version }) =>
|
|
49
|
+
limit(async () => {
|
|
50
|
+
const content: Component = await cdn.getJson(
|
|
51
|
+
`${conf.storage.options.componentsDir}/${name}/${version}/package.json`,
|
|
52
|
+
true
|
|
53
|
+
);
|
|
54
|
+
details.components[name][version] = {
|
|
55
|
+
publishDate: content.oc.date || 0
|
|
56
|
+
};
|
|
72
57
|
})
|
|
58
|
+
)
|
|
73
59
|
);
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
lastEdit: getUnixUTCTimestamp(),
|
|
63
|
+
components: details.components
|
|
64
|
+
};
|
|
74
65
|
};
|
|
75
66
|
|
|
76
|
-
const save = (
|
|
77
|
-
data
|
|
78
|
-
callback: (err: string | null, data: unknown) => void
|
|
79
|
-
) => cdn.putFileContent(JSON.stringify(data), filePath(), true, callback);
|
|
67
|
+
const save = (data: ComponentsDetails): Promise<unknown> =>
|
|
68
|
+
cdn.putFileContent(JSON.stringify(data), filePath(), true);
|
|
80
69
|
|
|
81
|
-
const refresh = (
|
|
82
|
-
componentsList: ComponentsList
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (dirErr) {
|
|
90
|
-
return returnError(
|
|
91
|
-
'components_details_get',
|
|
92
|
-
dirErr,
|
|
93
|
-
callback as any
|
|
94
|
-
);
|
|
95
|
-
} else if (
|
|
96
|
-
jsonErr ||
|
|
97
|
-
!_.isEqual(dirDetails.components, details.components)
|
|
98
|
-
) {
|
|
99
|
-
save(dirDetails, saveErr => {
|
|
100
|
-
if (saveErr) {
|
|
101
|
-
return returnError(
|
|
102
|
-
'components_details_save',
|
|
103
|
-
saveErr,
|
|
104
|
-
callback as any
|
|
105
|
-
);
|
|
106
|
-
}
|
|
70
|
+
const refresh = async (
|
|
71
|
+
componentsList: ComponentsList
|
|
72
|
+
): Promise<ComponentsDetails> => {
|
|
73
|
+
const jsonDetails = await getFromJson().catch(() => undefined);
|
|
74
|
+
const dirDetails = await getFromDirectories({
|
|
75
|
+
componentsList,
|
|
76
|
+
details: jsonDetails
|
|
77
|
+
}).catch(err => returnError('components_details_get', err));
|
|
107
78
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
79
|
+
if (
|
|
80
|
+
!jsonDetails ||
|
|
81
|
+
!_.isEqual(dirDetails.components, jsonDetails.components)
|
|
82
|
+
) {
|
|
83
|
+
await save(dirDetails).catch(err =>
|
|
84
|
+
returnError('components_details_save', err)
|
|
114
85
|
);
|
|
115
|
-
|
|
86
|
+
return dirDetails;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return jsonDetails;
|
|
116
90
|
};
|
|
117
91
|
|
|
118
92
|
return {
|
|
@@ -1,23 +1,20 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import targz from 'targz';
|
|
3
|
+
import { promisify } from 'util';
|
|
3
4
|
import { PackageJson } from 'type-fest';
|
|
4
5
|
|
|
5
6
|
import getPackageJsonFromTempDir from './get-package-json-from-temp-dir';
|
|
6
7
|
|
|
7
|
-
export default function extractPackage(
|
|
8
|
+
export default async function extractPackage(
|
|
8
9
|
files:
|
|
9
10
|
| Express.Multer.File[]
|
|
10
11
|
| {
|
|
11
12
|
[fieldname: string]: Express.Multer.File[];
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
packageJson: PackageJson;
|
|
18
|
-
}
|
|
19
|
-
) => void
|
|
20
|
-
): void {
|
|
13
|
+
}
|
|
14
|
+
): Promise<{
|
|
15
|
+
outputFolder: string;
|
|
16
|
+
packageJson: PackageJson;
|
|
17
|
+
}> {
|
|
21
18
|
const packageFile: Express.Multer.File = (files as any)[0];
|
|
22
19
|
const packagePath = path.resolve(packageFile.path);
|
|
23
20
|
const packageUntarOutput = path.resolve(
|
|
@@ -27,22 +24,17 @@ export default function extractPackage(
|
|
|
27
24
|
);
|
|
28
25
|
const packageOutput = path.resolve(packageUntarOutput, '_package');
|
|
29
26
|
|
|
30
|
-
targz.decompress
|
|
31
|
-
{
|
|
32
|
-
src: packagePath,
|
|
33
|
-
dest: packageUntarOutput
|
|
34
|
-
},
|
|
35
|
-
err => {
|
|
36
|
-
if (err) {
|
|
37
|
-
return (callback as any)(err);
|
|
38
|
-
}
|
|
27
|
+
const decompress = promisify(targz.decompress);
|
|
39
28
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
29
|
+
await decompress({
|
|
30
|
+
src: packagePath,
|
|
31
|
+
dest: packageUntarOutput
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const packageJson = await getPackageJsonFromTempDir(packageOutput);
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
outputFolder: packageOutput,
|
|
38
|
+
packageJson: packageJson
|
|
39
|
+
};
|
|
48
40
|
}
|
|
@@ -3,8 +3,7 @@ import path from 'path';
|
|
|
3
3
|
import { PackageJson } from 'type-fest';
|
|
4
4
|
|
|
5
5
|
export default function getPackageJsonFromTempDir(
|
|
6
|
-
tempDirPath: string
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return fs.readJson(path.join(tempDirPath, 'package.json'), callback);
|
|
6
|
+
tempDirPath: string
|
|
7
|
+
): Promise<PackageJson> {
|
|
8
|
+
return fs.readJson(path.join(tempDirPath, 'package.json'));
|
|
10
9
|
}
|