@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.
Files changed (108) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +184 -0
  3. package/bin/dev.cmd +3 -0
  4. package/bin/dev.js +16 -0
  5. package/bin/run.cmd +3 -0
  6. package/bin/run.js +10 -0
  7. package/boilerplate-repo/.env.example +1 -0
  8. package/boilerplate-repo/.eslintrc.json +11 -0
  9. package/boilerplate-repo/.vscode/extensions.json +5 -0
  10. package/boilerplate-repo/.vscode/launch.json +13 -0
  11. package/boilerplate-repo/.vscode/tasks.json +20 -0
  12. package/boilerplate-repo/LICENSE +21 -0
  13. package/boilerplate-repo/README.md +650 -0
  14. package/boilerplate-repo/connectrc.js +7 -0
  15. package/boilerplate-repo/package.json +21 -0
  16. package/boilerplate-repo/src/fixtures/item/item.json +39 -0
  17. package/boilerplate-repo/src/fixtures/item_group/item_group.json +22 -0
  18. package/boilerplate-repo/src/fixtures/mapping/mapping.json +26 -0
  19. package/boilerplate-repo/src/fixtures/variation/variation.json +11 -0
  20. package/boilerplate-repo/src/templates/grouping/grouping.jsonata +37 -0
  21. package/boilerplate-repo/src/templates/helpers.jsonata +3 -0
  22. package/boilerplate-repo/src/templates/item/item.jsonata +26 -0
  23. package/boilerplate-repo/src/templates/item_group/item_group.jsonata +4 -0
  24. package/boilerplate-repo/src/templates/mapping/mapping.jsonata +34 -0
  25. package/boilerplate-repo/src/templates/variation/variation.jsonata +26 -0
  26. package/dist/commands/deploy.d.ts +10 -0
  27. package/dist/commands/deploy.d.ts.map +1 -0
  28. package/dist/commands/deploy.js +64 -0
  29. package/dist/commands/execute.d.ts +35 -0
  30. package/dist/commands/execute.d.ts.map +1 -0
  31. package/dist/commands/execute.js +145 -0
  32. package/dist/commands/init.d.ts +18 -0
  33. package/dist/commands/init.d.ts.map +1 -0
  34. package/dist/commands/init.js +172 -0
  35. package/dist/customer/config.d.ts +6 -0
  36. package/dist/customer/config.d.ts.map +1 -0
  37. package/dist/customer/config.js +40 -0
  38. package/dist/customer/get-connect-token.d.ts +15 -0
  39. package/dist/customer/get-connect-token.d.ts.map +1 -0
  40. package/dist/customer/get-connect-token.js +69 -0
  41. package/dist/customer/path.d.ts +26 -0
  42. package/dist/customer/path.d.ts.map +1 -0
  43. package/dist/customer/path.js +48 -0
  44. package/dist/customer/template-source-code.d.ts +12 -0
  45. package/dist/customer/template-source-code.d.ts.map +1 -0
  46. package/dist/customer/template-source-code.js +42 -0
  47. package/dist/helpers/build-config-file.d.ts +13 -0
  48. package/dist/helpers/build-config-file.d.ts.map +1 -0
  49. package/dist/helpers/build-config-file.js +62 -0
  50. package/dist/helpers/file-loaders.d.ts +19 -0
  51. package/dist/helpers/file-loaders.d.ts.map +1 -0
  52. package/dist/helpers/file-loaders.js +45 -0
  53. package/dist/helpers/find-deep-files.d.ts +7 -0
  54. package/dist/helpers/find-deep-files.d.ts.map +1 -0
  55. package/dist/helpers/find-deep-files.js +27 -0
  56. package/dist/helpers/generate-command-input.d.ts +19 -0
  57. package/dist/helpers/generate-command-input.d.ts.map +1 -0
  58. package/dist/helpers/generate-command-input.js +51 -0
  59. package/dist/helpers/is-git-repo-initialized.d.ts +5 -0
  60. package/dist/helpers/is-git-repo-initialized.d.ts.map +1 -0
  61. package/dist/helpers/is-git-repo-initialized.js +24 -0
  62. package/dist/helpers/ux-action.d.ts +2 -0
  63. package/dist/helpers/ux-action.d.ts.map +1 -0
  64. package/dist/helpers/ux-action.js +31 -0
  65. package/dist/http/deploy-request.d.ts +16 -0
  66. package/dist/http/deploy-request.d.ts.map +1 -0
  67. package/dist/http/deploy-request.js +45 -0
  68. package/dist/http/execute-templates-request.d.ts +10 -0
  69. package/dist/http/execute-templates-request.d.ts.map +1 -0
  70. package/dist/http/execute-templates-request.js +28 -0
  71. package/dist/http/get-connections-request.d.ts +18 -0
  72. package/dist/http/get-connections-request.d.ts.map +1 -0
  73. package/dist/http/get-connections-request.js +24 -0
  74. package/dist/http/http-client.d.ts +6 -0
  75. package/dist/http/http-client.d.ts.map +1 -0
  76. package/dist/http/http-client.js +57 -0
  77. package/dist/index.d.ts +2 -0
  78. package/dist/index.d.ts.map +1 -0
  79. package/dist/index.js +5 -0
  80. package/dist/prompt-data/filter-connections-by-template.d.ts +4 -0
  81. package/dist/prompt-data/filter-connections-by-template.d.ts.map +1 -0
  82. package/dist/prompt-data/filter-connections-by-template.js +30 -0
  83. package/dist/prompt-data/get-candidate-fixtures.d.ts +3 -0
  84. package/dist/prompt-data/get-candidate-fixtures.d.ts.map +1 -0
  85. package/dist/prompt-data/get-candidate-fixtures.js +49 -0
  86. package/dist/prompt-data/get-external-data-files.d.ts +3 -0
  87. package/dist/prompt-data/get-external-data-files.d.ts.map +1 -0
  88. package/dist/prompt-data/get-external-data-files.js +28 -0
  89. package/dist/prompt-data/get-template-files.d.ts +7 -0
  90. package/dist/prompt-data/get-template-files.d.ts.map +1 -0
  91. package/dist/prompt-data/get-template-files.js +50 -0
  92. package/dist/prompt-data/render-prompt.d.ts +9 -0
  93. package/dist/prompt-data/render-prompt.d.ts.map +1 -0
  94. package/dist/prompt-data/render-prompt.js +16 -0
  95. package/dist/rendering/render-repeat-input.d.ts +14 -0
  96. package/dist/rendering/render-repeat-input.d.ts.map +1 -0
  97. package/dist/rendering/render-repeat-input.js +25 -0
  98. package/dist/rendering/render-template-result.d.ts +2 -0
  99. package/dist/rendering/render-template-result.d.ts.map +1 -0
  100. package/dist/rendering/render-template-result.js +60 -0
  101. package/dist/rendering/render-tip.d.ts +6 -0
  102. package/dist/rendering/render-tip.d.ts.map +1 -0
  103. package/dist/rendering/render-tip.js +22 -0
  104. package/dist/types.d.ts +40 -0
  105. package/dist/types.d.ts.map +1 -0
  106. package/dist/types.js +2 -0
  107. package/oclif.manifest.json +129 -0
  108. package/package.json +98 -0
