oc 0.49.21 → 0.49.22

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.
Files changed (166) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/cli/domain/get-mocked-plugins.js +2 -3
  3. package/dist/cli/domain/handle-dependencies/ensure-compiler-is-declared-as-devDependency.js +1 -2
  4. package/dist/cli/domain/local.d.ts +1 -1
  5. package/dist/cli/domain/registry.d.ts +1 -1
  6. package/dist/cli/programmatic-api.d.ts +2 -2
  7. package/dist/components/oc-client/_package/package.json +1 -1
  8. package/dist/components/oc-client/package.json +1 -1
  9. package/dist/registry/domain/components-cache/components-list.d.ts +3 -3
  10. package/dist/registry/domain/components-cache/components-list.js +28 -5
  11. package/dist/registry/domain/components-cache/index.js +27 -22
  12. package/dist/registry/domain/components-details.js +1 -2
  13. package/dist/registry/domain/events-handler.d.ts +3 -3
  14. package/dist/registry/domain/plugins-initialiser.d.ts +1 -1
  15. package/dist/registry/domain/repository.d.ts +1 -1
  16. package/dist/registry/domain/storage-adapter.d.ts +2 -2
  17. package/dist/registry/domain/url-builder.d.ts +1 -1
  18. package/dist/registry/domain/validators/node-version.d.ts +3 -3
  19. package/dist/registry/domain/validators/oc-cli-version.d.ts +3 -3
  20. package/dist/registry/domain/validators/plugins-requirements.d.ts +1 -1
  21. package/dist/registry/domain/validators/registry-configuration.d.ts +1 -1
  22. package/dist/registry/domain/validators/uploaded-package.d.ts +1 -1
  23. package/dist/registry/index.js +2 -3
  24. package/dist/registry/routes/helpers/get-available-dependencies.js +2 -3
  25. package/dist/registry/routes/helpers/get-component-fallback.d.ts +1 -1
  26. package/dist/registry/routes/helpers/is-url-discoverable.js +1 -2
  27. package/dist/registry/views/info.d.ts +1 -1
  28. package/dist/registry/views/partials/selected-checkbox.d.ts +1 -1
  29. package/dist/types.d.ts +3 -3
  30. package/dist/utils/is-template-legacy.d.ts +1 -1
  31. package/logintervals.md +1 -1
  32. package/package.json +20 -20
  33. package/tsconfig.json +1 -1
  34. package/dist/components/oc-client/_package/src/oc-client.min.js +0 -3
  35. package/dist/components/oc-client/_package/src/oc-client.min.map +0 -1
  36. package/dist/components/oc-client/src/oc-client.min.js +0 -3
  37. package/dist/components/oc-client/src/oc-client.min.map +0 -1
  38. package/src/cli/commands.ts +0 -178
  39. package/src/cli/domain/clean.ts +0 -21
  40. package/src/cli/domain/get-components-by-dir.ts +0 -47
  41. package/src/cli/domain/get-mocked-plugins.ts +0 -154
  42. package/src/cli/domain/handle-dependencies/ensure-compiler-is-declared-as-devDependency.ts +0 -17
  43. package/src/cli/domain/handle-dependencies/get-compiler.ts +0 -35
  44. package/src/cli/domain/handle-dependencies/get-missing-dependencies.ts +0 -17
  45. package/src/cli/domain/handle-dependencies/index.ts +0 -93
  46. package/src/cli/domain/handle-dependencies/install-compiler.ts +0 -43
  47. package/src/cli/domain/handle-dependencies/install-missing-dependencies.ts +0 -48
  48. package/src/cli/domain/handle-dependencies/link-missing-dependencies.ts +0 -45
  49. package/src/cli/domain/handle-dependencies/require-template.ts +0 -62
  50. package/src/cli/domain/init-template/index.ts +0 -26
  51. package/src/cli/domain/init-template/install-template.ts +0 -52
  52. package/src/cli/domain/init-template/scaffold.ts +0 -45
  53. package/src/cli/domain/local.ts +0 -77
  54. package/src/cli/domain/mock.ts +0 -40
  55. package/src/cli/domain/package-components.ts +0 -61
  56. package/src/cli/domain/registry.ts +0 -147
  57. package/src/cli/domain/url-parser.ts +0 -44
  58. package/src/cli/domain/watch.ts +0 -33
  59. package/src/cli/facade/clean.ts +0 -75
  60. package/src/cli/facade/dev.ts +0 -214
  61. package/src/cli/facade/init.ts +0 -50
  62. package/src/cli/facade/mock.ts +0 -20
  63. package/src/cli/facade/package.ts +0 -65
  64. package/src/cli/facade/preview.ts +0 -28
  65. package/src/cli/facade/publish.ts +0 -209
  66. package/src/cli/facade/registry-add.ts +0 -23
  67. package/src/cli/facade/registry-ls.ts +0 -36
  68. package/src/cli/facade/registry-remove.ts +0 -23
  69. package/src/cli/facade/registry.ts +0 -9
  70. package/src/cli/index.ts +0 -142
  71. package/src/cli/logger.ts +0 -38
  72. package/src/cli/programmatic-api.ts +0 -142
  73. package/src/cli/validate-command.ts +0 -18
  74. package/src/components/oc-client/_package/package.json +0 -1
  75. package/src/components/oc-client/_package/server.js +0 -1
  76. package/src/components/oc-client/_package/src/oc-client.min.js +0 -3
  77. package/src/components/oc-client/_package/src/oc-client.min.map +0 -1
  78. package/src/components/oc-client/_package/template.js +0 -1
  79. package/src/components/oc-client/package.json +0 -26
  80. package/src/components/oc-client/server.js +0 -6
  81. package/src/components/oc-client/src/oc-client.min.js +0 -3
  82. package/src/components/oc-client/src/oc-client.min.map +0 -1
  83. package/src/components/oc-client/template.js +0 -4
  84. package/src/globals.d.ts +0 -103
  85. package/src/index.ts +0 -3
  86. package/src/oc-cli.js +0 -3
  87. package/src/registry/app-start.ts +0 -75
  88. package/src/registry/domain/authentication.ts +0 -59
  89. package/src/registry/domain/components-cache/components-list.ts +0 -70
  90. package/src/registry/domain/components-cache/index.ts +0 -90
  91. package/src/registry/domain/components-details.ts +0 -96
  92. package/src/registry/domain/events-handler.ts +0 -86
  93. package/src/registry/domain/extract-package.ts +0 -45
  94. package/src/registry/domain/get-package-json-from-temp-dir.ts +0 -9
  95. package/src/registry/domain/nested-renderer.ts +0 -88
  96. package/src/registry/domain/options-sanitiser.ts +0 -118
  97. package/src/registry/domain/plugins-initialiser.ts +0 -127
  98. package/src/registry/domain/register-templates.ts +0 -41
  99. package/src/registry/domain/repository.ts +0 -390
  100. package/src/registry/domain/require-wrapper.ts +0 -39
  101. package/src/registry/domain/sanitiser.ts +0 -60
  102. package/src/registry/domain/storage-adapter.ts +0 -85
  103. package/src/registry/domain/url-builder.ts +0 -80
  104. package/src/registry/domain/validators/component-parameters.ts +0 -112
  105. package/src/registry/domain/validators/index.ts +0 -24
  106. package/src/registry/domain/validators/node-version.ts +0 -59
  107. package/src/registry/domain/validators/oc-cli-version.ts +0 -52
  108. package/src/registry/domain/validators/package-json-validator.ts +0 -35
  109. package/src/registry/domain/validators/plugins-requirements.ts +0 -39
  110. package/src/registry/domain/validators/registry-configuration.ts +0 -143
  111. package/src/registry/domain/validators/uploaded-package.ts +0 -49
  112. package/src/registry/domain/version-handler.ts +0 -25
  113. package/src/registry/index.ts +0 -117
  114. package/src/registry/middleware/base-url-handler.ts +0 -16
  115. package/src/registry/middleware/cors.ts +0 -18
  116. package/src/registry/middleware/discovery-handler.ts +0 -20
  117. package/src/registry/middleware/file-uploads.ts +0 -28
  118. package/src/registry/middleware/index.ts +0 -53
  119. package/src/registry/middleware/request-handler.ts +0 -30
  120. package/src/registry/router.ts +0 -85
  121. package/src/registry/routes/component-info.ts +0 -119
  122. package/src/registry/routes/component-preview.ts +0 -87
  123. package/src/registry/routes/component.ts +0 -53
  124. package/src/registry/routes/components.ts +0 -107
  125. package/src/registry/routes/dependencies.ts +0 -27
  126. package/src/registry/routes/helpers/apply-default-values.ts +0 -29
  127. package/src/registry/routes/helpers/get-available-dependencies.ts +0 -31
  128. package/src/registry/routes/helpers/get-component-fallback.ts +0 -139
  129. package/src/registry/routes/helpers/get-component-retrieving-info.ts +0 -44
  130. package/src/registry/routes/helpers/get-component.ts +0 -583
  131. package/src/registry/routes/helpers/get-components-history.ts +0 -40
  132. package/src/registry/routes/helpers/is-url-discoverable.ts +0 -18
  133. package/src/registry/routes/index.ts +0 -127
  134. package/src/registry/routes/plugins.ts +0 -19
  135. package/src/registry/routes/publish.ts +0 -89
  136. package/src/registry/routes/static-redirector.ts +0 -74
  137. package/src/registry/views/index.ts +0 -66
  138. package/src/registry/views/info.ts +0 -89
  139. package/src/registry/views/partials/component-author.ts +0 -32
  140. package/src/registry/views/partials/component-parameters.ts +0 -53
  141. package/src/registry/views/partials/component-state.ts +0 -14
  142. package/src/registry/views/partials/component-versions.ts +0 -16
  143. package/src/registry/views/partials/components-dependencies.ts +0 -26
  144. package/src/registry/views/partials/components-history.ts +0 -24
  145. package/src/registry/views/partials/components-list.ts +0 -65
  146. package/src/registry/views/partials/components-plugins.ts +0 -23
  147. package/src/registry/views/partials/components-templates.ts +0 -36
  148. package/src/registry/views/partials/layout.ts +0 -32
  149. package/src/registry/views/partials/property.ts +0 -17
  150. package/src/registry/views/partials/selected-checkbox.ts +0 -16
  151. package/src/registry/views/preview.ts +0 -37
  152. package/src/registry/views/static/index.ts +0 -92
  153. package/src/registry/views/static/info.ts +0 -43
  154. package/src/registry/views/static/style.ts +0 -277
  155. package/src/resources/index.ts +0 -279
  156. package/src/resources/settings.ts +0 -17
  157. package/src/types.ts +0 -251
  158. package/src/utils/clean-require.ts +0 -35
  159. package/src/utils/date-stringify.ts +0 -23
  160. package/src/utils/error-to-string.ts +0 -13
  161. package/src/utils/is-template-legacy.ts +0 -7
  162. package/src/utils/is-template-valid.ts +0 -19
  163. package/src/utils/module-exists.ts +0 -14
  164. package/src/utils/npm-utils.ts +0 -109
  165. package/src/utils/put.ts +0 -35
  166. package/src/utils/strip-version.ts +0 -6
