grunt-build-control
Advanced tools
Comparing version 0.1.5 to 0.1.6
@@ -29,3 +29,5 @@ /* | ||
clean: { | ||
tests: ['tmp'], | ||
tests: [ | ||
'test/mock-repo' | ||
] | ||
}, | ||
@@ -38,12 +40,2 @@ | ||
}, | ||
testbranch: { | ||
options: { | ||
branch: 'test-branch', | ||
remote: '../', | ||
commit: true, | ||
push: true, | ||
connectCommits: false, | ||
tag: pkg.version | ||
} | ||
}, | ||
production: { | ||
@@ -61,4 +53,6 @@ options: { | ||
// Unit tests. | ||
nodeunit: { | ||
tests: ['test/*_test.js'], | ||
mochaTest: { | ||
test: { | ||
src: ['test/tests.js'] | ||
} | ||
} | ||
@@ -74,2 +68,3 @@ }); | ||
grunt.loadNpmTasks('grunt-contrib-nodeunit'); | ||
grunt.loadNpmTasks('grunt-mocha-test'); | ||
@@ -80,4 +75,3 @@ // Whenever the "test" task is run, first clean the "tmp" dir, then run this | ||
'clean', | ||
'buildcontrol', | ||
'nodeunit' | ||
'mochaTest' | ||
]); | ||
@@ -84,0 +78,0 @@ |
{ | ||
"name": "grunt-build-control", | ||
"description": "Automate version control tasks for your project's built code. Keep built code in sync with source code, maintain multiple branches of built code, commit with automatic messages, and push to remote repositories.", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"homepage": "https://github.com/robwierzbowski/grunt-build-control", | ||
@@ -31,6 +31,11 @@ "author": "Rob Wierzbowski <hello@robwierzbowski.com> (http://robwierzbowski)", | ||
"devDependencies": { | ||
"async": "^0.9.0", | ||
"chai": "^1.9.2", | ||
"fs-extra": "^0.12.0", | ||
"grunt": "~0.4.1", | ||
"grunt-cli": "^0.1.13", | ||
"grunt-contrib-clean": "~0.4.0", | ||
"grunt-contrib-jshint": "~0.1.1", | ||
"grunt-contrib-clean": "~0.4.0", | ||
"grunt-contrib-nodeunit": "~0.1.2", | ||
"grunt": "~0.4.1" | ||
"grunt-mocha-test": "^0.12.1" | ||
}, | ||
@@ -37,0 +42,0 @@ "peerDependencies": { |
@@ -26,3 +26,3 @@ # grunt-build-control | ||
or, as is often the case with [Yeoman](http://yeoman.io) generators, your Gruntfile will already load plugins automatically with: | ||
```js | ||
@@ -36,3 +36,3 @@ require('load-grunt-tasks')(grunt); | ||
Automate version control tasks for your project's built code. | ||
Automate version control tasks for your project's built code. | ||
@@ -49,4 +49,4 @@ Keep built code in sync with source code, maintain multiple branches of built code, commit with automatic messages, and push to remote repositories. | ||
#### dir | ||
Type: `String` | ||
@@ -57,4 +57,4 @@ Default: `dist` | ||
#### branch | ||
Type: `String` | ||
@@ -65,4 +65,4 @@ Default: `dist` | ||
#### remote | ||
Type: `String` | ||
@@ -73,4 +73,22 @@ Default: `../` | ||
#### login | ||
Type: `String` | ||
Default: `''` | ||
Optional, but provide in conjunction with `token`. | ||
The `remote` will be formatted to include the token and login. | ||
ex: `https://login@github.com/user/repo.git` | ||
#### token | ||
Type: `String` | ||
Default: `''` | ||
Optional, but provide in conjunction with `login`. | ||
The `remote` will be formatted to include the token and login. | ||
ex: `https://login:token@github.com/user/repo.git` | ||
#### commit | ||
Type: `Boolean` | ||
@@ -81,4 +99,4 @@ Default: `false` | ||
#### tag | ||
Type: `Boolean` or `String` | ||
@@ -89,4 +107,4 @@ Default: `false` | ||
#### push | ||
Type: `Boolean` | ||
@@ -97,4 +115,4 @@ Default: `false` | ||
#### message | ||
Type: `String` | ||
@@ -111,4 +129,4 @@ Default: `Built %sourceName% from commit %sourceCommit% on branch %sourceBranch% ` | ||
#### connectCommits | ||
Type: `Boolean` | ||
@@ -121,3 +139,3 @@ Default: `true` | ||
A common use of grunt-build-control is to commit and push built code to the GitHub pages branch of the main repository, or to the master branch of a git-based deployment server like Heroku. | ||
A common use of grunt-build-control is to commit and push built code to the GitHub pages branch of the main repository, or to the master branch of a git-based deployment server like Heroku. | ||
@@ -166,5 +184,5 @@ ```js | ||
In this example a user is working on a Yeoman-based web app, with their project's source code hosted at `git@github.com:example_user/example_webapp.git`. To deploy they first run `grunt build` to build a minified, optimized version of their app into the 'dist' directory. | ||
In this example a user is working on a Yeoman-based web app, with their project's source code hosted at `git@github.com:example_user/example_webapp.git`. To deploy they first run `grunt build` to build a minified, optimized version of their app into the 'dist' directory. | ||
Running `grunt buildcontrol:pages` commits the built code to the gh-pages branch of the 'dist/.git' repository and pushes to the gh-pages branch of `git@github.com:example_user/example_webapp.git`. | ||
Running `grunt buildcontrol:pages` commits the built code to the gh-pages branch of the 'dist/.git' repository and pushes to the gh-pages branch of `git@github.com:example_user/example_webapp.git`. | ||
@@ -179,3 +197,3 @@ Running `grunt buildcontrol:heroku` will commit the built code to the master branch of the 'dist/.git' repository, tag the latest commit in 'dist/.git' with the value of `pkg.version` if the tag doesn't already exist, and push refs and tags to the master branch of `git@heroku.com:example-heroku-webapp-1988.git`. | ||
In order to scope gitignore rules to the build directory only, create a file named 'gitignore' in your source directory: | ||
In order to scope gitignore rules to the build directory only, create a file named 'gitignore' in your source directory: | ||
@@ -206,3 +224,3 @@ ```shell | ||
<!-- | ||
<!-- | ||
## Todo: | ||
@@ -217,3 +235,3 @@ | ||
--> | ||
## Contribute | ||
@@ -235,2 +253,1 @@ | ||
[](https://bitdeli.com/free "Bitdeli Badge") | ||
@@ -16,2 +16,3 @@ /* | ||
var shelljs = require('shelljs'); | ||
var url = require('url'); | ||
@@ -28,2 +29,4 @@ grunt.registerMultiTask('buildcontrol', 'Version control built code.', function() { | ||
remote: '../', | ||
login: '', | ||
token: '', | ||
commit: false, | ||
@@ -45,2 +48,28 @@ tag: false, | ||
// Build remote if sensitive information is passed in | ||
if (options.login && options.token) { | ||
var remote = url.parse(options.remote); | ||
options.remote = url.format({ | ||
protocol: remote.protocol, | ||
auth: options.login + ':' + options.token, | ||
host: remote.host, | ||
path: remote.path | ||
}); | ||
} | ||
function maskSensitive(str) { | ||
return str | ||
.replace(options.login + ':' + options.token, '<CREDENTIALS>', 'gm') | ||
.replace(options.token, '<TOKEN>', 'gmi'); | ||
} | ||
var log = {}; | ||
log.fail = {}; | ||
log.subhead = function(msg) {grunt.log.subhead(maskSensitive(msg));}; | ||
log.write = function(msg) {grunt.log.write(maskSensitive(msg));}; | ||
log.fail.warn = function(msg) {grunt.fail.warn(maskSensitive(msg));}; | ||
// Wraps shellJs calls that act on the file structure to give better Grunt | ||
@@ -60,2 +89,6 @@ // output and error handling | ||
if (options.login && options.token) { | ||
stream = false; | ||
} | ||
var shellResult = shelljs.exec(command, {silent: (!stream)}); | ||
@@ -65,7 +98,7 @@ | ||
if (verbose) { | ||
grunt.log.write(shellResult.output); | ||
log.write(shellResult.output); | ||
} | ||
} | ||
else { | ||
throw shellResult.output; | ||
throw maskSensitive(shellResult.output); | ||
} | ||
@@ -117,3 +150,3 @@ } | ||
if (!fs.existsSync(path.join(gruntDir, options.dir, '.git'))) { | ||
grunt.log.subhead('Creating git repository in ' + options.dir + '.'); | ||
log.subhead('Creating git repository in ' + options.dir + '.'); | ||
@@ -129,3 +162,3 @@ execWrap('git init'); | ||
if (shelljs.exec('git remote', {silent: true}).output.indexOf(remoteName) === -1) { | ||
grunt.log.subhead('Creating remote.'); | ||
log.subhead('Creating remote.'); | ||
execWrap('git remote add ' + remoteName + ' ' + options.remote); | ||
@@ -162,3 +195,3 @@ } | ||
function safeUpdate () { | ||
grunt.log.subhead('Fetching ' + options.branch + ' history from ' + options.remote + '.'); | ||
log.subhead('Fetching ' + options.branch + ' history from ' + options.remote + '.'); | ||
@@ -200,9 +233,16 @@ // `--update-head-ok` allows fetch on a branch with uncommited changes | ||
if (shelljs.exec('git status --porcelain', {silent: true}).output === '') { | ||
grunt.log.subhead('No changes to your branch. Skipping commit.'); | ||
log.subhead('No changes to your branch. Skipping commit.'); | ||
return; | ||
} | ||
grunt.log.subhead('Committing changes to ' + options.branch + '.'); | ||
log.subhead('Committing changes to ' + options.branch + '.'); | ||
execWrap('git add -A .'); | ||
execWrap('git commit -m "' + message + '"'); | ||
// generate commit message | ||
var commitFile = 'commitFile-' + crypto.createHash('md5').update(message).digest('hex').substring(0, 6); | ||
fs.writeFileSync(commitFile, message); | ||
execWrap('git commit --file=' + commitFile); | ||
fs.unlinkSync(commitFile); | ||
} | ||
@@ -214,7 +254,7 @@ | ||
if (shelljs.exec('git rev-parse --revs-only ' + options.tag, {silent: true}).output !== '') { | ||
grunt.log.subhead('The tag "' + options.tag + '" already exists. Skipping tagging.'); | ||
log.subhead('The tag "' + options.tag + '" already exists. Skipping tagging.'); | ||
return; | ||
} | ||
grunt.log.subhead('Tagging the local repository with ' + options.tag); | ||
log.subhead('Tagging the local repository with ' + options.tag); | ||
execWrap('git tag ' + options.tag); | ||
@@ -225,3 +265,3 @@ } | ||
function gitPush () { | ||
grunt.log.subhead('Pushing ' + options.branch + ' to ' + options.remote); | ||
log.subhead('Pushing ' + options.branch + ' to ' + options.remote); | ||
execWrap('git push ' + remoteName + ' ' + options.branch, false, true); | ||
@@ -248,3 +288,3 @@ | ||
remoteName = options.remote; | ||
// Regex to test for remote url | ||
@@ -279,3 +319,3 @@ var remoteUrlRegex = new RegExp('.+[\\/:].+'); | ||
// Create local branch | ||
grunt.log.subhead('Creating branch "' + options.branch + '".'); | ||
log.subhead('Creating branch "' + options.branch + '".'); | ||
execWrap('git checkout --orphan ' + options.branch); | ||
@@ -301,3 +341,3 @@ } | ||
catch (e) { | ||
grunt.fail.warn(e); | ||
log.fail.warn(e); | ||
done(false); | ||
@@ -304,0 +344,0 @@ } |
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
55110
33
616
238
9
2
1