@@ -0,0 +1,172 @@
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 (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const path = __importStar(require("path"));
30
+ const child_process_1 = require("child_process");
31
+ const prompts_1 = require("@inquirer/prompts");
32
+ const fs_extra_1 = __importDefault(require("fs-extra"));
33
+ const replace_in_file_1 = __importDefault(require("replace-in-file"));
34
+ const core_1 = require("@oclif/core");
35
+ const kleur_1 = __importDefault(require("kleur"));
36
+ const get_connections_request_1 = require("../http/get-connections-request");
37
+ const build_config_file_1 = require("../helpers/build-config-file");
38
+ const ux_action_1 = require("../helpers/ux-action");
39
+ const get_connect_token_1 = require("../customer/get-connect-token");
40
+ const render_tip_1 = require("../rendering/render-tip");
41
+ const is_git_repo_initialized_1 = require("../helpers/is-git-repo-initialized");
42
+ const BOILERPLATE_REPO_PATH = "../../boilerplate-repo";
43
+ class Init extends core_1.Command {
44
+ static description = "Bootstrap a new Constructor.io Connect CLI repository.";
45
+ static examples = [
46
+ "<%= config.bin %> <%= command.id %>",
47
+ "<%= config.bin %> <%= command.id %> new-repo-name",
48
+ ];
49
+ static args = {
50
+ name: core_1.Args.string({
51
+ description: "name of the new folder",
52
+ required: true,
53
+ }),
54
+ };
55
+ async run() {
56
+ const { args } = await this.parse(Init);
57
+ const repoPath = path.join(process.cwd(), args.name);
58
+ core_1.ux.info([
59
+ `👋 Welcome to the ${kleur_1.default.bold("Constructor.io Connect CLI")}!\n`,
60
+ "Working with this CLI requires a Constructor Connect Auth Token. This is not the same as your Constructor API Token.",
61
+ `If you don't have one yet, please reach out over at partners@constructor.io.`,
62
+ ].join("\n"));
63
+ const connectAuthToken = await (0, get_connect_token_1.getConnectToken)(false);
64
+ const newDirExists = fs_extra_1.default.existsSync(repoPath);
65
+ if (!newDirExists) {
66
+ await this.createRepo({
67
+ repoName: args.name,
68
+ connectAuthToken,
69
+ repoPath,
70
+ });
71
+ }
72
+ else {
73
+ await this.updateRepo({
74
+ repoName: args.name,
75
+ connectAuthToken,
76
+ repoPath,
77
+ });
78
+ }
79
+ }
80
+ async createRepo(args) {
81
+ await this.generateRepositoryFiles(args);
82
+ fs_extra_1.default.appendFileSync(path.join(args.repoPath, ".env"), `CONNECT_AUTH_TOKEN=${args.connectAuthToken}\n`);
83
+ if (!(0, is_git_repo_initialized_1.isGitRepoInitialized)()) {
84
+ this.initGitRepoAndCommit(args);
85
+ }
86
+ else {
87
+ core_1.ux.log(`\n💡 Git repository already exists at this path, skipping initialization.`);
88
+ }
89
+ this.printSuccessfulInitMessage(args.repoName);
90
+ }
91
+ initGitRepoAndCommit(args) {
92
+ (0, child_process_1.execSync)(`git init ${args.repoPath} --initial-branch=main`);
93
+ (0, ux_action_1.uxAction)("🏁 Finishing installation", () => {
94
+ (0, child_process_1.execSync)(`(cd ${args.repoPath} && git add . && git commit -m "Initialize new Constructor.io Connect CLI repository")`);
95
+ })();
96
+ }
97
+ async updateRepo(args) {
98
+ core_1.ux.log(`\nYou are trying to initialize a new repo that already exists.`);
99
+ const shouldRefresh = await (0, prompts_1.confirm)({
100
+ message: "Do you want to regenerate the base repository files?",
101
+ });
102
+ if (shouldRefresh) {
103
+ await this.generateRepositoryFiles(args);
104
+ this.printSuccessfulInitMessage(args.repoName);
105
+ return;
106
+ }
107
+ core_1.ux.log(`\n🙅 Constructor.io Connect CLI repository not updated! 🙅
108
+ `);
109
+ }
110
+ async generateRepositoryFiles(args) {
111
+ core_1.ux.log("\n");
112
+ const connections = await (0, get_connections_request_1.getConnectionsForCompany)();
113
+ const connectionsDict = (0, build_config_file_1.buildConnectionsDictFromList)(connections);
114
+ const config = (0, build_config_file_1.buildConfigFromConnections)(connections);
115
+ (0, ux_action_1.uxAction)("🚀 Creating new Constructor.io Connect CLI repository", () => {
116
+ Init.createNewRepository(args.repoPath);
117
+ Init.replacePackageName(args.repoName, args.repoPath);
118
+ })();
119
+ (0, ux_action_1.uxAction)("📦 Installing dependencies", () => {
120
+ (0, child_process_1.execSync)(`(cd ${args.repoPath} && npm install)`);
121
+ })();
122
+ Init.replaceConfigValues(config, connectionsDict, args.repoPath);
123
+ }
124
+ static createNewRepository(newDir) {
125
+ const repoDir = path.join(__dirname, BOILERPLATE_REPO_PATH);
126
+ fs_extra_1.default.copySync(repoDir, newDir);
127
+ }
128
+ static replacePackageName(name, repoPath) {
129
+ const packageJsonPath = path.join(repoPath, "package.json");
130
+ replace_in_file_1.default.sync({
131
+ files: packageJsonPath,
132
+ from: "{{REPLACE_REPO_NAME}}",
133
+ to: name,
134
+ });
135
+ }
136
+ static replaceConfigValues(config, connections, repoPath) {
137
+ replace_in_file_1.default.replaceInFileSync({
138
+ files: path.join(repoPath, "connectrc.js"),
139
+ from: '"{{REPLACE_CONFIG}}"',
140
+ to: (0, build_config_file_1.buildConfigString)(config, connections),
141
+ });
142
+ replace_in_file_1.default.replaceInFileSync({
143
+ files: path.join(repoPath, "connectrc.js"),
144
+ from: '"{{REPLACE_CONNECTIONS}}"',
145
+ to: JSON.stringify(connections, null, 2),
146
+ });
147
+ // Run `lint:fix` to ensure the generated files are properly linted & formatted
148
+ (0, child_process_1.execSync)(`(cd ${repoPath} && npm run lint:fix)`);
149
+ }
150
+ printSuccessfulInitMessage(repoName) {
151
+ core_1.ux.log(kleur_1.default.bold([
152
+ "\n",
153
+ `🎉 Constructor.io Connect CLI repository initialized at ./${repoName}! 🎉`,
154
+ `\n`,
155
+ ].join("")));
156
+ (0, render_tip_1.renderTip)([
157
+ `You can already execute templates using the ${kleur_1.default.bold("execute")} command.`,
158
+ "The repo ships with some example templates and fixtures already mapped to your connections.",
159
+ "You can execute those templates to see the result data and modify them to your needs.",
160
+ ]);
161
+ (0, render_tip_1.renderTip)([
162
+ `If you don't intend to use a certain template (e.g. ${kleur_1.default.bold("item_groups.jsonata")}),`,
163
+ `you can just delete the file and remove the mention from ${kleur_1.default.bold("connectrc.js")}.`,
164
+ ]);
165
+ (0, render_tip_1.renderTip)([
166
+ `Check out the ${kleur_1.default.bold("README")} in the new repository for more information on how to get started`,
167
+ "with developing templates for the Constructor Connect platform.",
168
+ `Link: ${repoName}/README.md`,
169
+ ]);
170
+ }
171
+ }
172
+ exports.default = Init;
@@ -0,0 +1,6 @@
1
+ import { type Config } from "../types";
2
+ /**
3
+ * @returns The parsed connectrc.js file.
4
+ */
5
+ export declare function getRepositoryConfigFile(): Promise<Config>;
6
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/customer/config.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,UAAU,CAAC;AAIvC;;GAEG;AACH,wBAAsB,uBAAuB,IAAI,OAAO,CAAC,MAAM,CAAC,CAuC/D"}
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRepositoryConfigFile = void 0;
4
+ const errors_1 = require("@oclif/core/lib/errors");
5
+ const core_1 = require("@oclif/core");
6
+ const path_1 = require("./path");
7
+ /**
8
+ * @returns The parsed connectrc.js file.
9
+ */
10
+ async function getRepositoryConfigFile() {
11
+ const configPath = (0, path_1.getCustomerPath)("connectrc.js");
12
+ try {
13
+ return require(configPath);
14
+ }
15
+ catch (error) {
16
+ // To get ux.warn to render properly, we need to stop the action first
17
+ core_1.ux.action.stop("💥");
18
+ if (error.code === "MODULE_NOT_FOUND") {
19
+ throw new errors_1.CLIError(`💥 Could not find a connectrc.js file in the root directory!\nExpected to be at: ${configPath}`, {
20
+ code: error.code,
21
+ suggestions: [
22
+ "Make sure you have a connectrc.js file in the root directory of your repository.",
23
+ `If your root directory is not the same as your current working directory,
24
+ you can set the \`REPOSITORY_ROOT_DIRECTORY\` environment variable as a relative path
25
+ pointing to the correct connectrc.js directory.`,
26
+ ],
27
+ });
28
+ }
29
+ core_1.ux.warn(error.stack);
30
+ if (error.name?.includes("SyntaxError")) {
31
+ throw new errors_1.CLIError("💥 Syntax error found in your connectrc.js file!", {
32
+ code: "SYNTAX_ERROR",
33
+ });
34
+ }
35
+ throw new errors_1.CLIError("💥 Could not load your connectrc.js file! \nTake a look at the original error printed above.", {
36
+ code: error.code,
37
+ });
38
+ }
39
+ }
40
+ exports.getRepositoryConfigFile = getRepositoryConfigFile;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Gets the Connect Auth token that should be used for the API requests to the Connect API.
3
+ * First attempts to read from the environment variable CONNECT_AUTH_TOKEN. If it is not present
4
+ * it will prompt the user for the token instead. If `canSave` is true, it will also prompt the user
5
+ * if they want to save the token to the .env file.
6
+ *
7
+ * @param canSave Whether this is being called from a state where a token
8
+ * received by prompt can be saved to the .env file. For example, when running during
9
+ * the init command the repository does not yet exist and so there is nowhere to save the
10
+ * token when this function runs.
11
+ * @returns The connect auth token that should be used for the API requests.
12
+ */
13
+ export declare function getConnectTokenStore(): (canSave?: boolean) => Promise<string>;
14
+ export declare const getConnectToken: (canSave?: boolean) => Promise<string>;
15
+ //# sourceMappingURL=get-connect-token.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-connect-token.d.ts","sourceRoot":"","sources":["../../src/customer/get-connect-token.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,eAIvB,OAAO,KACf,QAAQ,MAAM,CAAC,CA2BnB;AAED,eAAO,MAAM,eAAe,aA9Bf,OAAO,KACf,QAAQ,MAAM,CA6BkC,CAAC"}
@@ -0,0 +1,69 @@
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 (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.getConnectToken = exports.getConnectTokenStore = void 0;
27
+ const fs = __importStar(require("fs-extra"));
28
+ const prompts_1 = require("@inquirer/prompts");
29
+ const core_1 = require("@oclif/core");
30
+ /**
31
+ * Gets the Connect Auth token that should be used for the API requests to the Connect API.
32
+ * First attempts to read from the environment variable CONNECT_AUTH_TOKEN. If it is not present
33
+ * it will prompt the user for the token instead. If `canSave` is true, it will also prompt the user
34
+ * if they want to save the token to the .env file.
35
+ *
36
+ * @param canSave Whether this is being called from a state where a token
37
+ * received by prompt can be saved to the .env file. For example, when running during
38
+ * the init command the repository does not yet exist and so there is nowhere to save the
39
+ * token when this function runs.
40
+ * @returns The connect auth token that should be used for the API requests.
41
+ */
42
+ function getConnectTokenStore() {
43
+ let connectToken;
44
+ return async function getConnectToken(canSave = true) {
45
+ if (!connectToken) {
46
+ if (!process.env.CONNECT_AUTH_TOKEN) {
47
+ core_1.ux.log();
48
+ connectToken = await core_1.ux.prompt("Enter your Connect Auth token 🔐", {
49
+ type: "mask",
50
+ });
51
+ if (canSave) {
52
+ const saveToken = await (0, prompts_1.confirm)({
53
+ message: "💾 Do you want to save this token in your .env for future use?",
54
+ });
55
+ if (saveToken) {
56
+ fs.appendFileSync(".env", `CONNECT_AUTH_TOKEN=${connectToken}\n`);
57
+ }
58
+ core_1.ux.log();
59
+ }
60
+ }
61
+ else {
62
+ connectToken = process.env.CONNECT_AUTH_TOKEN;
63
+ }
64
+ }
65
+ return connectToken;
66
+ };
67
+ }
68
+ exports.getConnectTokenStore = getConnectTokenStore;
69
+ exports.getConnectToken = getConnectTokenStore();
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @returns The provided path prepended with the root directory.
3
+ */
4
+ export declare function getCustomerPath(path: string): string;
5
+ /**
6
+ * Cleans up the template path, removing the root directory and the 'src/templates' prefix.
7
+ *
8
+ * This is needed to support the use of absolute paths in the templates, since those will
9
+ * be added later on when reading the files.
10
+ */
11
+ export declare function cleanupTemplatePath(path: string | undefined): string;
12
+ /**
13
+ * Cleans up the fixture path, removing the root directory and the 'src/fixtures' prefix.
14
+ *
15
+ * This is needed to support the use of absolute paths in the templates, since those will
16
+ * be added later on when reading the files.
17
+ */
18
+ export declare function cleanupFixturePath(path: string | undefined): string;
19
+ /**
20
+ * Cleans up the external data path, removing the root directory and the 'src/external-data' prefix.
21
+ *
22
+ * This is needed to support the use of absolute paths in the templates, since those will
23
+ * be added later on when reading the files.
24
+ */
25
+ export declare function cleanupExternalDataPath(path: string | undefined): string;
26
+ //# sourceMappingURL=path.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../../src/customer/path.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,UAE3C;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,UAE3D;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,UAE1D;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,UAE/D"}
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cleanupExternalDataPath = exports.cleanupFixturePath = exports.cleanupTemplatePath = exports.getCustomerPath = void 0;
4
+ /* eslint-disable @typescript-eslint/prefer-nullish-coalescing */
5
+ const path_1 = require("path");
6
+ /**
7
+ * @returns The provided path prepended with the root directory.
8
+ */
9
+ function getCustomerPath(path) {
10
+ return (0, path_1.join)(process.cwd(), process.env.REPOSITORY_ROOT_DIRECTORY || "", path);
11
+ }
12
+ exports.getCustomerPath = getCustomerPath;
13
+ /**
14
+ * Cleans up the template path, removing the root directory and the 'src/templates' prefix.
15
+ *
16
+ * This is needed to support the use of absolute paths in the templates, since those will
17
+ * be added later on when reading the files.
18
+ */
19
+ function cleanupTemplatePath(path) {
20
+ return cleanupAbsolutePath(path).replace("/src/templates/", "");
21
+ }
22
+ exports.cleanupTemplatePath = cleanupTemplatePath;
23
+ /**
24
+ * Cleans up the fixture path, removing the root directory and the 'src/fixtures' prefix.
25
+ *
26
+ * This is needed to support the use of absolute paths in the templates, since those will
27
+ * be added later on when reading the files.
28
+ */
29
+ function cleanupFixturePath(path) {
30
+ return cleanupAbsolutePath(path).replace("/src/fixtures/", "");
31
+ }
32
+ exports.cleanupFixturePath = cleanupFixturePath;
33
+ /**
34
+ * Cleans up the external data path, removing the root directory and the 'src/external-data' prefix.
35
+ *
36
+ * This is needed to support the use of absolute paths in the templates, since those will
37
+ * be added later on when reading the files.
38
+ */
39
+ function cleanupExternalDataPath(path) {
40
+ return cleanupAbsolutePath(path).replace("/src/external-data/", "");
41
+ }
42
+ exports.cleanupExternalDataPath = cleanupExternalDataPath;
43
+ function cleanupAbsolutePath(path) {
44
+ if (!path) {
45
+ return "";
46
+ }
47
+ return path.replace(process.cwd(), "");
48
+ }
@@ -0,0 +1,12 @@
1
+ import { type Config } from "../types";
2
+ /**
3
+ * Replaces the paths of the templates with their source code.
4
+ */
5
+ export declare function getTemplatesSourceCode(templates: Config["environments"][number]["templates"]): TemplateWithSourceCode;
6
+ export declare function getHelpersSourceCode(helpers: Config["helpers"]): Promise<string | undefined>;
7
+ type TemplateWithSourceCode = Promise<Array<{
8
+ connectionIds: string[];
9
+ sourceCode: Record<string, string | undefined>;
10
+ }>>;
11
+ export {};
12
+ //# sourceMappingURL=template-source-code.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"template-source-code.d.ts","sourceRoot":"","sources":["../../src/customer/template-source-code.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,UAAU,CAAC;AAqBvC;;GAEG;AACH,wBAAsB,sBAAsB,CAC1C,SAAS,EAAE,MAAM,CAAC,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC,WAAW,CAAC,GACrD,sBAAsB,CAexB;AAED,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,MAAM,CAAC,SAAS,CAAC,GACzB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAE7B;AAED,KAAK,sBAAsB,GAAG,OAAO,CACnC,KAAK,CAAC;IACJ,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;CAChD,CAAC,CACH,CAAC"}
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getHelpersSourceCode = exports.getTemplatesSourceCode = void 0;
4
+ const promises_1 = require("fs/promises");
5
+ const errors_1 = require("@oclif/core/lib/errors");
6
+ const path_1 = require("./path");
7
+ /**
8
+ * Loads the source code of a template from the file system.
9
+ */
10
+ async function loadSourceCode(path) {
11
+ if (!path) {
12
+ return undefined;
13
+ }
14
+ try {
15
+ return await (0, promises_1.readFile)((0, path_1.getCustomerPath)(path), "utf-8");
16
+ }
17
+ catch (error) {
18
+ throw new errors_1.CLIError(`Could not load "${path}" file. Please check your connectrc.js file.`);
19
+ }
20
+ }
21
+ /**
22
+ * Replaces the paths of the templates with their source code.
23
+ */
24
+ async function getTemplatesSourceCode(templates) {
25
+ return await Promise.all(templates.map(async ({ connection_ids: connectionIds, paths }) => {
26
+ return {
27
+ connectionIds,
28
+ sourceCode: {
29
+ item: await loadSourceCode(paths.item),
30
+ variation: await loadSourceCode(paths.variation),
31
+ item_group: await loadSourceCode(paths.item_group),
32
+ grouping: await loadSourceCode(paths.grouping),
33
+ mapping: await loadSourceCode(paths.mapping),
34
+ },
35
+ };
36
+ }));
37
+ }
38
+ exports.getTemplatesSourceCode = getTemplatesSourceCode;
39
+ async function getHelpersSourceCode(helpers) {
40
+ return await loadSourceCode(helpers);
41
+ }
42
+ exports.getHelpersSourceCode = getHelpersSourceCode;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * 1. Receive connections list, and transform it into the connections dictionary.
3
+ * - Store only connectionId, name, and slug.
4
+ * 2. Create the config object from a default config.
5
+ * 3. Create a connections environments array by making a filtered array of connections for each environment.
6
+ * 4. Map each object in the environments array to expand out
7
+ */
8
+ import { type ConnectionResponseDto } from "../http/get-connections-request";
9
+ import { type Config, type ConnectionConfigDict } from "../types";
10
+ export declare function buildConfigFromConnections(connections: ConnectionResponseDto[]): Config;
11
+ export declare function buildConnectionsDictFromList(connections: ConnectionResponseDto[]): ConnectionConfigDict;
12
+ export declare function buildConfigString(config: Config, connections: ConnectionConfigDict): string;
13
+ //# sourceMappingURL=build-config-file.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-config-file.d.ts","sourceRoot":"","sources":["../../src/helpers/build-config-file.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,KAAK,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAC7E,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAElE,wBAAgB,0BAA0B,CACxC,WAAW,EAAE,qBAAqB,EAAE,GACnC,MAAM,CAQR;AAED,wBAAgB,4BAA4B,CAC1C,WAAW,EAAE,qBAAqB,EAAE,wBAYrC;AAkCD,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,oBAAoB,GAChC,MAAM,CAUR"}
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildConfigString = exports.buildConnectionsDictFromList = exports.buildConfigFromConnections = void 0;
4
+ function buildConfigFromConnections(connections) {
5
+ const environments = getUniqueConnectionEnvs(connections);
6
+ return {
7
+ template_repository_version: "1.0.0",
8
+ helpers: "src/templates/helpers.jsonata",
9
+ environments: buildTemplateEnvironments(environments, connections),
10
+ };
11
+ }
12
+ exports.buildConfigFromConnections = buildConfigFromConnections;
13
+ function buildConnectionsDictFromList(connections) {
14
+ return connections.reduce((dict, conn) => {
15
+ if (conn.name) {
16
+ dict[conn.name] = {
17
+ id: conn.id,
18
+ slug: conn.slug,
19
+ environment: conn.environment,
20
+ };
21
+ }
22
+ return dict;
23
+ }, {});
24
+ }
25
+ exports.buildConnectionsDictFromList = buildConnectionsDictFromList;
26
+ function getUniqueConnectionEnvs(connections) {
27
+ return connections.reduce((envs, conn) => {
28
+ if (!envs.includes(conn.environment))
29
+ envs.push(conn.environment);
30
+ return envs;
31
+ }, []);
32
+ }
33
+ function buildTemplateEnvironments(environments, connections) {
34
+ return environments.map((env) => {
35
+ return {
36
+ environment: env,
37
+ templates: [
38
+ {
39
+ connection_ids: connections
40
+ .filter((conn) => conn.environment === env)
41
+ .map((conn) => conn.id),
42
+ paths: {
43
+ item: "src/templates/item/item.jsonata",
44
+ variation: "src/templates/variation/variation.jsonata",
45
+ item_group: "src/templates/item_group/item_group.jsonata",
46
+ grouping: "src/templates/grouping/grouping.jsonata",
47
+ mapping: "src/templates/mapping/mapping.jsonata",
48
+ },
49
+ },
50
+ ],
51
+ };
52
+ });
53
+ }
54
+ function buildConfigString(config, connections) {
55
+ let configString = JSON.stringify(config, null, 2);
56
+ for (const connectionName in connections) {
57
+ const conn = connections[connectionName];
58
+ configString = configString.replace(`"${conn.id}"`, `connections["${connectionName}"].id`);
59
+ }
60
+ return configString;
61
+ }
62
+ exports.buildConfigString = buildConfigString;
@@ -0,0 +1,19 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import fs from "fs-extra";
4
+ export declare const getCatalogFixture: (name: string, options?: fs.JsonReadOptions) => any;
5
+ export declare const getExternalDataFixture: (name: string, options?: fs.JsonReadOptions) => any;
6
+ export declare const getJSONataTemplate: (name: string, options?: BufferEncoding | (fs.ObjectEncodingOptions & {
7
+ flag?: string | undefined;
8
+ }) | null | undefined) => string | Buffer;
9
+ export declare const getTemplateHelpers: (name: string, options?: BufferEncoding | (fs.ObjectEncodingOptions & {
10
+ flag?: string | undefined;
11
+ }) | null | undefined) => string | Buffer;
12
+ export declare function createFileLoader<T, S extends any[]>({ prefix, fileLoader, suggestions, }: Args<T, S>): (name: string, ...args: S) => T;
13
+ interface Args<T, S extends any[]> {
14
+ prefix: string;
15
+ fileLoader: (prefix: string, ...args: S) => T;
16
+ suggestions?: string[];
17
+ }
18
+ export {};
19
+ //# sourceMappingURL=file-loaders.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-loaders.d.ts","sourceRoot":"","sources":["../../src/helpers/file-loaders.ts"],"names":[],"mappings":";;AAGA,OAAO,EAAE,MAAM,UAAU,CAAC;AAI1B,eAAO,MAAM,iBAAiB,SA0BP,MAAM,sCAtB3B,CAAC;AAEH,eAAO,MAAM,sBAAsB,SAoBZ,MAAM,sCAhB3B,CAAC;AAEH,eAAO,MAAM,kBAAkB,SAcR,MAAM;;yCAX3B,CAAC;AAEH,eAAO,MAAM,kBAAkB,SASR,MAAM;;yCAN3B,CAAC;AAEH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,CAAC,SAAS,GAAG,EAAE,EAAE,EACnD,MAAM,EACN,UAAU,EACV,WAAgB,GACjB,EAAE,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,CAc9C;AAED,UAAU,IAAI,CAAC,CAAC,EAAE,CAAC,SAAS,GAAG,EAAE;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC;IAC9C,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;CACxB"}
@@ -0,0 +1,45 @@
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
+ exports.createFileLoader = exports.getTemplateHelpers = exports.getJSONataTemplate = exports.getExternalDataFixture = exports.getCatalogFixture = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const errors_1 = require("@oclif/core/lib/errors");
9
+ const fs_extra_1 = __importDefault(require("fs-extra"));
10
+ const path_2 = require("../customer/path");
11
+ exports.getCatalogFixture = createFileLoader({
12
+ prefix: "src/fixtures",
13
+ fileLoader: fs_extra_1.default.readJSONSync,
14
+ suggestions: ["Ensure the file is a valid JSON file"],
15
+ });
16
+ exports.getExternalDataFixture = createFileLoader({
17
+ prefix: "src/fixtures/external_data",
18
+ fileLoader: fs_extra_1.default.readJSONSync,
19
+ suggestions: ["Ensure the file is a valid JSON file"],
20
+ });
21
+ exports.getJSONataTemplate = createFileLoader({
22
+ prefix: "src/templates",
23
+ fileLoader: fs_extra_1.default.readFileSync,
24
+ });
25
+ exports.getTemplateHelpers = createFileLoader({
26
+ prefix: "src/templates",
27
+ fileLoader: fs_extra_1.default.readFileSync,
28
+ });
29
+ function createFileLoader({ prefix, fileLoader, suggestions = [], }) {
30
+ return function (name, ...args) {
31
+ const filePath = (0, path_2.getCustomerPath)(path_1.default.join(prefix, name));
32
+ try {
33
+ return fileLoader(filePath, ...args);
34
+ }
35
+ catch (error) {
36
+ throw new errors_1.CLIError(`Error while loading ${filePath}: ${error.message}`, {
37
+ suggestions: [
38
+ "Ensure the file exists and is named correctly",
39
+ ...suggestions,
40
+ ],
41
+ });
42
+ }
43
+ };
44
+ }
45
+ exports.createFileLoader = createFileLoader;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Returns all files recursively in the given directory
3
+ * @param dir Directory to search for files
4
+ * @returns All files in the given directory, including in subdirectories
5
+ */
6
+ export declare function findDeepFiles(dir: string): string[];
7
+ //# sourceMappingURL=find-deep-files.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find-deep-files.d.ts","sourceRoot":"","sources":["../../src/helpers/find-deep-files.ts"],"names":[],"mappings":"AAMA;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAWnD"}
@@ -0,0 +1,27 @@
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
+ exports.findDeepFiles = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const fs_extra_1 = __importDefault(require("fs-extra"));
9
+ const path_2 = require("../customer/path");
10
+ /**
11
+ * Returns all files recursively in the given directory
12
+ * @param dir Directory to search for files
13
+ * @returns All files in the given directory, including in subdirectories
14
+ */
15
+ function findDeepFiles(dir) {
16
+ const files = fs_extra_1.default.readdirSync((0, path_2.getCustomerPath)(dir));
17
+ return files.reduce((files, currentPath) => {
18
+ const fullPath = path_1.default.join(dir, currentPath);
19
+ if (fs_extra_1.default.statSync((0, path_2.getCustomerPath)(fullPath)).isDirectory()) {
20
+ return [...files, ...findDeepFiles(fullPath)];
21
+ }
22
+ else {
23
+ return [...files, fullPath];
24
+ }
25
+ }, []);
26
+ }
27
+ exports.findDeepFiles = findDeepFiles;