Skip to content
This repository was archived by the owner on Jun 16, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions bin/wilfred.js
Original file line number Diff line number Diff line change
@@ -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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down
36 changes: 34 additions & 2 deletions lib/wilfred.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand All @@ -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 = [
{
Expand Down Expand Up @@ -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)
Expand Down