Skip to content

Commit

Permalink
add --no-pull option to gro publish
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanatkn committed Jun 16, 2024
1 parent d9d32d8 commit f1b8fa7
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/witty-comics-hide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ryanatkn/gro': patch
---

add `--no-pull` option to `gro publish`
2 changes: 1 addition & 1 deletion src/lib/check.task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export const task: Task<Args> = {
log.error(red('git status'));
await spawn('git', ['status']);
throw new Task_Error(
'failed check for git_check_clean_workspace:' +
'Failed check for git_check_clean_workspace:' +
error_message +
' - do you need to run `gro sync` or commit some files?',
);
Expand Down
24 changes: 19 additions & 5 deletions src/lib/publish.task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ import {IS_THIS_GRO} from './paths.js';
import {has_sveltekit_library} from './sveltekit_helpers.js';
import {update_changelog} from './changelog.js';
import {load_from_env} from './env.js';
import {Git_Branch, Git_Origin, git_checkout, git_fetch, git_pull} from './git.js';
import {
Git_Branch,
Git_Origin,
git_check_clean_workspace,
git_checkout,
git_fetch,
git_pull,
} from './git.js';

// publish.task.ts
// - usage: `gro publish patch`
Expand Down Expand Up @@ -45,6 +52,8 @@ export const Args = z
.default(false),
build: z.boolean({description: 'dual of no-build'}).default(true),
'no-build': z.boolean({description: 'opt out of building'}).default(false),
pull: z.boolean({description: 'dual of no-pull'}).default(true),
'no-pull': z.boolean({description: 'opt out of git pull'}).default(false),
})
.strict();
export type Args = z.infer<typeof Args>;
Expand All @@ -53,7 +62,7 @@ export const task: Task<Args> = {
summary: 'bump version, publish to npm, and git push',
Args,
run: async ({args, log, invoke_task}): Promise<void> => {
const {branch, origin, changelog, preserve_changelog, dry, check, install, build} = args;
const {branch, origin, changelog, preserve_changelog, dry, check, install, build, pull} = args;
if (dry) {
log.info(green('dry run!'));
}
Expand All @@ -74,14 +83,19 @@ export const task: Task<Args> = {

if (!(await find_cli('changeset'))) {
throw new Task_Error(
'changeset command not found: install @changesets/cli locally or globally',
'changeset command not found, install @changesets/cli locally or globally',
);
}

// Make sure we're on the right branch:
await git_fetch(origin, branch);
await git_checkout(branch);
await git_pull(origin, branch);
if (pull) {
if (await git_check_clean_workspace()) {
throw new Task_Error('The git workspace is not clean, pass --no-pull to bypass git pull');
}
await git_pull(origin, branch);
}

// Check before proceeding.
if (check) {
Expand All @@ -100,7 +114,7 @@ export const task: Task<Args> = {
} else {
const package_json_before = await load_package_json();
if (typeof package_json_before.version !== 'string') {
throw new Task_Error('failed to find package.json version');
throw new Task_Error('Failed to find package.json version');
}
const parsed_repo_url = parse_repo_url(package_json_before);
if (!parsed_repo_url) {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/reinstall.task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const task: Task<Args> = {
log.info('running the initial npm install');
const initial_install_result = await spawn('npm', ['i']);
if (!initial_install_result.ok) {
throw new Task_Error('failed initial npm install');
throw new Task_Error('Failed initial npm install');
}

// Deleting both the lockfile and node_modules upgrades to the latest minor/patch versions.
Expand All @@ -26,7 +26,7 @@ export const task: Task<Args> = {
const second_install_result = await spawn('npm', ['i']);
if (!second_install_result.ok) {
throw new Task_Error(
`failed npm install after deleting ${LOCKFILE_FILENAME} and ${NODE_MODULES_DIRNAME}`,
`Failed npm install after deleting ${LOCKFILE_FILENAME} and ${NODE_MODULES_DIRNAME}`,
);
}

Expand All @@ -36,7 +36,7 @@ export const task: Task<Args> = {
log.info(`running npm install one last time to clean ${LOCKFILE_FILENAME}`);
const final_install_result = await spawn('npm', ['i']);
if (!final_install_result.ok) {
throw new Task_Error('failed npm install');
throw new Task_Error('Failed npm install');
}
},
};
2 changes: 1 addition & 1 deletion src/lib/run.task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const task: Task<Args> = {
}

if (!(await exists(path))) {
throw new Task_Error('cannot find file to run at path: ' + path);
throw new Task_Error('Cannot find file to run at path: ' + path);
}

const loader_path = await resolve_gro_module_path('loader.js');
Expand Down
4 changes: 2 additions & 2 deletions src/lib/sveltekit_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ export const has_sveltekit_library = async (

export const sveltekit_sync = async (): Promise<void> => {
if (!(await find_cli(SVELTEKIT_CLI))) {
throw new Task_Error(`failed to find ${SVELTEKIT_CLI} CLI - do you need to run \`npm i\`?`);
throw new Task_Error(`Failed to find ${SVELTEKIT_CLI} CLI - do you need to run \`npm i\`?`);
}
const result = await spawn_cli(SVELTEKIT_CLI, ['sync']);
if (!result?.ok) {
throw new Task_Error(`failed ${SVELTEKIT_CLI} sync`);
throw new Task_Error(`Failed ${SVELTEKIT_CLI} sync`);
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/lib/sync.task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const task: Task<Args> = {
if (install) {
const result = await spawn('npm', ['i']);
if (!result.ok) {
throw new Task_Error('failed npm install');
throw new Task_Error('Failed npm install');
}
}

Expand Down

0 comments on commit f1b8fa7

Please sign in to comment.