cartographer-ai 1.0.5 → 1.0.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cartographer-ai",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "main": "src/commands.js",
5
5
  "type": "module",
6
6
  "bin": {
@@ -6,6 +6,8 @@ import { execSync } from "child_process";
6
6
  const regex =
7
7
  /@cartographer\s*((?:\s*(?:id|parentId|name|diagramType|context|spaceId|folderId):\s*[^,\n]+,\s*)*(?:\s*(?:id|parentId|name|diagramType|context|spaceId|folderId):\s*[^,\n]+)?)/;
8
8
  const ignoredDirectories = ["node_modules", ".git", "build"];
9
+ export const warningPrefix = "\x1b[33mWarning:\x1b[0m";
10
+ export const errorPrefix = "\x1b[31mError:\x1b[0m";
9
11
 
10
12
  export class Cartographer {
11
13
  constructor({ processAllFiles = false, spaceId, apiKey }) {
@@ -91,9 +93,14 @@ export class Cartographer {
91
93
  });
92
94
  } catch (error) {
93
95
  if (error?.response?.data?.error) {
94
- throw new Error(
96
+ const errorMessage = `${errorPrefix} ${
95
97
  error?.response?.data?.error ?? "Unexpected error occured"
96
- );
98
+ }`;
99
+
100
+ const err = new Error(errorMessage);
101
+ err.stack = "";
102
+
103
+ throw err;
97
104
  }
98
105
  }
99
106
  }
@@ -154,6 +161,27 @@ export class Cartographer {
154
161
  this.#getTrimmedFilePath(filePath, gitRoot)
155
162
  );
156
163
 
164
+ if (file.parentId) {
165
+ const forbidden = [
166
+ "id",
167
+ "name",
168
+ "diagramType",
169
+ "context",
170
+ "spaceId",
171
+ "folderId",
172
+ ].filter((key) => file[key]);
173
+
174
+ if (forbidden.length > 0) {
175
+ console.warn(
176
+ `${warningPrefix} File "${filePath}" is invalid. When "parentId" is present, the following attributes must not be used: ${forbidden.join(
177
+ ", "
178
+ )}. These attributes have been ignored.`
179
+ );
180
+ }
181
+
182
+ forbidden.forEach((field) => (file[field] = ""));
183
+ }
184
+
157
185
  return file;
158
186
  }
159
187
 
@@ -193,7 +221,11 @@ export class Cartographer {
193
221
 
194
222
  files[resolvedId].push(file);
195
223
  } catch (error) {
196
- throw new Error(`Error reading file ${filePath}:`, error.message);
224
+ const errorMessage = `${errorPrefix} Error reading file ${filePath}, error: ${error.message}`;
225
+ const err = new Error(errorMessage);
226
+ err.stack = "";
227
+
228
+ throw err;
197
229
  }
198
230
  });
199
231
 
package/src/commands.js CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  import fs from "fs";
4
4
  import path from "path";
5
+ import { Cartographer, errorPrefix } from "./cartographer.js";
5
6
  import { fileURLToPath } from "url";
6
- import { Cartographer } from "./cartographer.js";
7
7
 
8
8
  const args = process.argv.slice(2);
9
9
  const fields = ["spaceId", "apiKey"];
@@ -33,7 +33,11 @@ export const saveConfig = (configPath, newConfig) => {
33
33
 
34
34
  const handleCartographerCommand = (arg) => {
35
35
  if (!arg) {
36
- throw new Error("No command received");
36
+ const errorMessage = `${errorPrefix} No command received`;
37
+ const err = new Error(errorMessage);
38
+ err.stack = "";
39
+
40
+ throw err;
37
41
  }
38
42
 
39
43
  const config = loadConfig(configPath);
@@ -46,9 +50,14 @@ const handleCartographerCommand = (arg) => {
46
50
  }, []);
47
51
 
48
52
  if (missingFields.length > 0) {
49
- throw new Error(
50
- `Error: Missing required fields: ${missingFields.join(", ")}`
51
- );
53
+ const errorMessage = `${errorPrefix} Error: Missing required fields: ${missingFields.join(
54
+ ", "
55
+ )}`;
56
+
57
+ const err = new Error(errorMessage);
58
+ err.stack = "";
59
+
60
+ throw err;
52
61
  } else {
53
62
  const cartographer = new Cartographer({
54
63
  processAllFiles: config?.processAllFiles ?? false,
@@ -72,7 +81,11 @@ const handleCartographerCommand = (arg) => {
72
81
  const field = fields.find((field) => field === command);
73
82
 
74
83
  if (!field) {
75
- throw new Error(`Unknown command: ${command}`);
84
+ const errorMessage = `${errorPrefix} Unknown command: ${command}`;
85
+ const err = new Error(errorMessage);
86
+ err.stack = "";
87
+
88
+ throw err;
76
89
  }
77
90
 
78
91
  config[field] = value;