cartographer-ai 1.0.3 → 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.3",
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 }) {
@@ -90,9 +92,16 @@ export class Cartographer {
90
92
  },
91
93
  });
92
94
  } catch (error) {
93
- throw new Error(
94
- error?.response?.data?.error ?? "Unexpected error occured"
95
- );
95
+ if (error?.response?.data?.error) {
96
+ const errorMessage = `${errorPrefix} ${
97
+ error?.response?.data?.error ?? "Unexpected error occured"
98
+ }`;
99
+
100
+ const err = new Error(errorMessage);
101
+ err.stack = "";
102
+
103
+ throw err;
104
+ }
96
105
  }
97
106
  }
98
107
 
@@ -152,6 +161,27 @@ export class Cartographer {
152
161
  this.#getTrimmedFilePath(filePath, gitRoot)
153
162
  );
154
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
+
155
185
  return file;
156
186
  }
157
187
 
@@ -191,7 +221,11 @@ export class Cartographer {
191
221
 
192
222
  files[resolvedId].push(file);
193
223
  } catch (error) {
194
- 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;
195
229
  }
196
230
  });
197
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;