Skip to content

Commit

Permalink
Migrate to es6 (#10)
Browse files Browse the repository at this point in the history
* move changelog to README.md

* add .prettierrc for formatting

* add index file to load cli.js as esm

* update changelog in readme

Co-authored-by: Benjamin Jesuiter <[email protected]>
  • Loading branch information
bjesuiter and jesuiterb authored Apr 13, 2020
1 parent 980b71e commit 53f805e
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 86 deletions.
8 changes: 8 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"printWidth": 120,
"tabWidth": 4,
"useTabs": true,
"singleQuote": true,
"bracketSpacing": false,
"arrowParens": "avoid"
}
50 changes: 1 addition & 49 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,51 +1,3 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [1.1.4] - 2019-11-14

* Update dependencies to fix some known security issues

## [1.1.3] - 2019-04-22

* fix broken xo config
* allow backtick-strings
* catch parameter naming
* space around lines

* update dependencies

## [1.1.2] - 2019-04-21

* update dependencies

## [1.1.1] - 2018-08-01

* updated readme

## [1.1.0] - 2018-08-01

* extra options for git are now possible

## [1.0.2 + 1.0.3] - 2018-07-06

* Did some Housekeeping on this repository

### Added

* xo package with configuration
* deploy script in package.json which uses this push-to-git code to push itself to master.

## [1.0.1] - 2018-06-22

## Added

* Changelog file
* fixes binary name in README.md -> Usage

## [1.0.0] - 2018-06-22

Initial Release - See Readme for usage and features
see README.md
81 changes: 69 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
# Push to Git (CLI)

