oc 0.49.7 → 0.49.8
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 +22 -0
- package/README.md +2 -15
- package/dist/cli/domain/clean.d.ts +2 -2
- package/dist/cli/domain/clean.js +10 -13
- package/dist/cli/domain/get-components-by-dir.d.ts +1 -1
- package/dist/cli/domain/get-components-by-dir.js +8 -15
- package/dist/cli/domain/get-mocked-plugins.js +8 -6
- package/dist/cli/domain/handle-dependencies/ensure-compiler-is-declared-as-devDependency.d.ts +1 -1
- package/dist/cli/domain/handle-dependencies/ensure-compiler-is-declared-as-devDependency.js +4 -5
- package/dist/cli/domain/handle-dependencies/get-compiler.d.ts +1 -1
- package/dist/cli/domain/handle-dependencies/get-compiler.js +3 -3
- package/dist/cli/domain/handle-dependencies/index.d.ts +4 -3
- package/dist/cli/domain/handle-dependencies/index.js +40 -34
- package/dist/cli/domain/handle-dependencies/install-compiler.d.ts +1 -1
- package/dist/cli/domain/handle-dependencies/install-compiler.js +14 -7
- package/dist/cli/domain/handle-dependencies/install-missing-dependencies.d.ts +1 -1
- package/dist/cli/domain/handle-dependencies/install-missing-dependencies.js +13 -9
- package/dist/cli/domain/handle-dependencies/link-missing-dependencies.d.ts +1 -1
- package/dist/cli/domain/handle-dependencies/link-missing-dependencies.js +4 -8
- package/dist/cli/domain/init-template/index.d.ts +2 -2
- package/dist/cli/domain/init-template/index.js +6 -8
- package/dist/cli/domain/init-template/install-template.d.ts +2 -2
- package/dist/cli/domain/init-template/install-template.js +10 -9
- package/dist/cli/domain/init-template/scaffold.d.ts +2 -2
- package/dist/cli/domain/init-template/scaffold.js +7 -7
- package/dist/cli/domain/local.js +11 -10
- package/dist/cli/domain/mock.d.ts +1 -1
- package/dist/cli/domain/mock.js +21 -21
- package/dist/cli/domain/package-components.d.ts +1 -1
- package/dist/cli/domain/package-components.js +14 -17
- package/dist/cli/domain/registry.js +68 -81
- package/dist/cli/domain/watch.js +1 -1
- package/dist/cli/facade/clean.d.ts +10 -4
- package/dist/cli/facade/clean.js +38 -28
- package/dist/cli/facade/dev.d.ts +108 -15
- package/dist/cli/facade/dev.js +85 -99
- package/dist/cli/facade/init.d.ts +12 -5
- package/dist/cli/facade/init.js +22 -20
- package/dist/cli/facade/mock.d.ts +12 -5
- package/dist/cli/facade/mock.js +5 -6
- package/dist/cli/facade/package.d.ts +12 -5
- package/dist/cli/facade/package.js +30 -32
- package/dist/cli/facade/preview.d.ts +8 -3
- package/dist/cli/facade/preview.js +12 -10
- package/dist/cli/facade/publish.d.ts +16 -7
- package/dist/cli/facade/publish.js +94 -114
- package/dist/cli/facade/registry-add.d.ts +8 -3
- package/dist/cli/facade/registry-add.js +10 -9
- package/dist/cli/facade/registry-ls.d.ts +4 -1
- package/dist/cli/facade/registry-ls.js +19 -17
- package/dist/cli/facade/registry-remove.d.ts +8 -3
- package/dist/cli/facade/registry-remove.js +10 -9
- package/dist/cli/facade/registry.d.ts +4 -1
- package/dist/cli/facade/registry.js +6 -3
- package/dist/cli/index.js +3 -5
- package/dist/cli/programmatic-api.d.ts +1 -1
- package/dist/components/oc-client/_package/package.json +1 -1
- package/dist/components/oc-client/package.json +1 -1
- package/dist/registry/app-start.d.ts +2 -2
- package/dist/registry/app-start.js +20 -20
- package/dist/registry/domain/components-cache/components-list.d.ts +7 -6
- package/dist/registry/domain/components-cache/components-list.js +31 -45
- package/dist/registry/domain/components-cache/index.d.ts +6 -5
- package/dist/registry/domain/components-cache/index.js +47 -50
- package/dist/registry/domain/components-details.d.ts +5 -4
- package/dist/registry/domain/components-details.js +27 -38
- package/dist/registry/domain/extract-package.d.ts +2 -2
- package/dist/registry/domain/extract-package.js +9 -12
- package/dist/registry/domain/get-package-json-from-temp-dir.d.ts +1 -1
- package/dist/registry/domain/get-package-json-from-temp-dir.js +2 -2
- package/dist/registry/domain/nested-renderer.d.ts +7 -6
- package/dist/registry/domain/nested-renderer.js +36 -72
- package/dist/registry/domain/options-sanitiser.js +5 -3
- package/dist/registry/domain/plugins-initialiser.d.ts +3 -1
- package/dist/registry/domain/plugins-initialiser.js +29 -33
- package/dist/registry/domain/repository.js +78 -100
- package/dist/registry/domain/require-wrapper.js +1 -2
- package/dist/registry/domain/storage-adapter.d.ts +10 -0
- package/dist/registry/domain/storage-adapter.js +55 -0
- package/dist/registry/index.d.ts +2 -2
- package/dist/registry/index.js +15 -28
- package/dist/registry/middleware/index.d.ts +6 -2
- package/dist/registry/middleware/index.js +5 -1
- package/dist/registry/router.d.ts +2 -2
- package/dist/registry/router.js +0 -2
- package/dist/registry/routes/component-info.js +3 -2
- package/dist/registry/routes/component-preview.js +2 -1
- package/dist/registry/routes/components.js +1 -1
- package/dist/registry/routes/helpers/get-component-fallback.d.ts +2 -7
- package/dist/registry/routes/helpers/get-component.d.ts +5 -5
- package/dist/registry/routes/helpers/get-component.js +6 -5
- package/dist/registry/routes/helpers/is-url-discoverable.d.ts +2 -2
- package/dist/registry/routes/helpers/is-url-discoverable.js +15 -9
- package/dist/registry/routes/index.js +4 -3
- package/dist/registry/routes/publish.d.ts +1 -1
- package/dist/registry/routes/publish.js +32 -31
- package/dist/resources/settings.js +1 -1
- package/dist/types.d.ts +35 -43
- package/dist/utils/npm-utils.d.ts +6 -8
- package/dist/utils/npm-utils.js +20 -9
- package/dist/utils/put.d.ts +2 -1
- package/dist/utils/put.js +10 -29
- 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/registry/app-start.ts +27 -31
- 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/resources/settings.ts +1 -1
- package/src/types.ts +63 -136
- 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
|
}
|
|
@@ -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
|
}
|