@prismatic-io/prism 4.1.1 → 4.2.0
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/lib/commands/components/dev/run.js +19 -5
- package/lib/commands/components/dev/test.js +1 -1
- package/lib/commands/components/init/index.js +39 -100
- package/lib/generate/action.js +14 -66
- package/lib/generate/index.js +3 -9
- package/lib/generate/parse.js +8 -60
- package/lib/generate/sourceFile.js +7 -40
- package/lib/generate/util.js +1 -105
- package/lib/yeoman.js +1 -0
- package/oclif.manifest.json +1 -1
- package/package.json +5 -7
- package/lib/generate/client.js +0 -93
- package/lib/generate/connection.js +0 -77
- package/templates/component/assets/icon.png +0 -0
- package/templates/component/openapi/client.ts +0 -75
- package/templates/component/openapi/request.ts +0 -163
|
@@ -15,7 +15,7 @@ const spawnProcess = ([command, ...args], env) => {
|
|
|
15
15
|
};
|
|
16
16
|
class RunCommand extends core_1.Command {
|
|
17
17
|
async run() {
|
|
18
|
-
const { argv, flags: { integrationId,
|
|
18
|
+
const { argv, flags: { integrationId, connectionKey }, } = await this.parse(RunCommand);
|
|
19
19
|
const result = await (0, graphql_1.gqlRequest)({
|
|
20
20
|
document: (0, graphql_1.gql) `
|
|
21
21
|
query integration($id: ID!) {
|
|
@@ -42,7 +42,7 @@ class RunCommand extends core_1.Command {
|
|
|
42
42
|
},
|
|
43
43
|
});
|
|
44
44
|
const nodes = result.integration.testConfigVariables.nodes;
|
|
45
|
-
const [connection] = nodes.filter(({ requiredConfigVariable: { key } }) => key ===
|
|
45
|
+
const [connection] = nodes.filter(({ requiredConfigVariable: { key } }) => key === connectionKey);
|
|
46
46
|
if (!connection) {
|
|
47
47
|
core_1.CliUx.ux.error("Failed to find active connection.", { exit: 1 });
|
|
48
48
|
}
|
|
@@ -56,7 +56,21 @@ class RunCommand extends core_1.Command {
|
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
exports.default = RunCommand;
|
|
59
|
-
RunCommand.description =
|
|
59
|
+
RunCommand.description = `Fetch an integration's active connection and execute a CLI command with that connection's fields as an environment variable.`;
|
|
60
|
+
RunCommand.usage = "prism components:dev:run -i <value> -c <value> -- /command/to/run";
|
|
61
|
+
RunCommand.examples = [
|
|
62
|
+
{
|
|
63
|
+
description: `To simply print an integration's basic auth config variable named "My Credentials" and pipe the resulting JSON to jq, run:`,
|
|
64
|
+
command: `$ prism components:dev:run
|
|
65
|
+
--integrationId SW50ZWdyYXRpb246Y2YyMjJlMWUtMzJiYy00NTNhLWIzOWQtYTliNzUwMDAyNjBk
|
|
66
|
+
--connectionKey "My Credentials" --
|
|
67
|
+
printenv \${PRISMATIC_CONNECTION_VALUE} | jq`,
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
description: `If one of your integrations has an authenticated OAuth 2.0 config variable "Slack Connection", you could run your component's unit tests with that environment variable:`,
|
|
71
|
+
command: `$ prism components:dev:run -i SW50ZWexample -c "Slack Connection" -- yarn run test`,
|
|
72
|
+
},
|
|
73
|
+
];
|
|
60
74
|
// Allow us to manually capture argv so we can isolate the wrapped command.
|
|
61
75
|
RunCommand.strict = false;
|
|
62
76
|
// TODO: Make this derive from the component manifest using the same
|
|
@@ -67,9 +81,9 @@ RunCommand.flags = {
|
|
|
67
81
|
char: "i",
|
|
68
82
|
description: "Integration ID",
|
|
69
83
|
}),
|
|
70
|
-
|
|
84
|
+
connectionKey: core_1.Flags.string({
|
|
71
85
|
required: true,
|
|
72
86
|
char: "c",
|
|
73
|
-
description: "Key of the
|
|
87
|
+
description: "Key of the connection config variable to fetch meta/state for",
|
|
74
88
|
}),
|
|
75
89
|
};
|
|
@@ -179,7 +179,7 @@ class TestCommand extends core_1.Command {
|
|
|
179
179
|
integrationInfo: {
|
|
180
180
|
name: (0, definition_1.componentTestIntegrationName)(componentKey, name),
|
|
181
181
|
},
|
|
182
|
-
componentInfo: { key:
|
|
182
|
+
componentInfo: { key: definition.key, isPublic: isPublic !== null && isPublic !== void 0 ? isPublic : false },
|
|
183
183
|
actionInfo,
|
|
184
184
|
connectionInfo,
|
|
185
185
|
});
|
|
@@ -32,31 +32,10 @@ const path = __importStar(require("path"));
|
|
|
32
32
|
const wsdl_tsclient_1 = require("wsdl-tsclient");
|
|
33
33
|
const logger_1 = require("wsdl-tsclient/dist/src/utils/logger");
|
|
34
34
|
const index_1 = require("../../../generate/index");
|
|
35
|
-
const openapi_typescript_codegen_1 = require("openapi-typescript-codegen");
|
|
36
35
|
const prettier_1 = __importDefault(require("prettier"));
|
|
37
36
|
const glob_promise_1 = __importDefault(require("glob-promise"));
|
|
38
37
|
const yeoman_1 = require("../../../yeoman");
|
|
39
38
|
const componentNameRegex = /^[a-zA-Z0-9][a-zA-Z0-9-_]*[a-zA-Z0-9]$/;
|
|
40
|
-
const insertText = /* javascript */ `
|
|
41
|
-
interface EnhancedConfig extends Config {
|
|
42
|
-
timeout?: number;
|
|
43
|
-
CLIENT?: AxiosInstance;
|
|
44
|
-
}
|
|
45
|
-
export const EnhancedOpenAPI: EnhancedConfig = OpenAPI;`;
|
|
46
|
-
const injectAxiosToOpenAPI = async (basePath) => {
|
|
47
|
-
const fileLocation = path.resolve(basePath, "core", "request.ts");
|
|
48
|
-
const replaceLocation = path.join(__dirname, "..", "..", "..", "..", "templates", "component", "openapi", "request.ts");
|
|
49
|
-
await fs_1.promises.copyFile(replaceLocation, fileLocation);
|
|
50
|
-
const file = path.resolve(basePath, "core", "OpenAPI.ts");
|
|
51
|
-
const contents = await fs_1.promises.readFile(file);
|
|
52
|
-
const parts = [contents, insertText].join("\n\n").split("\n");
|
|
53
|
-
const additions = [
|
|
54
|
-
...parts.slice(0, 3),
|
|
55
|
-
/* javascript */ `import { AxiosInstance } from "axios";`,
|
|
56
|
-
...parts.slice(3),
|
|
57
|
-
].join("\n");
|
|
58
|
-
await fs_1.promises.writeFile(file, additions);
|
|
59
|
-
};
|
|
60
39
|
const getFilesToFormat = async (basename) => {
|
|
61
40
|
return await (0, glob_promise_1.default)("**/*.ts", {
|
|
62
41
|
ignore: ["**/node_modules/**"],
|
|
@@ -73,7 +52,7 @@ const formatSourceFiles = async (basePath, files) => {
|
|
|
73
52
|
};
|
|
74
53
|
class InitializeComponent extends core_1.Command {
|
|
75
54
|
async run() {
|
|
76
|
-
const { args: { name }, flags: { verbose, "wsdl-path": wsdlPath, "open-api-path": openApiPath
|
|
55
|
+
const { args: { name }, flags: { verbose, "wsdl-path": wsdlPath, "open-api-path": openApiPath }, } = await this.parse(InitializeComponent);
|
|
77
56
|
if (!componentNameRegex.test(name)) {
|
|
78
57
|
this.error(`'${name}' contains invalid characters. Please select a component name that starts and ends with alphanumeric characters, and contains only alphanumeric characters, hyphens, and underscores. See https://regex101.com/?regex=${encodeURIComponent(componentNameRegex.source)}`, { exit: 1 });
|
|
79
58
|
}
|
|
@@ -82,81 +61,50 @@ class InitializeComponent extends core_1.Command {
|
|
|
82
61
|
exit: 1,
|
|
83
62
|
});
|
|
84
63
|
}
|
|
85
|
-
if (skipAuth && !openApiPath) {
|
|
86
|
-
this.error("Auth templating is only supported when generating components from Open API specifications", {
|
|
87
|
-
exit: 1,
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
if (addRetry && !openApiPath) {
|
|
91
|
-
this.error("HTTP retry logic is only supported when generating components from OpenAPI specifications", {
|
|
92
|
-
exit: 1,
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
64
|
this.log(`Creating component directory for "${name}"...`);
|
|
96
65
|
await fs_1.promises.mkdir(name);
|
|
97
66
|
const cwd = process.cwd();
|
|
98
67
|
process.chdir(name);
|
|
99
|
-
|
|
100
|
-
|
|
68
|
+
if (openApiPath) {
|
|
69
|
+
await (0, yeoman_1.runGenerator)("formats", {
|
|
101
70
|
name,
|
|
102
|
-
|
|
103
|
-
connectionType: "basic",
|
|
104
|
-
skipInstall: true,
|
|
105
|
-
}
|
|
106
|
-
: { name, skipInstall: Boolean(wsdlPath) || Boolean(openApiPath) });
|
|
107
|
-
process.chdir(cwd);
|
|
108
|
-
if (wsdlPath) {
|
|
109
|
-
if (!verbose) {
|
|
110
|
-
// wsdl-tsclient emits pretty noisy logs that aren't particularly useful
|
|
111
|
-
logger_1.Logger.disabled();
|
|
112
|
-
}
|
|
113
|
-
const wsdlName = path.basename(wsdlPath).split(".wsdl")[0];
|
|
114
|
-
await (0, wsdl_tsclient_1.parseAndGenerate)(wsdlPath, path.join(name), {
|
|
115
|
-
caseInsensitiveNames: true,
|
|
116
|
-
});
|
|
117
|
-
await (0, index_1.generate)({
|
|
118
|
-
projectRoot: name,
|
|
119
|
-
projectTemplateName: wsdlName,
|
|
120
|
-
projectTemplatePath: wsdlPath,
|
|
121
|
-
projectType: "wsdl",
|
|
122
|
-
includeClient: false,
|
|
123
|
-
addRetry: false,
|
|
124
|
-
});
|
|
125
|
-
await (0, index_1.updatePackageJson)({
|
|
126
|
-
path: path.resolve(name, "package.json"),
|
|
127
|
-
dependencies: { soap: "0.40.0" },
|
|
71
|
+
openapi: openApiPath,
|
|
128
72
|
});
|
|
129
73
|
}
|
|
130
|
-
else
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
74
|
+
else {
|
|
75
|
+
// Legacy code paths (mostly; keep the component generator call)
|
|
76
|
+
await (0, yeoman_1.runGenerator)("component", process.env.NODE_ENV === "test"
|
|
77
|
+
? {
|
|
78
|
+
name,
|
|
79
|
+
description: "Prism-generated Component",
|
|
80
|
+
connectionType: "basic",
|
|
81
|
+
skipInstall: true,
|
|
82
|
+
}
|
|
83
|
+
: { name, skipInstall: Boolean(wsdlPath) });
|
|
84
|
+
// Need to pop back as the WSDL generator assumes it's a directory up
|
|
85
|
+
process.chdir(cwd);
|
|
86
|
+
if (wsdlPath) {
|
|
87
|
+
if (!verbose) {
|
|
88
|
+
// wsdl-tsclient emits pretty noisy logs that aren't particularly useful
|
|
89
|
+
logger_1.Logger.disabled();
|
|
90
|
+
}
|
|
91
|
+
const wsdlName = path.basename(wsdlPath).split(".wsdl")[0];
|
|
92
|
+
await (0, wsdl_tsclient_1.parseAndGenerate)(wsdlPath, name, {
|
|
93
|
+
caseInsensitiveNames: true,
|
|
94
|
+
});
|
|
95
|
+
await (0, index_1.generate)({
|
|
96
|
+
projectRoot: name,
|
|
97
|
+
projectTemplateName: wsdlName,
|
|
98
|
+
projectTemplatePath: wsdlPath,
|
|
99
|
+
});
|
|
100
|
+
await (0, index_1.updatePackageJson)({
|
|
101
|
+
path: path.resolve(name, "package.json"),
|
|
102
|
+
dependencies: { soap: "0.40.0" },
|
|
103
|
+
});
|
|
104
|
+
const filesToFormat = await getFilesToFormat(name);
|
|
105
|
+
await formatSourceFiles(name, filesToFormat);
|
|
106
|
+
}
|
|
107
|
+
this.log(`
|
|
160
108
|
"${name}" is ready for development.
|
|
161
109
|
To install dependencies, run either "npm install" or "yarn install"
|
|
162
110
|
To test the component, run "npm run test" or "yarn test"
|
|
@@ -165,6 +113,7 @@ To publish the component, run "prism components:publish"
|
|
|
165
113
|
|
|
166
114
|
For documentation on writing custom components, visit https://prismatic.io/docs/custom-components/writing-custom-components/
|
|
167
115
|
`);
|
|
116
|
+
}
|
|
168
117
|
}
|
|
169
118
|
}
|
|
170
119
|
exports.default = InitializeComponent;
|
|
@@ -178,21 +127,11 @@ InitializeComponent.flags = {
|
|
|
178
127
|
required: false,
|
|
179
128
|
description: "The path to an OpenAPI Specification file (JSON or YAML) used to generate a Component",
|
|
180
129
|
}),
|
|
181
|
-
"skip-auth": core_1.Flags.boolean({
|
|
182
|
-
required: false,
|
|
183
|
-
default: false,
|
|
184
|
-
description: "Skip templating authentication for an OpenAPI-based component. Use this option for OpenAPI specs that do not require authentication.",
|
|
185
|
-
}),
|
|
186
130
|
verbose: core_1.Flags.boolean({
|
|
187
131
|
required: false,
|
|
188
132
|
default: false,
|
|
189
133
|
description: "Output more verbose logging from Component generation",
|
|
190
134
|
}),
|
|
191
|
-
"add-retry": core_1.Flags.boolean({
|
|
192
|
-
required: false,
|
|
193
|
-
default: false,
|
|
194
|
-
description: "Add inputs to each action to utilize Axios retry logic",
|
|
195
|
-
}),
|
|
196
135
|
};
|
|
197
136
|
InitializeComponent.args = [
|
|
198
137
|
{
|
package/lib/generate/action.js
CHANGED
|
@@ -44,45 +44,19 @@ const getPerformFunctionWSDL = (projectTemplatePath, action) => {
|
|
|
44
44
|
})
|
|
45
45
|
.join(",")});`;
|
|
46
46
|
};
|
|
47
|
-
const
|
|
48
|
-
const
|
|
49
|
-
const
|
|
50
|
-
return `const result = await ${service}.${methodSignature.getName()}(${propertiesText});`;
|
|
51
|
-
};
|
|
52
|
-
const instantiatePerformFunction = (action, project, includeClient, addRetry) => {
|
|
53
|
-
const { projectTemplatePath, projectType } = project;
|
|
54
|
-
const clientCallParams = (0, util_1.appendRequiredFields)({
|
|
55
|
-
inputFields: ["connection"],
|
|
56
|
-
addRetry,
|
|
57
|
-
includeClient,
|
|
58
|
-
});
|
|
59
|
-
const clientCall = `initializeClient({ ${clientCallParams.join(", ")} });`;
|
|
60
|
-
let performFunction;
|
|
61
|
-
if (projectType === "wsdl") {
|
|
62
|
-
performFunction = getPerformFunctionWSDL(projectTemplatePath, action);
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
performFunction = getPerformFunctionOpenApi(action);
|
|
66
|
-
}
|
|
47
|
+
const instantiatePerformFunction = (action, project) => {
|
|
48
|
+
const { projectTemplatePath } = project;
|
|
49
|
+
const performFunction = getPerformFunctionWSDL(projectTemplatePath, action);
|
|
67
50
|
const performParams = action.actionObject.inputs
|
|
68
51
|
.filter(({ shouldImport }) => shouldImport)
|
|
69
52
|
.map(({ properties, shouldImport }) => {
|
|
70
53
|
const name = properties.map(({ propertyName }) => propertyName).join(",");
|
|
71
54
|
return shouldImport ? name : "";
|
|
72
55
|
});
|
|
73
|
-
const updatedPerformParams =
|
|
74
|
-
inputFields: includeClient
|
|
75
|
-
? ["connection", ...performParams]
|
|
76
|
-
: projectType === "wsdl"
|
|
77
|
-
? [...performParams, "headers"]
|
|
78
|
-
: performParams,
|
|
79
|
-
addRetry,
|
|
80
|
-
includeClient,
|
|
81
|
-
});
|
|
56
|
+
const updatedPerformParams = [...performParams, "headers"];
|
|
82
57
|
return `async ({logger}, ${updatedPerformParams.length > 0
|
|
83
58
|
? `{ ${updatedPerformParams.join(", ")} }: Record<string,any>`
|
|
84
59
|
: ""}) => {
|
|
85
|
-
${projectType === "openApi" && includeClient ? clientCall : ""}
|
|
86
60
|
${performFunction}
|
|
87
61
|
return {data: result};
|
|
88
62
|
}`;
|
|
@@ -128,7 +102,7 @@ const compileAction = (actionService, actionMethod, project) => {
|
|
|
128
102
|
actionObject: generateActionObject(actionMethod, project),
|
|
129
103
|
});
|
|
130
104
|
};
|
|
131
|
-
const writeAction = async (action, project
|
|
105
|
+
const writeAction = async (action, project) => {
|
|
132
106
|
const { actionFile } = project;
|
|
133
107
|
// Apparently you can't generate an Object without adding it to the file
|
|
134
108
|
// so this is our place holder to use as a template
|
|
@@ -147,16 +121,6 @@ const writeAction = async (action, project, includeClient, addRetry) => {
|
|
|
147
121
|
}
|
|
148
122
|
return shouldImport ? [name] : [];
|
|
149
123
|
});
|
|
150
|
-
const updatedInputFields = (0, util_1.appendRequiredFields)({
|
|
151
|
-
inputFields: includeClient
|
|
152
|
-
? [
|
|
153
|
-
`connection: { type: "connection", label: "connection", required: true }`,
|
|
154
|
-
...inputFields,
|
|
155
|
-
]
|
|
156
|
-
: inputFields,
|
|
157
|
-
includeClient,
|
|
158
|
-
addRetry,
|
|
159
|
-
});
|
|
160
124
|
object.addPropertyAssignments([
|
|
161
125
|
{
|
|
162
126
|
name: "display",
|
|
@@ -167,21 +131,19 @@ const writeAction = async (action, project, includeClient, addRetry) => {
|
|
|
167
131
|
},
|
|
168
132
|
{
|
|
169
133
|
name: "perform",
|
|
170
|
-
initializer: instantiatePerformFunction(action, project
|
|
134
|
+
initializer: instantiatePerformFunction(action, project),
|
|
171
135
|
},
|
|
172
136
|
{
|
|
173
137
|
name: "inputs",
|
|
174
|
-
initializer: `{${
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
`headers: {
|
|
138
|
+
initializer: `{${[
|
|
139
|
+
...inputFields,
|
|
140
|
+
`headers: {
|
|
178
141
|
label: "Headers",
|
|
179
142
|
type: "code",
|
|
180
143
|
comments: "Provide headers to the SOAP client",
|
|
181
144
|
default: '{}'
|
|
182
145
|
}`,
|
|
183
|
-
|
|
184
|
-
: [...updatedInputFields].join(", ")}}`,
|
|
146
|
+
]}}`,
|
|
185
147
|
},
|
|
186
148
|
]);
|
|
187
149
|
//Add the action payload to the action
|
|
@@ -211,16 +173,8 @@ const writeInputsImport = async (inputNames, { actionFile }) => {
|
|
|
211
173
|
namedImports: inputNames,
|
|
212
174
|
});
|
|
213
175
|
};
|
|
214
|
-
const generateActions = async (project
|
|
215
|
-
const {
|
|
216
|
-
if (projectType === "openApi" && includeClient) {
|
|
217
|
-
actionFile.addImportDeclarations([
|
|
218
|
-
{
|
|
219
|
-
moduleSpecifier: `./client`,
|
|
220
|
-
namedImports: ["initializeClient"],
|
|
221
|
-
},
|
|
222
|
-
]);
|
|
223
|
-
}
|
|
176
|
+
const generateActions = async (project) => {
|
|
177
|
+
const { actionFile, inputsFile } = project;
|
|
224
178
|
const methods = (0, parse_1.getActionMethods)(project);
|
|
225
179
|
const actions = (0, lodash_1.sortBy)(Object.entries(methods).flatMap(([service, actionMethods]) => {
|
|
226
180
|
const dedupedActions = (0, lodash_1.uniqBy)(actionMethods, (a) => a.getName());
|
|
@@ -239,14 +193,8 @@ const generateActions = async (project, includeClient, addRetry) => {
|
|
|
239
193
|
const dedupedServices = (0, lodash_1.sortBy)((0, lodash_1.uniq)(services));
|
|
240
194
|
await writeServicesImport(dedupedServices, project);
|
|
241
195
|
const inputNames = dedupedInputs.map(({ propertyName }) => propertyName);
|
|
242
|
-
await writeInputsImport(
|
|
243
|
-
|
|
244
|
-
inputFields: inputNames,
|
|
245
|
-
includeClient,
|
|
246
|
-
addRetry,
|
|
247
|
-
})) || []
|
|
248
|
-
: inputNames, project);
|
|
249
|
-
const actionPromises = actions.map((action) => writeAction(action, project, includeClient, projectType === "openApi" && addRetry));
|
|
196
|
+
await writeInputsImport(inputNames, project);
|
|
197
|
+
const actionPromises = actions.map((action) => writeAction(action, project));
|
|
250
198
|
await Promise.all(actionPromises);
|
|
251
199
|
const actionExports = (0, lodash_1.sortBy)(actions.map(({ key }) => key));
|
|
252
200
|
actionFile.addExportAssignment({
|
package/lib/generate/index.js
CHANGED
|
@@ -30,19 +30,13 @@ exports.updatePackageJson = exports.generate = void 0;
|
|
|
30
30
|
const path = __importStar(require("path"));
|
|
31
31
|
const sourceFile_1 = require("./sourceFile");
|
|
32
32
|
const action_1 = require("./action");
|
|
33
|
-
const client_1 = require("./client");
|
|
34
|
-
const connection_1 = require("./connection");
|
|
35
33
|
const prettier_1 = __importDefault(require("prettier"));
|
|
36
34
|
const fs_extra_1 = require("fs-extra");
|
|
37
|
-
const generate = async ({ projectRoot, projectTemplateName, projectTemplatePath,
|
|
35
|
+
const generate = async ({ projectRoot, projectTemplateName, projectTemplatePath, }) => {
|
|
38
36
|
var _a;
|
|
39
|
-
const project = (0, sourceFile_1.initializeProject)(projectRoot, projectTemplateName, projectTemplatePath
|
|
37
|
+
const project = (0, sourceFile_1.initializeProject)(projectRoot, projectTemplateName, projectTemplatePath);
|
|
40
38
|
const { componentProject } = project;
|
|
41
|
-
|
|
42
|
-
await (0, client_1.generateClient)(project);
|
|
43
|
-
await (0, connection_1.generateConnections)(project);
|
|
44
|
-
}
|
|
45
|
-
await (0, action_1.generateActions)(project, includeClient, projectType === "openApi" && addRetry);
|
|
39
|
+
await (0, action_1.generateActions)(project);
|
|
46
40
|
(_a = componentProject
|
|
47
41
|
.getSourceFile(path.join(projectRoot, "src", "index.test.ts"))) === null || _a === void 0 ? void 0 : _a.delete();
|
|
48
42
|
await componentProject.save();
|
package/lib/generate/parse.js
CHANGED
|
@@ -41,71 +41,19 @@ const getWSDLClientMethods = (clientPath, clientInterface, componentProject) =>
|
|
|
41
41
|
process.exit(1);
|
|
42
42
|
}
|
|
43
43
|
};
|
|
44
|
-
const getOpenApiMethods = (servicesPath, componentProject) => {
|
|
45
|
-
try {
|
|
46
|
-
const servicesFiles = componentProject
|
|
47
|
-
.getDirectoryOrThrow(servicesPath)
|
|
48
|
-
.getSourceFiles();
|
|
49
|
-
const serviceToMethodsMapping = Object.fromEntries(servicesFiles.map((serviceFile) => {
|
|
50
|
-
let methods = [];
|
|
51
|
-
const serviceClass = serviceFile.getClassOrThrow(serviceFile.getBaseName().split(".ts")[0]);
|
|
52
|
-
methods = serviceClass
|
|
53
|
-
.getMethods()
|
|
54
|
-
.map((method) => method.getSignature().getDeclaration());
|
|
55
|
-
return [serviceClass.getNameOrThrow(), methods];
|
|
56
|
-
}));
|
|
57
|
-
return serviceToMethodsMapping;
|
|
58
|
-
}
|
|
59
|
-
catch (error) {
|
|
60
|
-
console.error("Unable to find services directory." + error);
|
|
61
|
-
process.exit(1);
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
const isPrimitiveType = (type) => type.isObject() ||
|
|
65
|
-
type.isLiteral() ||
|
|
66
|
-
type.isString() ||
|
|
67
|
-
type.isBoolean() ||
|
|
68
|
-
type.isNumber() ||
|
|
69
|
-
type.isAny() ||
|
|
70
|
-
type.isUndefined();
|
|
71
44
|
const getParamTypeDefinition = (project, parameter) => {
|
|
72
|
-
const { componentProject,
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
: paramName.split("Param")[0], {
|
|
78
|
-
pascalCase: true,
|
|
79
|
-
})}.ts`));
|
|
80
|
-
}
|
|
81
|
-
else if (projectType === "openApi") {
|
|
82
|
-
// The OpenAPI generator skips certain types
|
|
83
|
-
const paramType = parameter.getType();
|
|
84
|
-
if (isPrimitiveType(paramType) ||
|
|
85
|
-
paramType.getUnionTypes().every(isPrimitiveType)) {
|
|
86
|
-
return undefined;
|
|
87
|
-
}
|
|
88
|
-
return componentProject.getSourceFile(path.join(projectRoot, definitionDirectory, "models", `${(0, camelcase_1.default)(parameter.getName(), {
|
|
89
|
-
pascalCase: true,
|
|
90
|
-
})}.ts`));
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
console.error("Not implemented");
|
|
94
|
-
process.exit(1);
|
|
95
|
-
}
|
|
45
|
+
const { componentProject, projectRoot, definitionDirectory } = project;
|
|
46
|
+
const paramName = parameter.getName();
|
|
47
|
+
return componentProject.getSourceFile(path.join(projectRoot, definitionDirectory, "definitions", `${(0, camelcase_1.default)(!paramName.includes("Param") ? paramName : paramName.split("Param")[0], {
|
|
48
|
+
pascalCase: true,
|
|
49
|
+
})}.ts`));
|
|
96
50
|
};
|
|
97
51
|
exports.getParamTypeDefinition = getParamTypeDefinition;
|
|
98
52
|
// Gather the methods that will be translated to actions
|
|
99
53
|
const getActionMethods = (projectStructure) => {
|
|
100
54
|
const { projectRoot, componentProject, projectTemplateName, definitionDirectory, } = projectStructure;
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
serviceMethods["createClientAsync"] = methods;
|
|
105
|
-
}
|
|
106
|
-
else if (projectStructure.projectType === "openApi") {
|
|
107
|
-
serviceMethods = getOpenApiMethods(path.join(projectRoot, definitionDirectory, "services"), componentProject);
|
|
108
|
-
}
|
|
109
|
-
return serviceMethods;
|
|
55
|
+
return {
|
|
56
|
+
createClientAsync: getWSDLClientMethods(path.join(projectRoot, definitionDirectory, "client.ts"), `${(0, camelcase_1.default)(projectTemplateName, { pascalCase: true })}Client`, componentProject),
|
|
57
|
+
};
|
|
110
58
|
};
|
|
111
59
|
exports.getActionMethods = getActionMethods;
|
|
@@ -30,7 +30,6 @@ exports.initializeProject = void 0;
|
|
|
30
30
|
const camelcase_1 = __importDefault(require("camelcase"));
|
|
31
31
|
const ts_morph_1 = require("ts-morph");
|
|
32
32
|
const path = __importStar(require("path"));
|
|
33
|
-
const util_1 = require("./util");
|
|
34
33
|
const initializeActionFile = (componentProject, projectRoot) => {
|
|
35
34
|
const actionFile = componentProject.createSourceFile(path.join(projectRoot, "src", "actions.ts"), undefined, { overwrite: true });
|
|
36
35
|
actionFile.addImportDeclaration({
|
|
@@ -39,14 +38,6 @@ const initializeActionFile = (componentProject, projectRoot) => {
|
|
|
39
38
|
});
|
|
40
39
|
return actionFile;
|
|
41
40
|
};
|
|
42
|
-
const initializeClientFile = (componentProject, projectRoot) => {
|
|
43
|
-
const clientFile = componentProject.createSourceFile(path.join(projectRoot, "src", "client.ts"), undefined, { overwrite: true });
|
|
44
|
-
return clientFile;
|
|
45
|
-
};
|
|
46
|
-
const initializeConnectionsFile = (componentProject, projectRoot) => {
|
|
47
|
-
const connectionsFile = componentProject.createSourceFile(path.join(projectRoot, "src", "connections.ts"), undefined, { overwrite: true });
|
|
48
|
-
return connectionsFile;
|
|
49
|
-
};
|
|
50
41
|
const initializeInputsFile = (componentProject, projectRoot) => {
|
|
51
42
|
const inputsFile = componentProject.createSourceFile(path.join(projectRoot, "src", "inputs.ts"), undefined, { overwrite: true });
|
|
52
43
|
inputsFile.addImportDeclaration({
|
|
@@ -60,12 +51,6 @@ const copyTemplateFileToProject = (componentProject, projectRoot, projectTemplat
|
|
|
60
51
|
const templateFile = componentProject.getSourceFileOrThrow(projectTemplatePath);
|
|
61
52
|
templateFile.copy(path.join(process.cwd(), projectRoot, fileName));
|
|
62
53
|
};
|
|
63
|
-
const initializeOpenApi = ({ projectRoot, projectTemplatePath, componentProject, }) => {
|
|
64
|
-
// Copy our template file into the component project
|
|
65
|
-
copyTemplateFileToProject(componentProject, projectRoot, projectTemplatePath, path.basename(projectTemplatePath));
|
|
66
|
-
// Return the relative path of the OpenAPI spec
|
|
67
|
-
return path.relative(path.join(projectRoot, "src"), path.join(projectRoot, path.basename(projectTemplatePath)));
|
|
68
|
-
};
|
|
69
54
|
const initializeWSDL = ({ projectRoot, projectTemplateName, projectTemplatePath, componentProject, actionFile, }) => {
|
|
70
55
|
const wsdlProjectLocation = path.join(projectRoot, `${projectTemplateName}.wsdl`);
|
|
71
56
|
// Copy the wsdl used for generation to the project root
|
|
@@ -77,47 +62,29 @@ const initializeWSDL = ({ projectRoot, projectTemplateName, projectTemplatePath,
|
|
|
77
62
|
// Return the relative path of the WSDL
|
|
78
63
|
return path.relative(path.join(projectRoot, "src"), wsdlProjectLocation);
|
|
79
64
|
};
|
|
80
|
-
const projectTypeSetup = (project
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
project.projectTemplatePath = wsdlPath;
|
|
85
|
-
}
|
|
86
|
-
else if (projectType === "openApi") {
|
|
87
|
-
const openApiPath = initializeOpenApi(project);
|
|
88
|
-
project.projectTemplatePath = openApiPath;
|
|
89
|
-
}
|
|
65
|
+
const projectTypeSetup = (project) => {
|
|
66
|
+
const wsdlPath = initializeWSDL(project);
|
|
67
|
+
// Update the WSDL Path to be in our component project
|
|
68
|
+
project.projectTemplatePath = wsdlPath;
|
|
90
69
|
};
|
|
91
|
-
const initializeProject = (projectRoot, projectTemplateName, projectTemplatePath
|
|
70
|
+
const initializeProject = (projectRoot, projectTemplateName, projectTemplatePath) => {
|
|
92
71
|
const componentProject = new ts_morph_1.Project({
|
|
93
72
|
tsConfigFilePath: path.join(projectRoot, "tsconfig.json"),
|
|
94
73
|
});
|
|
95
74
|
componentProject.addSourceFilesAtPaths(path.join(projectRoot, "**/*"));
|
|
96
75
|
const actionFile = initializeActionFile(componentProject, projectRoot);
|
|
97
76
|
const inputsFile = initializeInputsFile(componentProject, projectRoot);
|
|
98
|
-
if (projectType === "openApi" && inputsFile) {
|
|
99
|
-
(0, util_1.addRequiredInputs)(projectType, inputsFile, addRetry);
|
|
100
|
-
}
|
|
101
77
|
const project = {
|
|
102
78
|
projectRoot,
|
|
103
79
|
projectTemplateName: (0, camelcase_1.default)(projectTemplateName),
|
|
104
|
-
definitionDirectory:
|
|
105
|
-
? (0, camelcase_1.default)(projectTemplateName).toLowerCase()
|
|
106
|
-
: projectTemplateName,
|
|
80
|
+
definitionDirectory: (0, camelcase_1.default)(projectTemplateName).toLowerCase(),
|
|
107
81
|
projectTemplatePath,
|
|
108
|
-
projectType,
|
|
109
82
|
componentProject,
|
|
110
83
|
actionFile,
|
|
111
84
|
inputsFile,
|
|
112
85
|
};
|
|
113
|
-
if (projectType === "openApi" && includeClient) {
|
|
114
|
-
const clientFile = initializeClientFile(componentProject, projectRoot);
|
|
115
|
-
project.clientFile = clientFile;
|
|
116
|
-
const connectionsFile = initializeConnectionsFile(componentProject, projectRoot);
|
|
117
|
-
project.connectionsFile = connectionsFile;
|
|
118
|
-
}
|
|
119
86
|
// Setup type specific project details
|
|
120
|
-
projectTypeSetup(project
|
|
87
|
+
projectTypeSetup(project);
|
|
121
88
|
return project;
|
|
122
89
|
};
|
|
123
90
|
exports.initializeProject = initializeProject;
|