Skip to content

Commit

Permalink
var -> let, const
Browse files Browse the repository at this point in the history
  • Loading branch information
jednano committed Aug 14, 2019
1 parent b787a4a commit f1de717
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 82 deletions.
8 changes: 4 additions & 4 deletions bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

'use strict';

var program = require('commander');
var parse = require('cli-argparse');
var pollinate = require('./lib/index.js');
const program = require('commander');
const parse = require('cli-argparse');
const pollinate = require('./lib/index.js');

var parsed = parse(process.argv, { camelcase: false });
const parsed = parse(process.argv, { camelcase: false });

program
.version(require('./package.json').version)
Expand Down
10 changes: 5 additions & 5 deletions lib/complete.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@

'use strict';

var exec = require('child_process').exec;
var async = require('async');
var mv = require('mv');
const exec = require('child_process').exec;
const async = require('async');
const mv = require('mv');

module.exports = function (state, callback) {
var complete = state.data.complete;
const complete = state.data.complete;

async.series([
// Move all the files to the relative path "{{ name }}"
Expand All @@ -30,7 +30,7 @@ module.exports = function (state, callback) {
// Call the shell command specified as `complete`
function (next) {
if (complete !== undefined) {
var commands = (typeof complete === 'string')
const commands = (typeof complete === 'string')
? [complete]
: complete;
async.series(commands.map(onCommand)).then(next, next);
Expand Down
8 changes: 4 additions & 4 deletions lib/discard.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@

'use strict';

var rimraf = require('rimraf');
var async = require('async');
var isDirectory = require('is-directory');
const rimraf = require('rimraf');
const async = require('async');
const isDirectory = require('is-directory');

module.exports = function (state, callback) {
var discard = state.data.discard,
const discard = state.data.discard,
tmpPath = state.template.tmp;

// Remove the .git directory unless told otherwise
Expand Down
12 changes: 6 additions & 6 deletions lib/extend.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

'use strict';

var fs = require('fs');
var extend = require('extend');
var ospath = require('ospath');
var async = require('async');
var Hjson = require('hjson');
const fs = require('fs');
const extend = require('extend');
const ospath = require('ospath');
const async = require('async');
const Hjson = require('hjson');

module.exports = function (state, callback) {
var userData = {},
let userData = {},
projectData = {},
optionData = {};

Expand Down
52 changes: 26 additions & 26 deletions lib/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@

'use strict';

var fs = require('fs');
var mkdirp = require('mkdirp');
var cpr = require('cpr');
var rimraf = require('rimraf');
var ospath = require('ospath');
var request = require('request');
var uuid = require('uuid');
var isDirectory = require('is-directory').sync;
var async = require('async');
var exec = require('child_process').exec;
var Hjson = require('hjson');

var gitClone = function (url, ref, tmpPath, callback) {
const fs = require('fs');
const mkdirp = require('mkdirp');
const cpr = require('cpr');
const rimraf = require('rimraf');
const ospath = require('ospath');
const request = require('request');
const uuid = require('uuid');
const isDirectory = require('is-directory').sync;
const async = require('async');
const exec = require('child_process').exec;
const Hjson = require('hjson');

const gitClone = function (url, ref, tmpPath, callback) {
async.series([
function (next) {
exec('git clone ' + url + ' ' + tmpPath, function (err) {
Expand Down Expand Up @@ -57,8 +57,8 @@ var gitClone = function (url, ref, tmpPath, callback) {
});
};

var fetchGitHub = function (state, callback) {
var tmpPath = ospath.tmp() + '/' + uuid.v1(),
const fetchGitHub = function (state, callback) {
const tmpPath = ospath.tmp() + '/' + uuid.v1(),
inputUrl = state.template.input.split('#')[0],
inputRef = state.template.input.split('#')[1],
url = 'https://github.com/' + inputUrl + '.git';
Expand All @@ -74,8 +74,8 @@ var fetchGitHub = function (state, callback) {
});
};

var fetchDirectory = function (state, callback) {
var input = state.template.input,
const fetchDirectory = function (state, callback) {
const input = state.template.input,
tmpPath = ospath.tmp() + '/' + uuid.v1();

state.template.tmp = tmpPath;
Expand Down Expand Up @@ -106,8 +106,8 @@ var fetchDirectory = function (state, callback) {
});
};

var fetchGit = function (state, callback) {
var tmpPath = ospath.tmp() + '/' + uuid.v1(),
const fetchGit = function (state, callback) {
const tmpPath = ospath.tmp() + '/' + uuid.v1(),
inputUrl = state.template.input.split('#')[0],
inputRef = state.template.input.split('#')[1];

Expand All @@ -122,8 +122,8 @@ var fetchGit = function (state, callback) {
});
};

var fetchURL = function (state, callback) {
var tmpPath = ospath.tmp() + '/' + uuid.v1(),
const fetchURL = function (state, callback) {
const tmpPath = ospath.tmp() + '/' + uuid.v1(),
input = state.project.input,
response = request(input);

Expand All @@ -146,12 +146,12 @@ var fetchURL = function (state, callback) {
});
};

var fetchJSON = function (state, callback) {
const fetchJSON = function (state, callback) {
callback(null, state);
};

var fetchFile = function (state, callback) {
var tmpPath = ospath.tmp() + '/' + uuid.v1(),
const fetchFile = function (state, callback) {
const tmpPath = ospath.tmp() + '/' + uuid.v1(),
input = state.project.input;

// setup the tmp path
Expand All @@ -171,7 +171,7 @@ var fetchFile = function (state, callback) {
});
};

var fetchTemplate = function (state, callback) {
const fetchTemplate = function (state, callback) {
switch (state.template.source) {
case 'github':
fetchGitHub(state, callback);
Expand All @@ -185,7 +185,7 @@ var fetchTemplate = function (state, callback) {
}
};

var fetchProject = function (state, callback) {
const fetchProject = function (state, callback) {
switch (state.project.source) {
case 'url':
fetchURL(state, callback);
Expand Down
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

'use strict';

var async = require('async');
const async = require('async');

function runPollinate(input, callback) {
async.waterfall([
Expand Down
16 changes: 8 additions & 8 deletions lib/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

'use strict';

var isDirectory = require('is-directory').sync;
var isGitHub = function (input) { return input.match(/^(?!\.)[A-Za-z0-9\-_]+\/[A-Za-z0-9\-_]+$/g); };
var isFile = require('fs').existsSync;
var isURL = require('valid-url').isUri;
var isJSON = function (input) { try { JSON.parse(input); return true; } catch (e) { return false; } };
const isDirectory = require('is-directory').sync;
const isGitHub = function (input) { return input.match(/^(?!\.)[A-Za-z0-9\-_]+\/[A-Za-z0-9\-_]+$/g); };
const isFile = require('fs').existsSync;
const isURL = require('valid-url').isUri;
const isJSON = function (input) { try { JSON.parse(input); return true; } catch (e) { return false; } };

var getTemplateSource = function (input) {
var inputNoRef = input.split('#')[0];
const getTemplateSource = function (input) {
const inputNoRef = input.split('#')[0];
if (isDirectory(input)) {
return 'directory';
}
Expand All @@ -27,7 +27,7 @@ var getTemplateSource = function (input) {
return 'git';
};

var getProjectSource = function (input) {
const getProjectSource = function (input) {
if (isFile(input)) {
return 'file';
}
Expand Down
10 changes: 5 additions & 5 deletions lib/merge.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@

'use strict';

var async = require('async');
var extend = require('extend');
var fs = require('fs');
const async = require('async');
const extend = require('extend');
const fs = require('fs');

module.exports = function merge(state, callback) {
var mergeFiles = state.data.merge;
const mergeFiles = state.data.merge;

if (mergeFiles === undefined || mergeFiles.length === 0) {
callback(null, state);
Expand All @@ -29,7 +29,7 @@ module.exports = function merge(state, callback) {
}, next);
},
function (data, next) {
var merged;
let merged;
try {
merged = extend.apply(null, [true].concat(data.map(JSON.parse)));
} catch (error) {
Expand Down
16 changes: 8 additions & 8 deletions lib/move.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@

'use strict';

var mv = require('mv');
var async = require('async');
var fs = require('fs');
var mkdirp = require('mkdirp');
const mv = require('mv');
const async = require('async');
const fs = require('fs');
const mkdirp = require('mkdirp');

module.exports = function (state, callback) {
var move = state.data.move;
const move = state.data.move;

if (move === undefined || move.length === 0) {
callback(null, state);
return;
}

async.parallel(move.map(function (item) {
var orig = state.template.tmp + '/' + Object.keys(item)[0],
dest = state.template.tmp + '/' + item[Object.keys(item)[0]],
destPathOnly;
const orig = state.template.tmp + '/' + Object.keys(item)[0];
const dest = state.template.tmp + '/' + item[Object.keys(item)[0]];
let destPathOnly;

if (fs.existsSync(orig)) {
destPathOnly = dest.substring(0, dest.lastIndexOf('/'));
Expand Down
14 changes: 7 additions & 7 deletions lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@

'use strict';

var fs = require('fs');
var path = require('path');
var nunjucks = require('nunjucks');
var globby = require('globby');
var async = require('async');
const fs = require('fs');
const path = require('path');
const nunjucks = require('nunjucks');
const globby = require('globby');
const async = require('async');

module.exports = function (state, callback) {

var parse = state.data.parse,
const parse = state.data.parse,
filters = state.data.filters,
env = nunjucks.configure(state.template.tmp, { autoescape: false });

Expand All @@ -34,7 +34,7 @@ module.exports = function (state, callback) {
globby(parse, { cwd: state.template.tmp, nodir: true }).then(function (paths) {
async.parallel(paths.map(function (path) {
return function (next) {
var fullPath = state.template.tmp + '/' + path;
const fullPath = state.template.tmp + '/' + path;
fs.writeFile(fullPath, nunjucks.render(fullPath, state.data), next);
};
}), function (err) {
Expand Down
4 changes: 2 additions & 2 deletions lib/prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@

'use strict';

var prompt = require('prompt');
const prompt = require('prompt');

module.exports = function (state, callback) {
if (!state.template.data || state.project || Object.keys(state.options).length) {
callback(null, state);
return;
}

var items = Object.keys(state.template.data).filter(function (item) {
const items = Object.keys(state.template.data).filter(function (item) {
return ['parse', 'discard', 'move', 'complete', 'filters', 'merge', 'prompt'].indexOf(item) === -1;
});

Expand Down
12 changes: 6 additions & 6 deletions tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

'use strict';

var pollinate = require('../lib/index.js');
var assert = require('chai').assert;
var rimraf = require('rimraf');
var fs = require('fs');
var path = require('path');
const pollinate = require('../lib/index.js');
const assert = require('chai').assert;
const rimraf = require('rimraf');
const fs = require('fs');
const path = require('path');

describe('Test basic example', function () {
afterEach(function (done) {
Expand Down Expand Up @@ -185,7 +185,7 @@ describe('Test basic example', function () {
assert.isObject(result);
fs.readFile(path.join('newproject', 'package.json'), 'utf8', function (err, data) {
assert.isNull(err);
var parsed = JSON.parse(data);
let parsed = JSON.parse(data);
assert.equal(parsed.name, 'newproject');
assert.equal(parsed.version, '1.0.0');
assert.isOk(parsed.dependencies);
Expand Down

0 comments on commit f1de717

Please sign in to comment.