Skip to content

Commit

Permalink
Add logging. Fix push. Fix build exiting early when publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
Exidex committed Jan 29, 2024
1 parent 554766d commit a8ae5d8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { rollup, RollupBuild } from "rollup";
import { parseManifest, readManifest, rollupInputOptions, rollupOutputOptions, writeDistManifest } from "./config";


export async function build() {
export async function build(exit: boolean) {
console.log("Building...")
const manifestText = readManifest();

const manifest = parseManifest(manifestText);
Expand All @@ -24,6 +25,8 @@ export async function build() {
await rollupBuild.close();
}

process.exit(buildFailed ? 1 : 0);
if (exit) {
process.exit(buildFailed ? 1 : 0);
}
}

2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ program.command('dev')
program.command('build')
.description('Build a plugin')
.action(async () => {
await build()
await build(true)
});

program.command('publish')
Expand Down
13 changes: 10 additions & 3 deletions src/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import os from 'node:os';
import { build } from "./build";

export async function publish() {
await build()
await build(false)

const projectDir = process.cwd();
const projectGit = simpleGit(projectDir);
Expand All @@ -22,6 +22,7 @@ export async function publish() {

try {
// clone git repo into /tmp
console.log("Cloning repository to temporary directory...")
await simpleGit().clone(originUrl, tmpDir);
const cloneGit = simpleGit(tmpDir);

Expand All @@ -39,11 +40,14 @@ export async function publish() {
// create if detached branch doesn't exist
// switch to release branch
if (createBranch) {
console.log("Creating and switching to 'release' branch...")
await cloneGit.raw('checkout', '--orphan', 'release')
} else {
console.log("Switching to 'release' branch...")
await cloneGit.raw('checkout', 'release')
}

console.log("Copying data to 'release' branch...")
// remove everything from tmp repo
await cloneGit.raw('rm', '-rf', '.');

Expand All @@ -55,17 +59,20 @@ export async function publish() {
await cloneGit.raw('add', '-A')

// commit
console.log("Committing 'release' branch...")
const commitHashRaw = await projectGit.raw('rev-parse', 'HEAD')
const commitHash = commitHashRaw.trim()
await cloneGit.commit(`chore: deploy ${commitHash}`)

// add current version tag (overwrite if exists)
console.log("Tagging current version...")
await cloneGit.raw('tag', '--force', 'current-version', commitHash)

console.log("Pushing to 'origin' remote...")
// push
await cloneGit.push()
await cloneGit.push(['--set-upstream', "origin", 'release'])
// push tags
await cloneGit.pushTags()
await cloneGit.pushTags("origin")
} finally {
await rm(tmpDir, { recursive: true, force: true })
}
Expand Down

0 comments on commit a8ae5d8

Please sign in to comment.