@@ -1,17 +0,0 @@
1
- import strings from '../../../resources';
2
- import { Component } from '../../../types';
3
-
4
- export default function ensureCompilerIsDeclaredAsDevDependency(options: {
5
- componentPath: string;
6
- pkg: Component;
7
- template: string;
8
- }): string {
9
- const { componentPath, pkg, template } = options;
10
- const compilerDep = `${template}-compiler`;
11
- const isOk = pkg.devDependencies?.[compilerDep];
12
-
13
- if (!isOk)
14
- throw strings.errors.cli.TEMPLATE_DEP_MISSING(template, componentPath);
15
-
16
- return compilerDep;
17
- }
@@ -1,35 +0,0 @@
1
- import path from 'path';
2
- import { Template } from '../../../types';
3
-
4
- import cleanRequire from '../../../utils/clean-require';
5
- import { Logger } from '../../logger';
6
- import installCompiler from './install-compiler';
7
-
8
- export default function getCompiler(options: {
9
- compilerDep: string;
10
- componentPath: string;
11
- logger: Logger;
12
- pkg: { devDependencies: Record<string, string> };
13
- }): Promise<Template> {
14
- const { compilerDep, componentPath, logger, pkg } = options;
15
- const compilerPath = path.join(componentPath, 'node_modules', compilerDep);
16
- const compiler = cleanRequire<Template>(compilerPath, { justTry: true });
17
-
18
- if (compiler) {
19
- return Promise.resolve(compiler);
20
- }
21
-
22
- let dependency = compilerDep;
23
- if (pkg.devDependencies[compilerDep]) {
24
- dependency += `@${pkg.devDependencies[compilerDep]}`;
25
- }
26
-
27
- const installOptions = {
28
- compilerPath,
29
- componentPath,
30
- dependency,
31
- logger
32
- };
33
-
34
- return installCompiler(installOptions);
35
- }
@@ -1,17 +0,0 @@
1
- import path from 'path';
2
- import moduleExists from '../../../utils/module-exists';
3
-
4
- export default function getMissingDependencies(
5
- dependencies: Record<string, string> = {}
6
- ): string[] {
7
- const missing: string[] = [];
8
-
9
- Object.entries(dependencies).forEach(([dependency, version]) => {
10
- const pathToModule = path.resolve('node_modules/', dependency);
11
- if (!moduleExists(pathToModule)) {
12
- missing.push(`${dependency}@${version || 'latest'}`);
13
- }
14
- });
15
-
16
- return missing;
17
- }
@@ -1,93 +0,0 @@
1
- import coreModules from 'builtin-modules';
2
- import fs from 'fs-extra';
3
- import path from 'path';
4
-
5
- import ensureCompilerIsDeclaredAsDevDependency from './ensure-compiler-is-declared-as-devDependency';
6
- import getCompiler from './get-compiler';
7
- import installMissingDependencies from './install-missing-dependencies';
8
- import linkMissingDependencies from './link-missing-dependencies';
9
- import isTemplateLegacy from '../../../utils/is-template-legacy';
10
- import strings from '../../../resources';
11
- import { Logger } from '../../logger';
12
- import { Component, Template } from '../../../types';
13
-
14
- const getComponentPackageJson = (componentPath: string): Promise<Component> =>
15
- fs.readJson(path.join(componentPath, 'package.json'));
16
-
17
- const union = (a: ReadonlyArray<string>, b: ReadonlyArray<string>) => [
18
- ...new Set([...a, ...b])
19
- ];
20
-
21
- export default async function handleDependencies(options: {
22
- components: string[];
23
- logger: Logger;
24
- useComponentDependencies?: boolean;
25
- }): Promise<{
26
- modules: string[];
27
- templates: Array<Template>;
28
- }> {
29
- const { components, logger, useComponentDependencies } = options;
30
-
31
- const dependencies: Record<string, string> = {};
32
- const addDependencies = (componentDependencies?: Record<string, string>) =>
33
- Object.entries(componentDependencies || {}).forEach(
34
- ([dependency, version]) => {
35
- dependencies[dependency] = version;
36
- }
37
- );
38
-
39
- const templates: Record<string, Template> = {};
40
- const addTemplate = (templateName: string, template: Template) => {
41
- templates[templateName] = template;
42
- };
43
-
44
- const setupComponentDependencies = async (
45
- componentPath: string
46
- ): Promise<void> => {
47
- const pkg = await getComponentPackageJson(componentPath);
48
- addDependencies(pkg.dependencies);
49
-
50
- const template = pkg.oc.files.template.type;
51
- if (isTemplateLegacy(template)) {
52
- return;
53
- }
54
-
55
- const compilerDep = ensureCompilerIsDeclaredAsDevDependency({
56
- componentPath,
57
- pkg,
58
- template
59
- });
60
- Object.assign(options, { compilerDep });
61
-
62
- const compiler = await getCompiler({
63
- compilerDep,
64
- componentPath,
65
- logger,
66
- pkg: pkg as { devDependencies: Record<string, string> }
67
- });
68
- Object.assign(options, { compiler });
69
- addTemplate(template, compiler);
70
- };
71
-
72
- logger.warn(strings.messages.cli.CHECKING_DEPENDENCIES);
73
-
74
- for (const component of components) {
75
- await setupComponentDependencies(component);
76
- }
77
-
78
- const result = {
79
- modules: union(coreModules, Object.keys(dependencies)).sort(),
80
- templates: Object.values(templates)
81
- };
82
- if (useComponentDependencies) {
83
- linkMissingDependencies({
84
- componentPath: components[0],
85
- dependencies,
86
- logger
87
- });
88
- return result;
89
- }
90
-
91
- await installMissingDependencies({ dependencies, logger });
92
- return result;
93
- }
@@ -1,43 +0,0 @@
1
- import cleanRequire from '../../../utils/clean-require';
2
- import isTemplateValid from '../../../utils/is-template-valid';
3
- import * as npm from '../../../utils/npm-utils';
4
- import strings from '../../../resources/index';
5
- import { Logger } from '../../logger';
6
- import { Template } from '../../../types';
7
-
8
- export default async function installCompiler(options: {
9
- compilerPath: string;
10
- componentPath: string;
11
- dependency: string;
12
- logger: Logger;
13
- }): Promise<Template> {
14
- const { compilerPath, componentPath, dependency, logger } = options;
15
-
16
- logger.warn(strings.messages.cli.INSTALLING_DEPS(dependency, componentPath));
17
-
18
- const npmOptions = {
19
- dependency,
20
- installPath: componentPath,
21
- save: false,
22
- silent: true,
23
- usePrefix: false
24
- };
25
- const errorMsg = 'There was a problem while installing the compiler';
26
-
27
- try {
28
- await npm.installDependency(npmOptions);
29
- logger.ok('OK');
30
-
31
- const compiler = cleanRequire<Template>(compilerPath, { justTry: true });
32
-
33
- if (!isTemplateValid(compiler)) {
34
- throw errorMsg;
35
- }
36
-
37
- return compiler;
38
- } catch (err) {
39
- logger.err('FAIL');
40
-
41
- throw errorMsg;
42
- }
43
- }
@@ -1,48 +0,0 @@
1
- import path from 'path';
2
-
3
- import getMissingDependencies from './get-missing-dependencies';
4
- import * as npm from '../../../utils/npm-utils';
5
- import strings from '../../../resources/index';
6
- import { Logger } from '../../logger';
7
-
8
- export default async function installMissingDependencies(options: {
9
- dependencies: Record<string, string>;
10
- logger: Logger;
11
- }): Promise<void> {
12
- const { dependencies, logger } = options;
13
-
14
- const missing = getMissingDependencies(dependencies);
15
-
16
- if (!missing.length) {
17
- return;
18
- }
19
-
20
- const installPath = path.resolve('.');
21
-
22
- logger.warn(
23
- strings.messages.cli.INSTALLING_DEPS(missing.join(', '), installPath)
24
- );
25
-
26
- const npmOptions = {
27
- dependencies: missing,
28
- installPath,
29
- save: false,
30
- silent: false,
31
- usePrefix: true
32
- };
33
-
34
- try {
35
- await npm.installDependencies(npmOptions);
36
-
37
- if (getMissingDependencies(dependencies).length) {
38
- logger.err('FAIL');
39
- throw strings.errors.cli.DEPENDENCIES_INSTALL_FAIL;
40
- }
41
-
42
- logger.ok('OK');
43
- } catch (err) {
44
- logger.err('FAIL');
45
- if (err) logger.err(String(err));
46
- throw strings.errors.cli.DEPENDENCIES_INSTALL_FAIL;
47
- }
48
- }
@@ -1,45 +0,0 @@
1
- import path from 'path';
2
- import fs from 'fs-extra';
3
- import getMissingDependencies from './get-missing-dependencies';
4
- import strings from '../../../resources/index';
5
- import stripVersion from '../../../utils/strip-version';
6
- import { Logger } from '../../logger';
7
-
8
- export default async function linkMissingDependencies(options: {
9
- componentPath: string;
10
- dependencies: Record<string, string>;
11
- logger: Logger;
12
- }): Promise<void> {
13
- const { componentPath, dependencies, logger } = options;
14
-
15
- const missingDependencies = getMissingDependencies(dependencies);
16
-
17
- if (!missingDependencies.length) {
18
- return;
19
- }
20
-
21
- logger.warn(
22
- strings.messages.cli.LINKING_DEPENDENCIES(missingDependencies.join(', ')),
23
- true
24
- );
25
-
26
- const symLinkType = 'dir';
27
-
28
- for (const dependency of missingDependencies) {
29
- const moduleName = stripVersion(dependency);
30
- const pathToComponentModule = path.resolve(
31
- componentPath,
32
- 'node_modules',
33
- moduleName
34
- );
35
- const pathToModule = path.resolve('.', 'node_modules', moduleName);
36
- try {
37
- await fs.ensureSymlink(pathToComponentModule, pathToModule, symLinkType);
38
- } catch (err) {
39
- logger.err(
40
- strings.errors.cli.DEPENDENCY_LINK_FAIL(moduleName, String(err))
41
- );
42
- throw strings.errors.cli.DEPENDENCIES_LINK_FAIL;
43
- }
44
- }
45
- }
@@ -1,62 +0,0 @@
1
- import path from 'path';
2
-
3
- import cleanRequire from '../../../utils/clean-require';
4
- import isTemplateLegacy from '../../../utils/is-template-legacy';
5
- import isTemplateValid from '../../../utils/is-template-valid';
6
- import strings from '../../../resources';
7
- import { Component } from '../../../types';
8
-
9
- interface Template {
10
- compile: (
11
- opts: {
12
- publishPath: string;
13
- componentPath: string;
14
- componentPackage: any;
15
- ocPackage: any;
16
- minify: boolean;
17
- verbose: boolean;
18
- production: boolean | undefined;
19
- },
20
- cb: (err: Error | null, data: Component) => void
21
- ) => void;
22
- }
23
-
24
- export default function requireTemplate(
25
- template: string,
26
- options: { compiler: boolean; componentPath: string }
27
- ): Template {
28
- const requireOptions = options || {};
29
- let ocTemplate: Template | undefined;
30
-
31
- if (isTemplateLegacy(template)) {
32
- template = `oc-template-${template}`;
33
- }
34
-
35
- if (requireOptions.compiler) {
36
- template = `${template}-compiler`;
37
- }
38
-
39
- const localTemplate = path.join(__dirname, '../../node_modules', template);
40
- const relativeTemplate = path.resolve('.', 'node_modules', template);
41
- const componentRelativePath = path.join(
42
- requireOptions.componentPath,
43
- 'node_modules',
44
- template
45
- );
46
-
47
- [componentRelativePath, template, localTemplate, relativeTemplate].forEach(
48
- pathToTry => {
49
- ocTemplate = ocTemplate || cleanRequire(pathToTry, { justTry: true });
50
- }
51
- );
52
-
53
- if (!ocTemplate) {
54
- throw new Error(strings.errors.cli.TEMPLATE_NOT_FOUND(template));
55
- }
56
-
57
- if (!isTemplateValid(ocTemplate, requireOptions)) {
58
- throw new Error(strings.errors.cli.TEMPLATE_TYPE_NOT_VALID(template));
59
- }
60
-
61
- return ocTemplate;
62
- }
@@ -1,26 +0,0 @@
1
- import fs from 'fs-extra';
2
- import path from 'path';
3
-
4
- import installTemplate from './install-template';
5
- import * as npm from '../../../utils/npm-utils';
6
- import scaffold from './scaffold';
7
- import { Logger } from '../../logger';
8
-
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 }> {
16
- const { compiler, componentPath } = options;
17
- const compilerPath = path.join(componentPath, 'node_modules', compiler);
18
- const npmOptions = { initPath: componentPath, silent: true };
19
-
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 };
26
- }
@@ -1,52 +0,0 @@
1
- import tryRequire from 'try-require';
2
-
3
- import isTemplateValid from '../../../utils/is-template-valid';
4
- import * as npm from '../../../utils/npm-utils';
5
- import strings from '../../../resources';
6
- import { Logger } from '../../logger';
7
-
8
- interface Options {
9
- componentPath: string;
10
- templateType: string;
11
- compiler: string;
12
- logger: Logger;
13
- }
14
-
15
- export default async function installTemplate(
16
- options: Options
17
- ): Promise<{ ok: true }> {
18
- const { compiler, componentPath, logger, templateType } = options;
19
- const errorMessage = 'template type not valid';
20
-
21
- const npmOptions = {
22
- dependency: compiler,
23
- installPath: componentPath,
24
- isDev: true,
25
- save: true,
26
- usePrefix: false
27
- };
28
-
29
- logger.log(strings.messages.cli.installCompiler(compiler));
30
-
31
- try {
32
- const result = await npm.installDependency(npmOptions);
33
-
34
- const installedCompiler = tryRequire(result.dest);
35
-
36
- if (!isTemplateValid(installedCompiler, { compiler: true })) {
37
- throw errorMessage;
38
- }
39
- const version = installedCompiler.getInfo().version;
40
- logger.log(
41
- strings.messages.cli.installCompilerSuccess(
42
- templateType,
43
- compiler,
44
- version
45
- )
46
- );
47
-
48
- return { ok: true };
49
- } catch (err) {
50
- throw errorMessage;
51
- }
52
- }
@@ -1,45 +0,0 @@
1
- import fs from 'fs-extra';
2
- import path from 'path';
3
-
4
- import strings from '../../../resources';
5
-
6
- interface ScaffoldOptions {
7
- compiler: string;
8
- compilerPath: string;
9
- componentName: string;
10
- componentPath: string;
11
- templateType: string;
12
- }
13
-
14
- export default async function scaffold(
15
- options: ScaffoldOptions
16
- ): Promise<{ ok: true }> {
17
- const { compiler, compilerPath, componentName, componentPath, templateType } =
18
- options;
19
-
20
- const baseComponentPath = path.join(compilerPath, 'scaffold');
21
- const baseComponentFiles = path.join(baseComponentPath, 'src');
22
- const compilerPackage = await fs.readJson(
23
- path.join(compilerPath, 'package.json')
24
- );
25
-
26
- try {
27
- await fs.copy(baseComponentFiles, componentPath);
28
-
29
- const componentPackage = await fs.readJson(
30
- path.join(componentPath, 'package.json')
31
- );
32
- componentPackage.name = componentName;
33
- componentPackage.devDependencies[compiler] = compilerPackage.version;
34
- await fs.writeJson(componentPath + '/package.json', componentPackage, {
35
- spaces: 2
36
- });
37
-
38
- return { ok: true };
39
- } catch (error) {
40
- const url =
41
- (compilerPackage.bugs && compilerPackage.bugs.url) ||
42
- `the ${templateType} repo`;
43
- throw strings.errors.cli.scaffoldError(url, String(error));
44
- }
45
- }
@@ -1,77 +0,0 @@
1
- import fs from 'fs-extra';
2
- import targz from 'targz';
3
- import { promisify } from 'util';
4
-
5
- import * as clean from './clean';
6
- import getComponentsByDir from './get-components-by-dir';
7
- import initTemplate from './init-template';
8
- import isTemplateLegacy from '../../utils/is-template-legacy';
9
- import mock from './mock';
10
- import packageComponents from './package-components';
11
- import strings from '../../resources';
12
- import * as validator from '../../registry/domain/validators';
13
- import { Logger } from '../logger';
14
-
15
- export default function local() {
16
- return {
17
- clean,
18
- cleanup(compressedPackagePath: string): Promise<void> {
19
- return fs.unlink(compressedPackagePath);
20
- },
21
- compress(input: string, output: string): Promise<void> {
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
- });
30
- }
31
- }
32
- });
33
- },
34
- getComponentsByDir: getComponentsByDir(),
35
- async init(options: {
36
- componentName: string;
37
- logger: Logger;
38
- componentPath: string;
39
- templateType: string;
40
- }): Promise<void> {
41
- const { componentName, logger } = options;
42
- let { templateType } = options;
43
- if (!validator.validateComponentName(componentName)) {
44
- throw 'name not valid';
45
- }
46
-
47
- // LEGACY TEMPLATES WARNING
48
- if (isTemplateLegacy(templateType)) {
49
- const legacyName = templateType;
50
- templateType = legacyName.replace(
51
- legacyName,
52
- `oc-template-${legacyName}`
53
- );
54
- logger.warn(
55
- strings.messages.cli.legacyTemplateDeprecationWarning(
56
- legacyName,
57
- templateType
58
- )
59
- );
60
- }
61
- try {
62
- await initTemplate(
63
- Object.assign(options, {
64
- templateType,
65
- compiler: `${templateType}-compiler`
66
- })
67
- );
68
- } catch (e) {
69
- throw 'template type not valid';
70
- }
71
- },
72
- mock: mock(),
73
- package: packageComponents()
74
- };
75
- }
76
-
77
- export type Local = ReturnType<typeof local>;
@@ -1,40 +0,0 @@
1
- import fs from 'fs-extra';
2
- import path from 'path';
3
-
4
- import settings from '../../resources/settings';
5
-
6
- export default function mock() {
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 });
39
- };
40
- }
@@ -1,61 +0,0 @@
1
- import fs from 'fs-extra';
2
- import { promisify } from 'util';
3
- import path from 'path';
4
-
5
- import requireTemplate from './handle-dependencies/require-template';
6
- import * as validator from '../../registry/domain/validators';
7
- import { Component } from '../../types';
8
-
9
- export interface PackageOptions {
10
- componentPath: string;
11
- minify?: boolean;
12
- verbose?: boolean;
13
- production?: boolean;
14
- }
15
-
16
- const packageComponents =
17
- () =>
18
- async (options: PackageOptions): Promise<Component> => {
19
- const production = options.production;
20
- const componentPath = options.componentPath;
21
- const minify = options.minify === true;
22
- const verbose = options.verbose === true;
23
- const publishPath = path.join(componentPath, '_package');
24
- const componentPackagePath = path.join(componentPath, 'package.json');
25
- const ocPackagePath = path.join(__dirname, '../../../package.json');
26
-
27
- if (!fs.existsSync(componentPackagePath)) {
28
- throw new Error('component does not contain package.json');
29
- } else if (!fs.existsSync(ocPackagePath)) {
30
- throw new Error('error resolving oc internal dependencies');
31
- }
32
-
33
- await fs.emptyDir(publishPath);
34
-
35
- const componentPackage: Component = await fs.readJson(componentPackagePath);
36
- const ocPackage: Component = await fs.readJson(ocPackagePath);
37
-
38
- if (!validator.validateComponentName(componentPackage.name)) {
39
- throw new Error('name not valid');
40
- }
41
-
42
- const type = componentPackage.oc.files.template.type;
43
- const compileOptions = {
44
- publishPath,
45
- componentPath,
46
- componentPackage,
47
- ocPackage,
48
- minify,
49
- verbose,
50
- production
51
- };
52
-
53
- const ocTemplate = requireTemplate(type, {
54
- compiler: true,
55
- componentPath
56
- });
57
- const compile = promisify(ocTemplate.compile);
58
- return compile(compileOptions);
59
- };
60
-
61
- export default packageComponents;