MCPcopy
hub / github.com/ionic-team/capacitor / runPlatformHook

Function runPlatformHook

cli/src/common.ts:160–206  ·  view source on GitHub ↗
(
  config: Config,
  platformName: string,
  platformDir: string,
  hook: string,
)

Source from the content-addressed store, hash-verified

158}
159
160export 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
208export interface RunTaskOptions {
209 spinner?: boolean;

Callers 6

copyCommandFunction · 0.90
updateCommandFunction · 0.90
runCommandFunction · 0.90
addCommandFunction · 0.90
openCommandFunction · 0.90
runHooksFunction · 0.85

Calls 3

isNXMonorepoFunction · 0.90
findNXMonorepoRootFunction · 0.90
readJSONFunction · 0.85

Tested by

no test coverage detected