@constructor-io/constructorio-connect-cli 1.11.0 → 1.12.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/README.md +9 -0
- package/boilerplate-repo/.env.example +2 -1
- package/dist/commands/deploy.d.ts +3 -3
- package/dist/commands/deploy.d.ts.map +1 -1
- package/dist/commands/deploy.js +5 -4
- package/dist/commands/execute.d.ts +3 -3
- package/dist/commands/execute.d.ts.map +1 -1
- package/dist/commands/execute.js +13 -10
- package/dist/commands/generate-fixture.d.ts +3 -3
- package/dist/commands/generate-fixture.d.ts.map +1 -1
- package/dist/commands/generate-fixture.js +9 -8
- package/dist/commands/refresh-connections-command.d.ts +6 -0
- package/dist/commands/refresh-connections-command.d.ts.map +1 -0
- package/dist/commands/refresh-connections-command.js +14 -0
- package/dist/commands/trigger-catalog-sync.d.ts +3 -3
- package/dist/commands/trigger-catalog-sync.d.ts.map +1 -1
- package/dist/commands/trigger-catalog-sync.js +4 -4
- package/dist/customer/config.d.ts +15 -2
- package/dist/customer/config.d.ts.map +1 -1
- package/dist/customer/config.js +194 -2
- package/dist/functions/execute-template.js +5 -5
- package/dist/helpers/build-config-file.d.ts +11 -0
- package/dist/helpers/build-config-file.d.ts.map +1 -1
- package/dist/helpers/build-config-file.js +41 -8
- package/dist/helpers/print-warnings.d.ts +10 -1
- package/dist/helpers/print-warnings.d.ts.map +1 -1
- package/dist/helpers/print-warnings.js +9 -2
- package/dist/helpers/refresh-connections-list.d.ts +2 -0
- package/dist/helpers/refresh-connections-list.d.ts.map +1 -0
- package/dist/helpers/refresh-connections-list.js +103 -0
- package/dist/helpers/should-update-connections-list.d.ts +9 -0
- package/dist/helpers/should-update-connections-list.d.ts.map +1 -0
- package/dist/helpers/should-update-connections-list.js +42 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/oclif.manifest.json +20 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -38,6 +38,7 @@ With the new repository initialized, you can start developing your catalog integ
|
|
|
38
38
|
* [`constructorio-connect-cli generate-fixture`](#constructorio-connect-cli-generate-fixture)
|
|
39
39
|
* [`constructorio-connect-cli help [COMMAND]`](#constructorio-connect-cli-help-command)
|
|
40
40
|
* [`constructorio-connect-cli init NAME`](#constructorio-connect-cli-init-name)
|
|
41
|
+
* [`constructorio-connect-cli refresh-connections-command`](#constructorio-connect-cli-refresh-connections-command)
|
|
41
42
|
* [`constructorio-connect-cli trigger-catalog-sync`](#constructorio-connect-cli-trigger-catalog-sync)
|
|
42
43
|
|
|
43
44
|
## `constructorio-connect-cli deploy ENV`
|
|
@@ -167,6 +168,14 @@ EXAMPLES
|
|
|
167
168
|
```
|
|
168
169
|
|
|
169
170
|
|
|
171
|
+
## `constructorio-connect-cli refresh-connections-command`
|
|
172
|
+
|
|
173
|
+
```
|
|
174
|
+
USAGE
|
|
175
|
+
$ constructorio-connect-cli refresh-connections-command
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
|
|
170
179
|
## `constructorio-connect-cli trigger-catalog-sync`
|
|
171
180
|
|
|
172
181
|
Triggers a catalog sync for selected connection.
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
CONNECT_AUTH_TOKEN=
|
|
1
|
+
CONNECT_AUTH_TOKEN=
|
|
2
|
+
AUTO_REFRESH_CONNECTIONS=true
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default class Deploy extends
|
|
1
|
+
import { RefreshConnectionsCommand } from "./refresh-connections-command";
|
|
2
|
+
export default class Deploy extends RefreshConnectionsCommand {
|
|
3
3
|
static args: {
|
|
4
4
|
env: import("@oclif/core/lib/interfaces").Arg<string, Record<string, unknown>>;
|
|
5
5
|
};
|
|
6
6
|
static description: string;
|
|
7
7
|
static examples: string[];
|
|
8
|
-
|
|
8
|
+
runCommand(): Promise<any>;
|
|
9
9
|
}
|
|
10
10
|
//# sourceMappingURL=deploy.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../src/commands/deploy.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../src/commands/deploy.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAE1E,MAAM,CAAC,OAAO,OAAO,MAAO,SAAQ,yBAAyB;IAC3D,MAAM,CAAC,IAAI;;MAMT;IAEF,MAAM,CAAC,WAAW,SAGqF;IAEvG,MAAM,CAAC,QAAQ,WAIb;IAEI,UAAU,IAAI,OAAO,CAAC,GAAG,CAAC;CAgDjC"}
|
package/dist/commands/deploy.js
CHANGED
|
@@ -6,13 +6,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const core_1 = require("@oclif/core");
|
|
7
7
|
const errors_1 = require("@oclif/core/lib/errors");
|
|
8
8
|
const kleur_1 = __importDefault(require("kleur"));
|
|
9
|
-
const deploy_request_1 = require("../http/deploy-request");
|
|
10
9
|
const config_1 = require("../customer/config");
|
|
10
|
+
const get_connect_token_1 = require("../customer/get-connect-token");
|
|
11
11
|
const template_source_code_1 = require("../customer/template-source-code");
|
|
12
12
|
const ux_action_1 = require("../helpers/ux-action");
|
|
13
|
+
const deploy_request_1 = require("../http/deploy-request");
|
|
13
14
|
const render_tip_1 = require("../rendering/render-tip");
|
|
14
|
-
const
|
|
15
|
-
class Deploy extends
|
|
15
|
+
const refresh_connections_command_1 = require("./refresh-connections-command");
|
|
16
|
+
class Deploy extends refresh_connections_command_1.RefreshConnectionsCommand {
|
|
16
17
|
static args = {
|
|
17
18
|
env: core_1.Args.string({
|
|
18
19
|
options: ["development", "qa", "production", "demo"],
|
|
@@ -29,7 +30,7 @@ class Deploy extends core_1.Command {
|
|
|
29
30
|
"$ <%= config.bin %> deploy qa",
|
|
30
31
|
"$ <%= config.bin %> deploy production",
|
|
31
32
|
];
|
|
32
|
-
async
|
|
33
|
+
async runCommand() {
|
|
33
34
|
const { args } = await this.parse(Deploy);
|
|
34
35
|
const config = await (0, ux_action_1.uxAction)("📡 Reading your config", async () => {
|
|
35
36
|
return await (0, config_1.getRepositoryConfigFile)();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RefreshConnectionsCommand } from "./refresh-connections-command";
|
|
2
2
|
export declare const executePromptMessages: {
|
|
3
3
|
readonly template: "Select a template to execute";
|
|
4
4
|
readonly fixture: "Select a catalog fixture to run the template against";
|
|
@@ -15,7 +15,7 @@ interface ExecuteInputFlags {
|
|
|
15
15
|
"fixture-path"?: string;
|
|
16
16
|
"external-data-path"?: string;
|
|
17
17
|
}
|
|
18
|
-
export declare class Execute extends
|
|
18
|
+
export declare class Execute extends RefreshConnectionsCommand {
|
|
19
19
|
static flags: {
|
|
20
20
|
"template-path": import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
21
21
|
"fixture-path": import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
@@ -25,7 +25,7 @@ export declare class Execute extends Command {
|
|
|
25
25
|
static description: string;
|
|
26
26
|
static examples: string[];
|
|
27
27
|
input: ExecuteInputFlags;
|
|
28
|
-
|
|
28
|
+
runCommand(): Promise<void>;
|
|
29
29
|
/**
|
|
30
30
|
* Returns the template type, which is always equal to the folder name of the template path.
|
|
31
31
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../../src/commands/execute.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../../src/commands/execute.ts"],"names":[],"mappings":"AAgCA,OAAO,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAE1E,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,yBAAyB;IACpD,MAAM,CAAC,KAAK;;;;;MAgBV;IAEF,MAAM,CAAC,WAAW,SACkK;IAEpL,MAAM,CAAC,QAAQ,WAOb;IAEF,KAAK,EAAE,iBAAiB,CAAM;IAExB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAkCjC;;OAEG;IACH,OAAO,CAAC,eAAe;YAKT,UAAU;YAsBV,oBAAoB;YA+CpB,qBAAqB;YA0BrB,wBAAwB;CAevC"}
|
package/dist/commands/execute.js
CHANGED
|
@@ -7,28 +7,29 @@ exports.Execute = exports.executePromptMessages = void 0;
|
|
|
7
7
|
const os_1 = __importDefault(require("os"));
|
|
8
8
|
const core_1 = require("@oclif/core");
|
|
9
9
|
const errors_1 = require("@oclif/core/lib/errors");
|
|
10
|
+
const config_1 = require("../customer/config");
|
|
11
|
+
const path_1 = require("../customer/path");
|
|
12
|
+
const template_source_code_1 = require("../customer/template-source-code");
|
|
10
13
|
const file_loaders_1 = require("../helpers/file-loaders");
|
|
11
|
-
const
|
|
14
|
+
const print_warnings_1 = require("../helpers/print-warnings");
|
|
15
|
+
const ux_action_1 = require("../helpers/ux-action");
|
|
12
16
|
const get_connections_request_1 = require("../http/get-connections-request");
|
|
17
|
+
const send_template_execute_request_1 = require("../http/send-template-execute-request");
|
|
13
18
|
const filter_connections_by_template_1 = require("../prompt-data/filter-connections-by-template");
|
|
14
19
|
const get_candidate_fixtures_1 = require("../prompt-data/get-candidate-fixtures");
|
|
15
|
-
const get_template_files_1 = require("../prompt-data/get-template-files");
|
|
16
20
|
const get_external_data_files_1 = require("../prompt-data/get-external-data-files");
|
|
21
|
+
const get_template_files_1 = require("../prompt-data/get-template-files");
|
|
17
22
|
const render_prompt_1 = require("../prompt-data/render-prompt");
|
|
18
23
|
const render_repeat_input_1 = require("../rendering/render-repeat-input");
|
|
19
24
|
const render_template_result_1 = require("../rendering/render-template-result");
|
|
20
|
-
const
|
|
21
|
-
const config_1 = require("../customer/config");
|
|
22
|
-
const template_source_code_1 = require("../customer/template-source-code");
|
|
23
|
-
const ux_action_1 = require("../helpers/ux-action");
|
|
24
|
-
const print_warnings_1 = require("../helpers/print-warnings");
|
|
25
|
+
const refresh_connections_command_1 = require("./refresh-connections-command");
|
|
25
26
|
exports.executePromptMessages = {
|
|
26
27
|
template: "Select a template to execute",
|
|
27
28
|
fixture: "Select a catalog fixture to run the template against",
|
|
28
29
|
externalData: "Select external data to run the template against",
|
|
29
30
|
connection: "Select a connection to execute templates against",
|
|
30
31
|
};
|
|
31
|
-
class Execute extends
|
|
32
|
+
class Execute extends refresh_connections_command_1.RefreshConnectionsCommand {
|
|
32
33
|
static flags = {
|
|
33
34
|
"template-path": core_1.Flags.string({
|
|
34
35
|
description: "The path to the template to execute. Must be in the 'src/templates' directory.",
|
|
@@ -53,7 +54,7 @@ class Execute extends core_1.Command {
|
|
|
53
54
|
"$ <%= config.bin %> execute --template-path=mapping/mapping.jsonata",
|
|
54
55
|
];
|
|
55
56
|
input = {};
|
|
56
|
-
async
|
|
57
|
+
async runCommand() {
|
|
57
58
|
try {
|
|
58
59
|
const templateInput = await this.getTemplateExecInput();
|
|
59
60
|
const config = await (0, ux_action_1.uxAction)("📡 Reading your config", async () => {
|
|
@@ -71,7 +72,9 @@ class Execute extends core_1.Command {
|
|
|
71
72
|
});
|
|
72
73
|
(0, render_template_result_1.renderTemplateResult)(result);
|
|
73
74
|
if (result.warnings.length > 0) {
|
|
74
|
-
(0, print_warnings_1.printExecutionWarnings)(
|
|
75
|
+
(0, print_warnings_1.printExecutionWarnings)({
|
|
76
|
+
warnings: result.warnings,
|
|
77
|
+
});
|
|
75
78
|
}
|
|
76
79
|
if (!result?.success) {
|
|
77
80
|
this.exit(1);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default class GenerateFixture extends
|
|
1
|
+
import { RefreshConnectionsCommand } from "./refresh-connections-command";
|
|
2
|
+
export default class GenerateFixture extends RefreshConnectionsCommand {
|
|
3
3
|
static args: {};
|
|
4
4
|
static description: string;
|
|
5
5
|
static examples: string[];
|
|
6
|
-
|
|
6
|
+
runCommand(): Promise<any>;
|
|
7
7
|
getFixturePath(type: string, filename: string): string;
|
|
8
8
|
}
|
|
9
9
|
//# sourceMappingURL=generate-fixture.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-fixture.d.ts","sourceRoot":"","sources":["../../src/commands/generate-fixture.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"generate-fixture.d.ts","sourceRoot":"","sources":["../../src/commands/generate-fixture.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAE1E,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,yBAAyB;IACpE,MAAM,CAAC,IAAI,KAAM;IAEjB,MAAM,CAAC,WAAW,SAIhB;IAEF,MAAM,CAAC,QAAQ,WAA4C;IAErD,UAAU,IAAI,OAAO,CAAC,GAAG,CAAC;IAkDhC,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;CAU9C"}
|
|
@@ -4,18 +4,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const path_1 = __importDefault(require("path"));
|
|
7
|
+
const prompts_1 = require("@inquirer/prompts");
|
|
7
8
|
const core_1 = require("@oclif/core");
|
|
8
9
|
const fs_extra_1 = require("fs-extra");
|
|
9
|
-
const
|
|
10
|
+
const path_2 = require("../customer/path");
|
|
11
|
+
const file_exists_1 = require("../helpers/file-exists");
|
|
10
12
|
const ux_action_1 = require("../helpers/ux-action");
|
|
11
|
-
const render_tip_1 = require("../rendering/render-tip");
|
|
12
|
-
const render_prompt_1 = require("../prompt-data/render-prompt");
|
|
13
|
-
const types_1 = require("../types");
|
|
14
13
|
const get_fixture_1 = require("../http/get-fixture");
|
|
15
|
-
const
|
|
16
|
-
const path_2 = require("../customer/path");
|
|
14
|
+
const render_prompt_1 = require("../prompt-data/render-prompt");
|
|
17
15
|
const select_connections_1 = require("../prompt-data/select-connections");
|
|
18
|
-
|
|
16
|
+
const render_tip_1 = require("../rendering/render-tip");
|
|
17
|
+
const types_1 = require("../types");
|
|
18
|
+
const refresh_connections_command_1 = require("./refresh-connections-command");
|
|
19
|
+
class GenerateFixture extends refresh_connections_command_1.RefreshConnectionsCommand {
|
|
19
20
|
static args = {};
|
|
20
21
|
static description = `
|
|
21
22
|
This command will fetch one fixture from the server and save it into a specified file. This fixture file will be an example of how the data would be passed to the connector when executing the templates.\n
|
|
@@ -23,7 +24,7 @@ You are expected to customize this file to match the data you expect to cover in
|
|
|
23
24
|
Finally, if the file already exists you'll be prompted to overwrite it.
|
|
24
25
|
`;
|
|
25
26
|
static examples = ["$ <%= config.bin %> generate-fixture"];
|
|
26
|
-
async
|
|
27
|
+
async runCommand() {
|
|
27
28
|
const connectionId = await (0, select_connections_1.selectConnections)("Choose the connection to generate the fixture for");
|
|
28
29
|
const type = await (0, render_prompt_1.renderPrompt)({
|
|
29
30
|
promptMessage: "Choose the type of fixture you want to generate",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refresh-connections-command.d.ts","sourceRoot":"","sources":["../../src/commands/refresh-connections-command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAItC,8BAAsB,yBAA0B,SAAQ,OAAO;IAC7D,QAAQ,CAAC,UAAU,IAAI,OAAO,CAAC,GAAG,CAAC;IAE7B,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC;CAM1B"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RefreshConnectionsCommand = void 0;
|
|
4
|
+
const core_1 = require("@oclif/core");
|
|
5
|
+
const refresh_connections_list_1 = require("../helpers/refresh-connections-list");
|
|
6
|
+
class RefreshConnectionsCommand extends core_1.Command {
|
|
7
|
+
async run() {
|
|
8
|
+
if (!process.env.IS_CI && process.env.AUTO_REFRESH_CONNECTIONS) {
|
|
9
|
+
await (0, refresh_connections_list_1.refreshConnectionsList)();
|
|
10
|
+
}
|
|
11
|
+
return await this.runCommand();
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.RefreshConnectionsCommand = RefreshConnectionsCommand;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default class TriggerCatalogSync extends
|
|
1
|
+
import { RefreshConnectionsCommand } from "./refresh-connections-command";
|
|
2
|
+
export default class TriggerCatalogSync extends RefreshConnectionsCommand {
|
|
3
3
|
static args: {};
|
|
4
4
|
static description: string;
|
|
5
5
|
static examples: string[];
|
|
6
|
-
|
|
6
|
+
runCommand(): Promise<any>;
|
|
7
7
|
}
|
|
8
8
|
//# sourceMappingURL=trigger-catalog-sync.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trigger-catalog-sync.d.ts","sourceRoot":"","sources":["../../src/commands/trigger-catalog-sync.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"trigger-catalog-sync.d.ts","sourceRoot":"","sources":["../../src/commands/trigger-catalog-sync.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAE1E,MAAM,CAAC,OAAO,OAAO,kBAAmB,SAAQ,yBAAyB;IACvE,MAAM,CAAC,IAAI,KAAM;IAEjB,MAAM,CAAC,WAAW,SAGqF;IAEvG,MAAM,CAAC,QAAQ,WAA2B;IAEpC,UAAU,IAAI,OAAO,CAAC,GAAG,CAAC;CASjC"}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const core_1 = require("@oclif/core");
|
|
4
3
|
const trigger_catalog_sync_1 = require("../http/trigger-catalog-sync");
|
|
5
|
-
const render_tip_1 = require("../rendering/render-tip");
|
|
6
4
|
const select_connections_1 = require("../prompt-data/select-connections");
|
|
7
|
-
|
|
5
|
+
const render_tip_1 = require("../rendering/render-tip");
|
|
6
|
+
const refresh_connections_command_1 = require("./refresh-connections-command");
|
|
7
|
+
class TriggerCatalogSync extends refresh_connections_command_1.RefreshConnectionsCommand {
|
|
8
8
|
static args = {};
|
|
9
9
|
static description = `
|
|
10
10
|
Triggers a catalog sync for selected connection.
|
|
11
11
|
|
|
12
12
|
The script will use the \`CONNECT_AUTH_TOKEN\` environment variable to authenticate with Constructor.`;
|
|
13
13
|
static examples = ["$ <%= config.bin %>"];
|
|
14
|
-
async
|
|
14
|
+
async runCommand() {
|
|
15
15
|
const connectionId = await (0, select_connections_1.selectConnections)("Choose the connection to a trigger catalog sync");
|
|
16
16
|
await (0, trigger_catalog_sync_1.triggerCatalogSync)({ connectionId });
|
|
17
17
|
(0, render_tip_1.renderTip)(["🚀 Catalog sync triggered successfully!"]);
|
|
@@ -1,6 +1,19 @@
|
|
|
1
|
-
import { type Config } from "../types";
|
|
1
|
+
import { type Config, type ConnectionConfigDict } from "../types";
|
|
2
2
|
/**
|
|
3
|
-
* @returns The
|
|
3
|
+
* @returns The exported config from the connectrc.js file .
|
|
4
|
+
* @throws CLIError if the connectrc.js file is not found or contains a syntax error.
|
|
5
|
+
* @description This function attempts to load the connectrc.js file from the root directory of the repository.
|
|
6
|
+
* If the file is not found, it throws a CLIError with a message indicating the expected path.
|
|
4
7
|
*/
|
|
5
8
|
export declare function getRepositoryConfigFile(): Promise<Config>;
|
|
9
|
+
/**
|
|
10
|
+
* Reads the content of the connectrc.js file and returns the connections object and the content of the file
|
|
11
|
+
* @returns The connections object and the content of the connectrc.js file in {@link RawConfigContent}
|
|
12
|
+
*/
|
|
13
|
+
export declare function getRepositoryConnectionsAndConfig(): Promise<RawConfigContent>;
|
|
14
|
+
interface RawConfigContent {
|
|
15
|
+
fileContent: string;
|
|
16
|
+
existingConnections: ConnectionConfigDict;
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
6
19
|
//# sourceMappingURL=config.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/customer/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/customer/config.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAIlE;;;;;GAKG;AACH,wBAAsB,uBAAuB,IAAI,OAAO,CAAC,MAAM,CAAC,CAsC/D;AAED;;;GAGG;AACH,wBAAsB,iCAAiC,IAAI,OAAO,CAAC,gBAAgB,CAAC,CAyCnF;AA8HD,UAAU,gBAAgB;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,mBAAmB,EAAE,oBAAoB,CAAC;CAC3C"}
|
package/dist/customer/config.js
CHANGED
|
@@ -1,11 +1,50 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
36
|
exports.getRepositoryConfigFile = getRepositoryConfigFile;
|
|
4
|
-
|
|
37
|
+
exports.getRepositoryConnectionsAndConfig = getRepositoryConnectionsAndConfig;
|
|
38
|
+
const fs = __importStar(require("fs/promises"));
|
|
5
39
|
const core_1 = require("@oclif/core");
|
|
40
|
+
const errors_1 = require("@oclif/core/lib/errors");
|
|
41
|
+
const print_warnings_1 = require("../helpers/print-warnings");
|
|
6
42
|
const path_1 = require("./path");
|
|
7
43
|
/**
|
|
8
|
-
* @returns The
|
|
44
|
+
* @returns The exported config from the connectrc.js file .
|
|
45
|
+
* @throws CLIError if the connectrc.js file is not found or contains a syntax error.
|
|
46
|
+
* @description This function attempts to load the connectrc.js file from the root directory of the repository.
|
|
47
|
+
* If the file is not found, it throws a CLIError with a message indicating the expected path.
|
|
9
48
|
*/
|
|
10
49
|
async function getRepositoryConfigFile() {
|
|
11
50
|
const configPath = (0, path_1.getCustomerPath)("connectrc.js");
|
|
@@ -37,3 +76,156 @@ pointing to the correct connectrc.js directory.`,
|
|
|
37
76
|
});
|
|
38
77
|
}
|
|
39
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Reads the content of the connectrc.js file and returns the connections object and the content of the file
|
|
81
|
+
* @returns The connections object and the content of the connectrc.js file in {@link RawConfigContent}
|
|
82
|
+
*/
|
|
83
|
+
async function getRepositoryConnectionsAndConfig() {
|
|
84
|
+
const configPath = (0, path_1.getCustomerPath)("connectrc.js");
|
|
85
|
+
const fileContent = await readRawConfigFile(configPath);
|
|
86
|
+
// Get the connections object from the content of the connectrc.js file
|
|
87
|
+
const configMatch = fileContent.match(/const\s+connections\s*=\s*({[\s\S]*?});/);
|
|
88
|
+
if (isEmptyFileContent(fileContent, configPath) ||
|
|
89
|
+
!hasConfigMatch(configMatch) ||
|
|
90
|
+
!configMatch // just for configMatch[1] below since hasConfigMatch already checks for !configMatch
|
|
91
|
+
) {
|
|
92
|
+
return { fileContent: "", existingConnections: {} };
|
|
93
|
+
}
|
|
94
|
+
// Remove trailing commas from the connections object
|
|
95
|
+
const connectionsStr = configMatch[1].replace(/,(\s*[}\]])/g, "$1");
|
|
96
|
+
try {
|
|
97
|
+
return {
|
|
98
|
+
fileContent,
|
|
99
|
+
existingConnections: JSON.parse(connectionsStr),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
if (hasUnexpectedToken(error)) {
|
|
104
|
+
return handleUnexpectedTokenError(error, connectionsStr, fileContent);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
(0, print_warnings_1.printExecutionWarnings)({
|
|
108
|
+
warnings: [
|
|
109
|
+
{
|
|
110
|
+
type: "Config",
|
|
111
|
+
critical: true,
|
|
112
|
+
message: `Failed to parse the connections object in connectrc.js. Are you running a custom setup?`,
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
showDocsLink: false,
|
|
116
|
+
});
|
|
117
|
+
return { fileContent, existingConnections: {} };
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Reads the content of the connectrc.js file
|
|
123
|
+
* @param configPath The path to the connectrc.js file
|
|
124
|
+
* @returns The content of the connectrc.js file
|
|
125
|
+
*/
|
|
126
|
+
async function readRawConfigFile(configPath) {
|
|
127
|
+
try {
|
|
128
|
+
return await fs.readFile(configPath, "utf-8");
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
// If this function is called and "" is returned, it means that the file does not exist since
|
|
132
|
+
// connectrc.js is not supposed to be a blank file anyway
|
|
133
|
+
return "";
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Checks if the content of the connectrc.js file is empty
|
|
138
|
+
* @param fileContent The content of the connectrc.js file
|
|
139
|
+
* @param configPath The path to the connectrc.js file
|
|
140
|
+
* @returns true if the content of the connectrc.js file is empty
|
|
141
|
+
*/
|
|
142
|
+
function isEmptyFileContent(fileContent, configPath) {
|
|
143
|
+
if (!fileContent) {
|
|
144
|
+
(0, print_warnings_1.printExecutionWarnings)({
|
|
145
|
+
warnings: [
|
|
146
|
+
{
|
|
147
|
+
type: "Config",
|
|
148
|
+
critical: true,
|
|
149
|
+
message: `Could not find a connectrc.js file in the root directory!\nExpected to be at: ${configPath}`,
|
|
150
|
+
},
|
|
151
|
+
],
|
|
152
|
+
showDocsLink: false,
|
|
153
|
+
});
|
|
154
|
+
return true;
|
|
155
|
+
}
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Checks if the connections object is found in the connectrc.js file
|
|
160
|
+
* @param configMatch The result of matching the connections object in the connectrc.js file
|
|
161
|
+
* @returns true if the connections object is found in the connectrc.js file
|
|
162
|
+
*/
|
|
163
|
+
function hasConfigMatch(configMatch) {
|
|
164
|
+
if (!configMatch) {
|
|
165
|
+
(0, print_warnings_1.printExecutionWarnings)({
|
|
166
|
+
warnings: [
|
|
167
|
+
{
|
|
168
|
+
type: "Config",
|
|
169
|
+
critical: true,
|
|
170
|
+
message: "Could not find the `connections` variable in connectrc.js to keep your connections up to date. Are you running a custom setup?",
|
|
171
|
+
},
|
|
172
|
+
],
|
|
173
|
+
showDocsLink: false,
|
|
174
|
+
});
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Checks if the error is an unexpected token error
|
|
181
|
+
* @param error The error that is thrown when getting connections from connectrc.js
|
|
182
|
+
* @returns true if the error is an unexpected token error
|
|
183
|
+
*/
|
|
184
|
+
function hasUnexpectedToken(error) {
|
|
185
|
+
return (error instanceof SyntaxError &&
|
|
186
|
+
error.message.includes("Unexpected token") &&
|
|
187
|
+
error.message.includes("in JSON at position"));
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Checks if the connections object has properties without quotation marks, try to parse it with the properties in quotation marks
|
|
191
|
+
* and if it's the same, it means that there's something wrong with the connection name (perhaps a quotation mark in the name)
|
|
192
|
+
* @param _error The error that is thrown when getting connections from connectrc.js
|
|
193
|
+
* @param connectionsStr The connections object in connectrc.js
|
|
194
|
+
* @param fileContent The content of connectrc.js
|
|
195
|
+
* @returns The connections object and the content of connectrc.js
|
|
196
|
+
*/
|
|
197
|
+
function handleUnexpectedTokenError(_error, connectionsStr, fileContent) {
|
|
198
|
+
const QuotedConnectionStr = addQuotationMarksToProperties(connectionsStr);
|
|
199
|
+
if (connectionsStr !== QuotedConnectionStr) {
|
|
200
|
+
return {
|
|
201
|
+
fileContent,
|
|
202
|
+
existingConnections: JSON.parse(QuotedConnectionStr),
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
(0, print_warnings_1.printExecutionWarnings)({
|
|
207
|
+
warnings: [
|
|
208
|
+
{
|
|
209
|
+
type: "Config",
|
|
210
|
+
critical: true,
|
|
211
|
+
message: `Unable to parse the connections object. Please make sure that the config
|
|
212
|
+
file is defined as it was previously generated in the repo, as running custom setups to
|
|
213
|
+
map your connections isn't supported when automatically updating those.`,
|
|
214
|
+
},
|
|
215
|
+
],
|
|
216
|
+
showDocsLink: false,
|
|
217
|
+
});
|
|
218
|
+
return { fileContent, existingConnections: {} };
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Adds quotation marks to all properties in the {@link PartialConnection} make it JSON parsable
|
|
223
|
+
* @param connectionsStr The connections object in connectrc.js
|
|
224
|
+
* @returns The connections object with the specified properties in quotation marks
|
|
225
|
+
*/
|
|
226
|
+
function addQuotationMarksToProperties(connectionsStr) {
|
|
227
|
+
return connectionsStr.replace(/({\s*)([^{}]*)(\s*})/g, (_match, p1, p2, p3) => {
|
|
228
|
+
const updatedProperties = p2.replace(/(\w+):/g, '"$1":');
|
|
229
|
+
return `${p1}${updatedProperties}${p3}`;
|
|
230
|
+
});
|
|
231
|
+
}
|
|
@@ -5,14 +5,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.TYPE_OPTIONS = void 0;
|
|
7
7
|
exports.executeTemplate = executeTemplate;
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
8
|
const os_1 = __importDefault(require("os"));
|
|
10
|
-
const
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const config_1 = require("../customer/config");
|
|
11
11
|
const template_source_code_1 = require("../customer/template-source-code");
|
|
12
12
|
const file_loaders_1 = require("../helpers/file-loaders");
|
|
13
|
-
const config_1 = require("../customer/config");
|
|
14
|
-
const get_connections_request_1 = require("../http/get-connections-request");
|
|
15
13
|
const print_warnings_1 = require("../helpers/print-warnings");
|
|
14
|
+
const get_connections_request_1 = require("../http/get-connections-request");
|
|
15
|
+
const send_template_execute_request_1 = require("../http/send-template-execute-request");
|
|
16
16
|
exports.TYPE_OPTIONS = [
|
|
17
17
|
"item",
|
|
18
18
|
"variation",
|
|
@@ -49,7 +49,7 @@ async function executeTemplate(options) {
|
|
|
49
49
|
throw new Error(`Error executing template: ${result.error.message}`);
|
|
50
50
|
}
|
|
51
51
|
if (result.warnings.length > 0) {
|
|
52
|
-
(0, print_warnings_1.printExecutionWarnings)(result.warnings);
|
|
52
|
+
(0, print_warnings_1.printExecutionWarnings)({ warnings: result.warnings });
|
|
53
53
|
}
|
|
54
54
|
return result.data;
|
|
55
55
|
}
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import { type ConnectionResponseDto } from "../http/get-connections-request";
|
|
2
2
|
import { type Config, type ConnectionConfigDict } from "../types";
|
|
3
|
+
/**
|
|
4
|
+
* Builds the config object from the connections list.
|
|
5
|
+
* @param connections
|
|
6
|
+
* @param shouldCreateMappingTemplates
|
|
7
|
+
* @returns the config object
|
|
8
|
+
*/
|
|
3
9
|
export declare function buildConfigFromConnections(connections: ConnectionResponseDto[], shouldCreateMappingTemplates: boolean): Config;
|
|
10
|
+
/**
|
|
11
|
+
* Builds a dictionary of connections from array of connections sorted by environment and name.
|
|
12
|
+
* @param connections Array of connections
|
|
13
|
+
* @returns Dictionary of connections
|
|
14
|
+
*/
|
|
4
15
|
export declare function buildConnectionsDictFromList(connections: ConnectionResponseDto[]): ConnectionConfigDict;
|
|
5
16
|
export declare function buildConfigString(config: Config, connections: ConnectionConfigDict): string;
|
|
6
17
|
//# sourceMappingURL=build-config-file.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-config-file.d.ts","sourceRoot":"","sources":["../../src/helpers/build-config-file.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,KAAK,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAC7E,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,oBAAoB,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"build-config-file.d.ts","sourceRoot":"","sources":["../../src/helpers/build-config-file.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,KAAK,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAC7E,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAQlE;;;;;GAKG;AACH,wBAAgB,0BAA0B,CACxC,WAAW,EAAE,qBAAqB,EAAE,EACpC,4BAA4B,EAAE,OAAO,GACpC,MAAM,CAWR;AAED;;;;GAIG;AACH,wBAAgB,4BAA4B,CAC1C,WAAW,EAAE,qBAAqB,EAAE,GACnC,oBAAoB,CAiCtB;AAmDD,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,oBAAoB,GAChC,MAAM,CAmBR"}
|
|
@@ -14,6 +14,17 @@ exports.buildConfigString = buildConfigString;
|
|
|
14
14
|
* 4. Map each object in the environments array to expand out
|
|
15
15
|
*/
|
|
16
16
|
const path_1 = __importDefault(require("path"));
|
|
17
|
+
const environmentOrder = {
|
|
18
|
+
development: 1,
|
|
19
|
+
qa: 2,
|
|
20
|
+
production: 3,
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Builds the config object from the connections list.
|
|
24
|
+
* @param connections
|
|
25
|
+
* @param shouldCreateMappingTemplates
|
|
26
|
+
* @returns the config object
|
|
27
|
+
*/
|
|
17
28
|
function buildConfigFromConnections(connections, shouldCreateMappingTemplates) {
|
|
18
29
|
const environments = getUniqueConnectionEnvs(connections);
|
|
19
30
|
return {
|
|
@@ -21,15 +32,37 @@ function buildConfigFromConnections(connections, shouldCreateMappingTemplates) {
|
|
|
21
32
|
environments: buildTemplateEnvironments(environments, connections, shouldCreateMappingTemplates),
|
|
22
33
|
};
|
|
23
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Builds a dictionary of connections from array of connections sorted by environment and name.
|
|
37
|
+
* @param connections Array of connections
|
|
38
|
+
* @returns Dictionary of connections
|
|
39
|
+
*/
|
|
24
40
|
function buildConnectionsDictFromList(connections) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
41
|
+
const sortedConnections = connections
|
|
42
|
+
.filter((conn) => conn.name)
|
|
43
|
+
.sort((a, b) => {
|
|
44
|
+
// MAX_SAFE_INTEGER used just in case there are other environments not accounted for
|
|
45
|
+
const envOrderA = environmentOrder[a.environment] ?? Number.MAX_SAFE_INTEGER;
|
|
46
|
+
const envOrderB = environmentOrder[b.environment] ?? Number.MAX_SAFE_INTEGER;
|
|
47
|
+
return (
|
|
48
|
+
/**
|
|
49
|
+
* Sorts connections first by environment order, then by name.
|
|
50
|
+
*
|
|
51
|
+
* Example result:
|
|
52
|
+
*
|
|
53
|
+
* Dev A integration
|
|
54
|
+
* Dev B integration
|
|
55
|
+
* QA integration
|
|
56
|
+
* Prod integration
|
|
57
|
+
**/
|
|
58
|
+
envOrderA - envOrderB || a.name.localeCompare(b.name));
|
|
59
|
+
});
|
|
60
|
+
return sortedConnections.reduce((dict, conn) => {
|
|
61
|
+
dict[conn.name] = {
|
|
62
|
+
id: conn.id,
|
|
63
|
+
slug: conn.slug,
|
|
64
|
+
environment: conn.environment,
|
|
65
|
+
};
|
|
33
66
|
return dict;
|
|
34
67
|
}, {});
|
|
35
68
|
}
|
|
@@ -1,3 +1,12 @@
|
|
|
1
1
|
import { type TemplateValidatorWarning } from "../types";
|
|
2
|
-
export
|
|
2
|
+
export interface PrintExecutionWarningsArgs {
|
|
3
|
+
warnings: TemplateValidatorWarning[];
|
|
4
|
+
showDocsLink?: boolean;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Prints the warnings from the template execution, with a link to the documentation by default unless
|
|
8
|
+
* showDocsLink is set to false.
|
|
9
|
+
* @param {@link PrintExecutionWarningsArgs} args: The warnings to print and whether to show the documentation link (default true)
|
|
10
|
+
*/
|
|
11
|
+
export declare function printExecutionWarnings({ warnings, showDocsLink, }: PrintExecutionWarningsArgs): void;
|
|
3
12
|
//# sourceMappingURL=print-warnings.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"print-warnings.d.ts","sourceRoot":"","sources":["../../src/helpers/print-warnings.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,wBAAwB,EAAE,MAAM,UAAU,CAAC;AAEzD,wBAAgB,sBAAsB,CAAC,QAAQ,
|
|
1
|
+
{"version":3,"file":"print-warnings.d.ts","sourceRoot":"","sources":["../../src/helpers/print-warnings.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,wBAAwB,EAAE,MAAM,UAAU,CAAC;AAEzD,MAAM,WAAW,0BAA0B;IACzC,QAAQ,EAAE,wBAAwB,EAAE,CAAC;IACrC,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,EACrC,QAAQ,EACR,YAAmB,GACpB,EAAE,0BAA0B,QA+B5B"}
|
|
@@ -7,7 +7,12 @@ exports.printExecutionWarnings = printExecutionWarnings;
|
|
|
7
7
|
const core_1 = require("@oclif/core");
|
|
8
8
|
const kleur_1 = __importDefault(require("kleur"));
|
|
9
9
|
const terminal_link_1 = __importDefault(require("terminal-link"));
|
|
10
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Prints the warnings from the template execution, with a link to the documentation by default unless
|
|
12
|
+
* showDocsLink is set to false.
|
|
13
|
+
* @param {@link PrintExecutionWarningsArgs} args: The warnings to print and whether to show the documentation link (default true)
|
|
14
|
+
*/
|
|
15
|
+
function printExecutionWarnings({ warnings, showDocsLink = true, }) {
|
|
11
16
|
const originalLength = warnings.length;
|
|
12
17
|
if (warnings.length > 10) {
|
|
13
18
|
warnings = warnings.slice(0, 10);
|
|
@@ -22,7 +27,9 @@ function printExecutionWarnings(warnings) {
|
|
|
22
27
|
core_1.ux.log(`... and ${originalLength - 10} more`);
|
|
23
28
|
}
|
|
24
29
|
core_1.ux.log();
|
|
25
|
-
|
|
30
|
+
if (showDocsLink) {
|
|
31
|
+
core_1.ux.log(kleur_1.default.bold(`${(0, terminal_link_1.default)(kleur_1.default.bold("See documentation!"), `https://docs.constructor.com/docs/integrating-with-constructor-connect-cli-template-types-transformation-templates`)}`));
|
|
32
|
+
}
|
|
26
33
|
}
|
|
27
34
|
function printSingleWarning(warning) {
|
|
28
35
|
if (warning.critical) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refresh-connections-list.d.ts","sourceRoot":"","sources":["../../src/helpers/refresh-connections-list.ts"],"names":[],"mappings":"AAcA,wBAAsB,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC,CAY5D"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.refreshConnectionsList = refreshConnectionsList;
|
|
37
|
+
const fs = __importStar(require("fs/promises"));
|
|
38
|
+
const cli_ux_1 = require("@oclif/core/lib/cli-ux");
|
|
39
|
+
const config_1 = require("../customer/config");
|
|
40
|
+
const path_1 = require("../customer/path");
|
|
41
|
+
const get_connections_request_1 = require("../http/get-connections-request");
|
|
42
|
+
const render_prompt_1 = require("../prompt-data/render-prompt");
|
|
43
|
+
const build_config_file_1 = require("./build-config-file");
|
|
44
|
+
const should_update_connections_list_1 = require("./should-update-connections-list");
|
|
45
|
+
const ux_action_1 = require("./ux-action");
|
|
46
|
+
async function refreshConnectionsList() {
|
|
47
|
+
try {
|
|
48
|
+
const shouldUpdate = await checkConfigFileState();
|
|
49
|
+
if (!shouldUpdate) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
await updateConfigFile();
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
cli_ux_1.ux.log(`Error refreshing connections list: ${error.message}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async function fetchNewConnections() {
|
|
59
|
+
return (0, build_config_file_1.buildConnectionsDictFromList)(await (0, get_connections_request_1.getConnections)({
|
|
60
|
+
showLogs: false,
|
|
61
|
+
}));
|
|
62
|
+
}
|
|
63
|
+
async function promptForUpdate() {
|
|
64
|
+
return await (0, render_prompt_1.renderPrompt)({
|
|
65
|
+
promptMessage: "💡 Your connections in connectrc.js are out of date. Do you want to update it?",
|
|
66
|
+
choices: [
|
|
67
|
+
{ name: "Yes", value: true },
|
|
68
|
+
{ name: "No", value: false },
|
|
69
|
+
],
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
async function checkConfigFileState() {
|
|
73
|
+
const formattedConnections = await fetchNewConnections();
|
|
74
|
+
const { fileContent, existingConnections } = await (0, config_1.getRepositoryConnectionsAndConfig)();
|
|
75
|
+
if (!fileContent) {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
if (!(0, should_update_connections_list_1.shouldUpdateConnectionList)(existingConnections, formattedConnections)) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
const update = await promptForUpdate();
|
|
82
|
+
if (!update) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
async function updateConfigFile() {
|
|
88
|
+
const formattedConnections = await fetchNewConnections();
|
|
89
|
+
const rcPath = (0, path_1.getCustomerPath)("connectrc.js");
|
|
90
|
+
const { fileContent } = await (0, config_1.getRepositoryConnectionsAndConfig)();
|
|
91
|
+
if (!fileContent) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
await (0, ux_action_1.uxAction)("Updating connectrc.js", async () => {
|
|
95
|
+
const updatedContent = fileContent.replace(
|
|
96
|
+
// Match the connections object in connectrc.js
|
|
97
|
+
/const\s+connections\s*=\s*({[\s\S]*?});/,
|
|
98
|
+
// Replace the connections object with the new formatted connections
|
|
99
|
+
`const connections = ${JSON.stringify(formattedConnections, null, 2)};`);
|
|
100
|
+
await fs.writeFile(rcPath, updatedContent, "utf-8");
|
|
101
|
+
})();
|
|
102
|
+
cli_ux_1.ux.log("🎉 Successfully updated connections in connectrc.js");
|
|
103
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type ConnectionConfigDict } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* Checks if the connections in the config file are updated
|
|
4
|
+
* @param oldConnections
|
|
5
|
+
* @param newConnections
|
|
6
|
+
* @returns true if the two connections are equal (ie: connections in the config file are updated)
|
|
7
|
+
*/
|
|
8
|
+
export declare function shouldUpdateConnectionList(oldConnections: ConnectionConfigDict, newConnections: ConnectionConfigDict): boolean;
|
|
9
|
+
//# sourceMappingURL=should-update-connections-list.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"should-update-connections-list.d.ts","sourceRoot":"","sources":["../../src/helpers/should-update-connections-list.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,oBAAoB,EAA0B,MAAM,UAAU,CAAC;AAE7E;;;;;GAKG;AACH,wBAAgB,0BAA0B,CACxC,cAAc,EAAE,oBAAoB,EACpC,cAAc,EAAE,oBAAoB,GACnC,OAAO,CAoBT"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.shouldUpdateConnectionList = shouldUpdateConnectionList;
|
|
4
|
+
/**
|
|
5
|
+
* Checks if the connections in the config file are updated
|
|
6
|
+
* @param oldConnections
|
|
7
|
+
* @param newConnections
|
|
8
|
+
* @returns true if the two connections are equal (ie: connections in the config file are updated)
|
|
9
|
+
*/
|
|
10
|
+
function shouldUpdateConnectionList(oldConnections, newConnections) {
|
|
11
|
+
const oldConnectionNames = Object.keys(oldConnections);
|
|
12
|
+
const newConnectionNames = Object.keys(newConnections);
|
|
13
|
+
if (oldConnectionNames.length !== newConnectionNames.length) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
for (const name of oldConnectionNames) {
|
|
17
|
+
if (!newConnections[name]) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
if (!areConnectionPropertiesEqual(oldConnections, newConnections, name) ||
|
|
21
|
+
!areConnectionPropertiesEqual(newConnections, oldConnections, name)) {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Checks if the properties of connection A are present in connection B and whether they have the same values
|
|
29
|
+
* @param connectionsA
|
|
30
|
+
* @param connectionsB
|
|
31
|
+
* @param connectionName
|
|
32
|
+
* @returns true if the properties of connection A are present in connection B and have the same values
|
|
33
|
+
*/
|
|
34
|
+
function areConnectionPropertiesEqual(connectionsA, connectionsB, connectionName) {
|
|
35
|
+
for (const property in connectionsA[connectionName]) {
|
|
36
|
+
if (connectionsA[connectionName][property] !==
|
|
37
|
+
connectionsB[connectionName][property]) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return true;
|
|
42
|
+
}
|
package/dist/version.d.ts
CHANGED
package/dist/version.js
CHANGED
package/oclif.manifest.json
CHANGED
|
@@ -147,6 +147,25 @@
|
|
|
147
147
|
"init.js"
|
|
148
148
|
]
|
|
149
149
|
},
|
|
150
|
+
"refresh-connections-command": {
|
|
151
|
+
"aliases": [],
|
|
152
|
+
"args": {},
|
|
153
|
+
"flags": {},
|
|
154
|
+
"hasDynamicHelp": false,
|
|
155
|
+
"hiddenAliases": [],
|
|
156
|
+
"id": "refresh-connections-command",
|
|
157
|
+
"pluginAlias": "@constructor-io/constructorio-connect-cli",
|
|
158
|
+
"pluginName": "@constructor-io/constructorio-connect-cli",
|
|
159
|
+
"pluginType": "core",
|
|
160
|
+
"strict": true,
|
|
161
|
+
"enableJsonFlag": false,
|
|
162
|
+
"isESM": false,
|
|
163
|
+
"relativePath": [
|
|
164
|
+
"dist",
|
|
165
|
+
"commands",
|
|
166
|
+
"refresh-connections-command.js"
|
|
167
|
+
]
|
|
168
|
+
},
|
|
150
169
|
"trigger-catalog-sync": {
|
|
151
170
|
"aliases": [],
|
|
152
171
|
"args": {},
|
|
@@ -171,5 +190,5 @@
|
|
|
171
190
|
]
|
|
172
191
|
}
|
|
173
192
|
},
|
|
174
|
-
"version": "1.
|
|
193
|
+
"version": "1.12.0"
|
|
175
194
|
}
|
package/package.json
CHANGED