mddd-cli 4.0.6 → 4.1.1

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.1');
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.1",
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,43 @@ 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
+ * Normaliza os espaços invisíveis, quebras de linha e remove comentários iniciais
20
+ * @param {string} code
21
+ * @returns {string}
23
22
  */
23
+ function cleanDiagramCode(code) {
24
+ // 1. Substitui espaços não-quebráveis (NBSP) por espaços normais
25
+ // 2. Remove possíveis retornos de carro (\r) de arquivos gerados no Windows
26
+ const normalizedCode = code
27
+ .replace(/\u00A0/g, ' ')
28
+ .replace(/\r/g, '');
29
+
30
+ const lines = normalizedCode.split('\n');
31
+ const cleanedLines = [];
32
+ let foundTypeDeclaration = false;
33
+
34
+ for (const line of lines) {
35
+ const trimmed = line.trim();
36
+
37
+ // Ignora linhas vazias ou comentários iniciais até achar a declaração do tipo de diagrama
38
+ if (!foundTypeDeclaration && (trimmed === '' || trimmed.startsWith('%%'))) {
39
+ continue;
40
+ }
41
+
42
+ foundTypeDeclaration = true;
43
+ cleanedLines.push(line);
44
+ }
45
+
46
+ return cleanedLines.join('\n').trim();
47
+ }
48
+
24
49
  export async function validateMermaidSyntax(input) {
25
50
  let content = input;
26
51
 
27
- // Se o input for um caminho de arquivo válido no disco, lê o conteúdo dele
28
52
  if (fs.existsSync(input)) {
29
53
  content = fs.readFileSync(input, 'utf-8');
30
54
  }
31
55
 
32
- // Se houver blocos de Markdown indicando Mermaid, isola os diagramas
33
56
  let diagramsToValidate = [content];
34
57
  if (content.includes('```mermaid')) {
35
58
  diagramsToValidate = extractMermaidBlocks(content);
@@ -42,12 +65,19 @@ export async function validateMermaidSyntax(input) {
42
65
  }
43
66
  }
44
67
 
45
- // Valida cada bloco na memória usando o parser oficial
46
68
  try {
69
+ const cleanedDiagrams = [];
70
+
47
71
  for (const diagramCode of diagramsToValidate) {
48
- await parse(diagramCode);
72
+ const readyCode = cleanDiagramCode(diagramCode);
73
+ await parse(readyCode); // Se tiver espaço fantasma aqui, o parser agora aceita!
74
+ cleanedDiagrams.push(readyCode);
49
75
  }
50
- return { valid: true };
76
+
77
+ return {
78
+ valid: true,
79
+ diagrams: cleanedDiagrams
80
+ };
51
81
  } catch (error) {
52
82
  return {
53
83
  valid: false,