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
|
@@ -24,6 +24,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
25
|
const parse_author_1 = __importDefault(require("parse-author"));
|
|
26
26
|
const lodash_1 = __importDefault(require("lodash"));
|
|
27
|
+
const universalify_1 = require("universalify");
|
|
27
28
|
const getComponentFallback = __importStar(require("./helpers/get-component-fallback"));
|
|
28
29
|
const info_1 = __importDefault(require("../views/info"));
|
|
29
30
|
const is_url_discoverable_1 = __importDefault(require("./helpers/is-url-discoverable"));
|
|
@@ -55,7 +56,7 @@ function componentInfo(err, req, res, component) {
|
|
|
55
56
|
const parsedAuthor = getParsedAuthor(component);
|
|
56
57
|
let href = res.conf.baseUrl;
|
|
57
58
|
const repositoryUrl = lodash_1.default.get(component, 'repository.url', typeof component.repository === 'string' ? component.repository : null);
|
|
58
|
-
(0, is_url_discoverable_1.default)(href, (_err, result) => {
|
|
59
|
+
(0, universalify_1.fromPromise)(is_url_discoverable_1.default)(href, (_err, result) => {
|
|
59
60
|
if (!result.isDiscoverable) {
|
|
60
61
|
href = `//${req.headers.host}${res.conf.prefix}`;
|
|
61
62
|
}
|
|
@@ -78,7 +79,7 @@ function componentInfo(err, req, res, component) {
|
|
|
78
79
|
}
|
|
79
80
|
function componentInfoRoute(conf, repository) {
|
|
80
81
|
return function (req, res) {
|
|
81
|
-
repository.getComponent(req.params['componentName'], req.params['componentVersion'], (registryError, component) => {
|
|
82
|
+
(0, universalify_1.fromPromise)(repository.getComponent)(req.params['componentName'], req.params['componentVersion'], (registryError, component) => {
|
|
82
83
|
if (registryError && conf.fallbackRegistryUrl) {
|
|
83
84
|
return getComponentFallback.getComponentInfo(conf, req, res, registryError, (fallbackError, fallbackComponent) => componentInfo(fallbackError, req, res, fallbackComponent));
|
|
84
85
|
}
|
|
@@ -25,6 +25,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
25
25
|
const getComponentFallback = __importStar(require("./helpers/get-component-fallback"));
|
|
26
26
|
const preview_1 = __importDefault(require("../views/preview"));
|
|
27
27
|
const urlBuilder = __importStar(require("../domain/url-builder"));
|
|
28
|
+
const universalify_1 = require("universalify");
|
|
28
29
|
function componentPreview(err, req, res, component, templates) {
|
|
29
30
|
if (err) {
|
|
30
31
|
res.errorDetails = err.registryError || err;
|
|
@@ -54,7 +55,7 @@ function componentPreview(err, req, res, component, templates) {
|
|
|
54
55
|
}
|
|
55
56
|
function componentPreviewRoute(conf, repository) {
|
|
56
57
|
return (req, res) => {
|
|
57
|
-
repository.getComponent(req.params['componentName'], req.params['componentVersion'], (registryError, component) => {
|
|
58
|
+
(0, universalify_1.fromPromise)(repository.getComponent)(req.params['componentName'], req.params['componentVersion'], (registryError, component) => {
|
|
58
59
|
if (registryError && conf.fallbackRegistryUrl) {
|
|
59
60
|
return getComponentFallback.getComponentPreview(conf, req, res, registryError, (fallbackError, fallbackComponent) => {
|
|
60
61
|
componentPreview(fallbackError, req, res, fallbackComponent, repository.getTemplatesInfo());
|
|
@@ -31,7 +31,7 @@ function components(conf, repository) {
|
|
|
31
31
|
return returnError(registryErrors.BATCH_ROUTE_COMPONENTS_NOT_ARRAY);
|
|
32
32
|
}
|
|
33
33
|
if (!lodash_1.default.isEmpty(components)) {
|
|
34
|
-
const errors = lodash_1.default.compact(
|
|
34
|
+
const errors = lodash_1.default.compact(components.map((component, index) => {
|
|
35
35
|
return !component.name
|
|
36
36
|
? registryErrors.BATCH_ROUTE_COMPONENT_NAME_MISSING(index)
|
|
37
37
|
: '';
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { Request, Response } from 'express';
|
|
3
3
|
import { IncomingHttpHeaders } from 'http';
|
|
4
4
|
import { Component, Config } from '../../../types';
|
|
5
|
+
import { GetComponentResult } from './get-component';
|
|
5
6
|
declare type ComponentCallback = (err: {
|
|
6
7
|
registryError: any;
|
|
7
8
|
fallbackError: any;
|
|
@@ -10,13 +11,7 @@ export declare function getComponent(fallbackRegistryUrl: string, headers: Incom
|
|
|
10
11
|
name: string;
|
|
11
12
|
version: string;
|
|
12
13
|
parameters: IncomingHttpHeaders;
|
|
13
|
-
}, callback: (result:
|
|
14
|
-
status: number;
|
|
15
|
-
response: {
|
|
16
|
-
code: string;
|
|
17
|
-
error: Error;
|
|
18
|
-
};
|
|
19
|
-
} | Component) => void): void;
|
|
14
|
+
}, callback: (result: GetComponentResult) => void): void;
|
|
20
15
|
export declare function getComponentPreview(conf: Config, req: Request, res: Response, registryError: string | null, callback: ComponentCallback): void;
|
|
21
16
|
export declare function getComponentInfo(conf: Config, req: Request, res: Response, registryError: string | null, callback: ComponentCallback): void;
|
|
22
17
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Config, Repository } from '../../../types';
|
|
3
3
|
import { IncomingHttpHeaders } from 'http';
|
|
4
|
-
interface
|
|
4
|
+
export interface RendererOptions {
|
|
5
5
|
conf: Config;
|
|
6
6
|
headers: IncomingHttpHeaders;
|
|
7
7
|
ip: string;
|
|
@@ -10,7 +10,7 @@ interface Options {
|
|
|
10
10
|
version: string;
|
|
11
11
|
omitHref?: boolean;
|
|
12
12
|
}
|
|
13
|
-
export
|
|
13
|
+
export interface GetComponentResult {
|
|
14
14
|
status: number;
|
|
15
15
|
headers?: Record<string, string>;
|
|
16
16
|
response: {
|
|
@@ -18,6 +18,7 @@ export declare type GetComponentResult = {
|
|
|
18
18
|
code?: string;
|
|
19
19
|
error?: unknown;
|
|
20
20
|
version?: string;
|
|
21
|
+
html?: string;
|
|
21
22
|
requestVersion?: string;
|
|
22
23
|
name?: string;
|
|
23
24
|
details?: {
|
|
@@ -28,6 +29,5 @@ export declare type GetComponentResult = {
|
|
|
28
29
|
missingPlugins?: string[];
|
|
29
30
|
missingDependencies?: string[];
|
|
30
31
|
};
|
|
31
|
-
}
|
|
32
|
-
export default function getComponent(conf: Config, repository: Repository): (options:
|
|
33
|
-
export {};
|
|
32
|
+
}
|
|
33
|
+
export default function getComponent(conf: Config, repository: Repository): (options: RendererOptions, cb: (result: GetComponentResult) => void) => void;
|
|
@@ -41,6 +41,7 @@ const settings_1 = __importDefault(require("../../../resources/settings"));
|
|
|
41
41
|
const resources_1 = __importDefault(require("../../../resources"));
|
|
42
42
|
const urlBuilder = __importStar(require("../../domain/url-builder"));
|
|
43
43
|
const validator = __importStar(require("../../domain/validators"));
|
|
44
|
+
const universalify_1 = require("universalify");
|
|
44
45
|
function getComponent(conf, repository) {
|
|
45
46
|
const client = (0, oc_client_1.default)({ templates: conf.templates });
|
|
46
47
|
const cache = new nice_cache_1.default({
|
|
@@ -75,7 +76,7 @@ function getComponent(conf, repository) {
|
|
|
75
76
|
version: options.version || '',
|
|
76
77
|
parameters: options.parameters
|
|
77
78
|
};
|
|
78
|
-
repository.getComponent(requestedComponent.name, requestedComponent.version, (err, component) => {
|
|
79
|
+
(0, universalify_1.fromPromise)(repository.getComponent)(requestedComponent.name, requestedComponent.version, (err, component) => {
|
|
79
80
|
// check route exist for component and version
|
|
80
81
|
if (err) {
|
|
81
82
|
if (conf.fallbackRegistryUrl) {
|
|
@@ -264,7 +265,7 @@ function getComponent(conf, repository) {
|
|
|
264
265
|
returnResult(cached);
|
|
265
266
|
}
|
|
266
267
|
else {
|
|
267
|
-
repository.getCompiledView(component.name, component.version, (_err, templateText) => {
|
|
268
|
+
(0, universalify_1.fromPromise)(repository.getCompiledView)(component.name, component.version, (_err, templateText) => {
|
|
268
269
|
let ocTemplate;
|
|
269
270
|
try {
|
|
270
271
|
ocTemplate = repository.getTemplate(templateType);
|
|
@@ -299,8 +300,8 @@ function getComponent(conf, repository) {
|
|
|
299
300
|
env: conf.env,
|
|
300
301
|
params,
|
|
301
302
|
plugins: conf.plugins,
|
|
302
|
-
renderComponent: nestedRenderer.renderComponent,
|
|
303
|
-
renderComponents: nestedRenderer.renderComponents,
|
|
303
|
+
renderComponent: (0, universalify_1.fromPromise)(nestedRenderer.renderComponent),
|
|
304
|
+
renderComponents: (0, universalify_1.fromPromise)(nestedRenderer.renderComponents),
|
|
304
305
|
requestHeaders: options.headers,
|
|
305
306
|
requestIp: options.ip,
|
|
306
307
|
setEmptyResponse,
|
|
@@ -342,7 +343,7 @@ function getComponent(conf, repository) {
|
|
|
342
343
|
}
|
|
343
344
|
}
|
|
344
345
|
else {
|
|
345
|
-
repository.getDataProvider(component.name, component.version, (err, dataProvider) => {
|
|
346
|
+
(0, universalify_1.fromPromise)(repository.getDataProvider)(component.name, component.version, (err, dataProvider) => {
|
|
346
347
|
if (err) {
|
|
347
348
|
componentCallbackDone = true;
|
|
348
349
|
return callback({
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export default function isUrlDiscoverable(url: string
|
|
1
|
+
export default function isUrlDiscoverable(url: string): Promise<{
|
|
2
2
|
isDiscoverable: boolean;
|
|
3
|
-
}
|
|
3
|
+
}>;
|
|
@@ -3,14 +3,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
7
|
-
function isUrlDiscoverable(url
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
6
|
+
const got_1 = __importDefault(require("got"));
|
|
7
|
+
async function isUrlDiscoverable(url) {
|
|
8
|
+
var _a;
|
|
9
|
+
try {
|
|
10
|
+
const res = await (0, got_1.default)(url, {
|
|
11
|
+
headers: { accept: 'text/html' }
|
|
12
|
+
});
|
|
13
|
+
const isHtml = !!((_a = res.headers['content-type']) === null || _a === void 0 ? void 0 : _a.includes('text/html'));
|
|
14
|
+
return {
|
|
15
|
+
isDiscoverable: isHtml
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
catch (err) {
|
|
19
|
+
return { isDiscoverable: false };
|
|
20
|
+
}
|
|
15
21
|
}
|
|
16
22
|
exports.default = isUrlDiscoverable;
|
|
@@ -13,6 +13,7 @@ const get_components_history_1 = __importDefault(require("./helpers/get-componen
|
|
|
13
13
|
const get_available_dependencies_1 = __importDefault(require("./helpers/get-available-dependencies"));
|
|
14
14
|
const views_1 = __importDefault(require("../views"));
|
|
15
15
|
const urlBuilder = require("../domain/url-builder");
|
|
16
|
+
const universalify_1 = require("universalify");
|
|
16
17
|
const packageInfo = fs_extra_1.default.readJsonSync(path_1.default.join(__dirname, '..', '..', '..', 'package.json'));
|
|
17
18
|
const getParsedAuthor = (author) => {
|
|
18
19
|
author = author || {};
|
|
@@ -22,7 +23,7 @@ const mapComponentDetails = (component) => Object.assign(component, { author: ge
|
|
|
22
23
|
const isHtmlRequest = (headers) => !!headers.accept && headers.accept.indexOf('text/html') >= 0;
|
|
23
24
|
function default_1(repository) {
|
|
24
25
|
return (req, res, next) => {
|
|
25
|
-
repository.getComponents((err, components) => {
|
|
26
|
+
(0, universalify_1.fromPromise)(repository.getComponents)((err, components) => {
|
|
26
27
|
if (err) {
|
|
27
28
|
res.errorDetails = 'cdn not available';
|
|
28
29
|
res.status(404).json({ error: res.errorDetails });
|
|
@@ -37,7 +38,7 @@ function default_1(repository) {
|
|
|
37
38
|
let componentsInfo = [];
|
|
38
39
|
let componentsReleases = 0;
|
|
39
40
|
const stateCounts = {};
|
|
40
|
-
async_1.default.each(components, (component, callback) => repository.getComponent(component, (err, result) => {
|
|
41
|
+
async_1.default.each(components, (component, callback) => (0, universalify_1.fromPromise)(repository.getComponent)(component, undefined, (err, result) => {
|
|
41
42
|
if (err)
|
|
42
43
|
return callback(err);
|
|
43
44
|
if (result.oc && result.oc.date) {
|
|
@@ -50,7 +51,7 @@ function default_1(repository) {
|
|
|
50
51
|
if (err)
|
|
51
52
|
return next(err);
|
|
52
53
|
componentsInfo = lodash_1.default.sortBy(componentsInfo, 'name');
|
|
53
|
-
repository.getComponentsDetails((err, details) => {
|
|
54
|
+
(0, universalify_1.fromPromise)(repository.getComponentsDetails)((err, details) => {
|
|
54
55
|
// eslint-disable-next-line no-console
|
|
55
56
|
if (err)
|
|
56
57
|
console.log(err);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { Request, Response } from 'express';
|
|
2
2
|
import { Repository } from '../../types';
|
|
3
|
-
export default function publish(repository: Repository): (req: Request, res: Response) => void
|
|
3
|
+
export default function publish(repository: Repository): (req: Request, res: Response) => Promise<void>;
|
|
@@ -26,7 +26,7 @@ const extract_package_1 = __importDefault(require("../domain/extract-package"));
|
|
|
26
26
|
const index_1 = __importDefault(require("../../resources/index"));
|
|
27
27
|
const validator = __importStar(require("../domain/validators"));
|
|
28
28
|
function publish(repository) {
|
|
29
|
-
return function (req, res) {
|
|
29
|
+
return async function (req, res) {
|
|
30
30
|
if (!req.params['componentName'] || !req.params['componentVersion']) {
|
|
31
31
|
res.errorDetails = 'malformed request';
|
|
32
32
|
res.status(409).json({ error: res.errorDetails });
|
|
@@ -59,38 +59,39 @@ function publish(repository) {
|
|
|
59
59
|
});
|
|
60
60
|
return;
|
|
61
61
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
62
|
+
try {
|
|
63
|
+
const pkgDetails = await (0, extract_package_1.default)(files);
|
|
64
|
+
try {
|
|
65
|
+
await repository.publishComponent(pkgDetails, req.params['componentName'], req.params['componentVersion']);
|
|
66
|
+
res.status(200).json({ ok: true });
|
|
67
67
|
}
|
|
68
|
-
|
|
69
|
-
if (err) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return res.status(403).json({ error: err.msg });
|
|
73
|
-
}
|
|
74
|
-
else if (err.code === 'already_exists') {
|
|
75
|
-
res.errorDetails = `Component already exists: ${err.msg}`;
|
|
76
|
-
return res.status(403).json({ error: err.msg });
|
|
77
|
-
}
|
|
78
|
-
else if (err.code === 'name_not_valid') {
|
|
79
|
-
res.errorDetails = `Component name not valid: ${err.msg}`;
|
|
80
|
-
return res.status(409).json({ error: err.msg });
|
|
81
|
-
}
|
|
82
|
-
else if (err.code === 'version_not_valid') {
|
|
83
|
-
res.errorDetails = `Component version not valid: ${err.msg}`;
|
|
84
|
-
return res.status(409).json({ error: err.msg });
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
res.errorDetails = `Publish failed: ${err.msg}`;
|
|
88
|
-
return res.status(500).json({ error: err.msg });
|
|
89
|
-
}
|
|
68
|
+
catch (err) {
|
|
69
|
+
if (err.code === 'not_allowed') {
|
|
70
|
+
res.errorDetails = `Publish not allowed: ${err.msg}`;
|
|
71
|
+
res.status(403).json({ error: err.msg });
|
|
90
72
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
73
|
+
else if (err.code === 'already_exists') {
|
|
74
|
+
res.errorDetails = `Component already exists: ${err.msg}`;
|
|
75
|
+
res.status(403).json({ error: err.msg });
|
|
76
|
+
}
|
|
77
|
+
else if (err.code === 'name_not_valid') {
|
|
78
|
+
res.errorDetails = `Component name not valid: ${err.msg}`;
|
|
79
|
+
res.status(409).json({ error: err.msg });
|
|
80
|
+
}
|
|
81
|
+
else if (err.code === 'version_not_valid') {
|
|
82
|
+
res.errorDetails = `Component version not valid: ${err.msg}`;
|
|
83
|
+
res.status(409).json({ error: err.msg });
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
res.errorDetails = `Publish failed: ${err.msg}`;
|
|
87
|
+
res.status(500).json({ error: err.msg });
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
catch (err) {
|
|
92
|
+
res.errorDetails = `Package is not valid: ${err}`;
|
|
93
|
+
res.status(500).json({ error: 'package is not valid', details: err });
|
|
94
|
+
}
|
|
94
95
|
};
|
|
95
96
|
}
|
|
96
97
|
exports.default = publish;
|
|
@@ -4,7 +4,7 @@ exports.default = {
|
|
|
4
4
|
configFile: {
|
|
5
5
|
src: './oc.json'
|
|
6
6
|
},
|
|
7
|
-
filesToIgnoreOnDevWatch: /node_modules|package\.tar\.gz|_package|\.sw[op]|\.git\/|\.idea\/|\.DS_Store|oc\.json/,
|
|
7
|
+
filesToIgnoreOnDevWatch: /temp\/__oc|node_modules|package\.tar\.gz|_package|\.sw[op]|\.git\/|\.idea\/|\.DS_Store|oc\.json/,
|
|
8
8
|
maxLoopIterations: 1e9,
|
|
9
9
|
registry: {
|
|
10
10
|
acceptRenderedHeader: 'application/vnd.oc.rendered+json',
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { NextFunction, Request, Response } from 'express';
|
|
3
2
|
import { Logger } from './cli/logger';
|
|
4
3
|
import { PackageJson } from 'type-fest';
|
|
@@ -40,6 +39,15 @@ export interface ComponentsList {
|
|
|
40
39
|
components: Record<string, string[]>;
|
|
41
40
|
lastEdit: number;
|
|
42
41
|
}
|
|
42
|
+
export interface OcJsonConfig {
|
|
43
|
+
registries?: string[];
|
|
44
|
+
mocks?: {
|
|
45
|
+
plugins?: {
|
|
46
|
+
dynamic?: Record<string, string>;
|
|
47
|
+
static?: Record<string, string>;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
}
|
|
43
51
|
export interface OcParameter {
|
|
44
52
|
default?: string | boolean | number;
|
|
45
53
|
description?: string;
|
|
@@ -175,18 +183,6 @@ export interface Config {
|
|
|
175
183
|
timeout: number;
|
|
176
184
|
verbosity: number;
|
|
177
185
|
}
|
|
178
|
-
export interface Cdn {
|
|
179
|
-
adapterType: string;
|
|
180
|
-
getFile: (filePath: string, cb: (err: Error | null, data: string) => void) => void;
|
|
181
|
-
getJson<T>(filePath: string, force: boolean, cb: (err: string | null, data: T) => void): void;
|
|
182
|
-
getJson<T>(filePath: string, cb: (err: string | null, data: T) => void): void;
|
|
183
|
-
listSubDirectories: (dir: string, cb: (err: (Error & {
|
|
184
|
-
code?: string;
|
|
185
|
-
}) | null, data: string[]) => void) => void;
|
|
186
|
-
maxConcurrentRequests: number;
|
|
187
|
-
putDir: (folderPath: string, filePath: string, cb: (err: Error | null) => void) => void;
|
|
188
|
-
putFileContent: (data: unknown, path: string, isPrivate: boolean, callback: (err: string | null, data: unknown) => void) => void;
|
|
189
|
-
}
|
|
190
186
|
declare type CompiledTemplate = (model: unknown) => string;
|
|
191
187
|
interface CompilerOptions {
|
|
192
188
|
componentPackage: PackageJson & {
|
|
@@ -210,78 +206,74 @@ export interface Template {
|
|
|
210
206
|
}, cb: (err: Error | null, data: string) => void) => void;
|
|
211
207
|
}
|
|
212
208
|
export interface Plugin {
|
|
213
|
-
callback?: (
|
|
209
|
+
callback?: (error: unknown) => void;
|
|
214
210
|
description?: string;
|
|
215
211
|
name: string;
|
|
216
212
|
options?: any;
|
|
217
213
|
register: {
|
|
218
|
-
register: (options: unknown, dependencies: unknown, next: () => void) => void;
|
|
214
|
+
register: (options: unknown, dependencies: unknown, next: (error?: unknown) => void) => void;
|
|
219
215
|
execute: (...args: unknown[]) => unknown;
|
|
220
216
|
dependencies?: string[];
|
|
221
217
|
};
|
|
222
218
|
}
|
|
223
219
|
export interface RegistryCli {
|
|
224
|
-
add(registry: string
|
|
225
|
-
get(
|
|
226
|
-
getApiComponentByHref(href: string
|
|
227
|
-
getComponentPreviewUrlByUrl(componentHref: string
|
|
220
|
+
add(registry: string): Promise<void>;
|
|
221
|
+
get(): Promise<string[]>;
|
|
222
|
+
getApiComponentByHref(href: string): Promise<Component>;
|
|
223
|
+
getComponentPreviewUrlByUrl(componentHref: string): Promise<string>;
|
|
228
224
|
putComponent(options: {
|
|
229
225
|
username?: string;
|
|
230
226
|
password?: string;
|
|
231
227
|
route: string;
|
|
232
228
|
path: string;
|
|
233
|
-
}
|
|
234
|
-
remove(registry: string
|
|
229
|
+
}): Promise<void>;
|
|
230
|
+
remove(registry: string): Promise<void>;
|
|
235
231
|
}
|
|
236
232
|
export interface Local {
|
|
237
233
|
clean: {
|
|
238
|
-
fetchList: (dirPath: string
|
|
239
|
-
remove: (list: string[]
|
|
234
|
+
fetchList: (dirPath: string) => Promise<string[]>;
|
|
235
|
+
remove: (list: string[]) => Promise<void>;
|
|
240
236
|
};
|
|
241
|
-
cleanup: (compressedPackagePath: string
|
|
242
|
-
compress: (input: string, output: string
|
|
243
|
-
getComponentsByDir: (componentsDir: string, componentsToRun
|
|
237
|
+
cleanup: (compressedPackagePath: string) => Promise<void>;
|
|
238
|
+
compress: (input: string, output: string) => Promise<void>;
|
|
239
|
+
getComponentsByDir: (componentsDir: string, componentsToRun?: string[]) => Promise<string[]>;
|
|
244
240
|
init: (options: {
|
|
245
241
|
componentName: string;
|
|
246
242
|
logger: Logger;
|
|
247
243
|
componentPath: string;
|
|
248
244
|
templateType: string;
|
|
249
|
-
}
|
|
245
|
+
}) => Promise<void>;
|
|
250
246
|
mock: (params: {
|
|
251
247
|
targetType: string;
|
|
252
248
|
targetValue: string;
|
|
253
249
|
targetName: string;
|
|
254
|
-
}
|
|
250
|
+
}) => Promise<void>;
|
|
255
251
|
package: (options: {
|
|
256
252
|
componentPath: string;
|
|
257
253
|
minify?: boolean;
|
|
258
254
|
verbose?: boolean;
|
|
259
255
|
production?: boolean;
|
|
260
|
-
}
|
|
256
|
+
}) => Promise<Component>;
|
|
261
257
|
}
|
|
262
258
|
export interface Repository {
|
|
263
|
-
getCompiledView(componentName: string, componentVersion: string
|
|
264
|
-
getComponent(componentName: string, componentVersion
|
|
265
|
-
|
|
266
|
-
getComponentInfo(componentName: string, componentVersion: string, callback: (err: string | null, data: Component) => void): void;
|
|
259
|
+
getCompiledView(componentName: string, componentVersion: string): Promise<string>;
|
|
260
|
+
getComponent(componentName: string, componentVersion?: string): Promise<Component>;
|
|
261
|
+
getComponentInfo(componentName: string, componentVersion: string): Promise<Component>;
|
|
267
262
|
getComponentPath(componentName: string, componentVersion: string): void;
|
|
268
|
-
getComponents(
|
|
269
|
-
getComponentsDetails(
|
|
270
|
-
getComponentVersions(componentName: string
|
|
271
|
-
getDataProvider(componentName: string, componentVersion: string
|
|
263
|
+
getComponents(): Promise<string[]>;
|
|
264
|
+
getComponentsDetails(): Promise<ComponentsDetails>;
|
|
265
|
+
getComponentVersions(componentName: string): Promise<string[]>;
|
|
266
|
+
getDataProvider(componentName: string, componentVersion: string): Promise<{
|
|
272
267
|
content: string;
|
|
273
268
|
filePath: string;
|
|
274
|
-
}
|
|
269
|
+
}>;
|
|
275
270
|
getStaticClientMapPath: () => string;
|
|
276
271
|
getStaticClientPath: () => string;
|
|
277
272
|
getStaticFilePath: (componentName: string, componentVersion: string, filePath: string) => string;
|
|
278
273
|
getTemplate: (type: string) => Template;
|
|
279
274
|
getTemplatesInfo: () => TemplateInfo[];
|
|
280
|
-
init(
|
|
281
|
-
publishComponent(pkgDetails: any, componentName: string, componentVersion: string
|
|
282
|
-
code: string;
|
|
283
|
-
msg: string;
|
|
284
|
-
} | null, data: ComponentsDetails) => void): void;
|
|
275
|
+
init(): Promise<ComponentsList>;
|
|
276
|
+
publishComponent(pkgDetails: any, componentName: string, componentVersion: string): Promise<ComponentsDetails>;
|
|
285
277
|
}
|
|
286
278
|
declare global {
|
|
287
279
|
namespace Express {
|
|
@@ -1,22 +1,20 @@
|
|
|
1
|
-
declare type NoParameterCallback<T = unknown> = (err: T) => void;
|
|
2
1
|
export declare const init: (options: {
|
|
3
2
|
initPath: string;
|
|
4
3
|
silent: boolean;
|
|
5
|
-
}
|
|
4
|
+
}) => Promise<void>;
|
|
6
5
|
export declare const installDependencies: (options: {
|
|
7
6
|
dependencies: string[];
|
|
8
7
|
installPath: string;
|
|
9
8
|
silent: boolean;
|
|
10
9
|
usePrefix: boolean;
|
|
11
|
-
}
|
|
12
|
-
dest: string;
|
|
13
|
-
}
|
|
10
|
+
}) => Promise<{
|
|
11
|
+
dest: string[];
|
|
12
|
+
}>;
|
|
14
13
|
export declare const installDependency: (options: {
|
|
15
14
|
dependency: string;
|
|
16
15
|
installPath: string;
|
|
17
16
|
silent?: boolean;
|
|
18
17
|
usePrefix: boolean;
|
|
19
|
-
}
|
|
18
|
+
}) => Promise<{
|
|
20
19
|
dest: string;
|
|
21
|
-
}
|
|
22
|
-
export {};
|
|
20
|
+
}>;
|
package/dist/utils/npm-utils.js
CHANGED
|
@@ -21,23 +21,32 @@ const buildInstallCommand = (options) => {
|
|
|
21
21
|
}
|
|
22
22
|
return args;
|
|
23
23
|
};
|
|
24
|
-
const executeCommand = (options
|
|
24
|
+
const executeCommand = (options) => {
|
|
25
25
|
const cmd = (0, cross_spawn_1.default)('npm', [...options.command, '--no-package-lock'], {
|
|
26
26
|
cwd: options.path,
|
|
27
27
|
stdio: options.silent ? 'ignore' : 'inherit'
|
|
28
28
|
});
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
return new Promise((res, rej) => {
|
|
30
|
+
cmd.on('error', () => rej(new Error('error')));
|
|
31
|
+
cmd.on('close', code => {
|
|
32
|
+
if (code !== 0) {
|
|
33
|
+
rej(code);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
res();
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
});
|
|
31
40
|
};
|
|
32
41
|
const getFullPath = ({ installPath, dependency }) => path_1.default.join(installPath, 'node_modules', (0, strip_version_1.default)(dependency));
|
|
33
|
-
const init = (options
|
|
42
|
+
const init = (options) => {
|
|
34
43
|
const { initPath, silent } = options;
|
|
35
44
|
const npminit = ['init', '--yes'];
|
|
36
45
|
const cmdOptions = { path: initPath, command: npminit, silent };
|
|
37
|
-
executeCommand(cmdOptions
|
|
46
|
+
return executeCommand(cmdOptions);
|
|
38
47
|
};
|
|
39
48
|
exports.init = init;
|
|
40
|
-
const installDependencies = (options
|
|
49
|
+
const installDependencies = async (options) => {
|
|
41
50
|
const { dependencies, installPath, silent } = options;
|
|
42
51
|
const npmi = buildInstallCommand(options);
|
|
43
52
|
const cmdOptions = {
|
|
@@ -46,10 +55,11 @@ const installDependencies = (options, callback) => {
|
|
|
46
55
|
silent
|
|
47
56
|
};
|
|
48
57
|
const dest = dependencies.map(dependency => getFullPath({ installPath, dependency }));
|
|
49
|
-
executeCommand(cmdOptions
|
|
58
|
+
await executeCommand(cmdOptions);
|
|
59
|
+
return { dest };
|
|
50
60
|
};
|
|
51
61
|
exports.installDependencies = installDependencies;
|
|
52
|
-
const installDependency = (options
|
|
62
|
+
const installDependency = async (options) => {
|
|
53
63
|
const { dependency, installPath, silent } = options;
|
|
54
64
|
const npmi = buildInstallCommand(options);
|
|
55
65
|
const cmdOptions = {
|
|
@@ -58,6 +68,7 @@ const installDependency = (options, callback) => {
|
|
|
58
68
|
silent
|
|
59
69
|
};
|
|
60
70
|
const dest = getFullPath({ installPath, dependency });
|
|
61
|
-
executeCommand(cmdOptions
|
|
71
|
+
await executeCommand(cmdOptions);
|
|
72
|
+
return { dest };
|
|
62
73
|
};
|
|
63
74
|
exports.installDependency = installDependency;
|
package/dist/utils/put.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
declare function put(urlPath: string, files: string | string[], headers: Record<string, string | string[] | undefined>): Promise<string>;
|
|
2
|
+
export default put;
|
package/dist/utils/put.js
CHANGED
|
@@ -6,16 +6,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const form_data_1 = __importDefault(require("form-data"));
|
|
7
7
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const
|
|
10
|
-
function put(urlPath, files, headers
|
|
11
|
-
if (typeof headers === 'function') {
|
|
12
|
-
callback = headers;
|
|
13
|
-
headers = {};
|
|
14
|
-
}
|
|
9
|
+
const got_1 = __importDefault(require("got"));
|
|
10
|
+
async function put(urlPath, files, headers) {
|
|
15
11
|
const form = new form_data_1.default();
|
|
16
|
-
const options = { ...url_1.default.parse(urlPath), method: 'PUT', headers: {} };
|
|
17
|
-
let body = '';
|
|
18
|
-
let callbackDone = false;
|
|
19
12
|
if (!Array.isArray(files)) {
|
|
20
13
|
files = [files];
|
|
21
14
|
}
|
|
@@ -23,26 +16,14 @@ function put(urlPath, files, headers, callback) {
|
|
|
23
16
|
const fileName = path_1.default.basename(file);
|
|
24
17
|
form.append(fileName, fs_extra_1.default.createReadStream(file));
|
|
25
18
|
});
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return callback(err, undefined);
|
|
31
|
-
}
|
|
32
|
-
res.on('data', chunk => {
|
|
33
|
-
body += chunk;
|
|
34
|
-
});
|
|
35
|
-
res.on('end', () => {
|
|
36
|
-
if (!callbackDone) {
|
|
37
|
-
callbackDone = true;
|
|
38
|
-
if (res.statusCode !== 200) {
|
|
39
|
-
callback(body, undefined);
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
callback(null, body);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
});
|
|
19
|
+
const res = await (0, got_1.default)(urlPath, {
|
|
20
|
+
headers: { ...headers, ...form.getHeaders() },
|
|
21
|
+
method: 'PUT',
|
|
22
|
+
body: form
|
|
46
23
|
});
|
|
24
|
+
if (res.statusCode !== 200) {
|
|
25
|
+
throw res.body;
|
|
26
|
+
}
|
|
27
|
+
return res.body;
|
|
47
28
|
}
|
|
48
29
|
exports.default = put;
|