Skip to content

Commit

Permalink
feat: support quick release mode
Browse files Browse the repository at this point in the history
  • Loading branch information
linbudu599 committed Apr 8, 2022
1 parent baeaf08 commit c8cf460
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 55 deletions.
2 changes: 1 addition & 1 deletion packages/rtt/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@llab/rtt",
"version": "0.0.2-4",
"version": "0.0.4",
"description": "",
"main": "./dist/index.js",
"license": "MIT",
Expand Down
117 changes: 63 additions & 54 deletions scripts/release/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ export default function useReleaseProject(cli: CAC) {
) => {
const { dry = false, quick = false } = options ?? {};

if (quick) releaseType = 'patch';

const dryRunInfoLogger = (msg: MaybeArray<string>) =>
dry
? consola.info(
Expand Down Expand Up @@ -109,7 +111,6 @@ export default function useReleaseProject(cli: CAC) {
} else {
projectReleaseType = releaseType;
}
} else if (quick) {
} else {
projectReleaseType = (
await enquirer.prompt<{ type: ReleaseType }>({
Expand All @@ -128,6 +129,8 @@ export default function useReleaseProject(cli: CAC) {
'package.json'
);

consola.info(`Release Type: ${chalk.cyan(projectReleaseType)}`);

const { version: rawVersion, name: packageName } =
CLIUtils.readJsonSync<PackageJson>(projectPackageJsonPath);

Expand All @@ -153,7 +156,9 @@ export default function useReleaseProject(cli: CAC) {

dryRunInfoLogger(`Release ${chalk.cyan(releaseTag)}?`);

const confirmVersion = await CLIUtils.createConfirmSelector('Confirm?');
const confirmVersion = quick
? true
: await CLIUtils.createConfirmSelector('Confirm?');

if (!confirmVersion) {
consola.info('Release aborted.');
Expand Down Expand Up @@ -194,62 +199,66 @@ export default function useReleaseProject(cli: CAC) {
)}) built successfully.`
);

const { stdout } = await execa('git', ['diff'], {
stdio: 'pipe',
cwd: projectDirPath,
});
if (quick) {
consola.info(`Quick release mode. Skipping git flow.`);
} else {
const { stdout } = await execa('git', ['diff'], {
stdio: 'pipe',
cwd: projectDirPath,
});

if (!stdout) {
consola.error('No commit changes found, exit.');
process.exit(0);
}
if (!stdout) {
consola.error('No commit changes found, exit.');
process.exit(0);
}

await CLIUtils.useChildProcess(
`git add ${projectDirPath} --verbose --dry-run`
);
await CLIUtils.useChildProcess(
`git add ${projectDirPath} --verbose --dry-run`
);

const gitCZCommandArgs = [
'--type=release',
`--scope=${projectToRelease.split('-')[0]}`,
`--subject=Release ${releaseTag}`,
'--non-interactive',
];

dry
? consola.info(
`${chalk.white('DRY RUN MODE')}: Executing >>> ${chalk.cyan(
`git-cz ${gitCZCommandArgs.join(' ')}`
)}`
)
: await CLIUtils.useChildProcess(
`git-cz --${gitCZCommandArgs.join('')}`
);
const gitCZCommandArgs = [
'--type=release',
`--scope=${projectToRelease.split('-')[0]}`,
`--subject=Release ${releaseTag}`,
'--non-interactive',
];

dry
? consola.info(
`${chalk.white('DRY RUN MODE')}: Executing >>> ${chalk.cyan(
`git tag ${releaseTag}`
)}`
)
: await CLIUtils.useChildProcess(`git tag ${releaseTag}`);

dry
? consola.info(
`${chalk.white('DRY RUN MODE')}: Executing >>> ${chalk.cyan(
`git push origin refs/tags/${releaseTag} --verbose --progress`
)}`
)
: await CLIUtils.useChildProcess(
`git ${[
'push',
'origin',
`refs/tags/${releaseTag}`,
'--verbose',
'--progress',
].join(' ')}`
);
dry
? consola.info(
`${chalk.white('DRY RUN MODE')}: Executing >>> ${chalk.cyan(
`git-cz ${gitCZCommandArgs.join(' ')}`
)}`
)
: await CLIUtils.useChildProcess(
`git-cz --${gitCZCommandArgs.join('')}`
);

dry
? consola.info(
`${chalk.white('DRY RUN MODE')}: Executing >>> ${chalk.cyan(
`git tag ${releaseTag}`
)}`
)
: await CLIUtils.useChildProcess(`git tag ${releaseTag}`);

dry
? consola.info(
`${chalk.white('DRY RUN MODE')}: Executing >>> ${chalk.cyan(
`git push origin refs/tags/${releaseTag} --verbose --progress`
)}`
)
: await CLIUtils.useChildProcess(
`git ${[
'push',
'origin',
`refs/tags/${releaseTag}`,
'--verbose',
'--progress',
].join(' ')}`
);
}

dryRunInfoLogger(['Pubishing package...']);
dryRunInfoLogger('Pubishing package...');

const { stdout: logAs } = await execa(
'npm',
Expand Down Expand Up @@ -280,7 +289,7 @@ export default function useReleaseProject(cli: CAC) {
}
);

dryRunSuccessLogger(['Package published.']);
dryRunSuccessLogger('Package published.');
}
);
}
Expand Down

0 comments on commit c8cf460

Please sign in to comment.