Skip to content
This repository has been archived by the owner on Jul 29, 2022. It is now read-only.

Commit

Permalink
First commit. Tests currently disabled.
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesMGreene committed Feb 19, 2013
1 parent 7ddd03b commit ba7a10c
Show file tree
Hide file tree
Showing 10 changed files with 549 additions and 16 deletions.
15 changes: 2 additions & 13 deletions .gitignore
@@ -1,14 +1,3 @@
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz

pids
logs
results

node_modules
npm-debug.log
tmp
14 changes: 14 additions & 0 deletions .jshintrc
@@ -0,0 +1,14 @@
{
"curly": true,
"eqeqeq": true,
"immed": true,
"latedef": true,
"newcap": true,
"noarg": true,
"sub": true,
"undef": true,
"boss": true,
"eqnull": true,
"node": true,
"es5": true
}
191 changes: 191 additions & 0 deletions Gruntfile.js
@@ -0,0 +1,191 @@
/*
* grunt-chmod
* https://github.com/JamesMGreene/grunt-chmod
*
* Copyright (c) 2013 James M. Greene
* Licensed under the MIT license.
*/

'use strict';

module.exports = function(grunt) {

// Project configuration.
grunt.initConfig({
jshint: {
options: {
jshintrc: '.jshintrc',
},
all: [
'Gruntfile.js',
'tasks/**/*.js',
'test/**/*.js',
]
},

// Before generating any new files, remove any previously-created files.
clean: {
tests: ['tmp'],
},

// Configuration to be run (and then tested).
chmod: {
default_options: {
options: {
emit: true
},
files: ['tmp/default_options.json']
},
custom_options_without_string_mode: {
options: {
mode: {},
emit: true
},
files: ['tmp/custom_options_without_string_mode.json']
},
custom_options_with_empty_mode: {
options: {
mode: '',
emit: true
},
files: ['tmp/custom_options_with_empty_mode.json']
},
custom_options_with_invalid_mode: {
options: {
mode: '',
emit: true
},
files: ['tmp/custom_options_with_invalid_mode.json']
},
custom_options_file: {
options: {
mode: 'go-rwx',
emit: true
},
files: ['tmp/custom_options_file.json']
},
custom_options_dir: {
options: {
mode: 'go-rwx',
emit: true
},
files: ['tmp/custom_options_dir/']
}
},

// Unit tests.
nodeunit: {
all: ['test/*_test.js']
},



});

// Actually load this plugin's task(s).
grunt.loadTasks('tasks');

// These plugins provide necessary tasks.
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-nodeunit');

var forceValue = (function(val) {
return (typeof val === 'boolean' ? val : !!val);
})(grunt.option('force'));

// Enable force for tests to avoid the build halting on warnings
grunt.registerTask('force-enable', function() {
grunt.option('force', true);
});
grunt.registerTask('force-revert', function() {
grunt.option('force', forceValue);
});

// Test setup
grunt.registerTask('test-setup', function() {
grunt.file.mkdir('tmp');
});

// Test emission listeners
var args = (function() {
var slicer = Array.prototype.slice;
return function(argsObj) {
return slicer.call(argsObj, 0);
};
})();
var emissions = [],
taskTargetName;
grunt.registerTask('listeners-on', function() {
grunt.event.on('chmod.*', function(msg) {
if (this.event === 'chmod.taskTargetName') {
taskTargetName = msg;
return;
}
var emission = {
name: this.event,
args: args(arguments)
};
emissions.push(emission);
});
});
grunt.registerTask('listeners-off', function() {
grunt.file.write('tmp/' + taskTargetName + '.json', JSON.stringify(emissions));

emissions.length = 0;
grunt.event.removeAllListeners('chmod.*');
});

var badConfigOptions = [
'default_options',
'custom_options_without_string_mode',
'custom_options_with_empty_mode',
'custom_options_with_invalid_mode'
];
badConfigOptions.forEach(function(e, i) {
grunt.registerTask(
'test-prep-' + (i + 1),
[
'force-enable',
'listeners-on',
'chmod:' + e,
'listeners-off',
'force-revert'
]
);
});
var goodConfigOptions = [
'custom_options_file',
'custom_options_dir'
];
goodConfigOptions.forEach(function(e, i) {
grunt.registerTask(
'test-prep-' + (badConfigOptions.length + i + 1),
[
'listeners-on',
'chmod:' + e,
'listeners-off'
]
);
});

// Whenever the "test" task is run, first clean the "tmp" dir, then run this plugin's
// task(s), then test the result(s). Do NOT clean the "tmp" dir at the end!
grunt.registerTask(
'test',
(function() {
var taskList = [];
taskList.push('clean');
taskList.push('test-setup');
for (var i = 1, len = (badConfigOptions.length + goodConfigOptions.length + 1); i < len; i++) {
taskList.push('test-prep-' + i);
}
taskList.push('nodeunit');
return taskList;
})()
);

// By default: lint, run all tests, and clean it up.
grunt.registerTask('default', ['jshint', /*'test',*/ 'clean']);

};
22 changes: 22 additions & 0 deletions LICENSE-MIT
@@ -0,0 +1,22 @@
Copyright (c) 2013 James M. Greene

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
91 changes: 88 additions & 3 deletions README.md
@@ -1,4 +1,89 @@
grunt-chmod
===========
# grunt-chmod

