UNPKG

generador-clase-seis-pcgc

Version:

Generador de la Clase 6

40 lines (38 loc) 1.13 kB
var fs = require("fs"); var request = require("request"); var DIRECTORIOS = ['css','js','images']; var FILES = ['index.html','css/bootstrap.min.css']; var HTML_TEXT = '!>h1>{Generador de HTML}' var BOOTSTRAP_URL = 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css'; function createDirsInternal(){ DIRECTORIOS.forEach(function(dir) { fs.mkdir(dir); }); } function createFilesInternal(){ FILES.forEach(function(file){ var p = new Promise(function(exito,fracaso){ switch (file) { case 'index.html': console.log("FIJANDO CONTENIDO HTML"); exito(HTML_TEXT); break; case 'css/bootstrap.min.css': request.get(BOOTSTRAP_URL,function(error,responseObject,responseBody){ console.log("Fijando contenido BOOTSTRAP"); exito(responseBody); }); break; } }); p.then(function(contenido){ console.log("CREANDO ARCHIVO"); fs.writeFile(file,contenido); }); p.catch(function(error){ console.log("ERROR: "+error); }); }); } exports.createDirs = createDirsInternal; exports.createFiles = createFilesInternal;