Skip to content
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
3 changes: 3 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ function runPollinate(input, callback) {
function (state, next) {
require('./move.js')(state, next);
},
function (state, next) {
require('./link.js')(state, next);
},
function (state, next) {
require('./complete.js')(state, next);
}
Expand Down
56 changes: 56 additions & 0 deletions lib/link.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* __ __ _ _ _______ ____ _ _ _ _ _ ____ _____ ____ _
| \/ | / \ | |/ / ____| / ___| | | | / \ | \ | |/ ___| ____/ ___|| |
| |\/| | / _ \ | ' /| _| | | | |_| | / _ \ | \| | | _| _| \___ \| |
| | | |/ ___ \| . \| |___ | |___| _ |/ ___ \| |\ | |_| | |___ ___) |_|
|_| |_/_/ \_\_|\_\_____| \____|_| |_/_/ \_\_| \_|\____|_____|____/(_)
There is a 100% chance that this project can use improvements.
Pull requests are ALWAYS welcome, even if just amounts to a conversation. */

'use strict';

var async = require('async');
var fs = require('fs');
var path = require('path');
var cwd = process.cwd();

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

if (link === undefined) {
callback(null, state);
return;
}

process.chdir(state.template.tmp);

async.parallel(
link.map(
function (item) {
var symlinkPath = item[Object.keys(item)[0]],
relativeTarget = path.relative(Object.keys(item)[0], symlinkPath);

return function (done) {
fs.symlink(
relativeTarget,
symlinkPath,
function (err) {
if (err) {
done(err);
return;
}
done(null);
}
);
};
}
),
function (err) {
process.chdir(cwd);
if (err) {
callback(err);
return;
}
callback(null, state);
}
);
};
3 changes: 3 additions & 0 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@
"move":[
{ "origin-file": "new-name" }
],
"link": [
{ "origin-path": "linked/path" }
],
"complete":"some shell command"
}
3 changes: 3 additions & 0 deletions tests/mocks/template/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@
{ "project-name-dir": "{{ name }}" },
{ "project-name-nested": "{{ name }}/{{ name }}/{{ name }}.txt" }
],
"link": [
{ "{{ name }}.txt": "{{ name }}/{{ name }}/{{ name }}-link.txt" }
],
"complete": "git init {{ name }}"
}