@semacode/cli 1.5.11 → 1.5.16
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/README.md +6 -1
- package/dist/index.js +446 -32
- package/package.json +23 -32
- package/semacode-cli-1.3.1.tgz +0 -0
- package/src/angular-consumer-standalone.ts +312 -0
- package/src/cpp-symbols.ts +82 -0
- package/src/docs.ts +535 -0
- package/src/dotnet-http.ts +355 -0
- package/src/drift.ts +4933 -0
- package/src/go-http.ts +118 -0
- package/src/importador.ts +3891 -0
- package/src/index.ts +5641 -0
- package/src/java-http.ts +247 -0
- package/src/lua-symbols.ts +114 -0
- package/src/php-symbols.ts +462 -0
- package/src/projeto.ts +862 -0
- package/src/python-http.ts +258 -0
- package/src/rust-http.ts +125 -0
- package/src/tipos.ts +24 -0
- package/src/typescript-http.ts +1076 -0
- package/tsconfig.json +20 -0
- package/AGENTS.md +0 -272
- package/LICENSE +0 -22
- package/SEMA_BRIEF.curto.txt +0 -9
- package/SEMA_BRIEF.md +0 -63
- package/SEMA_BRIEF.micro.txt +0 -7
- package/SEMA_INDEX.json +0 -799
- package/dist/angular-consumer-standalone.d.ts +0 -6
- package/dist/angular-consumer-standalone.js.map +0 -1
- package/dist/cpp-symbols.d.ts +0 -10
- package/dist/cpp-symbols.js.map +0 -1
- package/dist/docs.d.ts +0 -56
- package/dist/docs.js.map +0 -1
- package/dist/dotnet-http.d.ts +0 -23
- package/dist/dotnet-http.js.map +0 -1
- package/dist/drift.d.ts +0 -225
- package/dist/drift.js.map +0 -1
- package/dist/go-http.d.ts +0 -23
- package/dist/go-http.js.map +0 -1
- package/dist/importador.d.ts +0 -31
- package/dist/importador.js.map +0 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.js.map +0 -1
- package/dist/java-http.d.ts +0 -23
- package/dist/java-http.js.map +0 -1
- package/dist/lua-symbols.d.ts +0 -10
- package/dist/lua-symbols.js.map +0 -1
- package/dist/php-symbols.d.ts +0 -24
- package/dist/php-symbols.js.map +0 -1
- package/dist/projeto.d.ts +0 -53
- package/dist/projeto.js.map +0 -1
- package/dist/python-http.d.ts +0 -23
- package/dist/python-http.js.map +0 -1
- package/dist/rust-http.d.ts +0 -23
- package/dist/rust-http.js.map +0 -1
- package/dist/tipos.d.ts +0 -3
- package/dist/tipos.js.map +0 -1
- package/dist/typescript-http.d.ts +0 -35
- package/dist/typescript-http.js.map +0 -1
- package/docs/AGENT_STARTER.md +0 -102
- package/docs/cli.md +0 -110
- package/docs/como-ensinar-a-sema-para-ia.md +0 -149
- package/docs/deploy.md +0 -70
- package/docs/documentacao.md +0 -63
- package/docs/env.md +0 -56
- package/docs/extensao-vscode.md +0 -45
- package/docs/fluxo-pratico-ia-sema.md +0 -177
- package/docs/instalacao-e-primeiro-uso.md +0 -112
- package/docs/integracao-com-ia.md +0 -101
- package/docs/mcp.md +0 -53
- package/docs/pagamento-ponta-a-ponta.md +0 -155
- package/docs/persistencia-vendor-first.md +0 -145
- package/docs/prompt-base-ia-sema.md +0 -104
- package/docs/rollback.md +0 -47
- package/docs/sintaxe.md +0 -244
- package/exemplos/agendamento.sema +0 -106
- package/exemplos/assinatura.sema +0 -136
- package/exemplos/auditoria.sema +0 -88
- package/exemplos/autenticacao.sema +0 -125
- package/exemplos/automacao.sema +0 -107
- package/exemplos/cadastro_usuario.sema +0 -54
- package/exemplos/calculadora.sema +0 -78
- package/exemplos/crud_simples.sema +0 -89
- package/exemplos/estoque.sema +0 -126
- package/exemplos/exportacao.sema +0 -94
- package/exemplos/fila.sema +0 -131
- package/exemplos/integracao_externa.sema +0 -94
- package/exemplos/multi_tenant.sema +0 -140
- package/exemplos/notificacao.sema +0 -98
- package/exemplos/operacao_estrategia.sema +0 -402
- package/exemplos/pagamento.sema +0 -222
- package/exemplos/pagamento_dominio.sema +0 -35
- package/exemplos/pedido.sema +0 -119
- package/exemplos/permissao.sema +0 -121
- package/exemplos/persistencia_vendor_first.sema +0 -86
- package/exemplos/relatorio.sema +0 -93
- package/exemplos/testes_embutidos.sema +0 -45
- package/exemplos/tratamento_erro.sema +0 -157
- package/exemplos/upload_arquivo.sema +0 -93
- package/exemplos/webhook.sema +0 -96
- package/llms-full.txt +0 -34
- package/llms.txt +0 -17
- package/node_modules/@sema/gerador-css/dist/index.d.ts +0 -3
- package/node_modules/@sema/gerador-css/dist/index.js +0 -592
- package/node_modules/@sema/gerador-css/dist/index.js.map +0 -1
- package/node_modules/@sema/gerador-css/package.json +0 -7
- package/node_modules/@sema/gerador-dart/dist/index.d.ts +0 -3
- package/node_modules/@sema/gerador-dart/dist/index.js +0 -44
- package/node_modules/@sema/gerador-dart/dist/index.js.map +0 -1
- package/node_modules/@sema/gerador-dart/package.json +0 -7
- package/node_modules/@sema/gerador-html/dist/index.d.ts +0 -3
- package/node_modules/@sema/gerador-html/dist/index.js +0 -163
- package/node_modules/@sema/gerador-html/dist/index.js.map +0 -1
- package/node_modules/@sema/gerador-html/package.json +0 -7
- package/node_modules/@sema/gerador-javascript/dist/index.d.ts +0 -3
- package/node_modules/@sema/gerador-javascript/dist/index.js +0 -421
- package/node_modules/@sema/gerador-javascript/dist/index.js.map +0 -1
- package/node_modules/@sema/gerador-javascript/package.json +0 -7
- package/node_modules/@sema/gerador-lua/dist/index.d.ts +0 -3
- package/node_modules/@sema/gerador-lua/dist/index.js +0 -328
- package/node_modules/@sema/gerador-lua/dist/index.js.map +0 -1
- package/node_modules/@sema/gerador-lua/package.json +0 -7
- package/node_modules/@sema/gerador-python/dist/index.d.ts +0 -6
- package/node_modules/@sema/gerador-python/dist/index.js +0 -729
- package/node_modules/@sema/gerador-python/dist/index.js.map +0 -1
- package/node_modules/@sema/gerador-python/package.json +0 -7
- package/node_modules/@sema/gerador-typescript/dist/index.d.ts +0 -6
- package/node_modules/@sema/gerador-typescript/dist/index.js +0 -793
- package/node_modules/@sema/gerador-typescript/dist/index.js.map +0 -1
- package/node_modules/@sema/gerador-typescript/package.json +0 -7
- package/node_modules/@sema/nucleo/dist/ast/tipos.d.ts +0 -123
- package/node_modules/@sema/nucleo/dist/ast/tipos.js +0 -2
- package/node_modules/@sema/nucleo/dist/ast/tipos.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/diagnosticos/index.d.ts +0 -21
- package/node_modules/@sema/nucleo/dist/diagnosticos/index.js +0 -12
- package/node_modules/@sema/nucleo/dist/diagnosticos/index.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/formatador/index.d.ts +0 -9
- package/node_modules/@sema/nucleo/dist/formatador/index.js +0 -460
- package/node_modules/@sema/nucleo/dist/formatador/index.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/index.d.ts +0 -35
- package/node_modules/@sema/nucleo/dist/index.js +0 -96
- package/node_modules/@sema/nucleo/dist/index.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/ir/conversor.d.ts +0 -5
- package/node_modules/@sema/nucleo/dist/ir/conversor.js +0 -883
- package/node_modules/@sema/nucleo/dist/ir/conversor.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/ir/modelos.d.ts +0 -345
- package/node_modules/@sema/nucleo/dist/ir/modelos.js +0 -2
- package/node_modules/@sema/nucleo/dist/ir/modelos.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/lexer/lexer.d.ts +0 -7
- package/node_modules/@sema/nucleo/dist/lexer/lexer.js +0 -122
- package/node_modules/@sema/nucleo/dist/lexer/lexer.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/lexer/tokens.d.ts +0 -8
- package/node_modules/@sema/nucleo/dist/lexer/tokens.js +0 -61
- package/node_modules/@sema/nucleo/dist/lexer/tokens.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/parser/parser.d.ts +0 -9
- package/node_modules/@sema/nucleo/dist/parser/parser.js +0 -771
- package/node_modules/@sema/nucleo/dist/parser/parser.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/persistencia/contratos.d.ts +0 -39
- package/node_modules/@sema/nucleo/dist/persistencia/contratos.js +0 -294
- package/node_modules/@sema/nucleo/dist/persistencia/contratos.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/semantico/analisador.d.ts +0 -57
- package/node_modules/@sema/nucleo/dist/semantico/analisador.js +0 -1617
- package/node_modules/@sema/nucleo/dist/semantico/analisador.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/semantico/estruturas.d.ts +0 -104
- package/node_modules/@sema/nucleo/dist/semantico/estruturas.js +0 -445
- package/node_modules/@sema/nucleo/dist/semantico/estruturas.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/semantico/seguranca.d.ts +0 -91
- package/node_modules/@sema/nucleo/dist/semantico/seguranca.js +0 -258
- package/node_modules/@sema/nucleo/dist/semantico/seguranca.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/util/arquivos.d.ts +0 -2
- package/node_modules/@sema/nucleo/dist/util/arquivos.js +0 -25
- package/node_modules/@sema/nucleo/dist/util/arquivos.js.map +0 -1
- package/node_modules/@sema/nucleo/package.json +0 -7
- package/node_modules/@sema/padroes/dist/index.d.ts +0 -25
- package/node_modules/@sema/padroes/dist/index.js +0 -316
- package/node_modules/@sema/padroes/dist/index.js.map +0 -1
- package/node_modules/@sema/padroes/package.json +0 -7
package/package.json
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@semacode/cli",
|
|
3
|
-
"version": "1.5.
|
|
4
|
-
"description": "CLI da Sema para validar contratos, medir drift e governar a navegacao operacional de agentes sobre software vivo, incluindo persistencia vendor-first para bancos reais.",
|
|
3
|
+
"version": "1.5.16",
|
|
5
4
|
"type": "module",
|
|
6
|
-
"
|
|
5
|
+
"description": "CLI da Sema para validar contratos, medir drift e governar a navegacao operacional de agentes sobre software vivo, incluindo persistencia vendor-first para bancos reais.",
|
|
7
6
|
"license": "MIT",
|
|
8
7
|
"repository": {
|
|
9
8
|
"type": "git",
|
|
@@ -28,47 +27,39 @@
|
|
|
28
27
|
"publishConfig": {
|
|
29
28
|
"access": "public"
|
|
30
29
|
},
|
|
30
|
+
"icon": "logo.png",
|
|
31
31
|
"bin": {
|
|
32
32
|
"sema": "dist/index.js"
|
|
33
33
|
},
|
|
34
34
|
"main": "dist/index.js",
|
|
35
35
|
"types": "dist/index.d.ts",
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
"exemplos",
|
|
40
|
-
"AGENTS.md",
|
|
41
|
-
"llms.txt",
|
|
42
|
-
"llms-full.txt",
|
|
43
|
-
"SEMA_BRIEF.md",
|
|
44
|
-
"SEMA_BRIEF.micro.txt",
|
|
45
|
-
"SEMA_BRIEF.curto.txt",
|
|
46
|
-
"SEMA_INDEX.json",
|
|
47
|
-
"logo.png",
|
|
48
|
-
"README.md",
|
|
49
|
-
"LICENSE"
|
|
50
|
-
],
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsc -p tsconfig.json"
|
|
38
|
+
},
|
|
51
39
|
"dependencies": {
|
|
52
|
-
"@sema/
|
|
53
|
-
"@sema/gerador-dart": "
|
|
54
|
-
"@sema/gerador-
|
|
55
|
-
"@sema/gerador-
|
|
56
|
-
"@sema/gerador-
|
|
57
|
-
"@sema/gerador-
|
|
58
|
-
"@sema/gerador-
|
|
59
|
-
"@sema/
|
|
60
|
-
"@sema/padroes": "
|
|
40
|
+
"@sema/gerador-css": "file:../gerador-css",
|
|
41
|
+
"@sema/gerador-dart": "file:../gerador-dart",
|
|
42
|
+
"@sema/gerador-html": "file:../gerador-html",
|
|
43
|
+
"@sema/gerador-javascript": "file:../gerador-javascript",
|
|
44
|
+
"@sema/gerador-lua": "file:../gerador-lua",
|
|
45
|
+
"@sema/gerador-python": "file:../gerador-python",
|
|
46
|
+
"@sema/gerador-typescript": "file:../gerador-typescript",
|
|
47
|
+
"@sema/nucleo": "file:../nucleo",
|
|
48
|
+
"@sema/padroes": "file:../padroes",
|
|
61
49
|
"typescript": "^5.8.3"
|
|
62
50
|
},
|
|
63
|
-
"
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"tsx": "^4.19.3"
|
|
53
|
+
},
|
|
54
|
+
"bundleDependencies": [
|
|
64
55
|
"@sema/nucleo",
|
|
56
|
+
"@sema/padroes",
|
|
57
|
+
"@sema/gerador-typescript",
|
|
58
|
+
"@sema/gerador-python",
|
|
65
59
|
"@sema/gerador-dart",
|
|
66
60
|
"@sema/gerador-lua",
|
|
67
|
-
"@sema/gerador-python",
|
|
68
|
-
"@sema/gerador-typescript",
|
|
69
61
|
"@sema/gerador-javascript",
|
|
70
62
|
"@sema/gerador-html",
|
|
71
|
-
"@sema/gerador-css"
|
|
72
|
-
"@sema/padroes"
|
|
63
|
+
"@sema/gerador-css"
|
|
73
64
|
]
|
|
74
65
|
}
|
|
Binary file
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import ts from "typescript";
|
|
4
|
+
|
|
5
|
+
export interface SuperficieAngularStandaloneConsumer {
|
|
6
|
+
rota: string;
|
|
7
|
+
arquivo: string;
|
|
8
|
+
tipoArquivo: "app" | "component";
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface ComponenteAngularStandaloneIndexado {
|
|
12
|
+
arquivo: string;
|
|
13
|
+
selector?: string;
|
|
14
|
+
imports: string[];
|
|
15
|
+
template: string;
|
|
16
|
+
raiz: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function normalizarCaminhoConsumer(caminhoArquivo: string): string {
|
|
20
|
+
return caminhoArquivo.replace(/\\/g, "/");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function arquivoEhComponenteAngularStandalone(relacaoArquivo: string): boolean {
|
|
24
|
+
const relacao = normalizarCaminhoConsumer(relacaoArquivo);
|
|
25
|
+
return /(?:^|\/)(?:src\/)?app\.component\.(?:ts|js)$/i.test(relacao)
|
|
26
|
+
|| /(?:^|\/)(?:src\/)?app\/.+\.component\.(?:ts|js)$/i.test(relacao)
|
|
27
|
+
|| /(?:^|\/)(?:src\/)?components\/.+\.component\.(?:ts|js)$/i.test(relacao);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function arquivoEhRaizAngularStandalone(relacaoArquivo: string): boolean {
|
|
31
|
+
const relacao = normalizarCaminhoConsumer(relacaoArquivo);
|
|
32
|
+
return /(?:^|\/)(?:src\/)?app\.component\.(?:ts|js)$/i.test(relacao)
|
|
33
|
+
|| /(?:^|\/)(?:src\/)?app\/app\.component\.(?:ts|js)$/i.test(relacao);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function resolverImportRelativoAngular(relacaoArquivoBase: string, especificador: string): string | undefined {
|
|
37
|
+
if (!especificador.startsWith(".")) {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
const baseDir = path.posix.dirname(normalizarCaminhoConsumer(relacaoArquivoBase));
|
|
41
|
+
for (const sufixo of ["", ".ts", ".tsx", ".js", ".jsx", "/index.ts", "/index.js"]) {
|
|
42
|
+
const candidato = path.posix.normalize(path.posix.join(baseDir, `${especificador}${sufixo}`));
|
|
43
|
+
if (/\.(?:ts|tsx|js|jsx)$/i.test(candidato)) {
|
|
44
|
+
return candidato;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function resolverTemplateRelativoAngular(relacaoArquivoBase: string, especificador: string): string | undefined {
|
|
51
|
+
if (!especificador.startsWith(".")) {
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
const baseDir = path.posix.dirname(normalizarCaminhoConsumer(relacaoArquivoBase));
|
|
55
|
+
const candidato = path.posix.normalize(path.posix.join(baseDir, especificador));
|
|
56
|
+
return /\.(?:html)$/i.test(candidato) ? candidato : undefined;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function extrairImportsTypeScriptAngular(relacaoArquivo: string, codigo: string): Map<string, string> {
|
|
60
|
+
const imports = new Map<string, string>();
|
|
61
|
+
for (const match of codigo.matchAll(/import\s*\{\s*([^}]+)\s*\}\s*from\s*["']([^"']+)["']/g)) {
|
|
62
|
+
const arquivoImportado = resolverImportRelativoAngular(relacaoArquivo, match[2]);
|
|
63
|
+
if (!arquivoImportado) {
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
for (const bruto of match[1].split(",")) {
|
|
67
|
+
const local = bruto.trim().split(/\s+as\s+/i).at(-1)?.trim();
|
|
68
|
+
if (local) {
|
|
69
|
+
imports.set(local, arquivoImportado);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
for (const match of codigo.matchAll(/import\s+([A-Za-z_]\w*)\s+from\s*["']([^"']+)["']/g)) {
|
|
74
|
+
const arquivoImportado = resolverImportRelativoAngular(relacaoArquivo, match[2]);
|
|
75
|
+
const local = match[1]?.trim();
|
|
76
|
+
if (arquivoImportado && local) {
|
|
77
|
+
imports.set(local, arquivoImportado);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return imports;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function nomePropriedadeObjeto(elemento: ts.ObjectLiteralElementLike): string | undefined {
|
|
84
|
+
if (!ts.isPropertyAssignment(elemento) && !ts.isShorthandPropertyAssignment(elemento)) {
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
const nome = elemento.name;
|
|
88
|
+
if (ts.isIdentifier(nome) || ts.isStringLiteral(nome)) {
|
|
89
|
+
return nome.text;
|
|
90
|
+
}
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function obterDecorators(node: ts.Node): readonly ts.Decorator[] {
|
|
95
|
+
return ts.canHaveDecorators(node) ? ts.getDecorators(node) ?? [] : [];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function obterObjetoDecoratorComponent(node: ts.ClassDeclaration): ts.ObjectLiteralExpression | undefined {
|
|
99
|
+
for (const decorator of obterDecorators(node)) {
|
|
100
|
+
const expr = decorator.expression;
|
|
101
|
+
if (!ts.isCallExpression(expr) || !ts.isIdentifier(expr.expression) || expr.expression.text !== "Component") {
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
const arg = expr.arguments[0];
|
|
105
|
+
if (arg && ts.isObjectLiteralExpression(arg)) {
|
|
106
|
+
return arg;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function obterExpressaoPropriedade(objeto: ts.ObjectLiteralExpression, nome: string): ts.Expression | undefined {
|
|
113
|
+
for (const propriedade of objeto.properties) {
|
|
114
|
+
if (nomePropriedadeObjeto(propriedade) !== nome) {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
if (ts.isPropertyAssignment(propriedade)) {
|
|
118
|
+
return propriedade.initializer;
|
|
119
|
+
}
|
|
120
|
+
if (ts.isShorthandPropertyAssignment(propriedade)) {
|
|
121
|
+
return propriedade.name;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function extrairTextoLiteral(expressao?: ts.Expression): string | undefined {
|
|
128
|
+
if (!expressao) {
|
|
129
|
+
return undefined;
|
|
130
|
+
}
|
|
131
|
+
if (ts.isStringLiteral(expressao) || ts.isNoSubstitutionTemplateLiteral(expressao)) {
|
|
132
|
+
return expressao.text;
|
|
133
|
+
}
|
|
134
|
+
if (ts.isTemplateExpression(expressao)) {
|
|
135
|
+
return expressao.getText().slice(1, -1);
|
|
136
|
+
}
|
|
137
|
+
return undefined;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function extrairIdentificadorImportado(expressao: ts.Expression): string | undefined {
|
|
141
|
+
if (ts.isIdentifier(expressao)) {
|
|
142
|
+
return expressao.text;
|
|
143
|
+
}
|
|
144
|
+
if (ts.isCallExpression(expressao)
|
|
145
|
+
&& ts.isIdentifier(expressao.expression)
|
|
146
|
+
&& expressao.expression.text === "forwardRef") {
|
|
147
|
+
const callback = expressao.arguments[0];
|
|
148
|
+
if (callback && (ts.isArrowFunction(callback) || ts.isFunctionExpression(callback))) {
|
|
149
|
+
if (ts.isIdentifier(callback.body)) {
|
|
150
|
+
return callback.body.text;
|
|
151
|
+
}
|
|
152
|
+
if (ts.isBlock(callback.body)) {
|
|
153
|
+
for (const statement of callback.body.statements) {
|
|
154
|
+
if (ts.isReturnStatement(statement) && statement.expression && ts.isIdentifier(statement.expression)) {
|
|
155
|
+
return statement.expression.text;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return undefined;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
async function extrairTemplateAngularStandalone(
|
|
165
|
+
baseProjeto: string,
|
|
166
|
+
relacaoArquivo: string,
|
|
167
|
+
metadata: ts.ObjectLiteralExpression,
|
|
168
|
+
): Promise<string> {
|
|
169
|
+
const templateInline = extrairTextoLiteral(obterExpressaoPropriedade(metadata, "template"));
|
|
170
|
+
if (templateInline) {
|
|
171
|
+
return templateInline;
|
|
172
|
+
}
|
|
173
|
+
const templateUrl = extrairTextoLiteral(obterExpressaoPropriedade(metadata, "templateUrl"));
|
|
174
|
+
if (!templateUrl) {
|
|
175
|
+
return "";
|
|
176
|
+
}
|
|
177
|
+
const templateRelativo = resolverTemplateRelativoAngular(relacaoArquivo, templateUrl);
|
|
178
|
+
if (!templateRelativo) {
|
|
179
|
+
return "";
|
|
180
|
+
}
|
|
181
|
+
try {
|
|
182
|
+
return await readFile(path.join(baseProjeto, templateRelativo), "utf8");
|
|
183
|
+
} catch {
|
|
184
|
+
return "";
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
async function indexarComponenteAngularStandalone(
|
|
189
|
+
baseProjeto: string,
|
|
190
|
+
arquivo: string,
|
|
191
|
+
): Promise<ComponenteAngularStandaloneIndexado | undefined> {
|
|
192
|
+
const relacaoArquivo = normalizarCaminhoConsumer(path.relative(baseProjeto, arquivo));
|
|
193
|
+
if (!arquivoEhComponenteAngularStandalone(relacaoArquivo)) {
|
|
194
|
+
return undefined;
|
|
195
|
+
}
|
|
196
|
+
const codigo = await readFile(arquivo, "utf8");
|
|
197
|
+
const sourceFile = ts.createSourceFile(arquivo, codigo, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
|
|
198
|
+
const imports = extrairImportsTypeScriptAngular(relacaoArquivo, codigo);
|
|
199
|
+
|
|
200
|
+
for (const statement of sourceFile.statements) {
|
|
201
|
+
if (!ts.isClassDeclaration(statement)) {
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
const metadata = obterObjetoDecoratorComponent(statement);
|
|
205
|
+
if (!metadata) {
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
const standalone = obterExpressaoPropriedade(metadata, "standalone");
|
|
209
|
+
if (!standalone || standalone.kind !== ts.SyntaxKind.TrueKeyword) {
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
const importsExpr = obterExpressaoPropriedade(metadata, "imports");
|
|
213
|
+
const importsArquivos = new Set<string>();
|
|
214
|
+
if (importsExpr && ts.isArrayLiteralExpression(importsExpr)) {
|
|
215
|
+
for (const elemento of importsExpr.elements) {
|
|
216
|
+
const nomeImportado = extrairIdentificadorImportado(elemento);
|
|
217
|
+
if (!nomeImportado) {
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
const arquivoImportado = imports.get(nomeImportado);
|
|
221
|
+
if (arquivoImportado) {
|
|
222
|
+
importsArquivos.add(arquivoImportado);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return {
|
|
228
|
+
arquivo: relacaoArquivo,
|
|
229
|
+
selector: extrairTextoLiteral(obterExpressaoPropriedade(metadata, "selector")),
|
|
230
|
+
imports: [...importsArquivos],
|
|
231
|
+
template: await extrairTemplateAngularStandalone(baseProjeto, relacaoArquivo, metadata),
|
|
232
|
+
raiz: arquivoEhRaizAngularStandalone(relacaoArquivo),
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
return undefined;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function templateReferenciaSelector(template: string, selector: string): boolean {
|
|
240
|
+
if (!template || !selector) {
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
243
|
+
const escapado = selector.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
244
|
+
return new RegExp(`<${escapado}(?:\\s|>)`, "i").test(template);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export async function coletarSuperficiesAngularStandaloneConsumer(
|
|
248
|
+
baseProjeto: string,
|
|
249
|
+
arquivos: string[],
|
|
250
|
+
): Promise<SuperficieAngularStandaloneConsumer[]> {
|
|
251
|
+
const componentes = new Map<string, ComponenteAngularStandaloneIndexado>();
|
|
252
|
+
for (const arquivo of arquivos) {
|
|
253
|
+
const componente = await indexarComponenteAngularStandalone(baseProjeto, arquivo);
|
|
254
|
+
if (componente) {
|
|
255
|
+
componentes.set(componente.arquivo, componente);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const raizes = [...componentes.values()].filter((componente) => componente.raiz);
|
|
260
|
+
if (raizes.length === 0) {
|
|
261
|
+
return [];
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const seletores = new Map<string, string[]>();
|
|
265
|
+
for (const componente of componentes.values()) {
|
|
266
|
+
if (!componente.selector) {
|
|
267
|
+
continue;
|
|
268
|
+
}
|
|
269
|
+
const existentes = seletores.get(componente.selector) ?? [];
|
|
270
|
+
existentes.push(componente.arquivo);
|
|
271
|
+
seletores.set(componente.selector, existentes);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const visitados = new Set<string>();
|
|
275
|
+
const fila = [...raizes];
|
|
276
|
+
while (fila.length > 0) {
|
|
277
|
+
const atual = fila.shift();
|
|
278
|
+
if (!atual || visitados.has(atual.arquivo)) {
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
visitados.add(atual.arquivo);
|
|
282
|
+
|
|
283
|
+
for (const arquivoImportado of atual.imports) {
|
|
284
|
+
const componenteImportado = componentes.get(arquivoImportado);
|
|
285
|
+
if (componenteImportado && !visitados.has(componenteImportado.arquivo)) {
|
|
286
|
+
fila.push(componenteImportado);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
for (const [selector, arquivosSelector] of seletores.entries()) {
|
|
291
|
+
if (!templateReferenciaSelector(atual.template, selector)) {
|
|
292
|
+
continue;
|
|
293
|
+
}
|
|
294
|
+
for (const arquivoSelector of arquivosSelector) {
|
|
295
|
+
const componenteSelector = componentes.get(arquivoSelector);
|
|
296
|
+
if (componenteSelector && !visitados.has(componenteSelector.arquivo)) {
|
|
297
|
+
fila.push(componenteSelector);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
return [...visitados]
|
|
304
|
+
.map<SuperficieAngularStandaloneConsumer>((arquivo) => ({
|
|
305
|
+
rota: "/",
|
|
306
|
+
arquivo,
|
|
307
|
+
tipoArquivo: raizes.some((raiz) => raiz.arquivo === arquivo) ? "app" : "component",
|
|
308
|
+
}))
|
|
309
|
+
.sort((a, b) =>
|
|
310
|
+
a.tipoArquivo.localeCompare(b.tipoArquivo, "pt-BR")
|
|
311
|
+
|| a.arquivo.localeCompare(b.arquivo, "pt-BR"));
|
|
312
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
export interface SimboloCppExtraido {
|
|
2
|
+
simbolo: string;
|
|
3
|
+
retorno?: string;
|
|
4
|
+
parametros: Array<{ nome: string; tipoTexto?: string; obrigatorio: boolean }>;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function extrairParametrosCpp(assinatura: string): Array<{ nome: string; tipoTexto?: string; obrigatorio: boolean }> {
|
|
8
|
+
return assinatura.split(",").map((parametroBruto) => {
|
|
9
|
+
const parametro = parametroBruto.trim();
|
|
10
|
+
if (!parametro || parametro === "void") {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
const semPadrao = parametro.split("=")[0]?.trim() ?? parametro;
|
|
14
|
+
const partes = semPadrao.split(/\s+/).filter(Boolean);
|
|
15
|
+
if (partes.length < 2) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
const nome = partes.at(-1)!.replace(/[&*]+$/, "");
|
|
19
|
+
const tipoTexto = partes.slice(0, -1).join(" ");
|
|
20
|
+
return {
|
|
21
|
+
nome,
|
|
22
|
+
tipoTexto,
|
|
23
|
+
obrigatorio: !parametro.includes("="),
|
|
24
|
+
};
|
|
25
|
+
}).filter((item): item is NonNullable<typeof item> => Boolean(item));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function extrairSimbolosCpp(codigo: string): SimboloCppExtraido[] {
|
|
29
|
+
const simbolos = new Map<string, SimboloCppExtraido>();
|
|
30
|
+
|
|
31
|
+
for (const match of codigo.matchAll(/(?:^|\n)\s*(?:inline\s+|static\s+|virtual\s+|constexpr\s+|friend\s+|extern\s+|template\s*<[^>]+>\s*)*(?:[\w:<>~*&]+\s+)+([A-Za-z_]\w*)::([A-Za-z_]\w*)\s*\(([^)]*)\)\s*(?:const)?\s*(?:\{|;)/g)) {
|
|
32
|
+
const simbolo = `${match[1]!}.${match[2]!}`;
|
|
33
|
+
simbolos.set(simbolo, {
|
|
34
|
+
simbolo,
|
|
35
|
+
parametros: extrairParametrosCpp(match[3] ?? ""),
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
for (const match of codigo.matchAll(/(?:^|\n)\s*(?:inline\s+|static\s+|virtual\s+|constexpr\s+|friend\s+|extern\s+)*(?:[\w:<>~*&]+\s+)+([A-Za-z_]\w*)\s*\(([^)]*)\)\s*(?:const)?\s*(?:\{|;)/g)) {
|
|
40
|
+
const nome = match[1]!;
|
|
41
|
+
if (["if", "for", "while", "switch", "return"].includes(nome)) {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (!simbolos.has(nome)) {
|
|
45
|
+
simbolos.set(nome, {
|
|
46
|
+
simbolo: nome,
|
|
47
|
+
parametros: extrairParametrosCpp(match[2] ?? ""),
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const pilhaClasses: string[] = [];
|
|
53
|
+
for (const linha of codigo.split(/\r?\n/)) {
|
|
54
|
+
const trim = linha.trim();
|
|
55
|
+
const classe = trim.match(/^(?:class|struct)\s+([A-Za-z_]\w*)/);
|
|
56
|
+
if (classe) {
|
|
57
|
+
pilhaClasses.push(classe[1]!);
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (trim.startsWith("};") || trim === "}" || trim === "};") {
|
|
61
|
+
pilhaClasses.pop();
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const metodoClasse = trim.match(/^(?:inline\s+|static\s+|virtual\s+|constexpr\s+)*(?:[\w:<>~*&]+\s+)+([A-Za-z_]\w*)\s*\(([^)]*)\)\s*(?:const)?\s*\{/);
|
|
66
|
+
if (metodoClasse && pilhaClasses.length > 0) {
|
|
67
|
+
const nomeClasse = pilhaClasses[pilhaClasses.length - 1]!;
|
|
68
|
+
const nomeMetodo = metodoClasse[1]!;
|
|
69
|
+
if (!["if", "for", "while", "switch"].includes(nomeMetodo)) {
|
|
70
|
+
const simbolo = `${nomeClasse}.${nomeMetodo}`;
|
|
71
|
+
if (!simbolos.has(simbolo)) {
|
|
72
|
+
simbolos.set(simbolo, {
|
|
73
|
+
simbolo,
|
|
74
|
+
parametros: extrairParametrosCpp(metodoClasse[2] ?? ""),
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return [...simbolos.values()];
|
|
82
|
+
}
|