Skip to content

Commit

Permalink
Add public flag
Browse files Browse the repository at this point in the history
  • Loading branch information
vilicvane committed Nov 22, 2023
1 parent d135832 commit 05d56d2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
24 changes: 13 additions & 11 deletions src/cli/@publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,26 @@ import Chalk from 'chalk';

import type {PatchedPackageEntry} from './@patch';

export async function publish({
packageDir,
originalName,
patchedName,
patchedVersion,
}: PatchedPackageEntry): Promise<void> {
export async function publish(
{packageDir, originalName, patchedName, patchedVersion}: PatchedPackageEntry,
publicAccess: boolean,
): Promise<void> {
console.info(
Chalk.red('publishing'),
`${patchedName}${Chalk.dim(
`@${patchedVersion} (originally ${originalName})`,
)}`,
);

const cp = spawn('npm', ['publish'], {
cwd: packageDir,
stdio: 'inherit',
shell: true,
});
const cp = spawn(
'npm',
['publish', ...(publicAccess ? ['--access', 'public'] : [])],
{
cwd: packageDir,
stdio: 'inherit',
shell: true,
},
);

const [code] = (await once(cp, 'exit')) as [number];

Expand Down
9 changes: 6 additions & 3 deletions src/cli/commands/publish.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Command, Errors} from '@oclif/core';
import {Command, Errors, Flags} from '@oclif/core';

import {COMMON_FLAGS} from '../@command';
import {hasUnstagedChanges, resetUnstagedChanges} from '../@git';
Expand All @@ -8,7 +8,7 @@ import {publish} from '../@publish';
export class PublishCommand extends Command {
override async run(): Promise<void> {
const {
flags: {scope, package: packagePatterns},
flags: {scope, package: packagePatterns, public: publicAccess},
} = await this.parse(PublishCommand);

const cwd = process.cwd();
Expand All @@ -22,7 +22,7 @@ export class PublishCommand extends Command {
const entries = await patch(cwd, packagePatterns, scope);

for (const entry of entries) {
await publish(entry);
await publish(entry, publicAccess);
}

await resetUnstagedChanges(cwd);
Expand All @@ -39,5 +39,8 @@ export class PublishCommand extends Command {

static override flags = {
...COMMON_FLAGS,
public: Flags.boolean({
description: 'Append "--access public" to npm publish command.',
}),
};
}

0 comments on commit 05d56d2

Please sign in to comment.