diff --git a/bin/wilfred.js b/bin/wilfred.js index 6e6e62c..a07ae13 100644 --- a/bin/wilfred.js +++ b/bin/wilfred.js @@ -1,12 +1,12 @@ #!/usr/bin/env node 'use strict'; -var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); - Object.defineProperty(exports, "__esModule", { value: true }); +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + var _os = require('os'); var _os2 = _interopRequireDefault(_os); @@ -43,6 +43,7 @@ var CONFIG_PATH = _path2.default.join(HOMEDIR, '.' + PKG.name + '.json'); var DEFAULT_CONFIG = { boilerplates: [] }; +var WILFREDIGNORE_FILENAME = '.wilfredignore'; _commander2.default.version(PKG.version).usage('[options] [boilerplate name] [location]').option('-a, --add', 'Save given path as boilerplate').option('-f, --force', 'Force copying the boilerplate to destination').option('-l, --list', 'Returns the list of boilerplates').option('-r, --remove', 'Remove boilerplate by name').option('-s, --silent', 'Run in silent mode (requires passing at least boilerplate parameter)').parse(process.argv); @@ -130,6 +131,17 @@ var Wilfred = function () { !_commander2.default.silent && console.log(options.boilerplate, 'added as boilerplate!'); }); } + }, { + key: 'readIgnoreFileSync', + value: function readIgnoreFileSync(root) { + var paths = []; + try { + paths = _fsExtra2.default.readFileSync(root + "\\" + WILFREDIGNORE_FILENAME).toString().split("\n").map(function (value) { + return value.replace("/", "\\").trim(); + }); + } catch (error) {} + return paths; + } }, { key: 'copy', value: function copy(options) { @@ -139,7 +151,15 @@ var Wilfred = function () { return item.boilerplate === options.boilerplate; }), execCopy = function execCopy(from, to) { - _fsExtra2.default.copy(from, to, function (err) { + var ignorePaths = _this2.readIgnoreFileSync(from); + + var filter = function filter(path) { + return ignorePaths.every(function (value, index) { + return path !== from + "\\" + value; + }); + }; + + _fsExtra2.default.copy(from, to, { filter: filter }, function (err) { if (err) return console.error(err); !_commander2.default.silent && console.log('Boilerplate copied to destination!'); _this2.postCopy(to); diff --git a/lib/wilfred.js b/lib/wilfred.js index d1f2dc5..092f52a 100644 --- a/lib/wilfred.js +++ b/lib/wilfred.js @@ -14,6 +14,7 @@ const CONFIG_PATH = path.join(HOMEDIR, `.${PKG.name}.json`) const DEFAULT_CONFIG = { boilerplates: [] } +const WILFREDIGNORE_FILENAME = '.wilfredignore' program .version(PKG.version) @@ -23,6 +24,7 @@ program .option('-l, --list', 'Returns the list of boilerplates') .option('-r, --remove', 'Remove boilerplate by name') .option('-s, --silent', 'Run in silent mode (requires passing at least boilerplate parameter)') + .option('-p, --path [name]', 'Returns path to a boilerplate by its name') .parse(process.argv) class Wilfred { @@ -42,6 +44,16 @@ class Wilfred { return this.remove(); } + if(program.path) { + var bp = this.config.boilerplates.find(item => item.boilerplate === program.path); + if(bp) { + console.log(bp.path); + } else { + console.log('Boilerplate not found...'); + } + return; + } + if (program.add) { this.questions = [ { @@ -102,11 +114,31 @@ class Wilfred { !program.silent && console.log(options.boilerplate, 'added as boilerplate!') }) } - + + readIgnoreFileSync(root){ + var paths = [] + try { + paths = fs.readFileSync(root + "\\" + WILFREDIGNORE_FILENAME).toString().split("\n").map((value) => { + return value.replace("/", "\\").trim(); + }); + } catch (error) { + + } + return paths; + } + copy(options) { let bp = this.config.boilerplates.find(item => item.boilerplate === options.boilerplate), execCopy = (from, to) => { - fs.copy(from, to, (err) => { + var ignorePaths = this.readIgnoreFileSync(from); + + var filter = (path) => { + return ignorePaths.every((value, index) => { + return path !== (from + "\\" + value); + }); + } + + fs.copy(from, to, { filter: filter }, (err) => { if (err) return console.error(err) !program.silent && console.log('Boilerplate copied to destination!') this.postCopy(to)