UNPKG

tronbox

Version:

TronBox - Simple development framework for Tron

1 lines 1.49 kB
"use strict";function normalizeURL(url){url=url||"https://github.com/tronsuper/bare-box";if(url.indexOf("://")!==-1||url.indexOf("git@")!==-1){return url}if(url.split("/").length===2){return"https://github.com/"+url}if(url.indexOf("/")===-1){if(url.indexOf("-box")===-1){url=url+"-box"}return"https://github.com/tronsuper/"+url}throw new Error("Box specified in invalid format")}function formatCommands(commands){var names=Object.keys(commands);var maxLength=Math.max.apply(null,names.map(function(name){return name.length}));return names.map(function(name){var spacing=Array(maxLength-name.length+1).join(" ");return" "+name+": "+spacing+commands[name]})}var command={command:"unbox",description:"Download a tronbox Box, a pre-built tronbox project",builder:{},run:function run(options,done){var Config=require("../../components/Config");var Box=require("../../components/Box");var OS=require("os");var config=Config["default"]()["with"]({logger:console});var url=normalizeURL(options._[0]);Box.unbox(url,options.working_directory||config.working_directory,{logger:config.logger}).then(function(boxConfig){config.logger.log("Unbox successful. Sweet!"+OS.EOL);var commandMessages=formatCommands(boxConfig.commands);if(commandMessages.length>0){config.logger.log("Commands:"+OS.EOL)}commandMessages.forEach(function(message){config.logger.log(message)});if(boxConfig.epilogue){config.logger.log(boxConfig.epilogue.replace("\n",OS.EOL))}done()})["catch"](done)}};module.exports=command;