Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions fontes/importador/importador-pitugues.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import * as sistemaArquivos from 'fs';
import * as caminho from 'path';
import * as sistemaOperacional from 'os';

import { LexadorInterface, SimboloInterface } from '@designliquido/delegua/interfaces';
import { cyrb53 } from '@designliquido/delegua/geracao-identificadores';

import { LexadorPitugues } from '@designliquido/delegua';
import { RetornoImportador } from './retorno-importador';
import { ImportadorInterface } from '../interfaces';
import { ErroImportacao } from '../excecoes';

export class ImportadorPitugues implements ImportadorInterface<SimboloInterface> {
diretorioBase: string = process.cwd();

Check warning on line 14 in fontes/importador/importador-pitugues.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
lexador: LexadorInterface<SimboloInterface>;
arquivosAbertos: { [identificador: string]: string };
conteudoArquivosAbertos: { [identificador: string]: string[] };
depuracao: boolean;

constructor(

Check warning on line 20 in fontes/importador/importador-pitugues.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
arquivosAbertos: { [identificador: string]: string },
conteudoArquivosAbertos: { [identificador: string]: string[] },
depuracao: boolean
) {
this.lexador = new LexadorPitugues();

Check warning on line 25 in fontes/importador/importador-pitugues.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
this.arquivosAbertos = arquivosAbertos;

Check warning on line 26 in fontes/importador/importador-pitugues.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
this.conteudoArquivosAbertos = conteudoArquivosAbertos;

Check warning on line 27 in fontes/importador/importador-pitugues.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
this.depuracao = depuracao;

Check warning on line 28 in fontes/importador/importador-pitugues.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

importar(

Check warning on line 31 in fontes/importador/importador-pitugues.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
caminhoRelativoArquivo: string,
hashArquivoAnterior: number
): RetornoImportador<SimboloInterface> {
const nomeArquivo = caminho.basename(caminhoRelativoArquivo);

Check warning on line 35 in fontes/importador/importador-pitugues.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
let caminhoAbsolutoArquivo: string;

if (hashArquivoAnterior < 0) {
caminhoAbsolutoArquivo = caminho.resolve(caminhoRelativoArquivo);

Check warning on line 39 in fontes/importador/importador-pitugues.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
} else {
const diretorioFonte = caminho.dirname(
this.arquivosAbertos[hashArquivoAnterior]

Check warning on line 42 in fontes/importador/importador-pitugues.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
);
caminhoAbsolutoArquivo = caminho.resolve(
diretorioFonte,
caminhoRelativoArquivo
);

Check warning on line 47 in fontes/importador/importador-pitugues.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 48 in fontes/importador/importador-pitugues.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 48 in fontes/importador/importador-pitugues.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 48 in fontes/importador/importador-pitugues.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

const hashArquivo = cyrb53(caminhoAbsolutoArquivo.toLowerCase());

Check warning on line 50 in fontes/importador/importador-pitugues.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

if (!sistemaArquivos.existsSync(caminhoAbsolutoArquivo)) {
throw new ErroImportacao(
caminhoAbsolutoArquivo,
`Não foi possível encontrar arquivo importado: ${nomeArquivo}.`,
);

Check warning on line 56 in fontes/importador/importador-pitugues.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 57 in fontes/importador/importador-pitugues.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 57 in fontes/importador/importador-pitugues.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

const dadosDoArquivo: Buffer = sistemaArquivos.readFileSync(
caminhoAbsolutoArquivo

Check warning on line 60 in fontes/importador/importador-pitugues.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
);
const conteudoDoArquivo: string[] = dadosDoArquivo
.toString()
.replace(sistemaOperacional.EOL, '\n')
.split('\n')
.map(linha => linha + '\0');

Check warning on line 66 in fontes/importador/importador-pitugues.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 66 in fontes/importador/importador-pitugues.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 66 in fontes/importador/importador-pitugues.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function

const retornoLexador = this.lexador.mapear(
conteudoDoArquivo,
hashArquivo

Check warning on line 70 in fontes/importador/importador-pitugues.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
);
this.arquivosAbertos[hashArquivo] = caminho.resolve(
caminhoAbsolutoArquivo
);

Check warning on line 74 in fontes/importador/importador-pitugues.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

if (this.depuracao) {
this.conteudoArquivosAbertos[hashArquivo] = conteudoDoArquivo;

Check warning on line 77 in fontes/importador/importador-pitugues.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 78 in fontes/importador/importador-pitugues.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 78 in fontes/importador/importador-pitugues.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

return {
nomeArquivo,
hashArquivo,
retornoLexador
} as RetornoImportador<SimboloInterface>;

Check warning on line 84 in fontes/importador/importador-pitugues.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}
}
3 changes: 2 additions & 1 deletion fontes/importador/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './importador';
export * from './importador-javascript';
export * from './retorno-importador';
export * from './importador-pitugues';
export * from './retorno-importador';
Loading