New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

branch-deploy

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

branch-deploy - npm Package Compare versions

Comparing version

to
0.1.0

66

index.js
import chalk from 'chalk'
import { Command } from 'commander'
import { readFile } from 'fs/promises'
import inquirer from 'inquirer'

@@ -6,7 +8,22 @@ import { exit } from 'process'

// @TODO: configurable
const packageJson = JSON.parse(await readFile('package.json', 'utf8'))
const remoteName = 'origin'
const branchNamePrefix = 'deploy'
const program = new Command()
program
.name('branch-deploy')
.description('Makes deploy by push easier.')
.version(packageJson.version)
.option('-a, --all', 'push to all deploy branches', false)
.option('-r, --remote <name>', 'remote name', 'origin')
.option('-p, --prefix <string>', 'filter branches by prefix', 'deploy')
program.parse(process.argv)
const options = program.opts()
const remoteName = options.remote
const branchNamePrefix = options.prefix
const git = (() => {

@@ -57,3 +74,3 @@ try {

chalk.red(
`Not a single deploy branch found in ${chalk.magenta(
`Not a single deploy branch found in remote ${chalk.magenta(
remoteName,

@@ -66,15 +83,19 @@ )} starting with ${chalk.magenta(branchNamePrefix)}.`,

const targetBranches =
deployBranches.length === 1
? deployBranches // @TODO: ask for confirmation
: (
await inquirer.prompt({
type: 'checkbox',
name: 'result',
message: `Which branch do you want ${chalk.magenta(
'HEAD',
)} to push to?`,
choices: deployBranches,
})
).result
const targetBranches = await (async () => {
if (deployBranches.length === 1) {
// @TODO: ask for confirmation
return deployBranches
}
if (options.all) {
return deployBranches
}
return (
await inquirer.prompt({
type: 'checkbox',
name: 'result',
message: `Which branch do you want ${chalk.magenta('HEAD')} to push to?`,
choices: deployBranches,
})
).result
})()

@@ -86,5 +107,12 @@ if (targetBranches.length === 0) {

for (const targetBranch of targetBranches) {
if (targetBranches.length > 1) {
console.log(`Pushing to ${chalk.magenta(targetBranches.length)} branches.`)
}
for (let i = 0; i < targetBranches.length; i++) {
const targetBranch = targetBranches[i]
const count =
targetBranches.length > 1 ? `[${i + 1}/${targetBranches.length}] ` : ''
console.log(
`Pushing ${chalk.magenta('HEAD')} to branch ${chalk.magenta(
`${count}Pushing ${chalk.magenta('HEAD')} to branch ${chalk.magenta(
targetBranch,

@@ -91,0 +119,0 @@ )}…`,

{
"name": "branch-deploy",
"version": "0.0.8",
"version": "0.1.0",
"description": "Deploy by pushing to a deploy* branch made simplier.",

@@ -34,2 +34,3 @@ "main": "index.js",

"chalk": "^5.2.0",
"commander": "^10.0.0",
"inquirer": "^9.1.4",

@@ -36,0 +37,0 @@ "simple-git": "^3.16.1"

@@ -16,1 +16,27 @@ # Branch deploy [![npm](https://img.shields.io/npm/v/branch-deploy.svg)](https://www.npmjs.com/package/branch-deploy)

![demo screencast](https://raw.githubusercontent.com/FilipChalupa/branch-deploy/HEAD/screencast.gif)
### Optional Options
#### Show help
```bash
npx branch-deploy --help
```
#### Push to all deploy branches
```bash
npx branch-deploy --all
```
#### Use different branch prefix
```bash
npx branch-deploy --prefix staging
```
#### Use different remote name
```bash
npx branch-deploy --prefix not-origin
```