mirror of
https://github.com/actraiser/dustlayer.git
synced 2025-06-18 17:05:47 -04:00
59 lines
1.9 KiB
JavaScript
59 lines
1.9 KiB
JavaScript
#!/usr/bin/env node
|
|
var dust = require('../bin/dust');
|
|
exports.list = function(){
|
|
dust.github.getJSON(dust.config.mods[dust.config.activeMod].tutorialsIdentifier, function (res){
|
|
formatTutorialsList(res);
|
|
});
|
|
};
|
|
|
|
exports.create = function downloadTutorial(repo){
|
|
if (dust.shell.test('-d',repo)){
|
|
console.log("Deleting previous download")
|
|
dust.shell.exec('rm -rf ' + repo);
|
|
}
|
|
dust.shell.exec("git clone https://github.com/actraiser/" + repo + '.git ');
|
|
dust.shell.exec("rm -rf " + repo + '/.git');
|
|
dust.color.reset();
|
|
dust.shell.exit(0);
|
|
console.log("Tutorial with id #" + id + " not found!");
|
|
dust.shell.exit(1);
|
|
}
|
|
|
|
function downloadTutorial(repo){
|
|
console.log("downloading from repo " + repo);
|
|
dust.tutorials.create(repo);
|
|
}
|
|
|
|
function formatTutorialsList(data){
|
|
var list = new Array();
|
|
console.log("-----------------------------------------------------");
|
|
for (var i = 0, iLen = data.length; i < iLen; i++) {
|
|
var formattedName = formatName(data[i].name);
|
|
dust.color.bold();
|
|
console.log(formattedName + " by " + data[i].owner);
|
|
list.push(formattedName);
|
|
dust.color.reset();
|
|
console.log(data[i].description);
|
|
console.log("Tutorial: " + data[i].homepage);
|
|
console.log("-----------------------------------------------------");
|
|
dust.color.reset();
|
|
}
|
|
dust.color.yellow().bold();
|
|
console.log("Please choose which tutorial code to download: ");
|
|
|
|
|
|
dust.cmd.choose(list, function(i){
|
|
console.log('you chose "%s"', i, list[i]);
|
|
downloadTutorial(data[i].name);
|
|
});
|
|
|
|
dust.color.reset();
|
|
}
|
|
|
|
function formatName(repositoryName){
|
|
var strippedName = repositoryName.match(new RegExp(dust.config.mods[dust.config.activeMod].tutorialsIdentifier + '-','i'));
|
|
strippedName = repositoryName.replace(strippedName[0], '');
|
|
strippedName = strippedName.replace(/-/g, ' ');
|
|
return strippedName;
|
|
}
|