A Grunt plugin to modify file permissions, i.e. like using `chmod`.
> A Grunt task plugin to modify file permissions, a la `chmod`.
## Getting Started
This plugin requires Grunt `~0.4.0`

If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

```shell
npm install grunt-chmod --save-dev
```

One the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

```js
grunt.loadNpmTasks('grunt-chmod');
```

## The "chmod" task

### Overview
In your project's Gruntfile, add a section named `chmod` to the data object passed into `grunt.initConfig()`.

```js
grunt.initConfig({
chmod: {
options: {
// Task-specific options go here.
},
your_target: {
// Target-specific file lists and/or options go here.
},
},
})
```

### Options

#### options.separator
Type: `String`
Default value: `', '`

A string value that is used to do something with whatever.

#### options.punctuation
Type: `String`
Default value: `'.'`

A string value that is used to do something else with whatever else.

### Usage Examples

#### Default Options
In this example, the default options are used to do something with whatever. So if the `testing` file has the content `Testing` and the `123` file had the content `1 2 3`, the generated result would be `Testing, 1 2 3.`

```js
grunt.initConfig({
chmod: {
options: {},
files: {
'dest/default_options': ['src/testing', 'src/123'],
},
},
})
```

#### Custom Options
In this example, custom options are used to do something else with whatever else. So if the `testing` file has the content `Testing` and the `123` file had the content `1 2 3`, the generated result in this case would be `Testing: 1 2 3 !!!`

```js
grunt.initConfig({
chmod: {
options: {
separator: ': ',
punctuation: ' !!!',
},
files: {
'dest/default_options': ['src/testing', 'src/123'],
},
},
})
```

## Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/).

## Release History
_(Nothing yet)_
41 changes: 41 additions & 0 deletions package.json
@@ -0,0 +1,41 @@
{
"name": "grunt-chmod",
"description": "A Grunt task plugin to modify file permissions, a la `chmod`.",
"version": "0.1.0",
"homepage": "https://github.com/JamesMGreene/grunt-chmod",
"author": {
"name": "James M. Greene",
"email": "james.m.greene@gmail.com",
"url": "http://jamesgreene.net/"
},
"repository": {
"type": "git",
"url": "git://github.com/JamesMGreene/grunt-chmod.git"
},
"bugs": {
"url": "https://github.com/JamesMGreene/grunt-chmod/issues"
},
"licenses": [
{
"type": "MIT",
"url": "https://github.com/JamesMGreene/grunt-chmod/blob/master/LICENSE-MIT"
}
],
"main": "Gruntfile.js",
"engines": {
"node": ">= 0.8.0"
},
"scripts": {
"test": "grunt test"
},
"devDependencies": {
"grunt-contrib-jshint": "~0.1.1",
"grunt-contrib-clean": "~0.4.0",
"grunt-contrib-nodeunit": "~0.1.2",
"grunt": "~0.4.0"
},
"keywords": [
"gruntplugin",
"chmod"
]
}

0 comments on commit ba7a10c

Please sign in to comment.