mddd-cli 4.0.6 → 4.1.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/bin/cli.js CHANGED
@@ -17,7 +17,7 @@ const program = new Command();
17
17
  program
18
18
  .name('md')
19
19
  .description('Manager for co-located specifications for Mermaid Diagram Driven Development (MDDD)')
20
- .version('4.0.6');
20
+ .version('4.1.0');
21
21
 
22
22
  // ==========================================
23
23
  // COMMAND: md init
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mddd-cli",
3
- "version": "4.0.6",
3
+ "version": "4.1.0",
4
4
  "description": "Official CLI for modular, co-located, and versioned Mermaid Diagram Driven Development (MDDD).",
5
5
  "type": "module",
6
6
  "exports": "./bin/cli.js",
@@ -1,9 +1,6 @@
1
1
  import { parse } from '@mermaid-js/parser';
2
2
  import fs from 'node:fs';
3
3
 
4
- /**
5
- * Filtra o texto para extrair apenas o que está dentro dos blocos ```mermaid
6
- */
7
4
  function extractMermaidBlocks(text) {
8
5
  const regex = /```mermaid\s*([\s\S]*?)\s*```/g;
9
6
  const blocks = [];
@@ -19,17 +16,38 @@ function extractMermaidBlocks(text) {
19
16
  }
20
17
 
21
18
  /**
22
- * Valida o conteúdo recebido (pode ser o caminho de um arquivo ou a string direta)
19
+ * Limpa comentários do topo do diagrama que quebram o parser do Mermaid
20
+ * @param {string} code
21
+ * @returns {string}
23
22
  */
23
+ function cleanDiagramCode(code) {
24
+ // Remove linhas que começam com %% no topo do arquivo antes da declaração do tipo
25
+ const lines = code.split('\n');
26
+ const cleanedLines = [];
27
+ let foundTypeDeclaration = false;
28
+
29
+ for (const line of lines) {
30
+ const trimmed = line.trim();
31
+
32
+ // Ignora linhas vazias ou comentários iniciais até achar a declaração do diagrama
33
+ if (!foundTypeDeclaration && (trimmed === '' || trimmed.startsWith('%%'))) {
34
+ continue;
35
+ }
36
+
37
+ foundTypeDeclaration = true;
38
+ cleanedLines.push(line);
39
+ }
40
+
41
+ return cleanedLines.join('\n').trim();
42
+ }
43
+
24
44
  export async function validateMermaidSyntax(input) {
25
45
  let content = input;
26
46
 
27
- // Se o input for um caminho de arquivo válido no disco, lê o conteúdo dele
28
47
  if (fs.existsSync(input)) {
29
48
  content = fs.readFileSync(input, 'utf-8');
30
49
  }
31
50
 
32
- // Se houver blocos de Markdown indicando Mermaid, isola os diagramas
33
51
  let diagramsToValidate = [content];
34
52
  if (content.includes('```mermaid')) {
35
53
  diagramsToValidate = extractMermaidBlocks(content);
@@ -42,10 +60,11 @@ export async function validateMermaidSyntax(input) {
42
60
  }
43
61
  }
44
62
 
45
- // Valida cada bloco na memória usando o parser oficial
46
63
  try {
47
64
  for (const diagramCode of diagramsToValidate) {
48
- await parse(diagramCode);
65
+ // Aplica a limpeza antes de mandar para o parser em memória
66
+ const readyCode = cleanDiagramCode(diagramCode);
67
+ await parse(readyCode);
49
68
  }
50
69
  return { valid: true };
51
70
  } catch (error) {