oc 0.49.21 → 0.49.23
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 +8 -0
- package/dist/cli/domain/get-mocked-plugins.js +2 -3
- package/dist/cli/domain/handle-dependencies/ensure-compiler-is-declared-as-devDependency.js +1 -2
- package/dist/cli/domain/local.d.ts +1 -1
- package/dist/cli/domain/registry.d.ts +1 -1
- package/dist/cli/programmatic-api.d.ts +2 -2
- package/dist/components/oc-client/_package/package.json +1 -1
- package/dist/components/oc-client/package.json +1 -1
- package/dist/registry/domain/components-cache/components-list.d.ts +3 -3
- package/dist/registry/domain/components-cache/components-list.js +28 -5
- package/dist/registry/domain/components-cache/index.js +27 -22
- package/dist/registry/domain/components-details.js +1 -2
- package/dist/registry/domain/events-handler.d.ts +3 -3
- package/dist/registry/domain/plugins-initialiser.d.ts +1 -1
- package/dist/registry/domain/repository.d.ts +1 -1
- package/dist/registry/domain/storage-adapter.d.ts +2 -2
- package/dist/registry/domain/url-builder.d.ts +1 -1
- package/dist/registry/domain/validators/node-version.d.ts +3 -3
- package/dist/registry/domain/validators/oc-cli-version.d.ts +3 -3
- package/dist/registry/domain/validators/plugins-requirements.d.ts +1 -1
- package/dist/registry/domain/validators/registry-configuration.d.ts +1 -1
- package/dist/registry/domain/validators/uploaded-package.d.ts +1 -1
- package/dist/registry/index.js +2 -3
- package/dist/registry/routes/helpers/get-available-dependencies.js +2 -3
- package/dist/registry/routes/helpers/get-component-fallback.d.ts +1 -1
- package/dist/registry/routes/helpers/is-url-discoverable.js +1 -2
- package/dist/registry/views/info.d.ts +1 -1
- package/dist/registry/views/partials/selected-checkbox.d.ts +1 -1
- package/dist/types.d.ts +3 -3
- package/dist/utils/is-template-legacy.d.ts +1 -1
- package/logintervals.md +1 -1
- package/package.json +20 -20
- package/tsconfig.json +1 -1
- package/src/cli/commands.ts +0 -178
- package/src/cli/domain/clean.ts +0 -21
- package/src/cli/domain/get-components-by-dir.ts +0 -47
- package/src/cli/domain/get-mocked-plugins.ts +0 -154
- package/src/cli/domain/handle-dependencies/ensure-compiler-is-declared-as-devDependency.ts +0 -17
- package/src/cli/domain/handle-dependencies/get-compiler.ts +0 -35
- package/src/cli/domain/handle-dependencies/get-missing-dependencies.ts +0 -17
- package/src/cli/domain/handle-dependencies/index.ts +0 -93
- package/src/cli/domain/handle-dependencies/install-compiler.ts +0 -43
- package/src/cli/domain/handle-dependencies/install-missing-dependencies.ts +0 -48
- package/src/cli/domain/handle-dependencies/link-missing-dependencies.ts +0 -45
- package/src/cli/domain/handle-dependencies/require-template.ts +0 -62
- package/src/cli/domain/init-template/index.ts +0 -26
- package/src/cli/domain/init-template/install-template.ts +0 -52
- package/src/cli/domain/init-template/scaffold.ts +0 -45
- package/src/cli/domain/local.ts +0 -77
- package/src/cli/domain/mock.ts +0 -40
- package/src/cli/domain/package-components.ts +0 -61
- package/src/cli/domain/registry.ts +0 -147
- package/src/cli/domain/url-parser.ts +0 -44
- package/src/cli/domain/watch.ts +0 -33
- package/src/cli/facade/clean.ts +0 -75
- package/src/cli/facade/dev.ts +0 -214
- package/src/cli/facade/init.ts +0 -50
- package/src/cli/facade/mock.ts +0 -20
- package/src/cli/facade/package.ts +0 -65
- package/src/cli/facade/preview.ts +0 -28
- package/src/cli/facade/publish.ts +0 -209
- package/src/cli/facade/registry-add.ts +0 -23
- package/src/cli/facade/registry-ls.ts +0 -36
- package/src/cli/facade/registry-remove.ts +0 -23
- package/src/cli/facade/registry.ts +0 -9
- package/src/cli/index.ts +0 -142
- package/src/cli/logger.ts +0 -38
- package/src/cli/programmatic-api.ts +0 -142
- package/src/cli/validate-command.ts +0 -18
- package/src/components/oc-client/_package/package.json +0 -1
- package/src/components/oc-client/_package/server.js +0 -1
- package/src/components/oc-client/_package/src/oc-client.min.js +0 -3
- package/src/components/oc-client/_package/src/oc-client.min.map +0 -1
- package/src/components/oc-client/_package/template.js +0 -1
- package/src/components/oc-client/package.json +0 -26
- package/src/components/oc-client/server.js +0 -6
- package/src/components/oc-client/src/oc-client.min.js +0 -3
- package/src/components/oc-client/src/oc-client.min.map +0 -1
- package/src/components/oc-client/template.js +0 -4
- package/src/globals.d.ts +0 -103
- package/src/index.ts +0 -3
- package/src/oc-cli.js +0 -3
- package/src/registry/app-start.ts +0 -75
- package/src/registry/domain/authentication.ts +0 -59
- package/src/registry/domain/components-cache/components-list.ts +0 -70
- package/src/registry/domain/components-cache/index.ts +0 -90
- package/src/registry/domain/components-details.ts +0 -96
- package/src/registry/domain/events-handler.ts +0 -86
- package/src/registry/domain/extract-package.ts +0 -45
- package/src/registry/domain/get-package-json-from-temp-dir.ts +0 -9
- package/src/registry/domain/nested-renderer.ts +0 -88
- package/src/registry/domain/options-sanitiser.ts +0 -118
- package/src/registry/domain/plugins-initialiser.ts +0 -127
- package/src/registry/domain/register-templates.ts +0 -41
- package/src/registry/domain/repository.ts +0 -390
- package/src/registry/domain/require-wrapper.ts +0 -39
- package/src/registry/domain/sanitiser.ts +0 -60
- package/src/registry/domain/storage-adapter.ts +0 -85
- package/src/registry/domain/url-builder.ts +0 -80
- package/src/registry/domain/validators/component-parameters.ts +0 -112
- package/src/registry/domain/validators/index.ts +0 -24
- package/src/registry/domain/validators/node-version.ts +0 -59
- package/src/registry/domain/validators/oc-cli-version.ts +0 -52
- package/src/registry/domain/validators/package-json-validator.ts +0 -35
- package/src/registry/domain/validators/plugins-requirements.ts +0 -39
- package/src/registry/domain/validators/registry-configuration.ts +0 -143
- package/src/registry/domain/validators/uploaded-package.ts +0 -49
- package/src/registry/domain/version-handler.ts +0 -25
- package/src/registry/index.ts +0 -117
- package/src/registry/middleware/base-url-handler.ts +0 -16
- package/src/registry/middleware/cors.ts +0 -18
- package/src/registry/middleware/discovery-handler.ts +0 -20
- package/src/registry/middleware/file-uploads.ts +0 -28
- package/src/registry/middleware/index.ts +0 -53
- package/src/registry/middleware/request-handler.ts +0 -30
- package/src/registry/router.ts +0 -85
- package/src/registry/routes/component-info.ts +0 -119
- package/src/registry/routes/component-preview.ts +0 -87
- package/src/registry/routes/component.ts +0 -53
- package/src/registry/routes/components.ts +0 -107
- package/src/registry/routes/dependencies.ts +0 -27
- package/src/registry/routes/helpers/apply-default-values.ts +0 -29
- package/src/registry/routes/helpers/get-available-dependencies.ts +0 -31
- package/src/registry/routes/helpers/get-component-fallback.ts +0 -139
- package/src/registry/routes/helpers/get-component-retrieving-info.ts +0 -44
- package/src/registry/routes/helpers/get-component.ts +0 -583
- package/src/registry/routes/helpers/get-components-history.ts +0 -40
- package/src/registry/routes/helpers/is-url-discoverable.ts +0 -18
- package/src/registry/routes/index.ts +0 -127
- package/src/registry/routes/plugins.ts +0 -19
- package/src/registry/routes/publish.ts +0 -89
- package/src/registry/routes/static-redirector.ts +0 -74
- package/src/registry/views/index.ts +0 -66
- package/src/registry/views/info.ts +0 -89
- package/src/registry/views/partials/component-author.ts +0 -32
- package/src/registry/views/partials/component-parameters.ts +0 -53
- package/src/registry/views/partials/component-state.ts +0 -14
- package/src/registry/views/partials/component-versions.ts +0 -16
- package/src/registry/views/partials/components-dependencies.ts +0 -26
- package/src/registry/views/partials/components-history.ts +0 -24
- package/src/registry/views/partials/components-list.ts +0 -65
- package/src/registry/views/partials/components-plugins.ts +0 -23
- package/src/registry/views/partials/components-templates.ts +0 -36
- package/src/registry/views/partials/layout.ts +0 -32
- package/src/registry/views/partials/property.ts +0 -17
- package/src/registry/views/partials/selected-checkbox.ts +0 -16
- package/src/registry/views/preview.ts +0 -37
- package/src/registry/views/static/index.ts +0 -92
- package/src/registry/views/static/info.ts +0 -43
- package/src/registry/views/static/style.ts +0 -277
- package/src/resources/index.ts +0 -279
- package/src/resources/settings.ts +0 -17
- package/src/types.ts +0 -251
- package/src/utils/clean-require.ts +0 -35
- package/src/utils/date-stringify.ts +0 -23
- package/src/utils/error-to-string.ts +0 -13
- package/src/utils/is-template-legacy.ts +0 -7
- package/src/utils/is-template-valid.ts +0 -19
- package/src/utils/module-exists.ts +0 -14
- package/src/utils/npm-utils.ts +0 -109
- package/src/utils/put.ts +0 -35
- package/src/utils/strip-version.ts +0 -6
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import async from 'async';
|
|
2
|
-
import parseAuthor from 'parse-author';
|
|
3
|
-
import _ from 'lodash';
|
|
4
|
-
import path from 'path';
|
|
5
|
-
import fs from 'fs-extra';
|
|
6
|
-
|
|
7
|
-
import dateStringified from '../../utils/date-stringify';
|
|
8
|
-
import getComponentsHistory from './helpers/get-components-history';
|
|
9
|
-
import getAvailableDependencies from './helpers/get-available-dependencies';
|
|
10
|
-
import indexView from '../views';
|
|
11
|
-
import urlBuilder = require('../domain/url-builder');
|
|
12
|
-
import type { Repository } from '../domain/repository';
|
|
13
|
-
import { Author, Component, ParsedComponent } from '../../types';
|
|
14
|
-
import { NextFunction, Request, Response } from 'express';
|
|
15
|
-
import { IncomingHttpHeaders } from 'http';
|
|
16
|
-
import { PackageJson } from 'type-fest';
|
|
17
|
-
import { fromPromise } from 'universalify';
|
|
18
|
-
|
|
19
|
-
const packageInfo: PackageJson = fs.readJsonSync(
|
|
20
|
-
path.join(__dirname, '..', '..', '..', 'package.json')
|
|
21
|
-
);
|
|
22
|
-
|
|
23
|
-
const getParsedAuthor = (author?: Author | string): Author => {
|
|
24
|
-
author = author || {};
|
|
25
|
-
return typeof author === 'string' ? parseAuthor(author) : author;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const mapComponentDetails = (component: Component): ParsedComponent =>
|
|
29
|
-
Object.assign(component, { author: getParsedAuthor(component.author) });
|
|
30
|
-
|
|
31
|
-
const isHtmlRequest = (headers: IncomingHttpHeaders) =>
|
|
32
|
-
!!headers.accept && headers.accept.indexOf('text/html') >= 0;
|
|
33
|
-
|
|
34
|
-
export default function (repository: Repository) {
|
|
35
|
-
return (req: Request, res: Response, next: NextFunction): void => {
|
|
36
|
-
fromPromise(repository.getComponents)((err, components) => {
|
|
37
|
-
if (err) {
|
|
38
|
-
res.errorDetails = 'cdn not available';
|
|
39
|
-
res.status(404).json({ error: res.errorDetails });
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const baseResponse = {
|
|
44
|
-
href: res.conf.baseUrl,
|
|
45
|
-
ocVersion: packageInfo.version,
|
|
46
|
-
type: res.conf.local ? 'oc-registry-local' : 'oc-registry'
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
if (isHtmlRequest(req.headers) && !!res.conf.discovery) {
|
|
50
|
-
let componentsInfo: ParsedComponent[] = [];
|
|
51
|
-
let componentsReleases = 0;
|
|
52
|
-
const stateCounts: { deprecated?: number; experimental?: number } = {};
|
|
53
|
-
|
|
54
|
-
async.each(
|
|
55
|
-
components,
|
|
56
|
-
(component, callback) =>
|
|
57
|
-
fromPromise(repository.getComponent)(
|
|
58
|
-
component,
|
|
59
|
-
undefined,
|
|
60
|
-
(err, result) => {
|
|
61
|
-
if (err) return callback(err as any);
|
|
62
|
-
|
|
63
|
-
if (result.oc && result.oc.date) {
|
|
64
|
-
result.oc.stringifiedDate = dateStringified(
|
|
65
|
-
new Date(result.oc.date)
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
componentsInfo.push(mapComponentDetails(result));
|
|
70
|
-
componentsReleases += result.allVersions.length;
|
|
71
|
-
callback();
|
|
72
|
-
}
|
|
73
|
-
),
|
|
74
|
-
err => {
|
|
75
|
-
if (err) return next(err);
|
|
76
|
-
|
|
77
|
-
componentsInfo = _.sortBy(componentsInfo, 'name');
|
|
78
|
-
fromPromise(repository.getComponentsDetails)((err, details) => {
|
|
79
|
-
// eslint-disable-next-line no-console
|
|
80
|
-
if (err) console.log(err);
|
|
81
|
-
res.send(
|
|
82
|
-
indexView(
|
|
83
|
-
// @ts-ignore
|
|
84
|
-
Object.assign(baseResponse, {
|
|
85
|
-
availableDependencies: getAvailableDependencies(
|
|
86
|
-
res.conf.dependencies
|
|
87
|
-
),
|
|
88
|
-
availablePlugins: res.conf.plugins,
|
|
89
|
-
components: componentsInfo,
|
|
90
|
-
componentsReleases,
|
|
91
|
-
componentsList: componentsInfo.map(component => {
|
|
92
|
-
const state: 'deprecated' | 'experimental' | undefined =
|
|
93
|
-
_.get(component, 'oc.state', '');
|
|
94
|
-
if (state) {
|
|
95
|
-
stateCounts[state] = (stateCounts[state] || 0) + 1;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return {
|
|
99
|
-
name: component.name,
|
|
100
|
-
author: component.author,
|
|
101
|
-
state
|
|
102
|
-
};
|
|
103
|
-
}),
|
|
104
|
-
componentsHistory:
|
|
105
|
-
!res.conf.local && getComponentsHistory(details),
|
|
106
|
-
q: req.query['q'] || '',
|
|
107
|
-
stateCounts,
|
|
108
|
-
templates: repository.getTemplatesInfo(),
|
|
109
|
-
title: 'OpenComponents Registry'
|
|
110
|
-
})
|
|
111
|
-
)
|
|
112
|
-
);
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
);
|
|
116
|
-
} else {
|
|
117
|
-
res.status(200).json(
|
|
118
|
-
Object.assign(baseResponse, {
|
|
119
|
-
components: _.map(components, component =>
|
|
120
|
-
urlBuilder.component(component, res.conf.baseUrl)
|
|
121
|
-
)
|
|
122
|
-
})
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
};
|
|
127
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { Request, Response } from 'express';
|
|
2
|
-
import { Config } from '../../types';
|
|
3
|
-
|
|
4
|
-
export default function plugins(conf: Config) {
|
|
5
|
-
return (_req: Request, res: Response): void => {
|
|
6
|
-
if (res.conf.discovery) {
|
|
7
|
-
const plugins = Object.entries(conf.plugins).map(
|
|
8
|
-
([pluginName, pluginFn]) => ({
|
|
9
|
-
name: pluginName,
|
|
10
|
-
description: pluginFn.toString()
|
|
11
|
-
})
|
|
12
|
-
);
|
|
13
|
-
|
|
14
|
-
res.status(200).json(plugins);
|
|
15
|
-
} else {
|
|
16
|
-
res.status(401);
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { Request, Response } from 'express';
|
|
2
|
-
import extractPackage from '../domain/extract-package';
|
|
3
|
-
import strings from '../../resources/index';
|
|
4
|
-
import * as validator from '../domain/validators';
|
|
5
|
-
import type { Repository } from '../domain/repository';
|
|
6
|
-
|
|
7
|
-
export default function publish(repository: Repository) {
|
|
8
|
-
return async function (req: Request, res: Response): Promise<void> {
|
|
9
|
-
if (!req.params['componentName'] || !req.params['componentVersion']) {
|
|
10
|
-
res.errorDetails = 'malformed request';
|
|
11
|
-
res.status(409).json({ error: res.errorDetails });
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const packageValidation = validator.validatePackage(req.files);
|
|
16
|
-
if (!packageValidation.isValid) {
|
|
17
|
-
res.errorDetails = 'package is not valid';
|
|
18
|
-
res.status(409).json({ error: res.errorDetails });
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
const files = packageValidation.files;
|
|
22
|
-
|
|
23
|
-
const ocCliValidationResult = validator.validateOcCliVersion(
|
|
24
|
-
req.headers['user-agent']
|
|
25
|
-
);
|
|
26
|
-
if (!ocCliValidationResult.isValid) {
|
|
27
|
-
res.errorDetails = strings.errors.registry.OC_CLI_VERSION_IS_NOT_VALID(
|
|
28
|
-
ocCliValidationResult.error.registryVersion,
|
|
29
|
-
ocCliValidationResult.error.cliVersion
|
|
30
|
-
);
|
|
31
|
-
res.status(409).json({
|
|
32
|
-
code: 'cli_version_not_valid',
|
|
33
|
-
error: res.errorDetails,
|
|
34
|
-
details: ocCliValidationResult.error
|
|
35
|
-
});
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const nodeValidationResult = validator.validateNodeVersion(
|
|
40
|
-
req.headers['user-agent'],
|
|
41
|
-
process.version
|
|
42
|
-
);
|
|
43
|
-
if (!nodeValidationResult.isValid) {
|
|
44
|
-
res.errorDetails = strings.errors.registry.NODE_CLI_VERSION_IS_NOT_VALID(
|
|
45
|
-
nodeValidationResult.error.registryNodeVersion,
|
|
46
|
-
nodeValidationResult.error.cliNodeVersion
|
|
47
|
-
);
|
|
48
|
-
res.status(409).json({
|
|
49
|
-
code: 'node_version_not_valid',
|
|
50
|
-
error: res.errorDetails,
|
|
51
|
-
details: nodeValidationResult.error
|
|
52
|
-
});
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
try {
|
|
57
|
-
const pkgDetails = await extractPackage(files, res.conf.tarExtractMode);
|
|
58
|
-
|
|
59
|
-
try {
|
|
60
|
-
await repository.publishComponent(
|
|
61
|
-
pkgDetails,
|
|
62
|
-
req.params['componentName'],
|
|
63
|
-
req.params['componentVersion']
|
|
64
|
-
);
|
|
65
|
-
res.status(200).json({ ok: true });
|
|
66
|
-
} catch (err: any) {
|
|
67
|
-
if (err.code === 'not_allowed') {
|
|
68
|
-
res.errorDetails = `Publish not allowed: ${err.msg}`;
|
|
69
|
-
res.status(403).json({ error: err.msg });
|
|
70
|
-
} else if (err.code === 'already_exists') {
|
|
71
|
-
res.errorDetails = `Component already exists: ${err.msg}`;
|
|
72
|
-
res.status(403).json({ error: err.msg });
|
|
73
|
-
} else if (err.code === 'name_not_valid') {
|
|
74
|
-
res.errorDetails = `Component name not valid: ${err.msg}`;
|
|
75
|
-
res.status(409).json({ error: err.msg });
|
|
76
|
-
} else if (err.code === 'version_not_valid') {
|
|
77
|
-
res.errorDetails = `Component version not valid: ${err.msg}`;
|
|
78
|
-
res.status(409).json({ error: err.msg });
|
|
79
|
-
} else {
|
|
80
|
-
res.errorDetails = `Publish failed: ${err.msg}`;
|
|
81
|
-
res.status(500).json({ error: err.msg });
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
} catch (err) {
|
|
85
|
-
res.errorDetails = `Package is not valid: ${err}`;
|
|
86
|
-
res.status(500).json({ error: 'package is not valid', details: err });
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import fs from 'fs-extra';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { Request, Response } from 'express';
|
|
4
|
-
|
|
5
|
-
import * as storageUtils from 'oc-storage-adapters-utils';
|
|
6
|
-
import type { Repository } from '../domain/repository';
|
|
7
|
-
|
|
8
|
-
export default function staticRedirector(repository: Repository) {
|
|
9
|
-
return function (req: Request, res: Response): void {
|
|
10
|
-
let filePath;
|
|
11
|
-
const clientPath = `${res.conf.prefix || '/'}oc-client/client.js`;
|
|
12
|
-
const clientMapPath = `${
|
|
13
|
-
res.conf.prefix || '/'
|
|
14
|
-
}oc-client/oc-client.min.map`;
|
|
15
|
-
|
|
16
|
-
if (req.route.path === clientPath) {
|
|
17
|
-
if (res.conf.local) {
|
|
18
|
-
filePath = path.join(
|
|
19
|
-
__dirname,
|
|
20
|
-
'../../components/oc-client/_package/src/oc-client.min.js'
|
|
21
|
-
);
|
|
22
|
-
} else {
|
|
23
|
-
return res.redirect(repository.getStaticClientPath());
|
|
24
|
-
}
|
|
25
|
-
} else if (req.route.path === clientMapPath) {
|
|
26
|
-
if (res.conf.local) {
|
|
27
|
-
filePath = path.join(
|
|
28
|
-
__dirname,
|
|
29
|
-
'../../components/oc-client/_package/src/oc-client.min.map'
|
|
30
|
-
);
|
|
31
|
-
} else {
|
|
32
|
-
return res.redirect(repository.getStaticClientMapPath());
|
|
33
|
-
}
|
|
34
|
-
} else if (req.params['componentName'] === 'oc-client') {
|
|
35
|
-
filePath = path.join(
|
|
36
|
-
__dirname,
|
|
37
|
-
'../../components/oc-client/_package/' + req.params[0]
|
|
38
|
-
);
|
|
39
|
-
} else {
|
|
40
|
-
filePath =
|
|
41
|
-
path.join(res.conf.path, req.params['componentName']) +
|
|
42
|
-
'/_package/' +
|
|
43
|
-
req.params[0];
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (!fs.existsSync(filePath)) {
|
|
47
|
-
res.errorDetails = `File ${filePath} not found`;
|
|
48
|
-
res.status(404).json({ err: res.errorDetails });
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const stats = fs.statSync(filePath);
|
|
53
|
-
if (stats.isDirectory()) {
|
|
54
|
-
res.errorDetails = 'Forbidden: Directory Listing Denied';
|
|
55
|
-
res.status(403).json({ err: res.errorDetails });
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const fileStream = fs.createReadStream(filePath);
|
|
60
|
-
const fileInfo = storageUtils.getFileInfo(filePath);
|
|
61
|
-
|
|
62
|
-
if (fileInfo.mimeType) {
|
|
63
|
-
res.set('Content-Type', fileInfo.mimeType);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (fileInfo.gzip) {
|
|
67
|
-
res.set('Content-Encoding', 'gzip');
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
fileStream.on('open', () => {
|
|
71
|
-
fileStream.pipe(res);
|
|
72
|
-
});
|
|
73
|
-
};
|
|
74
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import dependencies from './partials/components-dependencies';
|
|
2
|
-
import history from './partials/components-history';
|
|
3
|
-
import list from './partials/components-list';
|
|
4
|
-
import templates from './partials/components-templates';
|
|
5
|
-
import plugins from './partials/components-plugins';
|
|
6
|
-
import indexJS from './static/index';
|
|
7
|
-
|
|
8
|
-
import getLayout from './partials/layout';
|
|
9
|
-
import getProperty from './partials/property';
|
|
10
|
-
import { VM } from '../../types';
|
|
11
|
-
|
|
12
|
-
export default function indexView(vm: VM): string {
|
|
13
|
-
const tabs = {
|
|
14
|
-
dependencies: dependencies(vm),
|
|
15
|
-
history: history(vm),
|
|
16
|
-
list: list(vm),
|
|
17
|
-
templates: templates(vm),
|
|
18
|
-
plugins: plugins(vm)
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const layout = getLayout(vm);
|
|
22
|
-
const property = getProperty();
|
|
23
|
-
|
|
24
|
-
const getCount = (state: 'deprecated' | 'experimental') =>
|
|
25
|
-
vm.stateCounts[state] || 0;
|
|
26
|
-
const isLocal = vm.type !== 'oc-registry';
|
|
27
|
-
|
|
28
|
-
const componentsValue = `${vm.components.length} (${getCount(
|
|
29
|
-
'experimental'
|
|
30
|
-
)} experimental, ${getCount('deprecated')} deprecated)`;
|
|
31
|
-
|
|
32
|
-
const extraLinks =
|
|
33
|
-
` | <a href="#components-history" class="tab-link">History</a>` +
|
|
34
|
-
` | <a href="#components-templates" class="tab-link">Available templates</a>` +
|
|
35
|
-
` | <a href="#components-dependencies" class="tab-link">Available dependencies</a>` +
|
|
36
|
-
` | <a href="#components-plugins" class="tab-link">Available plugins</a>`;
|
|
37
|
-
|
|
38
|
-
const registryType = isLocal ? 'Local dev registry' : 'On-line registry';
|
|
39
|
-
|
|
40
|
-
const componentReleases = !isLocal
|
|
41
|
-
? property('Components releases', vm.componentsReleases)
|
|
42
|
-
: '';
|
|
43
|
-
|
|
44
|
-
const content = `${property('Base url', vm.href, true)}
|
|
45
|
-
${property('Version', vm.ocVersion)}
|
|
46
|
-
${property('Components', componentsValue)}
|
|
47
|
-
${componentReleases}
|
|
48
|
-
${property('Registry type', registryType)}
|
|
49
|
-
<h2 id="menuList">
|
|
50
|
-
<a href="#components-list" class="tab-link">Components</a>
|
|
51
|
-
${!isLocal ? extraLinks : ''}
|
|
52
|
-
</h2>
|
|
53
|
-
${tabs.list}
|
|
54
|
-
${tabs.history}
|
|
55
|
-
${tabs.templates}
|
|
56
|
-
${tabs.dependencies}
|
|
57
|
-
${tabs.plugins}`;
|
|
58
|
-
|
|
59
|
-
const scripts = `<script>
|
|
60
|
-
var q = "${encodeURIComponent(vm.q)}", componentsList = ${JSON.stringify(
|
|
61
|
-
vm.componentsList
|
|
62
|
-
)};
|
|
63
|
-
${indexJS}</script>`;
|
|
64
|
-
|
|
65
|
-
return layout({ content, scripts });
|
|
66
|
-
}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { Component } from '../../types';
|
|
2
|
-
|
|
3
|
-
import getComponentAuthor from './partials/component-author';
|
|
4
|
-
import getComponentParameters from './partials/component-parameters';
|
|
5
|
-
import getComponentState from './partials/component-state';
|
|
6
|
-
import getComponentVersions from './partials/component-versions';
|
|
7
|
-
import infoJS from './static/info';
|
|
8
|
-
import getLayout from './partials/layout';
|
|
9
|
-
import getProperty from './partials/property';
|
|
10
|
-
import isTemplateLegacy from '../../utils/is-template-legacy';
|
|
11
|
-
|
|
12
|
-
interface Vm {
|
|
13
|
-
parsedAuthor: { name?: string; email?: string; url?: string };
|
|
14
|
-
component: Component;
|
|
15
|
-
dependencies: string[];
|
|
16
|
-
href: string;
|
|
17
|
-
sandBoxDefaultQs: string;
|
|
18
|
-
title: string;
|
|
19
|
-
repositoryUrl: string;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export default function info(vm: Vm): string {
|
|
23
|
-
const componentAuthor = getComponentAuthor(vm);
|
|
24
|
-
const componentParameters = getComponentParameters(vm);
|
|
25
|
-
const componentState = getComponentState(vm);
|
|
26
|
-
const componentVersions = getComponentVersions(vm);
|
|
27
|
-
const layout = getLayout(vm);
|
|
28
|
-
const property = getProperty();
|
|
29
|
-
|
|
30
|
-
const showArray = (title: string, arr?: string[]) =>
|
|
31
|
-
property(title, !!arr && arr.length > 0 ? arr.join(', ') : 'none');
|
|
32
|
-
|
|
33
|
-
const { component, dependencies, href, repositoryUrl, sandBoxDefaultQs } = vm;
|
|
34
|
-
|
|
35
|
-
const componentHref = `${href}${component.name}/${component.version}/${sandBoxDefaultQs}`;
|
|
36
|
-
|
|
37
|
-
const publishDate = component.oc.date
|
|
38
|
-
? new Date(component.oc.date)
|
|
39
|
-
: 'not available';
|
|
40
|
-
|
|
41
|
-
const publishAgent = component.oc.version
|
|
42
|
-
? `OC CLI ${component.oc.version}`
|
|
43
|
-
: 'not available';
|
|
44
|
-
|
|
45
|
-
const templateType = component.oc.files.template.type;
|
|
46
|
-
const compiler = `${templateType}-compiler`;
|
|
47
|
-
const template = `${templateType} (${
|
|
48
|
-
isTemplateLegacy(templateType)
|
|
49
|
-
? 'legacy'
|
|
50
|
-
: compiler + '@' + component.oc.files.template.version
|
|
51
|
-
})`;
|
|
52
|
-
|
|
53
|
-
const content = `<a class="back" href="${href}"><< All components</a>
|
|
54
|
-
<h2>${component.name} ${componentVersions()}</h2>
|
|
55
|
-
<p class="w-100">${component.description} ${componentState()}</p>
|
|
56
|
-
<h3>Component Info</h3>
|
|
57
|
-
${property('Repository', repositoryUrl || 'not available', !!repositoryUrl)}
|
|
58
|
-
${componentAuthor()}
|
|
59
|
-
${property('Publish date', publishDate)}
|
|
60
|
-
${property('Publish agent', publishAgent)}
|
|
61
|
-
${property('Template', template)}
|
|
62
|
-
${showArray('Node.js dependencies', dependencies)}
|
|
63
|
-
${showArray('Plugin dependencies', component.oc.plugins)}
|
|
64
|
-
${componentParameters()}
|
|
65
|
-
<h3>Code</h3>
|
|
66
|
-
<p>
|
|
67
|
-
You can edit the following area and then
|
|
68
|
-
<a href="#refresh" class="refresh-preview">refresh</a>
|
|
69
|
-
to apply the change into the preview window.
|
|
70
|
-
</p>
|
|
71
|
-
<div class="field"><p>Component's href:</p></div>
|
|
72
|
-
<textarea class="w-100" id="href" placeholder="Insert component href here">${componentHref}</textarea>
|
|
73
|
-
<div class="field"><p>Accept-Language header:</p></div>
|
|
74
|
-
<input class="w-100" id="lang" type="text" value="*" />
|
|
75
|
-
<h3>
|
|
76
|
-
Preview (
|
|
77
|
-
<a class="refresh-preview" href="#refresh">Refresh</a>
|
|
78
|
-
|
|
|
79
|
-
<a class="open-preview" href="#open">Open</a>
|
|
80
|
-
)
|
|
81
|
-
</h3>
|
|
82
|
-
<iframe class="preview" src="~preview/${sandBoxDefaultQs}"></iframe>`;
|
|
83
|
-
|
|
84
|
-
const scripts = `<script>var thisComponentHref="${href}${component.name}/";
|
|
85
|
-
${infoJS}
|
|
86
|
-
</script>`;
|
|
87
|
-
|
|
88
|
-
return layout({ content, scripts });
|
|
89
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
const componentAuthor =
|
|
2
|
-
(vm: {
|
|
3
|
-
parsedAuthor: {
|
|
4
|
-
name?: string;
|
|
5
|
-
email?: string;
|
|
6
|
-
url?: string;
|
|
7
|
-
};
|
|
8
|
-
}) =>
|
|
9
|
-
(): string => {
|
|
10
|
-
const author = vm.parsedAuthor;
|
|
11
|
-
let placeholder = '';
|
|
12
|
-
|
|
13
|
-
if (!author.name && !author.email && !author.url) {
|
|
14
|
-
placeholder += `<span>not available</span>`;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
if (author.name) {
|
|
18
|
-
placeholder += `<span>${author.name} </span>`;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
if (author.email) {
|
|
22
|
-
placeholder += `<span><a href="mailto:${author.email}">${author.email}</a> </span>`;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if (author.url) {
|
|
26
|
-
placeholder += `<span><a href="${author.url}" target="_blank">${author.url}</a></span>`;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return `<div class="field"><p>Author:</p>${placeholder}</div>`;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export default componentAuthor;
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { Component, OcParameter } from '../../../types';
|
|
2
|
-
|
|
3
|
-
const componentParameters =
|
|
4
|
-
({ component }: { component: Component }) =>
|
|
5
|
-
(): string => {
|
|
6
|
-
let parameters = `<h3>Parameters</h3>`;
|
|
7
|
-
|
|
8
|
-
if (!component.oc.parameters) {
|
|
9
|
-
return `${parameters}<p class="w-100">none</p>`;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const parameterRow = (param: OcParameter, paramName: string) => {
|
|
13
|
-
const mandatory = param.mandatory ? 'mandatory' : 'optional';
|
|
14
|
-
const description = param.description
|
|
15
|
-
? `<span>${param.description}</span><br /><br />`
|
|
16
|
-
: '';
|
|
17
|
-
const defaultParam =
|
|
18
|
-
!param.mandatory && param.default
|
|
19
|
-
? `<br /><br /><span class="bold">Default:</span><span>${param.default}</span>`
|
|
20
|
-
: '';
|
|
21
|
-
|
|
22
|
-
return `<div class="row">
|
|
23
|
-
<div class="parameter">
|
|
24
|
-
<span class="bold">${paramName}</span>
|
|
25
|
-
<span>(${param.type}, ${mandatory})</span>
|
|
26
|
-
</div>
|
|
27
|
-
<div class="parameter-description">
|
|
28
|
-
${description}
|
|
29
|
-
<span class="bold">Example:</span>
|
|
30
|
-
<span>${param.example}</span>
|
|
31
|
-
${defaultParam}
|
|
32
|
-
</div>
|
|
33
|
-
</div>`;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const rows = Object.keys(component.oc.parameters)
|
|
37
|
-
.map(parameterName =>
|
|
38
|
-
parameterRow(component.oc.parameters[parameterName], parameterName)
|
|
39
|
-
)
|
|
40
|
-
.join('');
|
|
41
|
-
|
|
42
|
-
parameters += `<div id="plugins" class="table">
|
|
43
|
-
<div class="row header">
|
|
44
|
-
<div class="parameter">Parameters</div>
|
|
45
|
-
<div class="parameter-description"></div>
|
|
46
|
-
</div>
|
|
47
|
-
${rows}
|
|
48
|
-
</div>`;
|
|
49
|
-
|
|
50
|
-
return parameters;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
export default componentParameters;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Component } from '../../../types';
|
|
2
|
-
|
|
3
|
-
const componentState =
|
|
4
|
-
({ component }: { component: Component }) =>
|
|
5
|
-
(): string =>
|
|
6
|
-
!component.oc.state
|
|
7
|
-
? ''
|
|
8
|
-
: `<span class="details-state">
|
|
9
|
-
<span class="component-state-${component.oc.state.toLowerCase()}">
|
|
10
|
-
${component.oc.state}
|
|
11
|
-
</span>
|
|
12
|
-
</span>`;
|
|
13
|
-
|
|
14
|
-
export default componentState;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Component } from '../../../types';
|
|
2
|
-
|
|
3
|
-
const componentVersions =
|
|
4
|
-
({ component }: { component: Component }) =>
|
|
5
|
-
(): string => {
|
|
6
|
-
const componentOption = (version: string) =>
|
|
7
|
-
`<option value="${version}"${
|
|
8
|
-
version === component.version ? ' selected="selected"' : ''
|
|
9
|
-
}>${version}</option>`;
|
|
10
|
-
|
|
11
|
-
return `<select id="versions">${component.allVersions
|
|
12
|
-
.map(componentOption)
|
|
13
|
-
.join('')}</select>`;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export default componentVersions;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { VM } from '../../../types';
|
|
2
|
-
|
|
3
|
-
export default function componentsDependencies(vm: VM): string {
|
|
4
|
-
const dependencyRow = ({
|
|
5
|
-
core,
|
|
6
|
-
link,
|
|
7
|
-
name,
|
|
8
|
-
version
|
|
9
|
-
}: {
|
|
10
|
-
core: boolean;
|
|
11
|
-
link: string;
|
|
12
|
-
name: string;
|
|
13
|
-
version: string;
|
|
14
|
-
}) => {
|
|
15
|
-
const label = name + (core ? ` (node.js core dependency)` : `@${version}`);
|
|
16
|
-
return `<a href="${link}" target="_blank">
|
|
17
|
-
<div class="componentRow row table">
|
|
18
|
-
<p class="release">${label}</p>
|
|
19
|
-
</div>
|
|
20
|
-
</a>`;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
return `<div id="components-dependencies" class="box">${vm.availableDependencies
|
|
24
|
-
.map(dependencyRow)
|
|
25
|
-
.join('')}</div>`;
|
|
26
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { VM } from '../../../types';
|
|
2
|
-
|
|
3
|
-
export default function componentsHistory(vm: VM): string {
|
|
4
|
-
const componentRow = ({
|
|
5
|
-
name,
|
|
6
|
-
publishDate,
|
|
7
|
-
version
|
|
8
|
-
}: {
|
|
9
|
-
name: string;
|
|
10
|
-
publishDate: string;
|
|
11
|
-
version: string;
|
|
12
|
-
}) =>
|
|
13
|
-
`<a href="${name}/${version}/~info">
|
|
14
|
-
<div class="componentRow row table">
|
|
15
|
-
<p class="release">${publishDate} - Published ${name}@${version}</p>
|
|
16
|
-
</div>
|
|
17
|
-
</a>`;
|
|
18
|
-
|
|
19
|
-
const history = vm.componentsHistory || [];
|
|
20
|
-
|
|
21
|
-
return `<div id="components-history" class="box">${history
|
|
22
|
-
.map(componentRow)
|
|
23
|
-
.join('')}</div>`;
|
|
24
|
-
}
|