oc 0.49.6 → 0.49.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -0
- package/README.md +2 -15
- package/dist/cli/commands.d.ts +163 -163
- package/dist/cli/commands.js +162 -162
- package/dist/cli/domain/clean.d.ts +2 -2
- package/dist/cli/domain/clean.js +24 -27
- package/dist/cli/domain/get-components-by-dir.d.ts +1 -1
- package/dist/cli/domain/get-components-by-dir.js +41 -48
- package/dist/cli/domain/get-mocked-plugins.d.ts +10 -10
- package/dist/cli/domain/get-mocked-plugins.js +89 -87
- package/dist/cli/domain/handle-dependencies/ensure-compiler-is-declared-as-devDependency.d.ts +6 -6
- package/dist/cli/domain/handle-dependencies/ensure-compiler-is-declared-as-devDependency.js +16 -17
- package/dist/cli/domain/handle-dependencies/get-compiler.d.ts +10 -10
- package/dist/cli/domain/handle-dependencies/get-compiler.js +28 -28
- package/dist/cli/domain/handle-dependencies/get-missing-dependencies.d.ts +1 -1
- package/dist/cli/domain/handle-dependencies/get-missing-dependencies.js +18 -18
- package/dist/cli/domain/handle-dependencies/index.d.ts +10 -9
- package/dist/cli/domain/handle-dependencies/index.js +70 -64
- package/dist/cli/domain/handle-dependencies/install-compiler.d.ts +8 -8
- package/dist/cli/domain/handle-dependencies/install-compiler.js +54 -47
- package/dist/cli/domain/handle-dependencies/install-missing-dependencies.d.ts +5 -5
- package/dist/cli/domain/handle-dependencies/install-missing-dependencies.js +59 -55
- package/dist/cli/domain/handle-dependencies/link-missing-dependencies.d.ts +6 -6
- package/dist/cli/domain/handle-dependencies/link-missing-dependencies.js +32 -36
- package/dist/cli/domain/handle-dependencies/require-template.d.ts +17 -17
- package/dist/cli/domain/handle-dependencies/require-template.js +34 -34
- package/dist/cli/domain/init-template/index.d.ts +10 -10
- package/dist/cli/domain/init-template/index.js +40 -42
- package/dist/cli/domain/init-template/install-template.d.ts +11 -11
- package/dist/cli/domain/init-template/install-template.js +54 -53
- package/dist/cli/domain/init-template/scaffold.d.ts +11 -11
- package/dist/cli/domain/init-template/scaffold.js +30 -30
- package/dist/cli/domain/local.d.ts +2 -2
- package/dist/cli/domain/local.js +82 -81
- package/dist/cli/domain/mock.d.ts +5 -5
- package/dist/cli/domain/mock.js +33 -33
- package/dist/cli/domain/package-components.d.ts +9 -9
- package/dist/cli/domain/package-components.js +67 -70
- package/dist/cli/domain/registry.d.ts +6 -6
- package/dist/cli/domain/registry.js +136 -149
- package/dist/cli/domain/url-parser.d.ts +14 -14
- package/dist/cli/domain/url-parser.js +31 -31
- package/dist/cli/domain/watch.d.ts +1 -1
- package/dist/cli/domain/watch.js +29 -29
- package/dist/cli/facade/clean.d.ts +16 -10
- package/dist/cli/facade/clean.js +58 -48
- package/dist/cli/facade/dev.d.ts +114 -21
- package/dist/cli/facade/dev.js +176 -190
- package/dist/cli/facade/init.d.ts +18 -11
- package/dist/cli/facade/init.js +39 -37
- package/dist/cli/facade/mock.d.ts +18 -11
- package/dist/cli/facade/mock.js +12 -13
- package/dist/cli/facade/package.d.ts +18 -11
- package/dist/cli/facade/package.js +49 -51
- package/dist/cli/facade/preview.d.ts +14 -9
- package/dist/cli/facade/preview.js +20 -18
- package/dist/cli/facade/publish.d.ts +23 -14
- package/dist/cli/facade/publish.js +145 -165
- package/dist/cli/facade/registry-add.d.ts +14 -9
- package/dist/cli/facade/registry-add.js +18 -17
- package/dist/cli/facade/registry-ls.d.ts +10 -7
- package/dist/cli/facade/registry-ls.js +27 -25
- package/dist/cli/facade/registry-remove.d.ts +14 -9
- package/dist/cli/facade/registry-remove.js +18 -17
- package/dist/cli/facade/registry.d.ts +5 -2
- package/dist/cli/facade/registry.js +9 -6
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.js +91 -93
- package/dist/cli/logger.d.ts +8 -8
- package/dist/cli/logger.js +19 -19
- package/dist/cli/programmatic-api.d.ts +84 -84
- package/dist/cli/programmatic-api.js +66 -66
- package/dist/cli/validate-command.d.ts +2 -2
- package/dist/cli/validate-command.js +18 -18
- package/dist/components/oc-client/_package/package.json +1 -1
- package/dist/components/oc-client/package.json +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +12 -12
- package/dist/oc-cli.d.ts +2 -2
- package/dist/oc-cli.js +3 -3
- package/dist/registry/app-start.d.ts +2 -2
- package/dist/registry/app-start.js +44 -44
- package/dist/registry/domain/authentication.d.ts +7 -8
- package/dist/registry/domain/authentication.js +53 -50
- package/dist/registry/domain/components-cache/components-list.d.ts +8 -7
- package/dist/registry/domain/components-cache/components-list.js +50 -64
- package/dist/registry/domain/components-cache/index.d.ts +7 -6
- package/dist/registry/domain/components-cache/index.js +76 -79
- package/dist/registry/domain/components-details.d.ts +6 -5
- package/dist/registry/domain/components-details.js +64 -75
- package/dist/registry/domain/events-handler.d.ts +40 -40
- package/dist/registry/domain/events-handler.js +37 -37
- package/dist/registry/domain/extract-package.d.ts +8 -8
- package/dist/registry/domain/extract-package.js +26 -29
- package/dist/registry/domain/get-package-json-from-temp-dir.d.ts +2 -2
- package/dist/registry/domain/get-package-json-from-temp-dir.js +11 -11
- package/dist/registry/domain/nested-renderer.d.ts +14 -13
- package/dist/registry/domain/nested-renderer.js +59 -95
- package/dist/registry/domain/options-sanitiser.d.ts +6 -6
- package/dist/registry/domain/options-sanitiser.js +106 -104
- package/dist/registry/domain/plugins-initialiser.d.ts +3 -1
- package/dist/registry/domain/plugins-initialiser.js +95 -99
- package/dist/registry/domain/register-templates.d.ts +5 -5
- package/dist/registry/domain/register-templates.js +30 -30
- package/dist/registry/domain/repository.d.ts +2 -2
- package/dist/registry/domain/repository.js +237 -259
- package/dist/registry/domain/require-wrapper.d.ts +2 -2
- package/dist/registry/domain/require-wrapper.js +33 -34
- package/dist/registry/domain/sanitiser.d.ts +2 -2
- package/dist/registry/domain/sanitiser.js +52 -52
- package/dist/registry/domain/storage-adapter.d.ts +10 -0
- package/dist/registry/domain/storage-adapter.js +55 -0
- package/dist/registry/domain/url-builder.d.ts +10 -10
- package/dist/registry/domain/url-builder.js +60 -60
- package/dist/registry/domain/validators/component-parameters.d.ts +11 -11
- package/dist/registry/domain/validators/component-parameters.js +79 -79
- package/dist/registry/domain/validators/index.d.ts +16 -16
- package/dist/registry/domain/validators/index.js +29 -29
- package/dist/registry/domain/validators/node-version.d.ts +15 -15
- package/dist/registry/domain/validators/node-version.js +40 -40
- package/dist/registry/domain/validators/oc-cli-version.d.ts +15 -15
- package/dist/registry/domain/validators/oc-cli-version.js +34 -34
- package/dist/registry/domain/validators/package-json-validator.d.ts +13 -13
- package/dist/registry/domain/validators/package-json-validator.js +23 -23
- package/dist/registry/domain/validators/plugins-requirements.d.ts +9 -9
- package/dist/registry/domain/validators/plugins-requirements.js +22 -22
- package/dist/registry/domain/validators/registry-configuration.d.ts +9 -9
- package/dist/registry/domain/validators/registry-configuration.js +113 -113
- package/dist/registry/domain/validators/uploaded-package.d.ts +14 -14
- package/dist/registry/domain/validators/uploaded-package.js +25 -25
- package/dist/registry/domain/version-handler.d.ts +2 -2
- package/dist/registry/domain/version-handler.js +22 -22
- package/dist/registry/index.d.ts +48 -48
- package/dist/registry/index.js +107 -120
- package/dist/registry/middleware/base-url-handler.d.ts +2 -2
- package/dist/registry/middleware/base-url-handler.js +12 -12
- package/dist/registry/middleware/cors.d.ts +2 -2
- package/dist/registry/middleware/cors.js +11 -11
- package/dist/registry/middleware/discovery-handler.d.ts +2 -2
- package/dist/registry/middleware/discovery-handler.js +15 -15
- package/dist/registry/middleware/file-uploads.d.ts +2 -2
- package/dist/registry/middleware/file-uploads.js +23 -23
- package/dist/registry/middleware/index.d.ts +7 -3
- package/dist/registry/middleware/index.js +51 -47
- package/dist/registry/middleware/request-handler.d.ts +2 -2
- package/dist/registry/middleware/request-handler.js +30 -30
- package/dist/registry/router.d.ts +3 -3
- package/dist/registry/router.js +56 -58
- package/dist/registry/routes/component-info.d.ts +3 -3
- package/dist/registry/routes/component-info.js +90 -89
- package/dist/registry/routes/component-preview.d.ts +3 -3
- package/dist/registry/routes/component-preview.js +68 -67
- package/dist/registry/routes/component.d.ts +3 -3
- package/dist/registry/routes/component.js +43 -43
- package/dist/registry/routes/components.d.ts +3 -3
- package/dist/registry/routes/components.js +78 -78
- package/dist/registry/routes/dependencies.d.ts +3 -3
- package/dist/registry/routes/dependencies.js +28 -28
- package/dist/registry/routes/helpers/apply-default-values.d.ts +2 -2
- package/dist/registry/routes/helpers/apply-default-values.js +13 -13
- package/dist/registry/routes/helpers/get-available-dependencies.d.ts +8 -8
- package/dist/registry/routes/helpers/get-available-dependencies.js +24 -24
- package/dist/registry/routes/helpers/get-component-fallback.d.ts +17 -22
- package/dist/registry/routes/helpers/get-component-fallback.js +91 -91
- package/dist/registry/routes/helpers/get-component-retrieving-info.d.ts +20 -20
- package/dist/registry/routes/helpers/get-component-retrieving-info.js +24 -24
- package/dist/registry/routes/helpers/get-component.d.ts +33 -33
- package/dist/registry/routes/helpers/get-component.js +406 -405
- package/dist/registry/routes/helpers/get-components-history.d.ts +8 -8
- package/dist/registry/routes/helpers/get-components-history.js +28 -28
- package/dist/registry/routes/helpers/is-url-discoverable.d.ts +3 -3
- package/dist/registry/routes/helpers/is-url-discoverable.js +22 -16
- package/dist/registry/routes/index.d.ts +3 -3
- package/dist/registry/routes/index.js +93 -92
- package/dist/registry/routes/plugins.d.ts +3 -3
- package/dist/registry/routes/plugins.js +17 -17
- package/dist/registry/routes/publish.d.ts +3 -3
- package/dist/registry/routes/publish.js +97 -96
- package/dist/registry/routes/static-redirector.d.ts +3 -3
- package/dist/registry/routes/static-redirector.js +63 -63
- package/dist/registry/views/index.d.ts +2 -2
- package/dist/registry/views/index.js +39 -39
- package/dist/registry/views/info.d.ts +16 -16
- package/dist/registry/views/info.js +44 -41
- package/dist/registry/views/partials/component-author.d.ts +8 -8
- package/dist/registry/views/partials/component-author.js +20 -20
- package/dist/registry/views/partials/component-parameters.d.ts +5 -5
- package/dist/registry/views/partials/component-parameters.js +24 -24
- package/dist/registry/views/partials/component-state.d.ts +5 -5
- package/dist/registry/views/partials/component-state.js +6 -6
- package/dist/registry/views/partials/component-versions.d.ts +5 -5
- package/dist/registry/views/partials/component-versions.js +9 -9
- package/dist/registry/views/partials/components-dependencies.d.ts +2 -2
- package/dist/registry/views/partials/components-dependencies.js +12 -12
- package/dist/registry/views/partials/components-history.d.ts +2 -2
- package/dist/registry/views/partials/components-history.js +10 -10
- package/dist/registry/views/partials/components-list.d.ts +2 -2
- package/dist/registry/views/partials/components-list.js +26 -26
- package/dist/registry/views/partials/components-plugins.d.ts +2 -2
- package/dist/registry/views/partials/components-plugins.js +8 -8
- package/dist/registry/views/partials/components-templates.d.ts +2 -2
- package/dist/registry/views/partials/components-templates.js +14 -14
- package/dist/registry/views/partials/layout.d.ts +8 -8
- package/dist/registry/views/partials/layout.js +11 -11
- package/dist/registry/views/partials/property.d.ts +2 -2
- package/dist/registry/views/partials/property.js +11 -11
- package/dist/registry/views/partials/selected-checkbox.d.ts +4 -4
- package/dist/registry/views/partials/selected-checkbox.js +7 -7
- package/dist/registry/views/preview.d.ts +8 -8
- package/dist/registry/views/preview.js +9 -9
- package/dist/registry/views/static/index.d.ts +2 -2
- package/dist/registry/views/static/index.js +3 -3
- package/dist/registry/views/static/info.d.ts +2 -2
- package/dist/registry/views/static/info.js +15 -4
- package/dist/registry/views/static/style.d.ts +2 -2
- package/dist/registry/views/static/style.js +3 -3
- package/dist/resources/index.d.ts +134 -134
- package/dist/resources/index.js +145 -145
- package/dist/resources/settings.d.ts +17 -17
- package/dist/resources/settings.js +18 -18
- package/dist/types.d.ts +287 -285
- package/dist/types.js +2 -2
- package/dist/utils/clean-require.d.ts +16 -16
- package/dist/utils/clean-require.js +18 -18
- package/dist/utils/date-stringify.d.ts +1 -1
- package/dist/utils/date-stringify.js +22 -22
- package/dist/utils/error-to-string.d.ts +1 -1
- package/dist/utils/error-to-string.js +15 -15
- package/dist/utils/is-template-legacy.d.ts +3 -3
- package/dist/utils/is-template-legacy.js +6 -6
- package/dist/utils/is-template-valid.d.ts +4 -4
- package/dist/utils/is-template-valid.js +12 -12
- package/dist/utils/module-exists.d.ts +1 -1
- package/dist/utils/module-exists.js +15 -15
- package/dist/utils/npm-utils.d.ts +20 -22
- package/dist/utils/npm-utils.js +74 -63
- package/dist/utils/put.d.ts +2 -1
- package/dist/utils/put.js +29 -48
- package/dist/utils/strip-version.d.ts +1 -1
- package/dist/utils/strip-version.js +11 -11
- package/logintervals.md +1 -1
- package/package.json +6 -1
- package/src/cli/domain/clean.ts +10 -20
- package/src/cli/domain/get-components-by-dir.ts +12 -26
- package/src/cli/domain/get-mocked-plugins.ts +32 -26
- package/src/cli/domain/handle-dependencies/ensure-compiler-is-declared-as-devDependency.ts +8 -12
- package/src/cli/domain/handle-dependencies/get-compiler.ts +8 -11
- package/src/cli/domain/handle-dependencies/index.ts +55 -109
- package/src/cli/domain/handle-dependencies/install-compiler.ts +22 -15
- package/src/cli/domain/handle-dependencies/install-missing-dependencies.ts +19 -13
- package/src/cli/domain/handle-dependencies/link-missing-dependencies.ts +8 -16
- package/src/cli/domain/init-template/index.ts +13 -20
- package/src/cli/domain/init-template/install-template.ts +11 -12
- package/src/cli/domain/init-template/scaffold.ts +9 -12
- package/src/cli/domain/local.ts +19 -22
- package/src/cli/domain/mock.ts +32 -36
- package/src/cli/domain/package-components.ts +14 -25
- package/src/cli/domain/registry.ts +80 -116
- package/src/cli/domain/watch.ts +1 -1
- package/src/cli/facade/clean.ts +37 -37
- package/src/cli/facade/dev.ts +159 -182
- package/src/cli/facade/init.ts +36 -38
- package/src/cli/facade/mock.ts +11 -10
- package/src/cli/facade/package.ts +44 -49
- package/src/cli/facade/preview.ts +20 -18
- package/src/cli/facade/publish.ts +134 -172
- package/src/cli/facade/registry-add.ts +16 -15
- package/src/cli/facade/registry-ls.ts +27 -22
- package/src/cli/facade/registry-remove.ts +16 -15
- package/src/cli/facade/registry.ts +7 -5
- package/src/cli/index.ts +3 -5
- package/src/components/oc-client/_package/package.json +1 -1
- package/src/components/oc-client/package.json +1 -1
- package/src/globals.d.ts +38 -0
- package/src/oc-cli.js +0 -0
- package/src/registry/app-start.ts +27 -31
- package/src/registry/domain/authentication.ts +5 -13
- package/src/registry/domain/components-cache/components-list.ts +45 -67
- package/src/registry/domain/components-cache/index.ts +55 -60
- package/src/registry/domain/components-details.ts +49 -75
- package/src/registry/domain/extract-package.ts +19 -27
- package/src/registry/domain/get-package-json-from-temp-dir.ts +3 -4
- package/src/registry/domain/nested-renderer.ts +64 -122
- package/src/registry/domain/options-sanitiser.ts +6 -3
- package/src/registry/domain/plugins-initialiser.ts +45 -49
- package/src/registry/domain/repository.ts +129 -235
- package/src/registry/domain/require-wrapper.ts +1 -2
- package/src/registry/domain/storage-adapter.ts +85 -0
- package/src/registry/index.ts +48 -79
- package/src/registry/middleware/index.ts +10 -2
- package/src/registry/router.ts +2 -10
- package/src/registry/routes/component-info.ts +4 -3
- package/src/registry/routes/component-preview.ts +3 -2
- package/src/registry/routes/components.ts +1 -1
- package/src/registry/routes/helpers/get-component-fallback.ts +3 -9
- package/src/registry/routes/helpers/get-component.ts +11 -9
- package/src/registry/routes/helpers/is-url-discoverable.ts +14 -15
- package/src/registry/routes/index.ts +18 -13
- package/src/registry/routes/publish.ts +31 -34
- package/src/registry/views/info.ts +5 -2
- package/src/registry/views/static/info.ts +12 -1
- package/src/resources/settings.ts +1 -1
- package/src/types.ts +80 -141
- package/src/utils/npm-utils.ts +38 -37
- package/src/utils/put.ts +15 -37
|
@@ -5,21 +5,23 @@ import * as npm from '../../../utils/npm-utils';
|
|
|
5
5
|
import strings from '../../../resources/index';
|
|
6
6
|
import { Logger } from '../../logger';
|
|
7
7
|
|
|
8
|
-
export default function installMissingDependencies(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
): void {
|
|
8
|
+
export default async function installMissingDependencies(options: {
|
|
9
|
+
dependencies: Record<string, string>;
|
|
10
|
+
logger: Logger;
|
|
11
|
+
}): Promise<void> {
|
|
12
12
|
const { dependencies, logger } = options;
|
|
13
13
|
|
|
14
14
|
const missing = getMissingDependencies(dependencies);
|
|
15
15
|
|
|
16
16
|
if (!missing.length) {
|
|
17
|
-
return
|
|
17
|
+
return;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
const installPath = path.resolve('.');
|
|
21
|
-
|
|
22
|
-
logger.warn(
|
|
21
|
+
|
|
22
|
+
logger.warn(
|
|
23
|
+
strings.messages.cli.INSTALLING_DEPS(missing.join(', '), installPath)
|
|
24
|
+
);
|
|
23
25
|
|
|
24
26
|
const npmOptions = {
|
|
25
27
|
dependencies: missing,
|
|
@@ -29,14 +31,18 @@ export default function installMissingDependencies(
|
|
|
29
31
|
usePrefix: true
|
|
30
32
|
};
|
|
31
33
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
+
try {
|
|
35
|
+
await npm.installDependencies(npmOptions);
|
|
36
|
+
|
|
37
|
+
if (getMissingDependencies(dependencies).length) {
|
|
34
38
|
logger.err('FAIL');
|
|
35
|
-
|
|
36
|
-
return callback(strings.errors.cli.DEPENDENCIES_INSTALL_FAIL);
|
|
39
|
+
throw strings.errors.cli.DEPENDENCIES_INSTALL_FAIL;
|
|
37
40
|
}
|
|
38
41
|
|
|
39
42
|
logger.ok('OK');
|
|
40
|
-
|
|
41
|
-
|
|
43
|
+
} catch (err) {
|
|
44
|
+
logger.err('FAIL');
|
|
45
|
+
if (err) logger.err(String(err));
|
|
46
|
+
throw strings.errors.cli.DEPENDENCIES_INSTALL_FAIL;
|
|
47
|
+
}
|
|
42
48
|
}
|
|
@@ -5,20 +5,17 @@ import strings from '../../../resources/index';
|
|
|
5
5
|
import stripVersion from '../../../utils/strip-version';
|
|
6
6
|
import { Logger } from '../../logger';
|
|
7
7
|
|
|
8
|
-
export default function linkMissingDependencies(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
},
|
|
14
|
-
callback: (err: string | null) => void
|
|
15
|
-
): void {
|
|
8
|
+
export default async function linkMissingDependencies(options: {
|
|
9
|
+
componentPath: string;
|
|
10
|
+
dependencies: Record<string, string>;
|
|
11
|
+
logger: Logger;
|
|
12
|
+
}): Promise<void> {
|
|
16
13
|
const { componentPath, dependencies, logger } = options;
|
|
17
14
|
|
|
18
15
|
const missingDependencies = getMissingDependencies(dependencies);
|
|
19
16
|
|
|
20
17
|
if (!missingDependencies.length) {
|
|
21
|
-
return
|
|
18
|
+
return;
|
|
22
19
|
}
|
|
23
20
|
|
|
24
21
|
logger.warn(
|
|
@@ -27,7 +24,6 @@ export default function linkMissingDependencies(
|
|
|
27
24
|
);
|
|
28
25
|
|
|
29
26
|
const symLinkType = 'dir';
|
|
30
|
-
let symLinkError = false;
|
|
31
27
|
|
|
32
28
|
for (const dependency of missingDependencies) {
|
|
33
29
|
const moduleName = stripVersion(dependency);
|
|
@@ -38,16 +34,12 @@ export default function linkMissingDependencies(
|
|
|
38
34
|
);
|
|
39
35
|
const pathToModule = path.resolve('.', 'node_modules', moduleName);
|
|
40
36
|
try {
|
|
41
|
-
fs.
|
|
37
|
+
await fs.ensureSymlink(pathToComponentModule, pathToModule, symLinkType);
|
|
42
38
|
} catch (err) {
|
|
43
|
-
symLinkError = true;
|
|
44
39
|
logger.err(
|
|
45
40
|
strings.errors.cli.DEPENDENCY_LINK_FAIL(moduleName, String(err))
|
|
46
41
|
);
|
|
42
|
+
throw strings.errors.cli.DEPENDENCIES_LINK_FAIL;
|
|
47
43
|
}
|
|
48
44
|
}
|
|
49
|
-
|
|
50
|
-
return !symLinkError
|
|
51
|
-
? callback(null)
|
|
52
|
-
: callback(strings.errors.cli.DEPENDENCIES_LINK_FAIL);
|
|
53
45
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import async from 'async';
|
|
2
1
|
import fs from 'fs-extra';
|
|
3
2
|
import path from 'path';
|
|
4
3
|
|
|
@@ -7,27 +6,21 @@ import * as npm from '../../../utils/npm-utils';
|
|
|
7
6
|
import scaffold from './scaffold';
|
|
8
7
|
import { Logger } from '../../logger';
|
|
9
8
|
|
|
10
|
-
export default function initTemplate(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
},
|
|
18
|
-
callback: (err: string | null, data: { ok: true }) => void
|
|
19
|
-
): void {
|
|
9
|
+
export default async function initTemplate(options: {
|
|
10
|
+
componentPath: string;
|
|
11
|
+
templateType: string;
|
|
12
|
+
componentName: string;
|
|
13
|
+
compiler: string;
|
|
14
|
+
logger: Logger;
|
|
15
|
+
}): Promise<{ ok: true }> {
|
|
20
16
|
const { compiler, componentPath } = options;
|
|
21
17
|
const compilerPath = path.join(componentPath, 'node_modules', compiler);
|
|
22
18
|
const npmOptions = { initPath: componentPath, silent: true };
|
|
23
19
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
],
|
|
31
|
-
callback as any
|
|
32
|
-
);
|
|
20
|
+
await fs.ensureDir(componentPath);
|
|
21
|
+
await npm.init(npmOptions);
|
|
22
|
+
await installTemplate(options);
|
|
23
|
+
await scaffold(Object.assign(options, { compilerPath }));
|
|
24
|
+
|
|
25
|
+
return { ok: true };
|
|
33
26
|
}
|
|
@@ -12,11 +12,11 @@ interface Options {
|
|
|
12
12
|
logger: Logger;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
export default function installTemplate(
|
|
16
|
-
options: Options
|
|
17
|
-
|
|
18
|
-
): void {
|
|
15
|
+
export default async function installTemplate(
|
|
16
|
+
options: Options
|
|
17
|
+
): Promise<{ ok: true }> {
|
|
19
18
|
const { compiler, componentPath, logger, templateType } = options;
|
|
19
|
+
const errorMessage = 'template type not valid';
|
|
20
20
|
|
|
21
21
|
const npmOptions = {
|
|
22
22
|
dependency: compiler,
|
|
@@ -28,16 +28,13 @@ export default function installTemplate(
|
|
|
28
28
|
|
|
29
29
|
logger.log(strings.messages.cli.installCompiler(compiler));
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
if (err) {
|
|
34
|
-
return callback(errorMessage, undefined as any);
|
|
35
|
-
}
|
|
31
|
+
try {
|
|
32
|
+
const result = await npm.installDependency(npmOptions);
|
|
36
33
|
|
|
37
34
|
const installedCompiler = tryRequire(result.dest);
|
|
38
35
|
|
|
39
36
|
if (!isTemplateValid(installedCompiler, { compiler: true })) {
|
|
40
|
-
|
|
37
|
+
throw errorMessage;
|
|
41
38
|
}
|
|
42
39
|
const version = installedCompiler.getInfo().version;
|
|
43
40
|
logger.log(
|
|
@@ -48,6 +45,8 @@ export default function installTemplate(
|
|
|
48
45
|
)
|
|
49
46
|
);
|
|
50
47
|
|
|
51
|
-
return
|
|
52
|
-
})
|
|
48
|
+
return { ok: true };
|
|
49
|
+
} catch (err) {
|
|
50
|
+
throw errorMessage;
|
|
51
|
+
}
|
|
53
52
|
}
|
|
@@ -11,38 +11,35 @@ interface ScaffoldOptions {
|
|
|
11
11
|
templateType: string;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
export default function scaffold(
|
|
15
|
-
options: ScaffoldOptions
|
|
16
|
-
|
|
17
|
-
): void {
|
|
14
|
+
export default async function scaffold(
|
|
15
|
+
options: ScaffoldOptions
|
|
16
|
+
): Promise<{ ok: true }> {
|
|
18
17
|
const { compiler, compilerPath, componentName, componentPath, templateType } =
|
|
19
18
|
options;
|
|
20
19
|
|
|
21
20
|
const baseComponentPath = path.join(compilerPath, 'scaffold');
|
|
22
21
|
const baseComponentFiles = path.join(baseComponentPath, 'src');
|
|
23
|
-
const compilerPackage = fs.
|
|
22
|
+
const compilerPackage = await fs.readJson(
|
|
24
23
|
path.join(compilerPath, 'package.json')
|
|
25
24
|
);
|
|
26
25
|
|
|
27
26
|
try {
|
|
28
|
-
fs.
|
|
27
|
+
await fs.copy(baseComponentFiles, componentPath);
|
|
29
28
|
|
|
30
|
-
const componentPackage = fs.
|
|
29
|
+
const componentPackage = await fs.readJson(
|
|
31
30
|
path.join(componentPath, 'package.json')
|
|
32
31
|
);
|
|
33
32
|
componentPackage.name = componentName;
|
|
34
33
|
componentPackage.devDependencies[compiler] = compilerPackage.version;
|
|
35
|
-
fs.
|
|
34
|
+
await fs.writeJson(componentPath + '/package.json', componentPackage, {
|
|
36
35
|
spaces: 2
|
|
37
36
|
});
|
|
38
37
|
|
|
39
|
-
return
|
|
38
|
+
return { ok: true };
|
|
40
39
|
} catch (error) {
|
|
41
40
|
const url =
|
|
42
41
|
(compilerPackage.bugs && compilerPackage.bugs.url) ||
|
|
43
42
|
`the ${templateType} repo`;
|
|
44
|
-
|
|
45
|
-
strings.errors.cli.scaffoldError(url, String(error))
|
|
46
|
-
);
|
|
43
|
+
throw strings.errors.cli.scaffoldError(url, String(error));
|
|
47
44
|
}
|
|
48
45
|
}
|
package/src/cli/domain/local.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fs from 'fs-extra';
|
|
2
2
|
import targz from 'targz';
|
|
3
|
+
import { promisify } from 'util';
|
|
3
4
|
|
|
4
5
|
import * as clean from './clean';
|
|
5
6
|
import getComponentsByDir from './get-components-by-dir';
|
|
@@ -14,31 +15,28 @@ import { Local } from '../../types';
|
|
|
14
15
|
export default function local(): Local {
|
|
15
16
|
return {
|
|
16
17
|
clean,
|
|
17
|
-
cleanup(compressedPackagePath: string
|
|
18
|
-
return fs.unlink(compressedPackagePath
|
|
18
|
+
cleanup(compressedPackagePath: string) {
|
|
19
|
+
return fs.unlink(compressedPackagePath);
|
|
19
20
|
},
|
|
20
|
-
compress(input, output
|
|
21
|
-
return targz.compress(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
});
|
|
30
|
-
}
|
|
21
|
+
compress(input, output) {
|
|
22
|
+
return promisify(targz.compress)({
|
|
23
|
+
src: input,
|
|
24
|
+
dest: output,
|
|
25
|
+
tar: {
|
|
26
|
+
map: function (file) {
|
|
27
|
+
return Object.assign(file, {
|
|
28
|
+
name: `_package/${file.name}`
|
|
29
|
+
});
|
|
31
30
|
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
35
33
|
},
|
|
36
34
|
getComponentsByDir: getComponentsByDir(),
|
|
37
|
-
init(options
|
|
35
|
+
async init(options) {
|
|
38
36
|
const { componentName, logger } = options;
|
|
39
37
|
let { templateType } = options;
|
|
40
38
|
if (!validator.validateComponentName(componentName)) {
|
|
41
|
-
|
|
39
|
+
throw 'name not valid';
|
|
42
40
|
}
|
|
43
41
|
|
|
44
42
|
// LEGACY TEMPLATES WARNING
|
|
@@ -56,15 +54,14 @@ export default function local(): Local {
|
|
|
56
54
|
);
|
|
57
55
|
}
|
|
58
56
|
try {
|
|
59
|
-
initTemplate(
|
|
57
|
+
await initTemplate(
|
|
60
58
|
Object.assign(options, {
|
|
61
59
|
templateType,
|
|
62
60
|
compiler: `${templateType}-compiler`
|
|
63
|
-
})
|
|
64
|
-
callback as any
|
|
61
|
+
})
|
|
65
62
|
);
|
|
66
63
|
} catch (e) {
|
|
67
|
-
|
|
64
|
+
throw 'template type not valid';
|
|
68
65
|
}
|
|
69
66
|
},
|
|
70
67
|
mock: mock(),
|
package/src/cli/domain/mock.ts
CHANGED
|
@@ -4,41 +4,37 @@ import path from 'path';
|
|
|
4
4
|
import settings from '../../resources/settings';
|
|
5
5
|
|
|
6
6
|
export default function mock() {
|
|
7
|
-
return function (
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
{ spaces: 2 },
|
|
40
|
-
callback
|
|
41
|
-
);
|
|
42
|
-
});
|
|
7
|
+
return async function (params: {
|
|
8
|
+
targetType: string;
|
|
9
|
+
targetValue: string;
|
|
10
|
+
targetName: string;
|
|
11
|
+
}): Promise<void> {
|
|
12
|
+
const localConfig = await fs
|
|
13
|
+
.readJson(settings.configFile.src)
|
|
14
|
+
.catch(() => ({}));
|
|
15
|
+
|
|
16
|
+
const mockType = params.targetType + 's';
|
|
17
|
+
|
|
18
|
+
if (!localConfig.mocks) {
|
|
19
|
+
localConfig.mocks = {};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (!localConfig.mocks[mockType]) {
|
|
23
|
+
localConfig.mocks[mockType] = {};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
let pluginType = 'static';
|
|
27
|
+
if (fs.existsSync(path.resolve(params.targetValue.toString()))) {
|
|
28
|
+
pluginType = 'dynamic';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (!localConfig.mocks[mockType][pluginType]) {
|
|
32
|
+
localConfig.mocks[mockType][pluginType] = {};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
localConfig.mocks[mockType][pluginType][params.targetName] =
|
|
36
|
+
params.targetValue;
|
|
37
|
+
|
|
38
|
+
return fs.writeJson(settings.configFile.src, localConfig, { spaces: 2 });
|
|
43
39
|
};
|
|
44
40
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import fs from 'fs-extra';
|
|
2
|
+
import { promisify } from 'util';
|
|
2
3
|
import path from 'path';
|
|
3
4
|
|
|
4
5
|
import requireTemplate from './handle-dependencies/require-template';
|
|
@@ -14,10 +15,7 @@ interface PackageOptions {
|
|
|
14
15
|
|
|
15
16
|
const packageComponents =
|
|
16
17
|
() =>
|
|
17
|
-
(
|
|
18
|
-
options: PackageOptions,
|
|
19
|
-
callback: (err: Error | null, data: Component) => void
|
|
20
|
-
): void => {
|
|
18
|
+
async (options: PackageOptions): Promise<Component> => {
|
|
21
19
|
const production = options.production;
|
|
22
20
|
const componentPath = options.componentPath;
|
|
23
21
|
const minify = options.minify === true;
|
|
@@ -27,24 +25,18 @@ const packageComponents =
|
|
|
27
25
|
const ocPackagePath = path.join(__dirname, '../../../package.json');
|
|
28
26
|
|
|
29
27
|
if (!fs.existsSync(componentPackagePath)) {
|
|
30
|
-
|
|
31
|
-
new Error('component does not contain package.json'),
|
|
32
|
-
undefined as any
|
|
33
|
-
);
|
|
28
|
+
throw new Error('component does not contain package.json');
|
|
34
29
|
} else if (!fs.existsSync(ocPackagePath)) {
|
|
35
|
-
|
|
36
|
-
new Error('error resolving oc internal dependencies'),
|
|
37
|
-
undefined as any
|
|
38
|
-
);
|
|
30
|
+
throw new Error('error resolving oc internal dependencies');
|
|
39
31
|
}
|
|
40
32
|
|
|
41
|
-
fs.
|
|
33
|
+
await fs.emptyDir(publishPath);
|
|
42
34
|
|
|
43
|
-
const componentPackage: Component = fs.
|
|
44
|
-
const ocPackage = fs.
|
|
35
|
+
const componentPackage: Component = await fs.readJson(componentPackagePath);
|
|
36
|
+
const ocPackage: Component = await fs.readJson(ocPackagePath);
|
|
45
37
|
|
|
46
38
|
if (!validator.validateComponentName(componentPackage.name)) {
|
|
47
|
-
|
|
39
|
+
throw new Error('name not valid');
|
|
48
40
|
}
|
|
49
41
|
|
|
50
42
|
const type = componentPackage.oc.files.template.type;
|
|
@@ -58,15 +50,12 @@ const packageComponents =
|
|
|
58
50
|
production
|
|
59
51
|
};
|
|
60
52
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
} catch (err) {
|
|
68
|
-
return callback(err as any, undefined as any);
|
|
69
|
-
}
|
|
53
|
+
const ocTemplate = requireTemplate(type, {
|
|
54
|
+
compiler: true,
|
|
55
|
+
componentPath
|
|
56
|
+
});
|
|
57
|
+
const compile = promisify(ocTemplate.compile);
|
|
58
|
+
return compile(compileOptions);
|
|
70
59
|
};
|
|
71
60
|
|
|
72
61
|
export default packageComponents;
|