@brunoluizdesiqueira/bbuilder-cli 1.0.6 → 1.0.8

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.
@@ -40,12 +40,12 @@ exports.buildCompilerFlags = buildCompilerFlags;
40
40
  exports.runCgrc = runCgrc;
41
41
  exports.runDcc64 = runDcc64;
42
42
  exports.runBuiltExecutable = runBuiltExecutable;
43
- const child_process_1 = require("child_process");
44
43
  const execa_1 = __importDefault(require("execa"));
45
44
  const fs = __importStar(require("fs"));
46
45
  const os = __importStar(require("os"));
47
46
  const path = __importStar(require("path"));
48
47
  const output_1 = require("../ui/output");
48
+ const delphiEnvCache = new Map();
49
49
  function buildCompilerFlags(buildType) {
50
50
  const baseDefines = 'DEBUG;ALT_CEF133_0;EUREKALOG';
51
51
  const releaseDefines = 'RELEASE;ALT_CEF133_0;EUREKALOG';
@@ -76,36 +76,57 @@ function buildDependencies(opts) {
76
76
  // dcc64 fail to resolve paths such as the Delphi runtime library.
77
77
  return opts.dependencyPaths.join(';');
78
78
  }
79
- function quoteForCmd(value) {
80
- if (!value)
81
- return '""';
82
- return `"${value.replace(/"/g, '\\"')}"`;
79
+ function parseWindowsEnv(output) {
80
+ const env = {};
81
+ for (const line of output.split(/\r?\n/)) {
82
+ const separatorIndex = line.indexOf('=');
83
+ if (separatorIndex <= 0)
84
+ continue;
85
+ const key = line.slice(0, separatorIndex).trim();
86
+ const value = line.slice(separatorIndex + 1);
87
+ if (!key)
88
+ continue;
89
+ env[key] = value;
90
+ }
91
+ return env;
83
92
  }
84
- async function runWindowsCommand(executable, args, cwd) {
85
- const command = [quoteForCmd(executable), ...args.map(quoteForCmd)].join(' ');
86
- await new Promise((resolve, reject) => {
87
- const child = (0, child_process_1.spawn)(command, {
88
- cwd,
89
- stdio: 'inherit',
90
- shell: true,
91
- });
92
- child.on('error', reject);
93
- child.on('exit', code => {
94
- if (code === 0) {
95
- resolve();
96
- return;
97
- }
98
- reject(new Error(`Command exited with code ${code ?? 'unknown'}`));
93
+ async function getDelphiEnvironment(delphiDir) {
94
+ const cached = delphiEnvCache.get(delphiDir);
95
+ if (cached) {
96
+ return cached;
97
+ }
98
+ const rsvarsPath = path.win32.join(delphiDir, 'bin', 'rsvars.bat');
99
+ if (!fs.existsSync(rsvarsPath)) {
100
+ (0, output_1.fatal)(`Arquivo não encontrado: ${rsvarsPath}`);
101
+ }
102
+ try {
103
+ const command = `call "${rsvarsPath}" >nul && set`;
104
+ const result = await (0, execa_1.default)('cmd.exe', ['/d', '/s', '/c', `"${command}"`], {
105
+ env: process.env,
99
106
  });
100
- });
107
+ const resolved = {
108
+ ...process.env,
109
+ ...parseWindowsEnv(result.stdout),
110
+ };
111
+ delphiEnvCache.set(delphiDir, resolved);
112
+ return resolved;
113
+ }
114
+ catch (error) {
115
+ const message = error instanceof Error ? error.message : String(error);
116
+ (0, output_1.fatal)(`Falha ao carregar o ambiente do Delphi via rsvars.bat (${rsvarsPath}). Detalhe: ${message}`);
117
+ }
101
118
  }
102
119
  async function runCgrc(opts, projectName) {
103
120
  const tempDir = path.join(os.tmpdir(), `BimerBuild_${projectName}`);
104
121
  const vrcFile = path.join(tempDir, `${projectName}.vrc`);
105
122
  const resFile = path.join(tempDir, `${projectName}.res`);
123
+ const delphiEnv = await getDelphiEnvironment(opts.delphiDir);
106
124
  (0, output_1.step)('Compilando recursos e embutindo ícone...');
107
125
  try {
108
- await runWindowsCommand(path.win32.join(opts.delphiDir, 'bin', 'cgrc.exe'), [vrcFile, `-fo${resFile}`]);
126
+ await (0, execa_1.default)(path.win32.join(opts.delphiDir, 'bin', 'cgrc.exe'), [vrcFile, `-fo${resFile}`], {
127
+ env: delphiEnv,
128
+ stdio: 'inherit',
129
+ });
109
130
  }
110
131
  catch {
111
132
  (0, output_1.fatal)('Falha do compilador CGRC ao gerar o arquivo de recursos .res.');
@@ -117,6 +138,7 @@ async function runDcc64(opts, projectName, workspaceDir) {
117
138
  const deps = buildDependencies(opts);
118
139
  const exeOut = path.win32.join('C:\\Temp', opts.envVersion, 'EXE');
119
140
  const dcuOut = path.win32.join('C:\\Temp', opts.envVersion, 'DCU');
141
+ const delphiEnv = await getDelphiEnvironment(opts.delphiDir);
120
142
  if (!fs.existsSync(exeOut))
121
143
  fs.mkdirSync(exeOut, { recursive: true });
122
144
  if (!fs.existsSync(dcuOut))
@@ -148,7 +170,11 @@ async function runDcc64(opts, projectName, workspaceDir) {
148
170
  `${projectName}.dpr`,
149
171
  ];
150
172
  try {
151
- await runWindowsCommand(dcc64, args, workspaceDir);
173
+ await (0, execa_1.default)(dcc64, args, {
174
+ cwd: workspaceDir,
175
+ env: delphiEnv,
176
+ stdio: 'inherit',
177
+ });
152
178
  }
153
179
  catch {
154
180
  (0, output_1.fatal)('Falha na compilação do Delphi. Verifique os logs de erro acima.');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brunoluizdesiqueira/bbuilder-cli",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "CLI de build local para projetos Delphi do Bimer",
5
5
  "license": "ISC",
6
6
  "repository": {