@brunoluizdesiqueira/bbuilder-cli 1.0.6 → 1.0.7

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,55 @@ 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 result = await (0, execa_1.default)('cmd.exe', ['/d', '/s', '/c', `call "${rsvarsPath}" >nul && set`], {
104
+ env: process.env,
99
105
  });
100
- });
106
+ const resolved = {
107
+ ...process.env,
108
+ ...parseWindowsEnv(result.stdout),
109
+ };
110
+ delphiEnvCache.set(delphiDir, resolved);
111
+ return resolved;
112
+ }
113
+ catch {
114
+ (0, output_1.fatal)('Falha ao carregar o ambiente do Delphi via rsvars.bat.');
115
+ }
101
116
  }
102
117
  async function runCgrc(opts, projectName) {
103
118
  const tempDir = path.join(os.tmpdir(), `BimerBuild_${projectName}`);
104
119
  const vrcFile = path.join(tempDir, `${projectName}.vrc`);
105
120
  const resFile = path.join(tempDir, `${projectName}.res`);
121
+ const delphiEnv = await getDelphiEnvironment(opts.delphiDir);
106
122
  (0, output_1.step)('Compilando recursos e embutindo ícone...');
107
123
  try {
108
- await runWindowsCommand(path.win32.join(opts.delphiDir, 'bin', 'cgrc.exe'), [vrcFile, `-fo${resFile}`]);
124
+ await (0, execa_1.default)(path.win32.join(opts.delphiDir, 'bin', 'cgrc.exe'), [vrcFile, `-fo${resFile}`], {
125
+ env: delphiEnv,
126
+ stdio: 'inherit',
127
+ });
109
128
  }
110
129
  catch {
111
130
  (0, output_1.fatal)('Falha do compilador CGRC ao gerar o arquivo de recursos .res.');
@@ -117,6 +136,7 @@ async function runDcc64(opts, projectName, workspaceDir) {
117
136
  const deps = buildDependencies(opts);
118
137
  const exeOut = path.win32.join('C:\\Temp', opts.envVersion, 'EXE');
119
138
  const dcuOut = path.win32.join('C:\\Temp', opts.envVersion, 'DCU');
139
+ const delphiEnv = await getDelphiEnvironment(opts.delphiDir);
120
140
  if (!fs.existsSync(exeOut))
121
141
  fs.mkdirSync(exeOut, { recursive: true });
122
142
  if (!fs.existsSync(dcuOut))
@@ -148,7 +168,11 @@ async function runDcc64(opts, projectName, workspaceDir) {
148
168
  `${projectName}.dpr`,
149
169
  ];
150
170
  try {
151
- await runWindowsCommand(dcc64, args, workspaceDir);
171
+ await (0, execa_1.default)(dcc64, args, {
172
+ cwd: workspaceDir,
173
+ env: delphiEnv,
174
+ stdio: 'inherit',
175
+ });
152
176
  }
153
177
  catch {
154
178
  (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.7",
4
4
  "description": "CLI de build local para projetos Delphi do Bimer",
5
5
  "license": "ISC",
6
6
  "repository": {