@constructor-io/constructorio-connect-cli 1.0.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/LICENSE +21 -0
- package/README.md +184 -0
- package/bin/dev.cmd +3 -0
- package/bin/dev.js +16 -0
- package/bin/run.cmd +3 -0
- package/bin/run.js +10 -0
- package/boilerplate-repo/.env.example +1 -0
- package/boilerplate-repo/.eslintrc.json +11 -0
- package/boilerplate-repo/.vscode/extensions.json +5 -0
- package/boilerplate-repo/.vscode/launch.json +13 -0
- package/boilerplate-repo/.vscode/tasks.json +20 -0
- package/boilerplate-repo/LICENSE +21 -0
- package/boilerplate-repo/README.md +650 -0
- package/boilerplate-repo/connectrc.js +7 -0
- package/boilerplate-repo/package.json +21 -0
- package/boilerplate-repo/src/fixtures/item/item.json +39 -0
- package/boilerplate-repo/src/fixtures/item_group/item_group.json +22 -0
- package/boilerplate-repo/src/fixtures/mapping/mapping.json +26 -0
- package/boilerplate-repo/src/fixtures/variation/variation.json +11 -0
- package/boilerplate-repo/src/templates/grouping/grouping.jsonata +37 -0
- package/boilerplate-repo/src/templates/helpers.jsonata +3 -0
- package/boilerplate-repo/src/templates/item/item.jsonata +26 -0
- package/boilerplate-repo/src/templates/item_group/item_group.jsonata +4 -0
- package/boilerplate-repo/src/templates/mapping/mapping.jsonata +34 -0
- package/boilerplate-repo/src/templates/variation/variation.jsonata +26 -0
- package/dist/commands/deploy.d.ts +10 -0
- package/dist/commands/deploy.d.ts.map +1 -0
- package/dist/commands/deploy.js +64 -0
- package/dist/commands/execute.d.ts +35 -0
- package/dist/commands/execute.d.ts.map +1 -0
- package/dist/commands/execute.js +145 -0
- package/dist/commands/init.d.ts +18 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +172 -0
- package/dist/customer/config.d.ts +6 -0
- package/dist/customer/config.d.ts.map +1 -0
- package/dist/customer/config.js +40 -0
- package/dist/customer/get-connect-token.d.ts +15 -0
- package/dist/customer/get-connect-token.d.ts.map +1 -0
- package/dist/customer/get-connect-token.js +69 -0
- package/dist/customer/path.d.ts +26 -0
- package/dist/customer/path.d.ts.map +1 -0
- package/dist/customer/path.js +48 -0
- package/dist/customer/template-source-code.d.ts +12 -0
- package/dist/customer/template-source-code.d.ts.map +1 -0
- package/dist/customer/template-source-code.js +42 -0
- package/dist/helpers/build-config-file.d.ts +13 -0
- package/dist/helpers/build-config-file.d.ts.map +1 -0
- package/dist/helpers/build-config-file.js +62 -0
- package/dist/helpers/file-loaders.d.ts +19 -0
- package/dist/helpers/file-loaders.d.ts.map +1 -0
- package/dist/helpers/file-loaders.js +45 -0
- package/dist/helpers/find-deep-files.d.ts +7 -0
- package/dist/helpers/find-deep-files.d.ts.map +1 -0
- package/dist/helpers/find-deep-files.js +27 -0
- package/dist/helpers/generate-command-input.d.ts +19 -0
- package/dist/helpers/generate-command-input.d.ts.map +1 -0
- package/dist/helpers/generate-command-input.js +51 -0
- package/dist/helpers/is-git-repo-initialized.d.ts +5 -0
- package/dist/helpers/is-git-repo-initialized.d.ts.map +1 -0
- package/dist/helpers/is-git-repo-initialized.js +24 -0
- package/dist/helpers/ux-action.d.ts +2 -0
- package/dist/helpers/ux-action.d.ts.map +1 -0
- package/dist/helpers/ux-action.js +31 -0
- package/dist/http/deploy-request.d.ts +16 -0
- package/dist/http/deploy-request.d.ts.map +1 -0
- package/dist/http/deploy-request.js +45 -0
- package/dist/http/execute-templates-request.d.ts +10 -0
- package/dist/http/execute-templates-request.d.ts.map +1 -0
- package/dist/http/execute-templates-request.js +28 -0
- package/dist/http/get-connections-request.d.ts +18 -0
- package/dist/http/get-connections-request.d.ts.map +1 -0
- package/dist/http/get-connections-request.js +24 -0
- package/dist/http/http-client.d.ts +6 -0
- package/dist/http/http-client.d.ts.map +1 -0
- package/dist/http/http-client.js +57 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/prompt-data/filter-connections-by-template.d.ts +4 -0
- package/dist/prompt-data/filter-connections-by-template.d.ts.map +1 -0
- package/dist/prompt-data/filter-connections-by-template.js +30 -0
- package/dist/prompt-data/get-candidate-fixtures.d.ts +3 -0
- package/dist/prompt-data/get-candidate-fixtures.d.ts.map +1 -0
- package/dist/prompt-data/get-candidate-fixtures.js +49 -0
- package/dist/prompt-data/get-external-data-files.d.ts +3 -0
- package/dist/prompt-data/get-external-data-files.d.ts.map +1 -0
- package/dist/prompt-data/get-external-data-files.js +28 -0
- package/dist/prompt-data/get-template-files.d.ts +7 -0
- package/dist/prompt-data/get-template-files.d.ts.map +1 -0
- package/dist/prompt-data/get-template-files.js +50 -0
- package/dist/prompt-data/render-prompt.d.ts +9 -0
- package/dist/prompt-data/render-prompt.d.ts.map +1 -0
- package/dist/prompt-data/render-prompt.js +16 -0
- package/dist/rendering/render-repeat-input.d.ts +14 -0
- package/dist/rendering/render-repeat-input.d.ts.map +1 -0
- package/dist/rendering/render-repeat-input.js +25 -0
- package/dist/rendering/render-template-result.d.ts +2 -0
- package/dist/rendering/render-template-result.d.ts.map +1 -0
- package/dist/rendering/render-template-result.js +60 -0
- package/dist/rendering/render-tip.d.ts +6 -0
- package/dist/rendering/render-tip.d.ts.map +1 -0
- package/dist/rendering/render-tip.js +22 -0
- package/dist/types.d.ts +40 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/oclif.manifest.json +129 -0
- package/package.json +98 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": 42,
|
|
3
|
+
"name": "Super Shoes",
|
|
4
|
+
"variations": [
|
|
5
|
+
{
|
|
6
|
+
"id": "42-red",
|
|
7
|
+
"name": "Super Shoes (Red)",
|
|
8
|
+
"price": 50,
|
|
9
|
+
"attributes": [
|
|
10
|
+
{
|
|
11
|
+
"name": "color",
|
|
12
|
+
"value": "red"
|
|
13
|
+
}
|
|
14
|
+
]
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"id": "42-blue",
|
|
18
|
+
"name": "Super Shoes (Blue)",
|
|
19
|
+
"price": 100,
|
|
20
|
+
"attributes": [
|
|
21
|
+
{
|
|
22
|
+
"name": "color",
|
|
23
|
+
"value": "blue"
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"id": "42-green",
|
|
29
|
+
"name": "Super Shoes (Green)",
|
|
30
|
+
"price": 75,
|
|
31
|
+
"attributes": [
|
|
32
|
+
{
|
|
33
|
+
"name": "color",
|
|
34
|
+
"value": "green"
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
]
|
|
39
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": 1,
|
|
3
|
+
"name": "Root Category",
|
|
4
|
+
"children": [
|
|
5
|
+
{
|
|
6
|
+
"id": 2,
|
|
7
|
+
"name": "Clothing"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"id": 3,
|
|
11
|
+
"name": "Shoes"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"id": 4,
|
|
15
|
+
"name": "Accessories"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"id": 5,
|
|
19
|
+
"name": "Electronics"
|
|
20
|
+
}
|
|
21
|
+
]
|
|
22
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "iphone-x",
|
|
3
|
+
"title": "iPhone X",
|
|
4
|
+
"description": "SIM-Free, Model A19211 6.5-inch Super Retina HD display with OLED technology A12 Bionic chip with ...",
|
|
5
|
+
"price": 899,
|
|
6
|
+
"discountPercentage": 17.94,
|
|
7
|
+
"rating": 4.44,
|
|
8
|
+
"stock": 34,
|
|
9
|
+
"brand": "Apple",
|
|
10
|
+
"category": "smartphones",
|
|
11
|
+
"thumbnail": "https://cdn.dummyjson.com/product-images/2/thumbnail.jpg",
|
|
12
|
+
"images": [
|
|
13
|
+
"https://cdn.dummyjson.com/product-images/2/1.jpg",
|
|
14
|
+
"https://cdn.dummyjson.com/product-images/2/2.jpg",
|
|
15
|
+
"https://cdn.dummyjson.com/product-images/2/3.jpg",
|
|
16
|
+
"https://cdn.dummyjson.com/product-images/2/thumbnail.jpg"
|
|
17
|
+
],
|
|
18
|
+
"colors": [
|
|
19
|
+
"midnight-black",
|
|
20
|
+
"fancy-silver",
|
|
21
|
+
"rich-gold",
|
|
22
|
+
"sky-blue",
|
|
23
|
+
"crimson-red",
|
|
24
|
+
"green-forest"
|
|
25
|
+
]
|
|
26
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/*
|
|
2
|
+
This template enables you to group variations together as items.
|
|
3
|
+
It'll use the variation data and expect you to return the item structure, just like in the item template.
|
|
4
|
+
|
|
5
|
+
When you use this template, a new item will be created for each unique ID that you return from this template,
|
|
6
|
+
but any additional items returned with the same ID will be ignored.
|
|
7
|
+
|
|
8
|
+
When creating new items, the base item information of the variation will be merged with the template result,
|
|
9
|
+
effectively filling in fields that you don't return from the template.
|
|
10
|
+
|
|
11
|
+
For example, suppose that you use the following logic to calculate the ID:
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
{
|
|
15
|
+
"id": $join([targetData.product_id, targetData.color])
|
|
16
|
+
}
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Let's assume that you have an item with 3 variations, containing the respective data:
|
|
20
|
+
|
|
21
|
+
1. product_id: 1, color: red, size: S
|
|
22
|
+
2. product_id: 1, color: red, size: M
|
|
23
|
+
3. product_id: 1, color: blue, size: S
|
|
24
|
+
|
|
25
|
+
The template will create 2 items:
|
|
26
|
+
|
|
27
|
+
1. id: 1-red
|
|
28
|
+
2. id: 1-blue
|
|
29
|
+
|
|
30
|
+
And you can return any extra item field on the template to customize the item structure,
|
|
31
|
+
allowing you to add any other pieces of information to the newly created items.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
{
|
|
35
|
+
"id": targetData.id,
|
|
36
|
+
"item_name": targetData.name
|
|
37
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
(
|
|
2
|
+
/* Import all helper functions defined in helpers.jsonata */
|
|
3
|
+
{{helpers}}
|
|
4
|
+
|
|
5
|
+
/* You can define variables and custom logic */
|
|
6
|
+
$name := targetData.name;
|
|
7
|
+
|
|
8
|
+
{
|
|
9
|
+
/* Use the `hello` helper function */
|
|
10
|
+
"item_name": $hello($name),
|
|
11
|
+
|
|
12
|
+
"metadata": [
|
|
13
|
+
{
|
|
14
|
+
"key": "colors",
|
|
15
|
+
"value": targetData.variations.attributes[name = "color"].value
|
|
16
|
+
}
|
|
17
|
+
],
|
|
18
|
+
|
|
19
|
+
"facets": [
|
|
20
|
+
{
|
|
21
|
+
"key": "price_average",
|
|
22
|
+
"value": $average(targetData.variations.price)
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/*
|
|
2
|
+
The mapping template allows you to map the input data to any format you want before the
|
|
3
|
+
actual transformations happen, using the transformation templates for each entity.
|
|
4
|
+
|
|
5
|
+
In this template, you can return three arrays: `items`, `variations`, and `item_groups`.
|
|
6
|
+
Each array can have any structure as defined by you, and you'll be able to use the
|
|
7
|
+
very same structure defined here in the transformation templates.
|
|
8
|
+
|
|
9
|
+
In the example defined below, we only care about mapping the items and item groups,
|
|
10
|
+
since variations are already embedded into each item.
|
|
11
|
+
|
|
12
|
+
If we wanted to ingest only variations (e.g. a partial sync), you'd return the
|
|
13
|
+
`variations` array filled with data instead.
|
|
14
|
+
|
|
15
|
+
Refer to the README for extended documentation on how to use the mapping template.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
(
|
|
19
|
+
/* Import all helper functions defined in helpers.jsonata */
|
|
20
|
+
{{helpers}}
|
|
21
|
+
|
|
22
|
+
{
|
|
23
|
+
"items": [
|
|
24
|
+
$merge([
|
|
25
|
+
targetData,
|
|
26
|
+
{ "__variations": targetData.colors.{ "color": $ } }
|
|
27
|
+
])
|
|
28
|
+
],
|
|
29
|
+
"variations": [],
|
|
30
|
+
"item_groups": [
|
|
31
|
+
{ "id": targetData.category }
|
|
32
|
+
]
|
|
33
|
+
}
|
|
34
|
+
)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
(
|
|
2
|
+
/* Import all helper functions defined in helpers.jsonata */
|
|
3
|
+
{{helpers}}
|
|
4
|
+
|
|
5
|
+
/* You can define variables and custom logic */
|
|
6
|
+
$name := targetData.name;
|
|
7
|
+
|
|
8
|
+
{
|
|
9
|
+
/* Use the `hello` helper function */
|
|
10
|
+
"item_name": $hello($name),
|
|
11
|
+
|
|
12
|
+
"metadata": [
|
|
13
|
+
{
|
|
14
|
+
"key": "color",
|
|
15
|
+
"value": targetData.attributes[name = "color"].value
|
|
16
|
+
}
|
|
17
|
+
],
|
|
18
|
+
|
|
19
|
+
"facets": [
|
|
20
|
+
{
|
|
21
|
+
"key": "price",
|
|
22
|
+
"value": targetData.price
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Command } from "@oclif/core";
|
|
2
|
+
export default class Deploy extends Command {
|
|
3
|
+
static args: {
|
|
4
|
+
env: import("@oclif/core/lib/interfaces").Arg<string, Record<string, unknown>>;
|
|
5
|
+
};
|
|
6
|
+
static description: string;
|
|
7
|
+
static examples: string[];
|
|
8
|
+
run(): Promise<any>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=deploy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../src/commands/deploy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,OAAO,EAAM,MAAM,aAAa,CAAC;AAchD,MAAM,CAAC,OAAO,OAAO,MAAO,SAAQ,OAAO;IACzC,MAAM,CAAC,IAAI;;MAMT;IAEF,MAAM,CAAC,WAAW,SAGqF;IAEvG,MAAM,CAAC,QAAQ,WAIb;IAEI,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC;CAgD1B"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const core_1 = require("@oclif/core");
|
|
7
|
+
const errors_1 = require("@oclif/core/lib/errors");
|
|
8
|
+
const kleur_1 = __importDefault(require("kleur"));
|
|
9
|
+
const deploy_request_1 = require("../http/deploy-request");
|
|
10
|
+
const config_1 = require("../customer/config");
|
|
11
|
+
const template_source_code_1 = require("../customer/template-source-code");
|
|
12
|
+
const ux_action_1 = require("../helpers/ux-action");
|
|
13
|
+
const render_tip_1 = require("../rendering/render-tip");
|
|
14
|
+
const get_connect_token_1 = require("../customer/get-connect-token");
|
|
15
|
+
class Deploy extends core_1.Command {
|
|
16
|
+
static args = {
|
|
17
|
+
env: core_1.Args.string({
|
|
18
|
+
options: ["development", "qa", "production", "demo"],
|
|
19
|
+
description: "The target Constructor environment to deploy to.",
|
|
20
|
+
required: true,
|
|
21
|
+
}),
|
|
22
|
+
};
|
|
23
|
+
static description = `
|
|
24
|
+
Deploys all templates defined on the \`connectrc.js\` file to the specified environment.
|
|
25
|
+
|
|
26
|
+
The script will use the \`CONNECT_AUTH_TOKEN\` environment variable to authenticate with Constructor.`;
|
|
27
|
+
static examples = [
|
|
28
|
+
"$ <%= config.bin %> deploy development",
|
|
29
|
+
"$ <%= config.bin %> deploy qa",
|
|
30
|
+
"$ <%= config.bin %> deploy production",
|
|
31
|
+
];
|
|
32
|
+
async run() {
|
|
33
|
+
const { args } = await this.parse(Deploy);
|
|
34
|
+
const config = await (0, ux_action_1.uxAction)("📡 Reading your config", async () => {
|
|
35
|
+
return await (0, config_1.getRepositoryConfigFile)();
|
|
36
|
+
})();
|
|
37
|
+
const environment = await (0, ux_action_1.uxAction)("✨ Validating your environment", async () => {
|
|
38
|
+
const env = config.environments.find(({ environment }) => environment === args.env);
|
|
39
|
+
if (!env) {
|
|
40
|
+
throw new errors_1.CLIError(`💥 Could not find an environment named ${kleur_1.default.bold(args.env)} in your ${kleur_1.default.bold("connectrc.js")} file.`);
|
|
41
|
+
}
|
|
42
|
+
return env;
|
|
43
|
+
})();
|
|
44
|
+
// Load the connect token to ensure we can authenticate with Constructor.
|
|
45
|
+
// We do this here because the terminal output gets weird when there is a prompt during a ux action.
|
|
46
|
+
await (0, get_connect_token_1.getConnectToken)();
|
|
47
|
+
const templates = await (0, template_source_code_1.getTemplatesSourceCode)(environment.templates);
|
|
48
|
+
const helpers = await (0, template_source_code_1.getHelpersSourceCode)(config.helpers);
|
|
49
|
+
await (0, ux_action_1.uxAction)("🚀 Deploying your templates", async () => {
|
|
50
|
+
await (0, deploy_request_1.performDeploy)({
|
|
51
|
+
environment: args.env,
|
|
52
|
+
templates,
|
|
53
|
+
helpers,
|
|
54
|
+
config,
|
|
55
|
+
});
|
|
56
|
+
})();
|
|
57
|
+
core_1.ux.log(`\n${kleur_1.default.bold("🎉 Deploy completed!")}\n`);
|
|
58
|
+
(0, render_tip_1.renderTip)(["Future catalog ingestions will use the new templates."]);
|
|
59
|
+
(0, render_tip_1.renderTip)([
|
|
60
|
+
"Check the Constructor dashboard to see your latest ingestion results.",
|
|
61
|
+
]);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.default = Deploy;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Command } from "@oclif/core";
|
|
2
|
+
export declare const executePromptMessages: {
|
|
3
|
+
readonly template: "Select a template to execute";
|
|
4
|
+
readonly fixture: "Select a catalog fixture to run the template against";
|
|
5
|
+
readonly externalData: "Select external data to run the template against";
|
|
6
|
+
readonly connection: "Select a connection to execute templates against";
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* The input flags in their potentially incomplete state as provided by the user
|
|
10
|
+
* and while being computed
|
|
11
|
+
*/
|
|
12
|
+
interface ExecuteInputFlags {
|
|
13
|
+
"template-path"?: string;
|
|
14
|
+
"connection-id"?: string;
|
|
15
|
+
"fixture-path"?: string;
|
|
16
|
+
"external-data-path"?: string;
|
|
17
|
+
}
|
|
18
|
+
export declare class Execute extends Command {
|
|
19
|
+
static flags: {
|
|
20
|
+
"template-path": import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
21
|
+
"fixture-path": import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
22
|
+
"external-data-path": import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
23
|
+
"connection-id": import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
24
|
+
};
|
|
25
|
+
static description: string;
|
|
26
|
+
static examples: string[];
|
|
27
|
+
input: ExecuteInputFlags;
|
|
28
|
+
run(): Promise<void>;
|
|
29
|
+
private parseFlags;
|
|
30
|
+
private getTemplateExecInput;
|
|
31
|
+
private calculateConnectionId;
|
|
32
|
+
private getConnectionForTemplate;
|
|
33
|
+
}
|
|
34
|
+
export {};
|
|
35
|
+
//# sourceMappingURL=execute.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../../src/commands/execute.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,OAAO,EAAM,MAAM,aAAa,CAAC;AA2BjD,eAAO,MAAM,qBAAqB;;;;;CAKxB,CAAC;AAEX;;;GAGG;AACH,UAAU,iBAAiB;IACzB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAYD,qBAAa,OAAQ,SAAQ,OAAO;IAClC,MAAM,CAAC,KAAK;;;;;MAgBV;IAEF,MAAM,CAAC,WAAW,SACkK;IAEpL,MAAM,CAAC,QAAQ,WAOb;IAEF,KAAK,EAAE,iBAAiB,CAAM;IAExB,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;YAgCZ,UAAU;YAsBV,oBAAoB;YA6CpB,qBAAqB;YA0BrB,wBAAwB;CAevC"}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Execute = exports.executePromptMessages = void 0;
|
|
4
|
+
const core_1 = require("@oclif/core");
|
|
5
|
+
const errors_1 = require("@oclif/core/lib/errors");
|
|
6
|
+
const file_loaders_1 = require("../helpers/file-loaders");
|
|
7
|
+
const execute_templates_request_1 = require("../http/execute-templates-request");
|
|
8
|
+
const get_connections_request_1 = require("../http/get-connections-request");
|
|
9
|
+
const filter_connections_by_template_1 = require("../prompt-data/filter-connections-by-template");
|
|
10
|
+
const get_candidate_fixtures_1 = require("../prompt-data/get-candidate-fixtures");
|
|
11
|
+
const get_template_files_1 = require("../prompt-data/get-template-files");
|
|
12
|
+
const get_external_data_files_1 = require("../prompt-data/get-external-data-files");
|
|
13
|
+
const render_prompt_1 = require("../prompt-data/render-prompt");
|
|
14
|
+
const render_repeat_input_1 = require("../rendering/render-repeat-input");
|
|
15
|
+
const render_template_result_1 = require("../rendering/render-template-result");
|
|
16
|
+
const path_1 = require("../customer/path");
|
|
17
|
+
exports.executePromptMessages = {
|
|
18
|
+
template: "Select a template to execute",
|
|
19
|
+
fixture: "Select a catalog fixture to run the template against",
|
|
20
|
+
externalData: "Select external data to run the template against",
|
|
21
|
+
connection: "Select a connection to execute templates against",
|
|
22
|
+
};
|
|
23
|
+
class Execute extends core_1.Command {
|
|
24
|
+
static flags = {
|
|
25
|
+
"template-path": core_1.Flags.string({
|
|
26
|
+
description: "The path to the template to execute. Must be in the 'src/templates' directory.",
|
|
27
|
+
}),
|
|
28
|
+
"fixture-path": core_1.Flags.string({
|
|
29
|
+
description: "The path to the fixture to execute the template against. Must be in the 'src/fixtures' directory.",
|
|
30
|
+
}),
|
|
31
|
+
"external-data-path": core_1.Flags.string({
|
|
32
|
+
description: "The path to the external data to execute the template against. Must be in the 'src/fixtures/external_data' directory.",
|
|
33
|
+
}),
|
|
34
|
+
"connection-id": core_1.Flags.string({
|
|
35
|
+
description: "The ID of the connection to execute the template against.",
|
|
36
|
+
}),
|
|
37
|
+
};
|
|
38
|
+
static description = "Execute a template against a connection and fixture to see the resulting transformed data. Each value not provided as a flag will be prompted for when the command is executed.";
|
|
39
|
+
static examples = [
|
|
40
|
+
"$ <%= config.bin %> execute",
|
|
41
|
+
"$ <%= config.bin %> execute --template-path=item/item.jsonata",
|
|
42
|
+
"$ <%= config.bin %> execute --template-path=variation/variation.jsonata",
|
|
43
|
+
"$ <%= config.bin %> execute --template-path=item_group/item_group.jsonata --fixture-path=item_group.json",
|
|
44
|
+
"$ <%= config.bin %> execute --template-path=grouping/grouping.jsonata --connection-id=example-connection-id",
|
|
45
|
+
"$ <%= config.bin %> execute --template-path=mapping/mapping.jsonata",
|
|
46
|
+
];
|
|
47
|
+
input = {};
|
|
48
|
+
async run() {
|
|
49
|
+
let result = null;
|
|
50
|
+
try {
|
|
51
|
+
const templateInput = await this.getTemplateExecInput();
|
|
52
|
+
core_1.ux.log("\n");
|
|
53
|
+
result = await (0, execute_templates_request_1.executeTemplates)({
|
|
54
|
+
template: (0, file_loaders_1.getJSONataTemplate)(templateInput.templatePath, "utf-8").toString(),
|
|
55
|
+
helpers: (0, file_loaders_1.getTemplateHelpers)("helpers.jsonata", "utf-8").toString(),
|
|
56
|
+
targetData: (0, file_loaders_1.getCatalogFixture)(templateInput.fixturePath),
|
|
57
|
+
externalData: templateInput.externalDataPath
|
|
58
|
+
? (0, file_loaders_1.getExternalDataFixture)(templateInput.externalDataPath)
|
|
59
|
+
: {},
|
|
60
|
+
connectionId: templateInput.connectionId,
|
|
61
|
+
});
|
|
62
|
+
core_1.ux.log("\n");
|
|
63
|
+
(0, render_template_result_1.renderTemplateResult)(result);
|
|
64
|
+
if (!result?.success) {
|
|
65
|
+
this.exit(1);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
finally {
|
|
69
|
+
(0, render_repeat_input_1.renderRepeatInput)(this, this.input);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
async parseFlags() {
|
|
73
|
+
const { flags } = await this.parse(Execute);
|
|
74
|
+
if (flags["template-path"]) {
|
|
75
|
+
this.input["template-path"] = (0, path_1.cleanupTemplatePath)(flags["template-path"]);
|
|
76
|
+
}
|
|
77
|
+
if (flags["fixture-path"]) {
|
|
78
|
+
this.input["fixture-path"] = (0, path_1.cleanupFixturePath)(flags["fixture-path"]);
|
|
79
|
+
}
|
|
80
|
+
if (flags["external-data-path"]) {
|
|
81
|
+
this.input["external-data-path"] = (0, path_1.cleanupExternalDataPath)(flags["external-data-path"]);
|
|
82
|
+
}
|
|
83
|
+
if (flags["connection-id"]) {
|
|
84
|
+
this.input["connection-id"] = flags["connection-id"];
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
async getTemplateExecInput() {
|
|
88
|
+
const allConnections = await (0, get_connections_request_1.getConnectionsForCompany)();
|
|
89
|
+
await this.parseFlags();
|
|
90
|
+
if (!this.input["template-path"]) {
|
|
91
|
+
const choices = await (0, get_template_files_1.getTemplateFiles)();
|
|
92
|
+
this.input["template-path"] = await (0, render_prompt_1.renderPrompt)({
|
|
93
|
+
choices,
|
|
94
|
+
promptMessage: exports.executePromptMessages.template,
|
|
95
|
+
emptyMessage: "No templates found",
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
if (!this.input["fixture-path"]) {
|
|
99
|
+
this.input["fixture-path"] = await (0, render_prompt_1.renderPrompt)({
|
|
100
|
+
choices: (0, get_candidate_fixtures_1.getCandidateFixtures)(this.input["template-path"]),
|
|
101
|
+
promptMessage: exports.executePromptMessages.fixture,
|
|
102
|
+
emptyMessage: "No fixtures found for this template",
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
if (!this.input["external-data-path"]) {
|
|
106
|
+
const choices = (0, get_external_data_files_1.getExternalDataFiles)();
|
|
107
|
+
if (choices.length) {
|
|
108
|
+
this.input["external-data-path"] = await (0, render_prompt_1.renderPrompt)({
|
|
109
|
+
choices,
|
|
110
|
+
promptMessage: exports.executePromptMessages.externalData,
|
|
111
|
+
emptyMessage: "No external data found",
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const connectionId = await this.calculateConnectionId(allConnections, this.input["template-path"]);
|
|
116
|
+
return {
|
|
117
|
+
templatePath: this.input["template-path"],
|
|
118
|
+
fixturePath: this.input["fixture-path"],
|
|
119
|
+
externalDataPath: this.input["external-data-path"] ?? "",
|
|
120
|
+
connectionId,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
async calculateConnectionId(allConnections, templatePath) {
|
|
124
|
+
let connection = allConnections.find((c) => c.id === this.input["connection-id"]);
|
|
125
|
+
if (this.input["connection-id"] && !connection) {
|
|
126
|
+
throw new errors_1.CLIError(`Connection with ID ${this.input["connection-id"]} not found`, {
|
|
127
|
+
suggestions: ["Check that the connectionId is correct"],
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
if (!connection) {
|
|
131
|
+
connection = await this.getConnectionForTemplate(templatePath, allConnections);
|
|
132
|
+
this.input["connection-id"] = connection.id;
|
|
133
|
+
}
|
|
134
|
+
return connection.id;
|
|
135
|
+
}
|
|
136
|
+
async getConnectionForTemplate(templatePath, allConnections) {
|
|
137
|
+
const choices = await (0, filter_connections_by_template_1.filterConnectionsByTemplate)(templatePath, allConnections);
|
|
138
|
+
return await (0, render_prompt_1.renderPrompt)({
|
|
139
|
+
choices,
|
|
140
|
+
promptMessage: exports.executePromptMessages.connection,
|
|
141
|
+
emptyMessage: "No mapped connections found for this template",
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
exports.Execute = Execute;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Command } from "@oclif/core";
|
|
2
|
+
export default class Init extends Command {
|
|
3
|
+
static description: string;
|
|
4
|
+
static examples: string[];
|
|
5
|
+
static args: {
|
|
6
|
+
name: import("@oclif/core/lib/interfaces").Arg<string, Record<string, unknown>>;
|
|
7
|
+
};
|
|
8
|
+
run(): Promise<void>;
|
|
9
|
+
private createRepo;
|
|
10
|
+
private initGitRepoAndCommit;
|
|
11
|
+
private updateRepo;
|
|
12
|
+
private generateRepositoryFiles;
|
|
13
|
+
static createNewRepository(newDir: string): void;
|
|
14
|
+
private static replacePackageName;
|
|
15
|
+
private static replaceConfigValues;
|
|
16
|
+
private printSuccessfulInitMessage;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=init.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAMA,OAAO,EAAQ,OAAO,EAAM,MAAM,aAAa,CAAC;AAiBhD,MAAM,CAAC,OAAO,OAAO,IAAK,SAAQ,OAAO;IACvC,MAAM,CAAC,WAAW,SAA4D;IAE9E,MAAM,CAAC,QAAQ,WAGb;IAEF,MAAM,CAAC,IAAI;;MAKT;IAEW,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;YA+BnB,UAAU;IAmBxB,OAAO,CAAC,oBAAoB;YAUd,UAAU;YAmBV,uBAAuB;WAmBvB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAKvD,OAAO,CAAC,MAAM,CAAC,kBAAkB;IAUjC,OAAO,CAAC,MAAM,CAAC,mBAAmB;IAqBlC,OAAO,CAAC,0BAA0B;CA4BnC"}
|