Skip to content

Commit

Permalink
firt commit
Browse files Browse the repository at this point in the history
  • Loading branch information
patiernom committed Aug 27, 2015
0 parents commit e2a7643
Show file tree
Hide file tree
Showing 12 changed files with 508 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
service_name: travis-ci
repo_token: ilP7K4EpLCfkhwXK67cbdpLNMmSsMeZIC
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Created by .ignore support plugin (hsz.mobi)
.idea/
node_modules/
tests/coverage/
18 changes: 18 additions & 0 deletions .jscsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"requireCurlyBraces": ["if", "else", "for", "while", "do", "try", "catch"],
"requireSpaceAfterKeywords": ["if", "else", "for", "while", "do", "switch", "return", "try", "catch"],
"disallowSpaceBeforeBinaryOperators": [","],
"disallowSpaceAfterBinaryOperators": ["!"],
"requireSpaceBeforeBinaryOperators": ["?", "+", "-", "/", "*", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="],
"requireSpaceAfterBinaryOperators": ["?", "+", "/", "*", ":", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="],
"disallowImplicitTypeConversion": ["string"],
"disallowKeywords": ["with"],
"disallowMultipleLineBreaks": true,
"disallowKeywordsOnNewLine": ["else"],
"disallowTrailingWhitespace": true,
"requireLineFeedAtFileEnd": true,
"validateJSDoc": {
"checkParamNames": true,
"requireParamTypes": true
}
}
22 changes: 22 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"curly": true,
"eqeqeq": true,
"immed": true,
"latedef": true,
"newcap": true,
"noarg": true,
"sub": true,
"undef": true,
"unused": true,
"boss": true,
"eqnull": true,
"node": true,
"globals": {
"describe" : false,
"it" : false,
"before" : false,
"beforeEach" : false,
"after" : false,
"afterEach" : false
}
}
9 changes: 9 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.idea
*.yml
node_modules/
tests/
.gitignore
.jscsrc
.jshintrc
gulpfile.js
.npmignore
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
language: node_js
node_js:
- '0.12'
- '0.11'
after_success:
- npm run coveralls
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2015 Marco Patierno

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.

94 changes: 94 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# gulp-less-json-variables

[![GitHub version][gulp-less-json-variables-fury-image]][gulp-less-json-variables-fury-url]
[![Dependency Status][gulp-less-json-variables-dependencies-image]][gulp-less-json-variables-dependencies-url]
[![devDependency Status][gulp-less-json-variables-devdependencies-image]][gulp-less-json-variables-devdependencies-url]
[![peerDependency Status][gulp-less-json-variables-peerdependencies-image]][gulp-less-json-variables-peerdependencies-url]
[![Build Status][gulp-less-json-variables-travis-image]][gulp-less-json-variables-travis-url]
[![Coverage Status][gulp-less-json-variables-coverage-image]][gulp-less-json-variables-coverage-url]

# Grulper Load Projects

