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,7 +1,6 @@
|
|
|
1
1
|
import fs from 'fs-extra';
|
|
2
2
|
import getUnixUtcTimestamp from 'oc-get-unix-utc-timestamp';
|
|
3
3
|
import path from 'path';
|
|
4
|
-
import _ from 'lodash';
|
|
5
4
|
|
|
6
5
|
import ComponentsCache from './components-cache';
|
|
7
6
|
import getComponentsDetails from './components-details';
|
|
@@ -9,23 +8,20 @@ import registerTemplates from './register-templates';
|
|
|
9
8
|
import settings from '../../resources/settings';
|
|
10
9
|
import strings from '../../resources';
|
|
11
10
|
import * as validator from './validators';
|
|
11
|
+
import getPromiseBasedAdapter from './storage-adapter';
|
|
12
12
|
import * as versionHandler from './version-handler';
|
|
13
13
|
import errorToString from '../../utils/error-to-string';
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
Component,
|
|
17
|
-
ComponentsDetails,
|
|
18
|
-
ComponentsList,
|
|
19
|
-
Config,
|
|
20
|
-
Repository
|
|
21
|
-
} from '../../types';
|
|
14
|
+
import { Component, Config, Repository } from '../../types';
|
|
15
|
+
import { StorageAdapter } from 'oc-storage-adapters-utils';
|
|
22
16
|
|
|
23
17
|
const packageInfo = fs.readJsonSync(
|
|
24
18
|
path.join(__dirname, '..', '..', '..', 'package.json')
|
|
25
19
|
);
|
|
26
20
|
|
|
27
21
|
export default function repository(conf: Config): Repository {
|
|
28
|
-
const cdn:
|
|
22
|
+
const cdn: StorageAdapter =
|
|
23
|
+
!conf.local &&
|
|
24
|
+
(getPromiseBasedAdapter(conf.storage.adapter(conf.storage.options)) as any);
|
|
29
25
|
const options = !conf.local ? conf.storage.options : null;
|
|
30
26
|
const repositorySource = conf.local
|
|
31
27
|
? 'local repository'
|
|
@@ -74,29 +70,28 @@ export default function repository(conf: Config): Repository {
|
|
|
74
70
|
validComponents.push('oc-client');
|
|
75
71
|
return validComponents;
|
|
76
72
|
},
|
|
77
|
-
getComponentVersions(
|
|
78
|
-
componentName: string,
|
|
79
|
-
callback: (err: string | null, data: string[]) => void
|
|
80
|
-
) {
|
|
73
|
+
getComponentVersions(componentName: string): Promise<string[]> {
|
|
81
74
|
if (componentName === 'oc-client') {
|
|
82
|
-
return
|
|
83
|
-
fs
|
|
75
|
+
return Promise.all([
|
|
76
|
+
fs
|
|
77
|
+
.readJson(path.join(__dirname, '../../../package.json'))
|
|
78
|
+
.then(x => x.version)
|
|
84
79
|
]);
|
|
85
80
|
}
|
|
86
81
|
|
|
87
|
-
if (!
|
|
88
|
-
return
|
|
82
|
+
if (!local.getComponents().includes(componentName)) {
|
|
83
|
+
return Promise.reject(
|
|
89
84
|
strings.errors.registry.COMPONENT_NOT_FOUND(
|
|
90
85
|
componentName,
|
|
91
86
|
repositorySource
|
|
92
|
-
)
|
|
93
|
-
undefined as any
|
|
87
|
+
)
|
|
94
88
|
);
|
|
95
89
|
}
|
|
96
90
|
|
|
97
|
-
|
|
98
|
-
fs
|
|
99
|
-
.
|
|
91
|
+
return Promise.all([
|
|
92
|
+
fs
|
|
93
|
+
.readJson(path.join(conf.path, `${componentName}/package.json`))
|
|
94
|
+
.then(x => x.version)
|
|
100
95
|
]);
|
|
101
96
|
},
|
|
102
97
|
getDataProvider(componentName: string) {
|
|
@@ -115,89 +110,49 @@ export default function repository(conf: Config): Repository {
|
|
|
115
110
|
};
|
|
116
111
|
|
|
117
112
|
const repository = {
|
|
118
|
-
getCompiledView(
|
|
119
|
-
componentName: string,
|
|
120
|
-
componentVersion: string,
|
|
121
|
-
callback: (err: Error | null, data: string) => void
|
|
122
|
-
) {
|
|
113
|
+
getCompiledView(componentName: string, componentVersion: string) {
|
|
123
114
|
if (conf.local) {
|
|
124
|
-
return
|
|
115
|
+
return Promise.resolve(local.getCompiledView(componentName));
|
|
125
116
|
}
|
|
126
117
|
|
|
127
|
-
cdn.getFile(
|
|
128
|
-
getFilePath(componentName, componentVersion, 'template.js')
|
|
129
|
-
callback
|
|
118
|
+
return cdn.getFile(
|
|
119
|
+
getFilePath(componentName, componentVersion, 'template.js')
|
|
130
120
|
);
|
|
131
121
|
},
|
|
132
|
-
getComponent(
|
|
133
|
-
componentName
|
|
134
|
-
componentVersionOrCallback:
|
|
135
|
-
| string
|
|
136
|
-
| ((err: string | null, data: Component) => void),
|
|
137
|
-
callbackMaybe?: (err: string | null, data: Component) => void
|
|
138
|
-
) {
|
|
139
|
-
const componentVersion: string | undefined =
|
|
140
|
-
typeof componentVersionOrCallback === 'function'
|
|
141
|
-
? undefined
|
|
142
|
-
: (componentVersionOrCallback as any);
|
|
143
|
-
const callback: (err: string | null, data: Component) => void =
|
|
144
|
-
typeof componentVersionOrCallback === 'function'
|
|
145
|
-
? (componentVersionOrCallback as any)
|
|
146
|
-
: callbackMaybe!;
|
|
147
|
-
|
|
148
|
-
repository.getComponentVersions(componentName, (err, allVersions) => {
|
|
149
|
-
if (err) {
|
|
150
|
-
return callback(err, undefined as any);
|
|
151
|
-
}
|
|
122
|
+
async getComponent(componentName: string, componentVersion?: string) {
|
|
123
|
+
const allVersions = await repository.getComponentVersions(componentName);
|
|
152
124
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
repositorySource
|
|
158
|
-
),
|
|
159
|
-
undefined as any
|
|
160
|
-
);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
const version = versionHandler.getAvailableVersion(
|
|
164
|
-
componentVersion,
|
|
165
|
-
allVersions
|
|
125
|
+
if (allVersions.length === 0) {
|
|
126
|
+
throw strings.errors.registry.COMPONENT_NOT_FOUND(
|
|
127
|
+
componentName,
|
|
128
|
+
repositorySource
|
|
166
129
|
);
|
|
130
|
+
}
|
|
167
131
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
componentVersion || '',
|
|
173
|
-
repositorySource
|
|
174
|
-
),
|
|
175
|
-
undefined as any
|
|
176
|
-
);
|
|
177
|
-
}
|
|
132
|
+
const version = versionHandler.getAvailableVersion(
|
|
133
|
+
componentVersion,
|
|
134
|
+
allVersions
|
|
135
|
+
);
|
|
178
136
|
|
|
179
|
-
|
|
137
|
+
if (!version) {
|
|
138
|
+
throw strings.errors.registry.COMPONENT_VERSION_NOT_FOUND(
|
|
180
139
|
componentName,
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
if (err) {
|
|
184
|
-
return callback(
|
|
185
|
-
`component not available: ${errorToString(err)}`,
|
|
186
|
-
null as any
|
|
187
|
-
);
|
|
188
|
-
}
|
|
189
|
-
callback(null, Object.assign(component, { allVersions }));
|
|
190
|
-
}
|
|
140
|
+
componentVersion || '',
|
|
141
|
+
repositorySource
|
|
191
142
|
);
|
|
192
|
-
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const component = await repository
|
|
146
|
+
.getComponentInfo(componentName, version)
|
|
147
|
+
.catch(err => {
|
|
148
|
+
throw `component not available: ${errorToString(err)}`;
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
return Object.assign(component, { allVersions });
|
|
193
152
|
},
|
|
194
|
-
getComponentInfo(
|
|
195
|
-
componentName: string,
|
|
196
|
-
componentVersion: string,
|
|
197
|
-
callback: (err: string | null, data: Component) => void
|
|
198
|
-
) {
|
|
153
|
+
getComponentInfo(componentName: string, componentVersion: string) {
|
|
199
154
|
if (conf.local) {
|
|
200
|
-
let componentInfo;
|
|
155
|
+
let componentInfo: Component;
|
|
201
156
|
|
|
202
157
|
if (componentName === 'oc-client') {
|
|
203
158
|
componentInfo = fs.readJsonSync(
|
|
@@ -213,15 +168,16 @@ export default function repository(conf: Config): Repository {
|
|
|
213
168
|
}
|
|
214
169
|
|
|
215
170
|
if (componentInfo.version === componentVersion) {
|
|
216
|
-
return
|
|
171
|
+
return Promise.resolve(componentInfo);
|
|
217
172
|
} else {
|
|
218
|
-
|
|
173
|
+
// eslint-disable-next-line prefer-promise-reject-errors
|
|
174
|
+
return Promise.reject('version not available');
|
|
219
175
|
}
|
|
220
176
|
}
|
|
221
177
|
|
|
222
|
-
cdn.getJson<Component>(
|
|
178
|
+
return cdn.getJson<Component>(
|
|
223
179
|
getFilePath(componentName, componentVersion, 'package.json'),
|
|
224
|
-
|
|
180
|
+
false
|
|
225
181
|
);
|
|
226
182
|
},
|
|
227
183
|
getComponentPath(componentName: string, componentVersion: string) {
|
|
@@ -230,54 +186,34 @@ export default function repository(conf: Config): Repository {
|
|
|
230
186
|
: `${options!['path']}${options!.componentsDir}/`;
|
|
231
187
|
return `${prefix}${componentName}/${componentVersion}/`;
|
|
232
188
|
},
|
|
233
|
-
getComponents(
|
|
189
|
+
async getComponents() {
|
|
234
190
|
if (conf.local) {
|
|
235
|
-
return
|
|
191
|
+
return local.getComponents();
|
|
236
192
|
}
|
|
237
193
|
|
|
238
|
-
componentsCache.get(
|
|
239
|
-
|
|
240
|
-
);
|
|
194
|
+
const { components } = await componentsCache.get();
|
|
195
|
+
return Object.keys(components);
|
|
241
196
|
},
|
|
242
|
-
getComponentsDetails(
|
|
243
|
-
callback: (err: string | null, data: ComponentsDetails) => void
|
|
244
|
-
) {
|
|
197
|
+
getComponentsDetails() {
|
|
245
198
|
if (conf.local) {
|
|
246
|
-
|
|
199
|
+
// when in local this won't get called
|
|
200
|
+
return Promise.resolve(null) as any;
|
|
247
201
|
}
|
|
248
202
|
|
|
249
|
-
componentsDetails.get(
|
|
203
|
+
return componentsDetails.get();
|
|
250
204
|
},
|
|
251
|
-
getComponentVersions(
|
|
252
|
-
componentName: string,
|
|
253
|
-
callback: (err: string | null, data: string[]) => void
|
|
254
|
-
) {
|
|
205
|
+
async getComponentVersions(componentName: string) {
|
|
255
206
|
if (conf.local) {
|
|
256
|
-
return local.getComponentVersions(componentName
|
|
207
|
+
return local.getComponentVersions(componentName);
|
|
257
208
|
}
|
|
258
209
|
|
|
259
|
-
componentsCache.get(
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
!!res && !!_.has(res.components, componentName)
|
|
263
|
-
? res.components[componentName]
|
|
264
|
-
: []
|
|
265
|
-
);
|
|
266
|
-
});
|
|
210
|
+
const res = await componentsCache.get();
|
|
211
|
+
|
|
212
|
+
return res.components[componentName] ? res.components[componentName] : [];
|
|
267
213
|
},
|
|
268
|
-
getDataProvider(
|
|
269
|
-
componentName: string,
|
|
270
|
-
componentVersion: string,
|
|
271
|
-
callback: (
|
|
272
|
-
err: Error | null,
|
|
273
|
-
data: {
|
|
274
|
-
content: string;
|
|
275
|
-
filePath: string;
|
|
276
|
-
}
|
|
277
|
-
) => void
|
|
278
|
-
) {
|
|
214
|
+
async getDataProvider(componentName: string, componentVersion: string) {
|
|
279
215
|
if (conf.local) {
|
|
280
|
-
return
|
|
216
|
+
return local.getDataProvider(componentName);
|
|
281
217
|
}
|
|
282
218
|
|
|
283
219
|
const filePath = getFilePath(
|
|
@@ -286,9 +222,9 @@ export default function repository(conf: Config): Repository {
|
|
|
286
222
|
'server.js'
|
|
287
223
|
);
|
|
288
224
|
|
|
289
|
-
cdn.getFile(filePath
|
|
290
|
-
|
|
291
|
-
|
|
225
|
+
const content = await cdn.getFile(filePath);
|
|
226
|
+
|
|
227
|
+
return { content, filePath };
|
|
292
228
|
},
|
|
293
229
|
getStaticClientPath: () =>
|
|
294
230
|
`${options!['path']}${getFilePath(
|
|
@@ -315,60 +251,42 @@ export default function repository(conf: Config): Repository {
|
|
|
315
251
|
|
|
316
252
|
getTemplatesInfo: () => templatesInfo,
|
|
317
253
|
getTemplate: (type: string) => templatesHash[type],
|
|
318
|
-
|
|
319
|
-
init(callback: (err: Error | null, data: ComponentsList | string) => void) {
|
|
254
|
+
async init() {
|
|
320
255
|
if (conf.local) {
|
|
321
|
-
|
|
256
|
+
// when in local this won't get called
|
|
257
|
+
return 'ok' as any;
|
|
322
258
|
}
|
|
323
259
|
|
|
324
|
-
componentsCache.load(
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
}
|
|
328
|
-
componentsDetails.refresh(componentsList, err =>
|
|
329
|
-
callback(err, componentsList)
|
|
330
|
-
);
|
|
331
|
-
});
|
|
260
|
+
const componentsList = await componentsCache.load();
|
|
261
|
+
|
|
262
|
+
return componentsDetails.refresh(componentsList);
|
|
332
263
|
},
|
|
333
|
-
publishComponent(
|
|
264
|
+
async publishComponent(
|
|
334
265
|
pkgDetails: any,
|
|
335
266
|
componentName: string,
|
|
336
|
-
componentVersion: string
|
|
337
|
-
callback: (
|
|
338
|
-
err: { code: string; msg: string } | null,
|
|
339
|
-
data: ComponentsDetails
|
|
340
|
-
) => void
|
|
267
|
+
componentVersion: string
|
|
341
268
|
) {
|
|
342
269
|
if (conf.local) {
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
},
|
|
348
|
-
undefined as any
|
|
349
|
-
);
|
|
270
|
+
throw {
|
|
271
|
+
code: strings.errors.registry.LOCAL_PUBLISH_NOT_ALLOWED_CODE,
|
|
272
|
+
msg: strings.errors.registry.LOCAL_PUBLISH_NOT_ALLOWED
|
|
273
|
+
};
|
|
350
274
|
}
|
|
351
275
|
|
|
352
276
|
if (!validator.validateComponentName(componentName)) {
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
},
|
|
358
|
-
undefined as any
|
|
359
|
-
);
|
|
277
|
+
throw {
|
|
278
|
+
code: strings.errors.registry.COMPONENT_NAME_NOT_VALID_CODE,
|
|
279
|
+
msg: strings.errors.registry.COMPONENT_NAME_NOT_VALID
|
|
280
|
+
};
|
|
360
281
|
}
|
|
361
282
|
|
|
362
283
|
if (!validator.validateVersion(componentVersion)) {
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
},
|
|
370
|
-
undefined as any
|
|
371
|
-
);
|
|
284
|
+
throw {
|
|
285
|
+
code: strings.errors.registry.COMPONENT_VERSION_NOT_VALID_CODE,
|
|
286
|
+
msg: strings.errors.registry.COMPONENT_VERSION_NOT_VALID(
|
|
287
|
+
componentVersion
|
|
288
|
+
)
|
|
289
|
+
};
|
|
372
290
|
}
|
|
373
291
|
|
|
374
292
|
const validationResult = validator.validatePackageJson(
|
|
@@ -379,69 +297,45 @@ export default function repository(conf: Config): Repository {
|
|
|
379
297
|
);
|
|
380
298
|
|
|
381
299
|
if (!validationResult.isValid) {
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
},
|
|
389
|
-
undefined as any
|
|
390
|
-
);
|
|
300
|
+
throw {
|
|
301
|
+
code: strings.errors.registry.COMPONENT_PUBLISHVALIDATION_FAIL_CODE,
|
|
302
|
+
msg: strings.errors.registry.COMPONENT_PUBLISHVALIDATION_FAIL(
|
|
303
|
+
String(validationResult.error)
|
|
304
|
+
)
|
|
305
|
+
};
|
|
391
306
|
}
|
|
392
307
|
|
|
393
|
-
repository.getComponentVersions(
|
|
394
|
-
componentName
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
err => {
|
|
421
|
-
if (err) {
|
|
422
|
-
return callback(err as any, undefined as any);
|
|
423
|
-
}
|
|
424
|
-
cdn.putDir(
|
|
425
|
-
pkgDetails.outputFolder,
|
|
426
|
-
`${
|
|
427
|
-
options!.componentsDir
|
|
428
|
-
}/${componentName}/${componentVersion}`,
|
|
429
|
-
err => {
|
|
430
|
-
if (err) {
|
|
431
|
-
return callback(err as any, undefined as any);
|
|
432
|
-
}
|
|
433
|
-
componentsCache.refresh((err, componentsList) => {
|
|
434
|
-
if (err) {
|
|
435
|
-
return callback(err as any, undefined as any);
|
|
436
|
-
}
|
|
437
|
-
componentsDetails.refresh(componentsList, callback as any);
|
|
438
|
-
});
|
|
439
|
-
}
|
|
440
|
-
);
|
|
441
|
-
}
|
|
442
|
-
);
|
|
443
|
-
}
|
|
308
|
+
const componentVersions = await repository.getComponentVersions(
|
|
309
|
+
componentName
|
|
310
|
+
);
|
|
311
|
+
|
|
312
|
+
if (
|
|
313
|
+
!versionHandler.validateNewVersion(componentVersion, componentVersions)
|
|
314
|
+
) {
|
|
315
|
+
throw {
|
|
316
|
+
code: strings.errors.registry.COMPONENT_VERSION_ALREADY_FOUND_CODE,
|
|
317
|
+
msg: strings.errors.registry.COMPONENT_VERSION_ALREADY_FOUND(
|
|
318
|
+
componentName,
|
|
319
|
+
componentVersion,
|
|
320
|
+
repositorySource
|
|
321
|
+
)
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
pkgDetails.packageJson.oc.date = getUnixUtcTimestamp();
|
|
326
|
+
|
|
327
|
+
await fs.writeJson(
|
|
328
|
+
path.join(pkgDetails.outputFolder, 'package.json'),
|
|
329
|
+
pkgDetails.packageJson
|
|
330
|
+
);
|
|
331
|
+
|
|
332
|
+
await cdn.putDir(
|
|
333
|
+
pkgDetails.outputFolder,
|
|
334
|
+
`${options!.componentsDir}/${componentName}/${componentVersion}`
|
|
444
335
|
);
|
|
336
|
+
|
|
337
|
+
const componentsList = await componentsCache.refresh();
|
|
338
|
+
return componentsDetails.refresh(componentsList);
|
|
445
339
|
}
|
|
446
340
|
};
|
|
447
341
|
|
|
@@ -2,7 +2,6 @@ import coreModules from 'builtin-modules';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import requirePackageName from 'require-package-name';
|
|
4
4
|
import tryRequire from 'try-require';
|
|
5
|
-
import _ from 'lodash';
|
|
6
5
|
|
|
7
6
|
import strings from '../../resources';
|
|
8
7
|
|
|
@@ -26,7 +25,7 @@ const throwError = (requirePath: string) => {
|
|
|
26
25
|
export default (injectedDependencies: string[]) =>
|
|
27
26
|
<T = unknown>(requirePath: string): T => {
|
|
28
27
|
const moduleName = requirePackageName(requirePath);
|
|
29
|
-
const isAllowed =
|
|
28
|
+
const isAllowed = injectedDependencies.includes(moduleName);
|
|
30
29
|
|
|
31
30
|
if (!isAllowed) {
|
|
32
31
|
return throwError(requirePath);
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { fromCallback } from 'universalify';
|
|
2
|
+
import { StorageAdapter } from 'oc-storage-adapters-utils';
|
|
3
|
+
|
|
4
|
+
type RemovePromiseOverload<T> = T extends {
|
|
5
|
+
(...args: infer B): void;
|
|
6
|
+
(...args: any[]): Promise<any>;
|
|
7
|
+
}
|
|
8
|
+
? (...args: B) => void
|
|
9
|
+
: T;
|
|
10
|
+
|
|
11
|
+
type LegacyStorageAdapter = {
|
|
12
|
+
[P in keyof StorageAdapter]: RemovePromiseOverload<StorageAdapter[P]>;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const officialAdapters = {
|
|
16
|
+
s3: { name: 'oc-s3-storage-adapter', firstPromiseBasedVersion: '1.2.0' },
|
|
17
|
+
gs: { name: 'oc-gs-storage-adapter', firstPromiseBasedVersion: '1.1.0' },
|
|
18
|
+
'azure-blob-storage': {
|
|
19
|
+
name: 'oc-azure-storage-adapter',
|
|
20
|
+
firstPromiseBasedVersion: '0.1.0'
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
type OfficialAdapter = keyof typeof officialAdapters;
|
|
24
|
+
|
|
25
|
+
function isOfficialAdapter(
|
|
26
|
+
adapter: LegacyStorageAdapter
|
|
27
|
+
): adapter is LegacyStorageAdapter & { adapterType: OfficialAdapter } {
|
|
28
|
+
return Object.keys(officialAdapters).includes(
|
|
29
|
+
adapter.adapterType as OfficialAdapter
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function isPromiseBased(tryFunction: () => unknown) {
|
|
34
|
+
try {
|
|
35
|
+
(tryFunction as () => Promise<unknown>)().catch(() => {
|
|
36
|
+
// To not throw unhandled promise exceptions
|
|
37
|
+
});
|
|
38
|
+
return true;
|
|
39
|
+
} catch (err) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function isLegacyAdapter(
|
|
45
|
+
adapter: StorageAdapter | LegacyStorageAdapter
|
|
46
|
+
): adapter is LegacyStorageAdapter {
|
|
47
|
+
return !isPromiseBased(() => (adapter as StorageAdapter).getFile(''));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function convertLegacyAdapter(adapter: LegacyStorageAdapter): StorageAdapter {
|
|
51
|
+
return {
|
|
52
|
+
getFile: fromCallback(adapter.getFile),
|
|
53
|
+
getJson: fromCallback(adapter.getJson),
|
|
54
|
+
listSubDirectories: fromCallback(adapter.listSubDirectories),
|
|
55
|
+
putDir: fromCallback(adapter.putDir),
|
|
56
|
+
putFile: fromCallback(adapter.putFile),
|
|
57
|
+
putFileContent: fromCallback(adapter.putFileContent),
|
|
58
|
+
getUrl: adapter.getUrl,
|
|
59
|
+
maxConcurrentRequests: adapter.maxConcurrentRequests,
|
|
60
|
+
adapterType: adapter.adapterType
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export default function getPromiseBasedAdapter(
|
|
65
|
+
adapter: StorageAdapter | LegacyStorageAdapter
|
|
66
|
+
): StorageAdapter {
|
|
67
|
+
if (isLegacyAdapter(adapter)) {
|
|
68
|
+
if (isOfficialAdapter(adapter)) {
|
|
69
|
+
const pkg = officialAdapters[adapter.adapterType];
|
|
70
|
+
process.emitWarning(
|
|
71
|
+
`Adapters now should work with promises. Consider upgrading your package ${pkg.name} to at least version ${pkg.firstPromiseBasedVersion}`,
|
|
72
|
+
'DeprecationWarning'
|
|
73
|
+
);
|
|
74
|
+
} else {
|
|
75
|
+
process.emitWarning(
|
|
76
|
+
'Your adapter is using the old interface of working with callbacks. Consider upgrading it to work with promises, as the previous one will be deprecated.',
|
|
77
|
+
'DeprecationWarning'
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return convertLegacyAdapter(adapter);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return adapter;
|
|
85
|
+
}
|