Package Release: Add release script (#33743)
This commit is contained in:
parent
537c8c44c7
commit
7fad8728ce
1665
pnpm-lock.yaml
1665
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
|
@ -20,13 +20,13 @@ import {
|
|||
} from '../../changelogger';
|
||||
|
||||
/**
|
||||
* PackageRelease class
|
||||
* PackagePrepare class
|
||||
*/
|
||||
export default class PackageRelease extends Command {
|
||||
export default class PackagePrepare extends Command {
|
||||
/**
|
||||
* CLI description
|
||||
*/
|
||||
static description = 'Release Monorepo JS packages';
|
||||
static description = 'Prepare Monorepo JS packages for Release';
|
||||
|
||||
/**
|
||||
* CLI arguments
|
||||
|
@ -55,7 +55,7 @@ export default class PackageRelease extends Command {
|
|||
* This method is called to execute the command
|
||||
*/
|
||||
async run(): Promise< void > {
|
||||
const { args, flags } = await this.parse( PackageRelease );
|
||||
const { args, flags } = await this.parse( PackagePrepare );
|
||||
|
||||
if ( ! args.packages && ! flags.all ) {
|
||||
this.error( 'No packages supplied.' );
|
||||
|
|
|
@ -0,0 +1,134 @@
|
|||
/**
|
||||
* External dependencies
|
||||
*/
|
||||
import { CliUx, Command, Flags } from '@oclif/core';
|
||||
import { execSync } from 'child_process';
|
||||
|
||||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
import {
|
||||
getAllPackges,
|
||||
validatePackage,
|
||||
getFilepathFromPackageName,
|
||||
} from '../../validate';
|
||||
import { MONOREPO_ROOT } from '../../const';
|
||||
|
||||
/**
|
||||
* PackageRelease class
|
||||
*/
|
||||
export default class PackageRelease extends Command {
|
||||
/**
|
||||
* CLI description
|
||||
*/
|
||||
static description = 'Release Monorepo JS packages';
|
||||
|
||||
/**
|
||||
* CLI arguments
|
||||
*/
|
||||
static args = [
|
||||
{
|
||||
name: 'packages',
|
||||
description:
|
||||
'Package to release, or packages to release separated by commas.',
|
||||
required: false,
|
||||
},
|
||||
];
|
||||
|
||||
/**
|
||||
* CLI flags.
|
||||
*/
|
||||
static flags = {
|
||||
all: Flags.boolean( {
|
||||
char: 'a',
|
||||
default: false,
|
||||
description: 'Perform prepare function on all packages.',
|
||||
} ),
|
||||
'dry-run': Flags.boolean( {
|
||||
char: 'd',
|
||||
default: false,
|
||||
description: 'Perform a dry run of pnpm publish',
|
||||
} ),
|
||||
branch: Flags.string( {
|
||||
char: 'b',
|
||||
description: 'Branch name to publish from',
|
||||
default: 'trunk',
|
||||
} ),
|
||||
'skip-install': Flags.boolean( {
|
||||
description: 'Skip pnpm install',
|
||||
default: false,
|
||||
} ),
|
||||
};
|
||||
|
||||
/**
|
||||
* This method is called to execute the command
|
||||
*/
|
||||
async run(): Promise< void > {
|
||||
const { args, flags } = await this.parse( PackageRelease );
|
||||
|
||||
if ( ! args.packages && ! flags.all ) {
|
||||
this.error( 'No packages supplied.' );
|
||||
}
|
||||
|
||||
if ( ! flags[ 'skip-install' ] ) {
|
||||
CliUx.ux.action.start( 'Installing all dependencies' );
|
||||
|
||||
execSync( 'pnpm install', {
|
||||
cwd: MONOREPO_ROOT,
|
||||
encoding: 'utf-8',
|
||||
stdio: 'inherit',
|
||||
} );
|
||||
|
||||
CliUx.ux.action.stop();
|
||||
}
|
||||
|
||||
if ( flags.all ) {
|
||||
this.publishPackages( getAllPackges(), flags );
|
||||
return;
|
||||
}
|
||||
|
||||
const packages = args.packages.split( ',' );
|
||||
|
||||
packages.forEach( ( name: string ) =>
|
||||
validatePackage( name, ( e: string ): void => this.error( e ) )
|
||||
);
|
||||
|
||||
this.publishPackages( packages, flags );
|
||||
}
|
||||
|
||||
/**
|
||||
* Publish packages for release.
|
||||
*
|
||||
* @param {Array<string>} packages Packages to prepare.
|
||||
* @param {boolean} dryRun pnpm dry run.
|
||||
*/
|
||||
private publishPackages(
|
||||
packages: Array< string >,
|
||||
{ 'dry-run': dryRun, branch }: { 'dry-run': boolean; branch: string }
|
||||
) {
|
||||
packages.forEach( ( name ) => {
|
||||
const verb = dryRun ? 'Performing dry run of' : 'Publishing';
|
||||
CliUx.ux.action.start( `${ verb } ${ name }` );
|
||||
|
||||
try {
|
||||
const cwd = getFilepathFromPackageName( name );
|
||||
return execSync(
|
||||
`SKIP_TURBO=true pnpm publish ${
|
||||
dryRun ? '--dry-run' : ''
|
||||
} --publish-branch=${ branch }`,
|
||||
{
|
||||
cwd,
|
||||
encoding: 'utf-8',
|
||||
stdio: 'inherit',
|
||||
}
|
||||
);
|
||||
} catch ( e ) {
|
||||
if ( e instanceof Error ) {
|
||||
this.error( e.message );
|
||||
}
|
||||
}
|
||||
|
||||
CliUx.ux.action.stop();
|
||||
} );
|
||||
}
|
||||
}
|
|
@ -1,8 +1,16 @@
|
|||
if ( ! process.env.TURBO_HASH ) {
|
||||
console.error( 'This project uses Turborepo. You should not run this script from the project directly.' );
|
||||
if ( ! process.env.TURBO_HASH && process.env.SKIP_TURBO !== 'true' ) {
|
||||
console.error(
|
||||
'This project uses Turborepo. You should not run this script from the project directly.'
|
||||
);
|
||||
if ( process.env.npm_lifecycle_event && process.env.npm_package_name ) {
|
||||
console.error( "\nTry running the following from the root of the monorepo instead:" );
|
||||
console.error( "pnpm -- turbo run %s --filter=%s\n", process.env.npm_lifecycle_event, process.env.npm_package_name );
|
||||
console.error(
|
||||
'\nTry running the following from the root of the monorepo instead:'
|
||||
);
|
||||
console.error(
|
||||
'pnpm -- turbo run %s --filter=%s\n',
|
||||
process.env.npm_lifecycle_event,
|
||||
process.env.npm_package_name
|
||||
);
|
||||
}
|
||||
process.exit( 1 );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue