hikaru-coffee
Advanced tools
Comparing version 1.3.0 to 1.3.1
@@ -17,2 +17,3 @@ // Generated by CoffeeScript 2.3.1 | ||
if (!(fn instanceof Function)) { | ||
throw new TypeError("fn must be a Function!"); | ||
return; | ||
@@ -19,0 +20,0 @@ } |
// Generated by CoffeeScript 2.3.1 | ||
(function() { | ||
var Generator, Hikaru, Logger, Renderer, Router, Translator, URL, cheerio, coffee, dateStrCompare, escapeHTML, fse, getAbsPathFn, getUrlFn, glob, highlight, marked, moment, nib, nunjucks, paginate, paginateCategories, path, removeControlChars, sortCategories, stylus, yaml; | ||
var Generator, Hikaru, Logger, Renderer, Router, Translator, URL, cheerio, coffee, colors, dateStrCompare, escapeHTML, fse, getAbsPathFn, getUrlFn, glob, highlight, marked, moment, nib, nunjucks, paginate, paginateCategories, path, removeControlChars, sortCategories, stylus, yaml; | ||
@@ -17,2 +17,4 @@ fse = require("fs-extra"); | ||
colors = require("colors/safe"); | ||
yaml = require("js-yaml"); | ||
@@ -62,26 +64,26 @@ | ||
return fse.mkdirp(workDir).then(() => { | ||
this.logger.debug(`Hikaru started initialization in \`${path.join(workDir, path.sep)}\`.`); | ||
this.logger.debug(`Hikaru is copying \`${colors.cyan(configPath || path.join(workDir, "config.yml"))}\`.`); | ||
return fse.copy(path.join(__dirname, "..", "dist", "config.yml"), configPath || path.join(workDir, "config.yml")); | ||
}).then(() => { | ||
this.logger.debug(`Hikaru copyed \`${configPath || path.join(workDir, "config.yml")}\`.`); | ||
this.logger.debug(`Hikaru is creating \`${colors.cyan(path.join(workDir, "src", path.sep))}\`.`); | ||
return fse.mkdirp(path.join(workDir, "src")); | ||
}).then(() => { | ||
this.logger.debug(`Hikaru created \`${path.join(workDir, "src", path.sep)}\`.`); | ||
this.logger.debug(`Hikaru is copying \`${colors.cyan(path.join(workDir, "src", "archives", "index.md"))}\`.`); | ||
return fse.copy(path.join(__dirname, "..", "dist", "archives.md"), path.join(workDir, "src", "archives", "index.md")); | ||
}).then(() => { | ||
this.logger.debug(`Hikaru copyed \`${path.join(workDir, "src", "archives", "index.md")}\`.`); | ||
this.logger.debug(`Hikaru is copying \`${colors.cyan(path.join(workDir, "src", "categories", "index.md"))}\`.`); | ||
return fse.copy(path.join(__dirname, "..", "dist", "categories.md"), path.join(workDir, "src", "categories", "index.md")); | ||
}).then(() => { | ||
this.logger.debug(`Hikaru copyed \`${path.join(workDir, "src", "categories", "index.md")}\`.`); | ||
this.logger.debug(`Hikaru is copying \`${colors.cyan(path.join(workDir, "src", "tags", "index.md"))}\`.`); | ||
return fse.copy(path.join(__dirname, "..", "dist", "tags.md"), path.join(workDir, "src", "tags", "index.md")); | ||
}).then(() => { | ||
this.logger.debug(`Hikaru copyed \`${path.join(workDir, "src", "tags", "index.md")}\`.`); | ||
this.logger.debug(`Hikaru is creating \`${colors.cyan(path.join(workDir, "doc", path.sep))}\`.`); | ||
return fse.mkdirp(path.join(workDir, "doc")); | ||
}).then(() => { | ||
this.logger.debug(`Hikaru created \`${path.join(workDir, "doc", path.sep)}\`.`); | ||
this.logger.debug(`Hikaru is creating \`${colors.cyan(path.join(workDir, "themes", path.sep))}\`.`); | ||
return fse.mkdirp(path.join(workDir, "themes")); | ||
}).then(() => { | ||
this.logger.debug(`Hikaru created \`${path.join(workDir, "themes", path.sep)}\`.`); | ||
return this.logger.debug(`Hikaru finished initialization in \`${workDir}\`.`); | ||
}).catch(this.logger.error); | ||
}).catch((err) => { | ||
this.logger.info("Hikaru catched some error during initializing!"); | ||
return this.logger.error(err); | ||
}); | ||
} | ||
@@ -105,5 +107,13 @@ | ||
results1.push(((r) => { | ||
return fse.remove(path.join(workDir, siteConfig["docDir"], r)).then(() => { | ||
return this.logger.debug(`Hikaru removed \`${path.join(workDir, siteConfig["docDir"], r)}\`.`); | ||
}).catch(this.logger.error); | ||
return fse.stat(path.join(workDir, siteConfig["docDir"], r)).then((stats) => { | ||
if (stats.isDirectory()) { | ||
this.logger.debug(`Hikaru is removing \`${colors.cyan(path.join(workDir, siteConfig["docDir"], r, path.sep))}\`.`); | ||
} else { | ||
this.logger.debug(`Hikaru is removing \`${colors.cyan(path.join(workDir, siteConfig["docDir"], r))}\`.`); | ||
} | ||
return fse.remove(path.join(workDir, siteConfig["docDir"], r)); | ||
}).catch((err) => { | ||
this.logger.info("Hikaru catched some error during cleaning!"); | ||
return this.logger.error(err); | ||
}); | ||
})(r)); | ||
@@ -127,3 +137,10 @@ } | ||
configPath = configPath || path.join(this.site["workDir"], "config.yml"); | ||
this.site["siteConfig"] = yaml.safeLoad(fse.readFileSync(configPath, "utf8")); | ||
try { | ||
this.site["siteConfig"] = yaml.safeLoad(fse.readFileSync(configPath, "utf8")); | ||
} catch (error) { | ||
err = error; | ||
this.logger.info("Hikaru cannot find site config!"); | ||
this.logger.error(err); | ||
process.exit(-1); | ||
} | ||
this.site["srcDir"] = path.join(this.site["workDir"], this.site["siteConfig"]["srcDir"]); | ||
@@ -145,8 +162,22 @@ this.site["docDir"] = path.join(this.site["workDir"], this.site["siteConfig"]["docDir"]); | ||
this.translator = new Translator(this.logger); | ||
defaultLanguage = yaml.safeLoad(fse.readFileSync(path.join(this.site["themeDir"], "languages", "default.yml"))); | ||
this.translator.register("default", defaultLanguage); | ||
try { | ||
defaultLanguage = yaml.safeLoad(fse.readFileSync(path.join(this.site["themeDir"], "languages", "default.yml"))); | ||
this.translator.register("default", defaultLanguage); | ||
} catch (error) { | ||
err = error; | ||
if (err["code"] === "ENOENT") { | ||
this.logger.info("Hikaru cannot find default language file in your theme."); | ||
} | ||
} | ||
this.router = new Router(this.logger, this.renderer, this.generator, this.translator, this.site); | ||
this.registerInternalRenderers(); | ||
this.registerInternalGenerators(); | ||
this.registerInternalRoutes(); | ||
try { | ||
this.registerInternalRenderers(); | ||
this.registerInternalGenerators(); | ||
this.registerInternalRoutes(); | ||
} catch (error) { | ||
err = error; | ||
this.logger.info("Hikaru cannot register internal functions!"); | ||
this.logger.error(err); | ||
process.exit(-2); | ||
} | ||
return this.router.route(); | ||
@@ -156,3 +187,3 @@ } | ||
registerInternalRenderers() { | ||
var markedConfig, njkConfig, njkEnv, renderer, stylConfig; | ||
var headerIds, markedConfig, njkConfig, njkEnv, renderer, stylConfig; | ||
njkConfig = Object.assign({ | ||
@@ -180,7 +211,14 @@ "autoescape": false | ||
}, this.site["siteConfig"]["marked"]); | ||
headerIds = {}; | ||
renderer = new marked.Renderer(); | ||
renderer.heading = function(text, level) { | ||
var escaped; | ||
var escaped, id; | ||
escaped = escapeHTML(text); | ||
return `<h${level} id="${escaped}">` + `<a class="headerlink" href="#${escaped}" title="${escaped}">` + "</a>" + `${text}` + `</h${level}>`; | ||
if (headerIds[escaped]) { | ||
id = `${escaped}-${headerIds[escaped]++}`; | ||
} else { | ||
id = escaped; | ||
headerIds[escaped] = 1; | ||
} | ||
return `<h${level} id="${id}">` + `<a class="headerlink" href="#${id}" title="${escaped}">` + "</a>" + `${text}` + `</h${level}>`; | ||
}; | ||
@@ -204,2 +242,3 @@ marked.setOptions({ | ||
}, markedConfig)); | ||
headerIds = {}; | ||
return resolve(data); | ||
@@ -206,0 +245,0 @@ } catch (error) { |
// Generated by CoffeeScript 2.3.1 | ||
(function() { | ||
var Logger; | ||
var Logger, colors; | ||
colors = require("colors/safe"); | ||
module.exports = Logger = class Logger { | ||
@@ -11,3 +13,3 @@ constructor(debug) { | ||
info(...strs) { | ||
return console.log("INFO:", ...strs); | ||
return console.log(colors.yellow("INFO:"), ...strs); | ||
} | ||
@@ -17,3 +19,3 @@ | ||
if (this.isDebug) { | ||
return console.debug("DEBUG:", ...strs); | ||
return console.debug(colors.green("DEBUG:"), ...strs); | ||
} | ||
@@ -23,3 +25,3 @@ } | ||
error(...strs) { | ||
return console.log("ERROR:", ...strs); | ||
return console.log(colors.red("ERROR:"), ...strs); | ||
} | ||
@@ -26,0 +28,0 @@ |
// Generated by CoffeeScript 2.3.1 | ||
(function() { | ||
var Renderer, path, | ||
var Renderer, colors, path, | ||
indexOf = [].indexOf; | ||
@@ -8,2 +8,4 @@ | ||
colors = require("colors/safe"); | ||
module.exports = Renderer = class Renderer { | ||
@@ -22,2 +24,3 @@ constructor(logger, skipRenderList) { | ||
if (!(fn instanceof Function)) { | ||
throw new TypeError("fn must be a Function!"); | ||
return; | ||
@@ -52,11 +55,14 @@ } | ||
data["docPath"] = path.join(dirname, `${basename}${docExt}`); | ||
this.logger.debug(`Hikaru is rendering \`${colors.cyan(data["srcPath"])}\` to \`${colors.cyan(data["docPath"])}\`...`); | ||
} else { | ||
data["docPath"] = data["srcPath"]; | ||
this.logger.debug(`Hikaru is rendering \`${colors.cyan(data["srcPath"])}\`...`); | ||
} | ||
return this.store[srcExt]["fn"](data, ctx); | ||
} | ||
return new Promise(function(resolve, reject) { | ||
return new Promise((resolve, reject) => { | ||
var err; | ||
try { | ||
data["docPath"] = data["srcPath"]; | ||
this.logger.debug(`Hikaru is rendering \`${colors.cyan(data["srcPath"])}\`...`); | ||
return resolve(data); | ||
@@ -63,0 +69,0 @@ } catch (error) { |
// Generated by CoffeeScript 2.3.1 | ||
(function() { | ||
var Router, dateStrCompare, fm, fse, getAbsPathFn, getUrlFn, glob, isCurrentPathFn, moment, path, yaml; | ||
var Router, colors, dateStrCompare, fm, fse, getAbsPathFn, getUrlFn, glob, isCurrentPathFn, moment, path, yaml; | ||
@@ -15,2 +15,4 @@ path = require("path"); | ||
colors = require("colors/safe"); | ||
moment = require("moment"); | ||
@@ -56,7 +58,10 @@ | ||
if (!(type in this.store)) { | ||
throw new TypeError(`type must be a String in ${Object.keys(this.store)}!`); | ||
return; | ||
} | ||
if (fn instanceof Function) { | ||
return this.store[type].push(fn); | ||
if (!(fn instanceof Function)) { | ||
throw new TypeError("fn must be a Function!"); | ||
return; | ||
} | ||
return this.store[type].push(fn); | ||
} | ||
@@ -76,3 +81,3 @@ | ||
readData(srcDir, srcPath) { | ||
this.logger.debug(`Hikaru is reading \`${path.join(srcDir, srcPath)}\`...`); | ||
this.logger.debug(`Hikaru is reading \`${colors.cyan(path.join(srcDir, srcPath))}\`...`); | ||
return fse.readFile(path.join(srcDir, srcPath), "utf8").then(function(raw) { | ||
@@ -89,3 +94,3 @@ return { | ||
writeData(srcDir, data) { | ||
this.logger.debug(`Hikaru is writing \`${path.join(this.site["docDir"], data["docPath"])}\`...`); | ||
this.logger.debug(`Hikaru is writing \`${colors.cyan(path.join(this.site["docDir"], data["docPath"]))}\`...`); | ||
if (data["content"] != null) { | ||
@@ -197,3 +202,5 @@ return fse.outputFile(path.join(this.site["docDir"], data["docPath"]), data["content"]); | ||
err = error; | ||
null; | ||
if (err["code"] === "ENOENT") { | ||
this.logger.info(`Hikaru cannot find \`${lang}\` language file in your theme.`); | ||
} | ||
} | ||
@@ -297,2 +304,6 @@ } | ||
return this.saveAssets(); | ||
}).catch((err) => { | ||
this.logger.info("Hikaru catched some error during generating!"); | ||
this.logger.error(err); | ||
return this.logger.info("Hikaru advise you to check generating files!"); | ||
}); | ||
@@ -314,5 +325,7 @@ return Promise.all([this.renderTemplates(), this.renderPages(), this.renderPosts()]); | ||
} | ||
this.savePosts(); | ||
this.savePages(); | ||
return this.saveData(); | ||
return Promise.all([this.savePosts(), this.savePages(), this.saveData()]); | ||
}).catch((err) => { | ||
this.logger.info("Hikaru catched some error during generating!"); | ||
this.logger.error(err); | ||
return this.logger.info("Hikaru advise you to check generating files!"); | ||
}); | ||
@@ -319,0 +332,0 @@ } |
@@ -19,2 +19,3 @@ // Generated by CoffeeScript 2.3.1 | ||
if (!(obj instanceof Object)) { | ||
throw new TypeError("obj must be a Object generated from yaml language file!"); | ||
return; | ||
@@ -42,2 +43,3 @@ } | ||
if (!(lang in this.store)) { | ||
this.logger.debug(`Hikaru cannot find language \`${lang}\`, using default.`); | ||
res = this.store["default"]; | ||
@@ -44,0 +46,0 @@ } |
{ | ||
"name": "hikaru-coffee", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "A static site generator that generates routes based on directories naturally.", | ||
@@ -30,2 +30,3 @@ "main": "lib/index.js", | ||
"coffeescript": "^2.3.1", | ||
"colors": "^1.3.2", | ||
"commander": "^2.17.1", | ||
@@ -32,0 +33,0 @@ "front-matter": "^2.3.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
98348
1249
15
+ Addedcolors@^1.3.2
+ Addedcolors@1.4.0(transitive)