[![Greenkeeper badge](https://badges.greenkeeper.io/bjesuiter/push-to-git.svg)](https://greenkeeper.io/)
This CLI tool is intended to be able to easily push the current branch to some target git repository or branch for deployment.
This is useful for services like resin.io, where pushing code to their git repository is the only way of deploying your app.

This CLI tool is intended to be able to easily push the current branch to some target git repository or branch for deployment.
This is useful for services like resin.io, where pushing code to their git repository is the only way of deploying your app.
This could also be used for DevOps situations where you have 3 branches 'production', 'staging', and 'testing' for example.
Normally you would have to

This could also be used for DevOps situations where you have 3 branches 'production', 'staging', and 'testing' for example.
Normally you would have to
* check out the desired deploy target branch,
* merge your current working branch / feature / bugfix / etc. into it,
* push the deploy target branch and
* check back into your working branch to continue work.
- check out the desired deploy target branch,
- merge your current working branch / feature / bugfix / etc. into it,
- push the deploy target branch and
- check back into your working branch to continue work.

This script simplifies this action (for example pushing your current branch to the testing slot) to
`push-to-git --target origin --branch testing`
And if you use this cli tool in npm scripts, you can make these deployments even simpler!


## Usage

```
Expand All @@ -35,13 +33,72 @@ And if you use this cli tool in npm scripts, you can make these deployments even
-f --force Forces git push
-h, --help output usage information
General Information:
General Information:
Version: 1.0.0
Purpose: Pushes the current branch to an arbitrary branch
Purpose: Pushes the current branch to an arbitrary branch
in the same or in another repository for deployment.
```

## Credits

Package created after
https://medium.com/netscape/a-guide-to-create-a-nodejs-command-line-package-c2166ad0452e

---

## Changelog

All notable changes to this project will be documented here.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

### [Next]

- Internals work with es-modules

### [1.1.4] - 2019-11-14

- Update dependencies to fix some known security issues

### [1.1.3] - 2019-04-22

- fix broken xo config

- allow backtick-strings
- catch parameter naming
- space around lines

- update dependencies

### [1.1.2] - 2019-04-21

- update dependencies

### [1.1.1] - 2018-08-01

- updated readme

### [1.1.0] - 2018-08-01

- extra options for git are now possible

### [1.0.2 + 1.0.3] - 2018-07-06

- Did some Housekeeping on this repository

#### Added

- xo package with configuration
- deploy script in package.json which uses this push-to-git code to push itself to master.

### [1.0.1] - 2018-06-22

#### Added

- Changelog file
- fixes binary name in README.md -> Usage

### [1.0.0] - 2018-06-22

Initial Release - See Readme for usage and features
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env node

// Set options as a parameter, environment variable, or rc file.
require = require('esm')(module /*, options*/);
module.exports = require('./src/cli.js');
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"description": "CLI tool to simplify deployment to 'external git repositories' or 'remote branches with attached onPush action webhooks'",
"main": "src/cli.js",
"bin": {
"push-to-git": "./src/cli.js"
"push-to-git": "index.js"
},
"scripts": {
"test": "xo",
"start": "./src/cli.js"
"start": "./index.js"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -46,6 +46,7 @@
},
"devDependencies": {
"ava": "^3.7.0",
"esm": "^3.2.25",
"xo": "^0.29.1"
},
"xo": {
Expand Down
46 changes: 23 additions & 23 deletions src/cli.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
#!/usr/bin/env node
const program = require('commander');
const {spawn} = require('child-process-promise');
const prompt = require('console-prompt');
const projectVersion = require('project-version');
import program from 'commander';
import {spawn} from 'child-process-promise';
import prompt from 'console-prompt';
import projectVersion from 'project-version';

// This file is used to upload the current branch to the master of the jb test application for mms on resin.io
// It is needed because there is no cross-platform way to capture the output of
// a command a to use it in command b from package.json script

program
.version(projectVersion, '-v, --version')
.option('-t --target <target>', 'Git Target to push to, this can be a full git address or a registered git remote name')
.option(
'-t --target <target>',
'Git Target to push to, this can be a full git address or a registered git remote name'
)
.option('-b --branch <branch>', 'Target branch name to push to, defaults to the same name like input branch')
.option('-e --extra <extra>', 'A string value with extra git options which should be used')
.option('-m --master', 'Sets the target branch to master per default')
Expand Down Expand Up @@ -40,7 +42,7 @@ if (process.argv.slice(2).length === 0) {
// Format: protocol://user@git-repo.address/path.git OR remote-name (like "origin")
const gitTarget = program.target;
let gitTargetBranch = program.branch;
const targetBranchDefault = (program.master) ? program.master : false;
const targetBranchDefault = program.master ? program.master : false;
const extraOptions = program.extra;
const force = program.force;
const dryRun = program.dryRun;
Expand All @@ -67,7 +69,9 @@ function runGitPush(gitParameters) {
}

// Git command to get the current branch name: git rev-parse --abbrev-ref HEAD
spawn('git', ['rev-parse', '--abbrev-ref', 'HEAD'], {capture: ['stdout', 'stderr']})
spawn('git', ['rev-parse', '--abbrev-ref', 'HEAD'], {
capture: ['stdout', 'stderr'],
})
.then(result => {
const currGitBranch = result.stdout.toString().trim();

Expand All @@ -77,15 +81,12 @@ spawn('git', ['rev-parse', '--abbrev-ref', 'HEAD'], {capture: ['stdout', 'stderr
}

if (gitTargetBranch === undefined) {
gitTargetBranch = (targetBranchDefault) ? 'master' : currGitBranch;
gitTargetBranch = targetBranchDefault ? 'master' : currGitBranch;
}

console.log(`Push current git branch [${currGitBranch}] to ${gitTargetBranch} of: \n` +
`${gitTarget}`);
console.log(`Push current git branch [${currGitBranch}] to ${gitTargetBranch} of: \n` + `${gitTarget}`);

const gitParameters = [
'push'
];
const gitParameters = ['push'];

if (force) {
gitParameters.push('-f');
Expand All @@ -102,19 +103,18 @@ spawn('git', ['rev-parse', '--abbrev-ref', 'HEAD'], {capture: ['stdout', 'stderr
git ${gitParameters.join(' ')}`);

if (isProduction) {
return prompt(`CAUTION: You are updating a production branch! Proceed? (yes | NO) `)
.then(value => {
if (value === 'yes' || value === 'y') {
return runGitPush(gitParameters);
}

console.log('Update canceled by user');
});
return prompt(`CAUTION: You are updating a production branch! Proceed? (yes | NO) `).then(value => {
if (value === 'yes' || value === 'y') {
return runGitPush(gitParameters);
}

console.log('Update canceled by user');
});
}

return runGitPush(gitParameters);
})
.catch(error => {
const err = (error.stderr) ? error.stderr : error;
const err = error.stderr ? error.stderr : error;
console.error('Execution Errors:', err);
});

0 comments on commit 53f805e

Please sign in to comment.