( config: Config, platformName: string, platformDir: string, hook: string, )
| 158 | } |
| 159 | |
| 160 | export async function runPlatformHook( |
| 161 | config: Config, |
| 162 | platformName: string, |
| 163 | platformDir: string, |
| 164 | hook: string, |
| 165 | ): Promise<void> { |
| 166 | const { spawn } = await import('child_process'); |
| 167 | let pkg; |
| 168 | if (isNXMonorepo(platformDir)) { |
| 169 | pkg = await readJSON(join(findNXMonorepoRoot(platformDir), 'package.json')); |
| 170 | } else { |
| 171 | pkg = await readJSON(join(platformDir, 'package.json')); |
| 172 | } |
| 173 | const cmd = pkg.scripts?.[hook]; |
| 174 | |
| 175 | if (!cmd) { |
| 176 | return; |
| 177 | } |
| 178 | |
| 179 | return new Promise((resolve, reject) => { |
| 180 | const p = spawn(cmd, { |
| 181 | stdio: 'inherit', |
| 182 | shell: true, |
| 183 | cwd: platformDir, |
| 184 | env: { |
| 185 | INIT_CWD: platformDir, |
| 186 | CAPACITOR_ROOT_DIR: config.app.rootDir, |
| 187 | CAPACITOR_WEB_DIR: config.app.webDirAbs, |
| 188 | CAPACITOR_CONFIG: JSON.stringify(config.app.extConfig), |
| 189 | CAPACITOR_PLATFORM_NAME: platformName, |
| 190 | ...process.env, |
| 191 | }, |
| 192 | }); |
| 193 | p.on('close', (code) => { |
| 194 | if (code === 0) { |
| 195 | resolve(); |
| 196 | } else { |
| 197 | reject( |
| 198 | new Error(`${hook} hook on ${platformName} failed with error code: ${code} while running command: ${cmd}`), |
| 199 | ); |
| 200 | } |
| 201 | }); |
| 202 | p.on('error', (err) => { |
| 203 | reject(err); |
| 204 | }); |
| 205 | }); |
| 206 | } |
| 207 | |
| 208 | export interface RunTaskOptions { |
| 209 | spinner?: boolean; |
no test coverage detected