Skip to content

Commit c41e892

Browse files
fix: execution commands cwd
1 parent 2ac630a commit c41e892

1 file changed

Lines changed: 47 additions & 14 deletions

File tree

index.js

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,10 @@ const runGlobalInstall = (command = 'i') => {
276276
continue;
277277
}
278278

279-
childProcess.execSync(`cd ${msDir} && npm ${command}`, { stdio: 'inherit' });
279+
childProcess.execSync(`npm ${command}`, {
280+
stdio: 'inherit',
281+
cwd: msDir,
282+
});
280283

281284
console.info(`Install done: ${msDir}`);
282285
}
@@ -305,7 +308,10 @@ const runGlobalUpdate = (packageName, version = null) => {
305308
);
306309
}
307310

308-
childProcess.execSync(`cd ${msDir} && npm update ${packageName}`, { stdio: 'inherit' });
311+
childProcess.execSync(`npm update ${packageName}`, {
312+
stdio: 'inherit',
313+
cwd: msDir,
314+
});
309315

310316
console.info(`Package updated for: ${msDir}`);
311317
}
@@ -318,12 +324,18 @@ const runSemanticRelease = (isDryRun = false) => {
318324
const microservices = getMicroservices(true, true);
319325

320326
for (const msDir of microservices) {
321-
childProcess.execSync(`cd ${msDir} && npx semantic-release ${isDryRun ? '--dryRun' : ''}`, {
327+
console.info(chalk.blue(`Begin release: ${msDir}`));
328+
329+
childProcess.execSync(`npx semantic-release ${isDryRun ? '--dryRun' : ''}`, {
322330
stdio: 'inherit',
323-
env: { ...process.env },
331+
cwd: msDir,
332+
env: {
333+
...process.env,
334+
SEMANTIC_WORKING_DIR: msDir,
335+
},
324336
});
325337

326-
console.info(`Semantic release done: ${msDir}`);
338+
console.info(chalk.green(`Semantic release done: ${msDir}`));
327339
}
328340
};
329341

@@ -334,7 +346,10 @@ const runLintStaged = () => {
334346
const microservices = getMicroservices(true, true);
335347

336348
for (const msDir of microservices) {
337-
childProcess.execSync(`cd ${msDir} && npx lint-staged`, { stdio: 'inherit' });
349+
childProcess.execSync('npx lint-staged', {
350+
stdio: 'inherit',
351+
cwd: msDir,
352+
});
338353

339354
console.info(`Lint staged done: ${msDir}`);
340355
}
@@ -347,7 +362,10 @@ const runBuild = () => {
347362
const microservices = getMicroservices(true, true);
348363

349364
for (const msDir of microservices) {
350-
childProcess.execSync(`cd ${msDir} && npm run build`, { stdio: 'inherit' });
365+
childProcess.execSync('npm run build', {
366+
stdio: 'inherit',
367+
cwd: msDir,
368+
});
351369

352370
const packageJsonJs = `${msDir}/lib/package.json.js`;
353371

@@ -370,8 +388,9 @@ const runTests = (withCoverage = false) => {
370388
const microservices = getMicroservices(true, true);
371389

372390
for (const msDir of microservices) {
373-
childProcess.execSync(`cd ${msDir} && ${withCoverage ? 'nyc' : ''} npm run test`, {
391+
childProcess.execSync(`${withCoverage ? 'nyc' : ''} npm run test`, {
374392
stdio: 'inherit',
393+
cwd: msDir,
375394
});
376395

377396
console.info(`Tests done: ${msDir}`);
@@ -385,7 +404,10 @@ const runCheckTypescript = () => {
385404
const microservices = getMicroservices(true, true);
386405

387406
for (const msDir of microservices) {
388-
childProcess.execSync(`cd ${msDir} && npm run ts:check`, { stdio: 'inherit' });
407+
childProcess.execSync('npm run ts:check', {
408+
stdio: 'inherit',
409+
cwd: msDir,
410+
});
389411

390412
console.info(`Typescript check done: ${msDir}`);
391413
}
@@ -418,7 +440,10 @@ const runLint = (shouldFix = false) => {
418440
const action = shouldFix ? 'fix' : 'check'
419441

420442
for (const msDir of microservices) {
421-
childProcess.execSync(`cd ${msDir} && npm run lint:${action}`, { stdio: 'inherit' });
443+
childProcess.execSync(`npm run lint:${action}`, {
444+
stdio: 'inherit',
445+
cwd: msDir,
446+
});
422447

423448
console.info(`Lint check done: ${msDir}`);
424449
}
@@ -679,11 +704,13 @@ const runExtendMicroservice = async (name, isStaging) => {
679704
replaceStrInFile('microservice-name', `microservice-${name}`, `${msSrcPath}/config/start.ts`);
680705
replaceStrInFile('microservice-name', `microservice-${name}`, `${msPath}/package.json`);
681706

682-
childProcess.execSync(`cd ${msPath} && npm i --save require-in-the-middle`, {
707+
childProcess.execSync('npm i --save require-in-the-middle', {
683708
stdio: 'inherit',
709+
cwd: msPath,
684710
});
685-
childProcess.execSync(`cd ${msPath} && npm i --save @lomray/microservice-${name}`, {
711+
childProcess.execSync(`npm i --save @lomray/microservice-${name}`, {
686712
stdio: 'inherit',
713+
cwd: msPath,
687714
});
688715

689716
break;
@@ -770,7 +797,10 @@ const runInitProject = async (name, isStaging) => {
770797
replaceStrInFile('"@lomray/microservices"', `"${appName}"`, `${root}/package-lock.json`);
771798
replaceStrInFile('Lomray-Software/microservices', repoName, `${root}/.github/workflows/build.yml`);
772799

773-
childProcess.execSync(`cd ${root} && npm ci --ignore-scripts`, { stdio: 'inherit' });
800+
childProcess.execSync('npm ci --ignore-scripts', {
801+
stdio: 'inherit',
802+
cwd: root,
803+
});
774804

775805
console.info(chalk.green('Done!'));
776806
}
@@ -841,7 +871,10 @@ const runAuthorizationPermissions = async (act, isProd) => {
841871

842872
console.log(`Seems like microservice running type is: ${chalk.green('node')}.`);
843873

844-
childProcess.execSync(`cd ${getMsFolder()}/authorization && npm run ${npmCommand}:${isProd ? 'prod' : 'dev'}`, { stdio: 'inherit' });
874+
childProcess.execSync(`npm run ${npmCommand}:${isProd ? 'prod' : 'dev'}`, {
875+
stdio: 'inherit',
876+
cwd: `${getMsFolder()}/authorization`,
877+
});
845878
}
846879

847880
program

0 commit comments

Comments
 (0)