Skip to content

Commit

Permalink
Merge pull request #196 from codemod-js/abort-semantic-release-monorepo
Browse files Browse the repository at this point in the history
Abort semantic release monorepo
  • Loading branch information
eventualbuddha authored Jan 3, 2019
2 parents b58704c + 751d668 commit e226dc2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 52 deletions.
17 changes: 1 addition & 16 deletions script/_commands/release.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,10 @@
import runInPackages from '../_utils/runInPackages';
import runInDirectory from '../_utils/runInDirectory';

export default async function main(
args: Array<string>,
stdin: NodeJS.ReadStream,
stdout: NodeJS.WriteStream,
stderr: NodeJS.WriteStream
): Promise<void> {
await runInDirectory(
stdin,
stdout,
stderr,
'.',
'npm',
['install', '-g', 'semantic-release', 'semantic-release-monorepo']
);
await runInPackages(
stdin,
stdout,
stderr,
'semantic-release',
['-e', 'semantic-release-monorepo']
);
await runInPackages(stdin, stdout, stderr, 'npx', ['semantic-release']);
}
34 changes: 0 additions & 34 deletions script/_utils/runInDirectory.ts

This file was deleted.

37 changes: 35 additions & 2 deletions script/_utils/runInPackages.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as globby from 'globby';
import { spawn } from 'child_process';
import { readFile } from 'mz/fs';
import { join } from 'path';
import runInDirectory from './runInDirectory';

export default async function runInPackages(
stdin: NodeJS.ReadStream,
Expand All @@ -12,10 +12,43 @@ export default async function runInPackages(
packages?: Array<string>
): Promise<void> {
for (const pkg of await (packages || findPackages())) {
await runInDirectory(stdin, stdout, stderr, pkg, command, args);
await runForPackage(stdin, stdout, stderr, pkg, command, args);
}
}

async function runForPackage(
stdin: NodeJS.ReadStream,
stdout: NodeJS.WriteStream,
stderr: NodeJS.WriteStream,
pkg: string,
command: string,
args: Array<string> = []
): Promise<void> {
return new Promise<void>((resolve, reject) => {
stdout.write(`${pkg}${command} ${args.join(' ')}\n`);

const child = spawn(
command,
args,
{
cwd: pkg,
stdio: [stdin, stdout, stderr]
});

child.on('exit', code => {
if (code === 0) {
resolve();
} else {
reject(new Error(`exit status was ${code} for command: ${command} args: [${args.join(' ')}]`));
}
});

child.on('error', error => {
reject(error);
});
});
}

async function findPackages(): Promise<Array<string>> {
const globs = JSON.parse(await readFile(join(__dirname, '../../package.json'), 'utf8')).workspaces;
return await globby(globs, { onlyDirectories: true });
Expand Down

0 comments on commit e226dc2

Please sign in to comment.