Skip to content

Commit

Permalink
Update js to es6 and verify with jshint
Browse files Browse the repository at this point in the history
  • Loading branch information
dpilafian authored and tracker1 committed Apr 12, 2019
1 parent 4983c32 commit b89f4ff
Show file tree
Hide file tree
Showing 4 changed files with 230 additions and 76 deletions.
36 changes: 16 additions & 20 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
/* jshint node: true */
'use strict';

/**
* Module dependencies.
*/

var Concat = require('concat-with-sourcemaps');
var through = require('through2');
var lodashTemplate = require('lodash.template');
var stream = require('stream');
var path = require('path');
var fs = require('fs');
const Concat = require('concat-with-sourcemaps');
const through = require('through2');
const lodashTemplate = require('lodash.template');
const stream = require('stream');
const path = require('path');

/**
* gulp-header plugin
*/

module.exports = function(headerText, data) {
module.exports = (headerText, data) => {
headerText = headerText || '';

function TransformStream(file, enc, cb) {
// format template
var filename = path.basename(file.path);
var template =
data === false
? headerText
const filename = path.basename(file.path);
const template =
data === false ?
headerText
: lodashTemplate(headerText)(
Object.assign({}, file.data || {}, { file: file, filename: filename }, data)
);
Expand All @@ -42,7 +38,7 @@ module.exports = function(headerText, data) {

// handle file stream;
if (file.isStream()) {
var stream = through();
const stream = through();
stream.write(Buffer.from(template));
stream.on('error', this.emit.bind(this, 'error'));
file.contents = file.contents.pipe(stream);
Expand All @@ -51,7 +47,7 @@ module.exports = function(headerText, data) {
}

// variables to handle direct file content manipulation
var concat = new Concat(true, filename);
const concat = new Concat(true, filename);

// add template
concat.add(null, Buffer.from(template));
Expand Down Expand Up @@ -82,14 +78,14 @@ module.exports = function(headerText, data) {
/**
* is stream?
*/
function isStream(obj) {
const isStream = (obj) => {
return obj instanceof stream.Stream;
}
};

/**
* Is File, and Exists
*/
function isExistingFile(file) {
const isExistingFile = (file) => {
try {
if (!(file && typeof file === 'object')) return false;
if (file.isDirectory()) return false;
Expand All @@ -98,4 +94,4 @@ function isExistingFile(file) {
if (typeof file.contents === 'string') return true;
} catch (err) {}
return false;
}
};
153 changes: 153 additions & 0 deletions package-lock.json

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

10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@
"directories": {
"test": "test"
},
"jshintConfig": {
"esversion": 8,
"strict": "implied",
"undef": true,
"unused": true,
"mocha": true,
"node": true
},
"scripts": {
"pretest": "jshint *.js test",
"test": "mocha --reporter spec",
"publish-major": "npm version major && git push origin master && git push --tags",
"publish-minor": "npm version minor && git push origin master && git push --tags",
Expand Down Expand Up @@ -51,6 +60,7 @@
},
"devDependencies": {
"gulp": "^4.0.0",
"jshint": "*",
"mocha": "*",
"should": "*",
"vinyl": "*"
Expand Down
Loading

0 comments on commit b89f4ff

Please sign in to comment.