Skip to content

Commit

Permalink
Fixing lil tweaks and adding linting rules
Browse files Browse the repository at this point in the history
  • Loading branch information
nfroidure committed Feb 21, 2016
1 parent dd154d7 commit 5899e2e
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 42 deletions.
21 changes: 21 additions & 0 deletions .eslintrc
@@ -0,0 +1,21 @@
{
"extends": "eslint-config-simplifield",
"env": {
"node": true,
"mocha": true
},
"globals": {
"require": false,
"describe": false,
"beforeEach": false,
"afterEach": false,
"before": false,
"after": false,
"it": false,
"sinon": false,
"module": false
},
"rules": {
"strict": [2, "global"]
}
}
2 changes: 1 addition & 1 deletion LICENCE
@@ -1,6 +1,6 @@
The MIT License

Copyright (c) 2014 Nicolas Froidure, <http://insertafter.com/>
Copyright (c) Nicolas Froidure, <http://insertafter.com/>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
10 changes: 6 additions & 4 deletions README.md
Expand Up @@ -13,7 +13,8 @@ First, install `buildbranch` globally:
npm install buildbranch -g
```

Then, from your master branch, run `buildbranch` with the branch and directory you want to publish. It will default to `gh-pages` and `www`.
Then, from your master branch, run `buildbranch` with the branch and directory
you want to publish. It will default to `gh-pages` and `www`.

```shell
buildbranch gh-pages www example.com
Expand All @@ -35,7 +36,7 @@ Then, use it in your build system:
remote: 'origin',
ignore: ['.git', 'www', 'node_modules'],
folder: 'www',
domain: 'example.com'
domain: 'example.com',
}, function(err) {
if(err) {
throw err;
Expand Down Expand Up @@ -95,9 +96,10 @@ The name of the file enabling custom domain name on you build platform.

##### options.commit
Type: `String`
Default: 'Build %curtimestamp%'
Default: 'Build $'

The commit label.
The commit label, the first `$` occurrence in the given string will be replaced
by the current date.

##### options.cwd
Type: `String`
Expand Down
20 changes: 12 additions & 8 deletions package.json
Expand Up @@ -14,16 +14,16 @@
"type": "git",
"url": "git://github.com/nfroidure/buildbranch.git"
},
"scripts": {
"lint": "eslint src/*.js",
"preversion": "npm run lint",
"cli": "env NPM_RUN_CLI=1"
},
"bugs": {
"url": "https://github.com/nfroidure/buildbranch/issues"
},
"licenses": [
{
"type": "MIT",
"url": "https://github.com/nfroidure/buildbranch/blob/master/LICENSE"
}
],
"main": "src/index.js",
"license": "MIT",
"main": "src/index",
"engines": {
"node": ">= 0.10.0"
},
Expand All @@ -38,6 +38,10 @@
"github"
],
"dependencies": {
"rimraf": "~2.2.6"
"rimraf": "^2.5.2"
},
"devDependencies": {
"eslint": "^1.10.1",
"eslint-config-simplifield": "^1.2.2"
}
}
15 changes: 8 additions & 7 deletions src/bin.js
@@ -1,18 +1,19 @@
#!/usr/bin/env node

var buildBranch = require('./index.js')
, branch = process.argv[2]
, dir = process.argv[3]
, domain = process.argv[4]
;
'use strict';

var buildBranch = require('./index.js');
var branch = process.argv[2];
var dir = process.argv[3];
var domain = process.argv[4];

buildBranch({
branch: branch || 'gh-pages',
folder: dir || 'www',
domain: domain || '',
}, function(err) {
}, function buildBranchCLICb(err) {
if(err) {
throw err;
}
console.log('Published!');
console.log('Published!'); // eslint-disable-line
});
43 changes: 21 additions & 22 deletions src/index.js
@@ -1,16 +1,15 @@
// Publish task
var exec = require('child_process').exec
, path = require('path')
, rimraf = require('rimraf')
, fs = require('fs')
;
'use strict';

var exec = require('child_process').exec;
var path = require('path');
var rimraf = require('rimraf');
var fs = require('fs');

function buildBranch(options, callback) {

var curBranch = 'master'
, execOptions = {}
, command = ''
;
var curBranch = 'master';
var execOptions = {};
var command = '';

// Checking options
options.folder = options.folder || 'www';
Expand All @@ -19,27 +18,28 @@ function buildBranch(options, callback) {
options.ignore = options.ignore || [];
options.ignore.push('.git', 'node_modules', options.folder);
options.cname = options.cname || 'CNAME';
options.commit = options.commit || 'Build '+(new Date());
options.commit = (options.commit || 'Build $').replace('$', (new Date()).toISOString());
options.cwd = options.cwd || process.cwd();
execOptions.cwd = options.cwd;

// Remember the current branch
command = 'git rev-parse --abbrev-ref HEAD'
command = 'git rev-parse --abbrev-ref HEAD';

exec(command, execOptions, function(err, stdout, stderr) {
exec(command, execOptions, function(err, stdout) {
if(err) {
callback(err); return;
}

curBranch = stdout.trim();

// Switch to ghpages branch
command = 'git branch -D ' + options.branch + ';'
+' git checkout --orphan ' + options.branch + ';'
+' git rm -r --cached .';
command = 'git branch -D ' + options.branch + ';' +
' git checkout --orphan ' + options.branch + ';' +
' git rm -r --cached .';

exec(command, execOptions, function(err) {
var ignore;

if(err) {
callback(err); return;
}
Expand Down Expand Up @@ -68,17 +68,17 @@ function buildBranch(options, callback) {
fs.writeFileSync(path.join(options.cwd, '.gitignore'), ignore.join('\n'));

// Commit files
command = 'git add .;'
+ ' git commit -m "' + options.commit.replace('"', '\\"') + '"';
command = 'git add .;' +
' git commit -m "' + options.commit.replace('"', '\\"') + '"';
exec(command, execOptions, function(err) {
if(err) {
callback(err); return;
}

// Pushing commit
command = 'git push -f ' + options.remote + ' ' + options.branch + ';'
+ ' git checkout ' + curBranch + ' ;'
+ ' git checkout .';
command = 'git push -f ' + options.remote + ' ' + options.branch + ';' +
' git checkout ' + curBranch + ' ;' +
' git checkout .';

exec(command, execOptions, function(err) {
if(err) {
Expand All @@ -94,4 +94,3 @@ function buildBranch(options, callback) {
}

module.exports = buildBranch;

0 comments on commit 5899e2e

Please sign in to comment.