A simple plugin for [Gulp](http://gulpjs.com/). This module write on source file, specified less variables from JSON config file.

## Installation

The easiest way is to keep `gulp-less-json-variables` as a devDependency in your `package.json`.
```json
{
"devDependencies": {
"gulp": "^3.9.0",
"gulp-less-json-variables": "1.0.0"
}
}
```

You can simple do it by:
```bash
npm install gulp-less-json-variables --save-dev
```


## API

### plugin(json)

Write on input file with the given variables from `json` and
returns a transform stream for use in your gulp pipeline.



## Usage
Create a JSON config file like this:
```json
{
"@gray-base": "#000",
"@gray-darker": "lighten(@gray-base, 13.5%)",
"@gray-dark": "lighten(@gray-base, 20%)",
"@gray": "lighten(@gray-base, 33.5%)",
...
}
```
this file contains the coupled key value representing less variables.


```javascript
var gulp = require('gulp'),
lessVars = require('gulp-less-json-variables'),
jsonVars = require('variables.json');

gulp.task('generate less variables', function() {
return gulp.src('less/variables.js')
.pipe(lessVars(jsonVars))
.pipe(gulp.dest('dist'));
});
```


## Contributing

In line 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 [gulp](http://gulpjs.com/).


## Release History

_(Nothing yet)_


## License

Licensed under the MIT license.


[gulp-less-json-variables-fury-image]: https://badge.fury.io/gh/patiernom%2Fgulp-less-json-variables-load-projects.svg
[gulp-less-json-variables-fury-url]: http://badge.fury.io/gh/patiernom%2Fgulp-less-json-variables-load-projects
[gulp-less-json-variables-dependencies-image]: https://david-dm.org/patiernom/gulp-less-json-variables-load-projects.svg
[gulp-less-json-variables-dependencies-url]: https://david-dm.org/patiernom/gulp-less-json-variables-load-projects
[gulp-less-json-variables-devdependencies-image]: https://david-dm.org/patiernom/gulp-less-json-variables-load-projects/dev-status.svg
[gulp-less-json-variables-devdependencies-url]: https://david-dm.org/patiernom/gulp-less-json-variables-load-projects#info=devDependencies
[gulp-less-json-variables-peerdependencies-image]: https://david-dm.org/patiernom/gulp-less-json-variables-load-projects/peer-status.svg
[gulp-less-json-variables-peerdependencies-url]: https://david-dm.org/patiernom/gulp-less-json-variables-load-projects#info=peerDependencies
[gulp-less-json-variables-travis-image]: https://travis-ci.org/patiernom/gulp-less-json-variables-load-projects.svg?branch=master
[gulp-less-json-variables-travis-url]: https://travis-ci.org/patiernom/gulp-less-json-variables-load-projects
[gulp-less-json-variables-coverage-image]: https://coveralls.io/repos/patiernom/gulp-less-json-variables-load-projects/badge.svg?branch=master&service=github
[gulp-less-json-variables-coverage-url]: https://coveralls.io/github/patiernom/gulp-less-json-variables-load-projects?branch=master
46 changes: 46 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* Created by marcopatierno on 27/07/15.
*/
'use strict';

var gulp = require('gulp'),
plugins = require('gulp-load-plugins')(),
paths = {
lint: ['./gulpfile.js', './index.js'],
tests: ['./tests/*.js', '!./tests/{temp,temp/**}']
};

gulp.task('lint', function () {
return gulp.src(paths.lint)
.pipe(plugins.jshint('.jshintrc'))
.pipe(plugins.jscs())
.pipe(plugins.jshint.reporter('jshint-stylish'));
});

gulp.task('istanbul', function (cb) {
gulp.src(['./index.js'])
.pipe(plugins.istanbul()) // Covering files
.pipe(plugins.istanbul.hookRequire()) // Force `require` to return covered files
.on('finish', function () {
gulp.src(['tests/*.js'], {cwd: __dirname})
.pipe(plugins.mocha())
.pipe(plugins.istanbul.writeReports({ // Creating the reports after tests ran
dir: './tests/coverage',
reportOpts: {
dir: './tests/coverage'
}
})
)
.on('end', cb);
});
});

gulp.task('mocha', function (cb) {
gulp.src(paths.tests, {cwd: __dirname})
.pipe(plugins.mocha())
.on('end', cb);
});

gulp.task('test', ['lint', 'mocha']);

gulp.task('default',['test']);
52 changes: 52 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"use strict";

var PLUGIN_NAME = 'gulp-less-json-variables',
through = require('through2'),
gutil = require('gulp-util'),
PluginError = gutil.PluginError,
util = require('util');

function formatVariable(key, value){
return util.format('%s = %s;\n', key.toString(), value);
}

function writeVariable(jsonVariables){
var str = '';

Object.keys(jsonVariables).forEach(function(key) {
str += formatVariable(key, jsonVariables[key]);
});

return new Buffer(str);
}

function lessJsonVariableStream(jsonVariables) {
var stream = through();
stream.write(writeVariable(jsonVariables));
return stream;
}

function gulpLessJsonVariables(jsonVariables) {
if (!jsonVariables) {
throw new PluginError(PLUGIN_NAME, 'Missing JSON variables!');
}

return through.obj(function(file, enc, cb) {
//if (!jsonVariables) {
// cb(new PluginError(PLUGIN_NAME, 'Missing JSON variables!'));
//}
if (file.isNull()) {
return cb(null, file);
}
if (file.isBuffer()) {
file.contents = Buffer.concat([writeVariable(jsonVariables)]);
}
if (file.isStream()) {
file.contents = file.contents.pipe(lessJsonVariableStream(jsonVariables));
}

cb(null, file);
});
}

module.exports = gulpLessJsonVariables;
54 changes: 54 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"name": "gulp-less-json-variables",
"version": "1.0.0",
"description": "A Gulp plugin for generate less variables file from JSON file",
"keywords": [
"gulp",
"plugin",
"less",
"variables",
"json"
],
"author": "Marco Patierno",
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/patiernom/gulp-less-json-variables.git"
},
"bugs": {
"url": "https://github.com/patiernom/gulp-less-json-variables/issues"
},
"homepage": "https://github.com/patiernom/gulp-less-json-variables#readme",
"main": "index.js",
"engines": {
"node": ">=0.10.22"
},
"dependencies": {
"gulp-util": "^3.0.6",
"through2": "^2.0.0"
},
"devDependencies": {
"chai": "^3.2.0",
"coveralls": "^2.11.2",
"event-stream": "^3.3.1",
"from2-string": "^1.1.0",
"gulp": "^3.9.0",
"gulp-istanbul": "^0.10.0",
"gulp-jscs": "^1.6.0",
"gulp-jshint": "^1.11.2",
"gulp-load-plugins": "^0.10.0",
"gulp-mocha": "^2.1.3",
"istanbul": "^0.3.17",
"jshint-stylish": "^2.0.1",
"mocha": "^2.2.5",
"mocha-lcov-reporter": "0.0.2",
"vinyl": "^0.5.1"
},
"directories": {
"test": "tests"
},
"scripts": {
"test": "gulp test",
"coveralls": "istanbul cover ./node_modules/mocha/bin/_mocha $(find tests -name '*.js') --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage"
}
}
Loading

0 comments on commit e2a7643

Please sign in to comment.