@prismatic-io/spectral 8.1.7 → 9.0.0-rc.10

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 (85) hide show
  1. package/bin/component-manifest.js +2 -0
  2. package/dist/generators/componentManifest/cli.d.ts +2 -0
  3. package/dist/generators/componentManifest/cli.js +136 -0
  4. package/dist/generators/componentManifest/createActions.d.ts +13 -0
  5. package/dist/generators/componentManifest/createActions.js +103 -0
  6. package/dist/generators/componentManifest/createConnections.d.ts +13 -0
  7. package/dist/generators/componentManifest/createConnections.js +115 -0
  8. package/dist/generators/componentManifest/createDataSources.d.ts +13 -0
  9. package/dist/generators/componentManifest/createDataSources.js +103 -0
  10. package/dist/generators/componentManifest/createStaticFiles.d.ts +80 -0
  11. package/dist/generators/componentManifest/createStaticFiles.js +145 -0
  12. package/dist/generators/componentManifest/createTriggers.d.ts +13 -0
  13. package/dist/generators/componentManifest/createTriggers.js +103 -0
  14. package/dist/generators/componentManifest/getImports.d.ts +7 -0
  15. package/dist/generators/componentManifest/getImports.js +16 -0
  16. package/dist/generators/componentManifest/getInputs.d.ts +34 -0
  17. package/dist/generators/componentManifest/getInputs.js +100 -0
  18. package/dist/generators/componentManifest/helpers.d.ts +5 -0
  19. package/dist/generators/componentManifest/helpers.js +11 -0
  20. package/dist/generators/componentManifest/index.d.ts +15 -0
  21. package/dist/generators/componentManifest/index.js +78 -0
  22. package/dist/generators/componentManifest/removeComponentManifest.d.ts +6 -0
  23. package/dist/generators/componentManifest/removeComponentManifest.js +21 -0
  24. package/dist/generators/componentManifest/templates/README.md.ejs +186 -0
  25. package/dist/generators/componentManifest/templates/actions/action.ts.ejs +19 -0
  26. package/dist/generators/componentManifest/templates/actions/index.ts.ejs +1 -0
  27. package/dist/generators/componentManifest/templates/connections/connection.ts.ejs +22 -0
  28. package/dist/generators/componentManifest/templates/connections/index.ts.ejs +1 -0
  29. package/dist/generators/componentManifest/templates/dataSources/dataSource.ts.ejs +19 -0
  30. package/dist/generators/componentManifest/templates/dataSources/index.ts.ejs +1 -0
  31. package/dist/generators/componentManifest/templates/index.ts.ejs +20 -0
  32. package/dist/generators/componentManifest/templates/package.json.ejs +24 -0
  33. package/dist/generators/componentManifest/templates/partials/importBarrel.ejs +9 -0
  34. package/dist/generators/componentManifest/templates/partials/imports.ejs +1 -0
  35. package/dist/generators/componentManifest/templates/partials/inputs.ejs +19 -0
  36. package/dist/generators/componentManifest/templates/partials/performArgs.ejs +10 -0
  37. package/dist/generators/componentManifest/templates/triggers/index.ts.ejs +1 -0
  38. package/dist/generators/componentManifest/templates/triggers/trigger.ts.ejs +19 -0
  39. package/dist/generators/componentManifest/templates/tsconfig.json.ejs +15 -0
  40. package/dist/generators/utils/capitalizeFirstLetter.d.ts +1 -0
  41. package/dist/generators/utils/capitalizeFirstLetter.js +5 -0
  42. package/dist/generators/utils/createDependencyImports.d.ts +5 -0
  43. package/dist/generators/utils/createDependencyImports.js +9 -0
  44. package/dist/generators/utils/createFlagHelpText.d.ts +12 -0
  45. package/dist/generators/utils/createFlagHelpText.js +19 -0
  46. package/dist/generators/utils/createTemplate.d.ts +9 -0
  47. package/dist/generators/utils/createTemplate.js +59 -0
  48. package/dist/generators/utils/generatePackageJsonVersion.d.ts +1 -0
  49. package/dist/generators/utils/generatePackageJsonVersion.js +14 -0
  50. package/dist/generators/utils/getComponentSignatureWithPrism.d.ts +5 -0
  51. package/dist/generators/utils/getComponentSignatureWithPrism.js +42 -0
  52. package/dist/generators/utils/getFlagBooleanValue.d.ts +11 -0
  53. package/dist/generators/utils/getFlagBooleanValue.js +17 -0
  54. package/dist/generators/utils/getFlagStringValue.d.ts +11 -0
  55. package/dist/generators/utils/getFlagStringValue.js +25 -0
  56. package/dist/generators/utils/truncatePathByFolder.d.ts +1 -0
  57. package/dist/generators/utils/truncatePathByFolder.js +5 -0
  58. package/dist/index.d.ts +16 -17
  59. package/dist/index.js +11 -11
  60. package/dist/serverTypes/convertIntegration.d.ts +2 -2
  61. package/dist/serverTypes/convertIntegration.js +241 -64
  62. package/dist/serverTypes/index.d.ts +7 -2
  63. package/dist/serverTypes/integration.d.ts +10 -2
  64. package/dist/testing.d.ts +7 -7
  65. package/dist/testing.js +1 -1
  66. package/dist/types/ActionDefinition.d.ts +2 -1
  67. package/dist/types/ActionPerformFunction.d.ts +9 -3
  68. package/dist/types/ComponentManifest.d.ts +36 -0
  69. package/dist/types/ComponentManifest.js +2 -0
  70. package/dist/types/ComponentRegistry.d.ts +83 -0
  71. package/dist/types/ComponentRegistry.js +5 -0
  72. package/dist/types/ConfigPages.d.ts +46 -0
  73. package/dist/types/ConfigPages.js +2 -0
  74. package/dist/types/ConfigVars.d.ts +138 -0
  75. package/dist/types/ConfigVars.js +18 -0
  76. package/dist/types/Inputs.d.ts +1 -1
  77. package/dist/types/IntegrationDefinition.d.ts +15 -137
  78. package/dist/types/IntegrationDefinition.js +0 -17
  79. package/dist/types/index.d.ts +4 -0
  80. package/dist/types/index.js +4 -0
  81. package/dist/util.d.ts +2 -0
  82. package/dist/util.js +17 -10
  83. package/package.json +12 -6
  84. /package/dist/serverTypes/{convert.d.ts → convertComponent.d.ts} +0 -0
  85. /package/dist/serverTypes/{convert.js → convertComponent.js} +0 -0
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ require("../dist/generators/componentManifest/cli.js").runMain(process);
@@ -0,0 +1,2 @@
1
+ /// <reference types="node" />
2
+ export declare const runMain: (process: NodeJS.Process) => Promise<void>;
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.runMain = void 0;
16
+ /* eslint-disable @typescript-eslint/no-var-requires */
17
+ /* eslint-disable @typescript-eslint/no-unsafe-member-access */
18
+ const path_1 = __importDefault(require("path"));
19
+ const fs_extra_1 = require("fs-extra");
20
+ const lodash_1 = require("lodash");
21
+ const index_1 = require("./index");
22
+ const createFlagHelpText_1 = require("../utils/createFlagHelpText");
23
+ const getFlagStringValue_1 = require("../utils/getFlagStringValue");
24
+ const getFlagBooleanValue_1 = require("../utils/getFlagBooleanValue");
25
+ const util_1 = require("../../util");
26
+ const runMain = (process) => __awaiter(void 0, void 0, void 0, function* () {
27
+ var _a, _b;
28
+ const componentDir = process.cwd();
29
+ const componentDistDir = path_1.default.join(componentDir, "dist", "index.js");
30
+ const args = process.argv.slice(2);
31
+ const flags = {
32
+ name: {
33
+ flag: ["--name", "-n"],
34
+ value: (0, getFlagStringValue_1.getFlagsStringValue)({
35
+ args,
36
+ flags: ["--name", "-n"],
37
+ }),
38
+ description: "The name of the component manifest. Defaults to the name of the current component being generated.",
39
+ },
40
+ verbose: {
41
+ flag: ["--verbose", "-v"],
42
+ value: (0, getFlagBooleanValue_1.getFlagsBooleanValue)({
43
+ args,
44
+ flags: ["--verbose", "-v"],
45
+ }),
46
+ description: "Provides more detailed or extensive information about the files being generated during the process.",
47
+ },
48
+ output_dir: {
49
+ flag: ["--output-dir", "-o"],
50
+ value: (0, getFlagStringValue_1.getFlagsStringValue)({
51
+ args,
52
+ flags: ["--output-dir", "-o"],
53
+ }),
54
+ description: "The output directory for the component manifest. Defaults to the sibling of the current component directory.",
55
+ },
56
+ registry: {
57
+ flag: ["--registry", "-r"],
58
+ value: (0, getFlagStringValue_1.getFlagsStringValue)({
59
+ args,
60
+ flags: ["--registry", "-r"],
61
+ }),
62
+ description: "The registry to publish the component manifest to (as a URI). This is where your package will be published. If not specified, it defaults to your system's default registry.",
63
+ },
64
+ dry_run: {
65
+ flag: ["--dry-run", "-d"],
66
+ value: (0, getFlagBooleanValue_1.getFlagsBooleanValue)({
67
+ args,
68
+ flags: ["--dry-run", "-d"],
69
+ }),
70
+ description: "Perform a dry run without generating the component manifest. This provides a preview of what you could expect to happen when running the command without this flag.",
71
+ },
72
+ skip_signature_verify: {
73
+ flag: ["--skip-signature-verify"],
74
+ value: (0, getFlagBooleanValue_1.getFlagsBooleanValue)({
75
+ args,
76
+ flags: ["--skip-signature-verify"],
77
+ }),
78
+ description: "This skips the signature verification process, always returning a component signature in the component manifest.",
79
+ },
80
+ help: {
81
+ flag: ["--help", "-h"],
82
+ value: (0, getFlagBooleanValue_1.getFlagsBooleanValue)({
83
+ args,
84
+ flags: ["--help", "-h"],
85
+ }),
86
+ description: "Show this help message.",
87
+ },
88
+ };
89
+ if (flags.help.value) {
90
+ (0, createFlagHelpText_1.createFlagHelpText)({
91
+ command: "component-manifest",
92
+ flags,
93
+ });
94
+ process.exit(0);
95
+ }
96
+ if (!componentDir) {
97
+ console.error("Please run this script using npm or yarn.");
98
+ process.exit(1);
99
+ }
100
+ if (!(0, fs_extra_1.existsSync)(componentDistDir)) {
101
+ console.error("Component build directory `dist` does not exist. Please verify that the component has been built.");
102
+ process.exit(1);
103
+ }
104
+ const component = require(componentDistDir).default;
105
+ if (!component ||
106
+ !(0, util_1.isObjectWithTruthyKeys)(component, ["key", "display"]) ||
107
+ !(0, util_1.isObjectWithOneTruthyKey)(component, [
108
+ "actions",
109
+ "connections",
110
+ "dataSources",
111
+ ])) {
112
+ console.error("Component is invalid.");
113
+ process.exit(1);
114
+ }
115
+ const packageJson = (0, fs_extra_1.readJsonSync)(path_1.default.join(__dirname, "../../../package.json"));
116
+ yield (0, index_1.createComponentManifest)({
117
+ component,
118
+ dryRun: flags.dry_run.value,
119
+ skipSignatureVerify: flags.skip_signature_verify.value,
120
+ packageName: (_a = flags.name.value) !== null && _a !== void 0 ? _a : `@component-manifests/${(0, lodash_1.kebabCase)(component.key)}`,
121
+ dependencies: {
122
+ spectral: packageJson.version,
123
+ dependencies: packageJson.dependencies,
124
+ devDependencies: packageJson.devDependencies,
125
+ },
126
+ verbose: flags.verbose.value,
127
+ sourceDir: path_1.default.join(__dirname, "templates"),
128
+ destinationDir: flags.output_dir.value
129
+ ? flags.output_dir.value
130
+ : path_1.default.join(componentDir, "..", flags.name.value
131
+ ? flags.name.value
132
+ : `${path_1.default.basename(componentDir)}-manifest`),
133
+ registry: (_b = flags.registry.value) !== null && _b !== void 0 ? _b : null,
134
+ });
135
+ });
136
+ exports.runMain = runMain;
@@ -0,0 +1,13 @@
1
+ import type { Component } from "../../serverTypes";
2
+ interface CreateActionsProps {
3
+ component: Component;
4
+ dryRun: boolean;
5
+ verbose: boolean;
6
+ sourceDir: string;
7
+ destinationDir: string;
8
+ }
9
+ export declare const createActions: ({ component, dryRun, verbose, sourceDir, destinationDir, }: CreateActionsProps) => Promise<{
10
+ actionIndex: string | void;
11
+ actions: (string | void)[];
12
+ }>;
13
+ export {};
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.createActions = void 0;
16
+ const path_1 = __importDefault(require("path"));
17
+ const getInputs_1 = require("./getInputs");
18
+ const getImports_1 = require("./getImports");
19
+ const helpers_1 = require("./helpers");
20
+ const createTemplate_1 = require("../utils/createTemplate");
21
+ const DOC_BLOCK = [
22
+ {
23
+ propertyKey: "comments",
24
+ },
25
+ {
26
+ propertyKey: "default",
27
+ },
28
+ {
29
+ propertyKey: "example",
30
+ },
31
+ {
32
+ propertyKey: "placeholder",
33
+ },
34
+ ];
35
+ const createActions = ({ component, dryRun, verbose, sourceDir, destinationDir, }) => __awaiter(void 0, void 0, void 0, function* () {
36
+ var _a, _b;
37
+ if (verbose) {
38
+ console.info("Creating actions...");
39
+ }
40
+ const actionIndex = yield renderActionsIndex({
41
+ actions: Object.entries((_a = component.actions) !== null && _a !== void 0 ? _a : {}).map(([actionKey, action]) => {
42
+ return {
43
+ key: action.key || actionKey,
44
+ };
45
+ }),
46
+ dryRun,
47
+ verbose,
48
+ sourceDir,
49
+ destinationDir,
50
+ });
51
+ const actions = yield Promise.all(Object.entries((_b = component.actions) !== null && _b !== void 0 ? _b : {}).map(([actionKey, action]) => __awaiter(void 0, void 0, void 0, function* () {
52
+ const inputs = (0, getInputs_1.getInputs)({
53
+ inputs: action.inputs,
54
+ docBlock: DOC_BLOCK,
55
+ });
56
+ const imports = (0, getImports_1.getImports)({ inputs });
57
+ return yield renderAction({
58
+ action: {
59
+ key: action.key || actionKey,
60
+ label: action.display.description,
61
+ description: action.display.description,
62
+ inputs,
63
+ },
64
+ imports,
65
+ dryRun,
66
+ verbose,
67
+ sourceDir,
68
+ destinationDir,
69
+ });
70
+ })));
71
+ if (verbose) {
72
+ console.info("");
73
+ }
74
+ return Promise.resolve({
75
+ actionIndex,
76
+ actions,
77
+ });
78
+ });
79
+ exports.createActions = createActions;
80
+ const renderActionsIndex = ({ actions, dryRun, verbose, sourceDir, destinationDir, }) => __awaiter(void 0, void 0, void 0, function* () {
81
+ return yield (0, createTemplate_1.createTemplate)({
82
+ source: path_1.default.join(sourceDir, "actions", "index.ts.ejs"),
83
+ destination: path_1.default.join(destinationDir, "actions", "index.ts"),
84
+ data: {
85
+ actions,
86
+ },
87
+ dryRun,
88
+ verbose,
89
+ });
90
+ });
91
+ const renderAction = ({ action, dryRun, imports, verbose, sourceDir, destinationDir, }) => __awaiter(void 0, void 0, void 0, function* () {
92
+ return yield (0, createTemplate_1.createTemplate)({
93
+ source: path_1.default.join(sourceDir, "actions", "action.ts.ejs"),
94
+ destination: path_1.default.join(destinationDir, "actions", `${action.key}.ts`),
95
+ data: {
96
+ action,
97
+ helpers: helpers_1.helpers,
98
+ imports,
99
+ },
100
+ dryRun,
101
+ verbose,
102
+ });
103
+ });
@@ -0,0 +1,13 @@
1
+ import type { Component } from "../../serverTypes";
2
+ interface CreateConnectionsProps {
3
+ component: Component;
4
+ dryRun: boolean;
5
+ verbose: boolean;
6
+ sourceDir: string;
7
+ destinationDir: string;
8
+ }
9
+ export declare const createConnections: ({ component, dryRun, verbose, sourceDir, destinationDir, }: CreateConnectionsProps) => Promise<{
10
+ connectionIndex: string | void;
11
+ connections: (string | void)[];
12
+ }>;
13
+ export {};
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.createConnections = void 0;
16
+ const path_1 = __importDefault(require("path"));
17
+ const getInputs_1 = require("./getInputs");
18
+ const getImports_1 = require("./getImports");
19
+ const helpers_1 = require("./helpers");
20
+ const createTemplate_1 = require("../utils/createTemplate");
21
+ const DOC_BLOCK = [
22
+ {
23
+ propertyKey: "comments",
24
+ },
25
+ {
26
+ propertyKey: "default",
27
+ },
28
+ {
29
+ propertyKey: "example",
30
+ },
31
+ {
32
+ propertyKey: "placeholder",
33
+ },
34
+ {
35
+ propertyKey: "onPremControlled",
36
+ propertyValue: true,
37
+ output: "This input will be supplied when using an on prem resource.",
38
+ },
39
+ {
40
+ propertyKey: "onPremiseControlled",
41
+ propertyValue: true,
42
+ output: "This input will be supplied when using an on prem resource.",
43
+ },
44
+ ];
45
+ const createConnections = ({ component, dryRun, verbose, sourceDir, destinationDir, }) => __awaiter(void 0, void 0, void 0, function* () {
46
+ var _a, _b;
47
+ if (verbose) {
48
+ console.info("Creating connections...");
49
+ }
50
+ const connectionIndex = yield renderConnectionsIndex({
51
+ connections: ((_a = component.connections) !== null && _a !== void 0 ? _a : []).map((connection) => {
52
+ return {
53
+ key: connection.key,
54
+ };
55
+ }),
56
+ dryRun,
57
+ verbose,
58
+ sourceDir,
59
+ destinationDir,
60
+ });
61
+ const connections = yield Promise.all(((_b = component.connections) !== null && _b !== void 0 ? _b : []).map((connection) => __awaiter(void 0, void 0, void 0, function* () {
62
+ const inputs = (0, getInputs_1.getInputs)({
63
+ inputs: connection.inputs,
64
+ docBlock: DOC_BLOCK,
65
+ });
66
+ const imports = (0, getImports_1.getImports)({ inputs });
67
+ const onPremAvailable = connection.inputs.some((input) => input.onPremControlled || input.onPremiseControlled);
68
+ return yield renderConnection({
69
+ connection: {
70
+ key: connection.key,
71
+ label: connection.label,
72
+ comments: connection.comments,
73
+ inputs,
74
+ onPremAvailable,
75
+ },
76
+ imports,
77
+ dryRun,
78
+ verbose,
79
+ sourceDir,
80
+ destinationDir,
81
+ });
82
+ })));
83
+ if (verbose) {
84
+ console.info("");
85
+ }
86
+ return Promise.resolve({
87
+ connectionIndex,
88
+ connections,
89
+ });
90
+ });
91
+ exports.createConnections = createConnections;
92
+ const renderConnectionsIndex = ({ connections, dryRun, verbose, sourceDir, destinationDir, }) => __awaiter(void 0, void 0, void 0, function* () {
93
+ return yield (0, createTemplate_1.createTemplate)({
94
+ source: path_1.default.join(sourceDir, "connections", "index.ts.ejs"),
95
+ destination: path_1.default.join(destinationDir, "connections", "index.ts"),
96
+ data: {
97
+ connections,
98
+ },
99
+ dryRun,
100
+ verbose,
101
+ });
102
+ });
103
+ const renderConnection = ({ connection, dryRun, imports, verbose, sourceDir, destinationDir, }) => __awaiter(void 0, void 0, void 0, function* () {
104
+ return yield (0, createTemplate_1.createTemplate)({
105
+ source: path_1.default.join(sourceDir, "connections", "connection.ts.ejs"),
106
+ destination: path_1.default.join(destinationDir, "connections", `${connection.key}.ts`),
107
+ data: {
108
+ connection,
109
+ helpers: helpers_1.helpers,
110
+ imports,
111
+ },
112
+ dryRun,
113
+ verbose,
114
+ });
115
+ });
@@ -0,0 +1,13 @@
1
+ import type { Component } from "../../serverTypes";
2
+ interface CreateDataSourcesProps {
3
+ component: Component;
4
+ dryRun: boolean;
5
+ verbose: boolean;
6
+ sourceDir: string;
7
+ destinationDir: string;
8
+ }
9
+ export declare const createDataSources: ({ component, dryRun, verbose, sourceDir, destinationDir, }: CreateDataSourcesProps) => Promise<{
10
+ dataSourceIndex: string | void;
11
+ dataSources: (string | void)[];
12
+ }>;
13
+ export {};
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.createDataSources = void 0;
16
+ const path_1 = __importDefault(require("path"));
17
+ const getInputs_1 = require("./getInputs");
18
+ const getImports_1 = require("./getImports");
19
+ const helpers_1 = require("./helpers");
20
+ const createTemplate_1 = require("../utils/createTemplate");
21
+ const DOC_BLOCK = [
22
+ {
23
+ propertyKey: "comments",
24
+ },
25
+ {
26
+ propertyKey: "default",
27
+ },
28
+ {
29
+ propertyKey: "example",
30
+ },
31
+ {
32
+ propertyKey: "placeholder",
33
+ },
34
+ ];
35
+ const createDataSources = ({ component, dryRun, verbose, sourceDir, destinationDir, }) => __awaiter(void 0, void 0, void 0, function* () {
36
+ var _a, _b;
37
+ if (verbose) {
38
+ console.info("Creating data sources...");
39
+ }
40
+ const dataSourceIndex = yield renderDataSourcesIndex({
41
+ dataSources: Object.entries((_a = component.dataSources) !== null && _a !== void 0 ? _a : {}).map(([dataSourceKey, dataSource]) => {
42
+ return {
43
+ key: dataSource.key || dataSourceKey,
44
+ };
45
+ }),
46
+ dryRun,
47
+ verbose,
48
+ sourceDir,
49
+ destinationDir,
50
+ });
51
+ const dataSources = yield Promise.all(Object.entries((_b = component.dataSources) !== null && _b !== void 0 ? _b : {}).map(([dataSourceKey, dataSource]) => __awaiter(void 0, void 0, void 0, function* () {
52
+ const inputs = (0, getInputs_1.getInputs)({
53
+ inputs: dataSource.inputs,
54
+ docBlock: DOC_BLOCK,
55
+ });
56
+ const imports = (0, getImports_1.getImports)({ inputs });
57
+ return yield renderDataSource({
58
+ dataSource: {
59
+ key: dataSource.key || dataSourceKey,
60
+ label: dataSource.display.label,
61
+ description: dataSource.display.description,
62
+ inputs,
63
+ },
64
+ imports,
65
+ dryRun,
66
+ verbose,
67
+ sourceDir,
68
+ destinationDir,
69
+ });
70
+ })));
71
+ if (verbose) {
72
+ console.info("");
73
+ }
74
+ return Promise.resolve({
75
+ dataSourceIndex,
76
+ dataSources,
77
+ });
78
+ });
79
+ exports.createDataSources = createDataSources;
80
+ const renderDataSourcesIndex = ({ dataSources, dryRun, verbose, sourceDir, destinationDir, }) => __awaiter(void 0, void 0, void 0, function* () {
81
+ return yield (0, createTemplate_1.createTemplate)({
82
+ source: path_1.default.join(sourceDir, "dataSources", "index.ts.ejs"),
83
+ destination: path_1.default.join(destinationDir, "dataSources", "index.ts"),
84
+ data: {
85
+ dataSources,
86
+ },
87
+ dryRun,
88
+ verbose,
89
+ });
90
+ });
91
+ const renderDataSource = ({ dataSource, dryRun, imports, verbose, sourceDir, destinationDir, }) => __awaiter(void 0, void 0, void 0, function* () {
92
+ return yield (0, createTemplate_1.createTemplate)({
93
+ source: path_1.default.join(sourceDir, "dataSources", "dataSource.ts.ejs"),
94
+ destination: path_1.default.join(destinationDir, "dataSources", `${dataSource.key}.ts`),
95
+ data: {
96
+ dataSource,
97
+ helpers: helpers_1.helpers,
98
+ imports,
99
+ },
100
+ dryRun,
101
+ verbose,
102
+ });
103
+ });
@@ -0,0 +1,80 @@
1
+ import type { Component } from "../../serverTypes";
2
+ export interface PackageDependencies {
3
+ spectral: string;
4
+ dependencies: Record<string, string>;
5
+ devDependencies: Record<string, string>;
6
+ }
7
+ interface CreateStaticFilesProps {
8
+ component: Component;
9
+ dryRun: boolean;
10
+ signature: string | null;
11
+ packageName: string;
12
+ dependencies: PackageDependencies;
13
+ verbose: boolean;
14
+ sourceDir: string;
15
+ destinationDir: string;
16
+ registry: string | null;
17
+ }
18
+ export declare const createStaticFiles: ({ component, dryRun, signature, packageName, dependencies, verbose, sourceDir, destinationDir, registry, }: CreateStaticFilesProps) => Promise<{
19
+ index: string | void;
20
+ packageJson: string | void;
21
+ tsConfig: string | void;
22
+ readme: string | void;
23
+ }>;
24
+ interface RenderIndexProps {
25
+ component: {
26
+ key: string;
27
+ public: boolean;
28
+ signature: string | null;
29
+ };
30
+ dryRun: boolean;
31
+ verbose: boolean;
32
+ sourceDir: string;
33
+ destinationDir: string;
34
+ }
35
+ export declare const renderIndex: ({ component, dryRun, verbose, sourceDir, destinationDir, }: RenderIndexProps) => Promise<string | void>;
36
+ interface RenderPackageJsonProps {
37
+ dryRun: boolean;
38
+ packageName: string;
39
+ dependencies: PackageDependencies;
40
+ verbose: boolean;
41
+ sourceDir: string;
42
+ destinationDir: string;
43
+ registry: string | null;
44
+ }
45
+ export declare const renderPackageJson: ({ dryRun, packageName, dependencies, verbose, sourceDir, destinationDir, registry, }: RenderPackageJsonProps) => Promise<string | void>;
46
+ interface RenderTsConfigProps {
47
+ dryRun: boolean;
48
+ verbose: boolean;
49
+ sourceDir: string;
50
+ destinationDir: string;
51
+ }
52
+ export declare const renderTsConfig: ({ dryRun, verbose, sourceDir, destinationDir, }: RenderTsConfigProps) => Promise<string | void>;
53
+ interface RenderReadmeProps {
54
+ component: {
55
+ key: string;
56
+ label: string;
57
+ description: string;
58
+ isPublic: boolean;
59
+ action: {
60
+ key: string;
61
+ } | null;
62
+ trigger: {
63
+ key: string;
64
+ } | null;
65
+ connection: {
66
+ key: string;
67
+ } | null;
68
+ dataSource: {
69
+ key: string;
70
+ type: string;
71
+ } | null;
72
+ };
73
+ dryRun: boolean;
74
+ packageName: string;
75
+ verbose: boolean;
76
+ sourceDir: string;
77
+ destinationDir: string;
78
+ }
79
+ export declare const renderReadme: ({ component, dryRun, packageName, verbose, sourceDir, destinationDir, }: RenderReadmeProps) => Promise<string | void>;
80
+ export {};