honkit 3.6.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +10 -0
- package/bin/honkit.js +8 -0
- package/lib/BuildGenerator.js +2 -0
- package/lib/__tests__/__fixtures__/honkit/book.js +9 -0
- package/lib/__tests__/githon.js +11 -0
- package/lib/__tests__/init.js +19 -0
- package/lib/__tests__/snapshot-honkit.js +45 -0
- package/lib/api/decodeConfig.js +17 -0
- package/lib/api/decodeGlobal.js +21 -0
- package/lib/api/decodePage.js +41 -0
- package/lib/api/deprecate.js +113 -0
- package/lib/api/encodeConfig.js +30 -0
- package/lib/api/encodeGlobal.js +226 -0
- package/lib/api/encodeNavigation.js +60 -0
- package/lib/api/encodePage.js +37 -0
- package/lib/api/encodeProgress.js +58 -0
- package/lib/api/encodeSummary.js +52 -0
- package/lib/api/index.js +15 -0
- package/lib/bin.js +46 -0
- package/lib/browser.js +41 -0
- package/lib/cli/build.js +36 -0
- package/lib/cli/buildEbook.js +63 -0
- package/lib/cli/getBook.js +24 -0
- package/lib/cli/getOutputFolder.js +19 -0
- package/lib/cli/index.js +11 -0
- package/lib/cli/init.js +17 -0
- package/lib/cli/options.js +38 -0
- package/lib/cli/parse.js +65 -0
- package/lib/cli/serve.js +184 -0
- package/lib/cli/server.js +116 -0
- package/lib/cli/watch.js +35 -0
- package/lib/constants/__tests__/configSchema.js +41 -0
- package/lib/constants/configDefault.js +9 -0
- package/lib/constants/configFiles.js +3 -0
- package/lib/constants/configSchema.js +235 -0
- package/lib/constants/defaultBlocks.js +48 -0
- package/lib/constants/defaultFilters.js +18 -0
- package/lib/constants/defaultPlugins.js +20 -0
- package/lib/constants/extsAsciidoc.js +3 -0
- package/lib/constants/extsMarkdown.js +3 -0
- package/lib/constants/ignoreFiles.js +3 -0
- package/lib/constants/pluginAssetsFolder.js +3 -0
- package/lib/constants/pluginHooks.js +3 -0
- package/lib/constants/pluginPrefix.js +3 -0
- package/lib/constants/pluginResources.js +7 -0
- package/lib/constants/templatesFolder.js +3 -0
- package/lib/constants/themePrefix.js +3 -0
- package/lib/fs/__tests__/mock.js +68 -0
- package/lib/fs/mock.js +88 -0
- package/lib/fs/node.js +44 -0
- package/lib/honkit.js +34 -0
- package/lib/index.js +17 -0
- package/lib/init.js +79 -0
- package/lib/json/encodeBook.js +41 -0
- package/lib/json/encodeBookWithPage.js +25 -0
- package/lib/json/encodeFile.js +20 -0
- package/lib/json/encodeGlossary.js +22 -0
- package/lib/json/encodeGlossaryEntry.js +16 -0
- package/lib/json/encodeLanguages.js +29 -0
- package/lib/json/encodeOutput.js +26 -0
- package/lib/json/encodeOutputWithPage.js +26 -0
- package/lib/json/encodePage.js +38 -0
- package/lib/json/encodeReadme.js +19 -0
- package/lib/json/encodeSummary.js +22 -0
- package/lib/json/encodeSummaryArticle.js +25 -0
- package/lib/json/encodeSummaryPart.js +19 -0
- package/lib/json/index.js +27 -0
- package/lib/models/__tests__/config.js +164 -0
- package/lib/models/__tests__/glossary.js +38 -0
- package/lib/models/__tests__/glossaryEntry.js +16 -0
- package/lib/models/__tests__/page.js +26 -0
- package/lib/models/__tests__/plugin.js +26 -0
- package/lib/models/__tests__/pluginDependency.js +71 -0
- package/lib/models/__tests__/summary.js +115 -0
- package/lib/models/__tests__/summaryArticle.js +62 -0
- package/lib/models/__tests__/summaryPart.js +24 -0
- package/lib/models/__tests__/templateBlock.js +172 -0
- package/lib/models/__tests__/templateEngine.js +49 -0
- package/lib/models/book.js +312 -0
- package/lib/models/config.js +152 -0
- package/lib/models/file.js +83 -0
- package/lib/models/fs.js +255 -0
- package/lib/models/glossary.js +90 -0
- package/lib/models/glossaryEntry.js +34 -0
- package/lib/models/hash.js +191 -0
- package/lib/models/ignore.js +40 -0
- package/lib/models/language.js +22 -0
- package/lib/models/languages.js +64 -0
- package/lib/models/output.js +109 -0
- package/lib/models/page.js +91 -0
- package/lib/models/parser.js +102 -0
- package/lib/models/plugin.js +139 -0
- package/lib/models/pluginDependency.js +192 -0
- package/lib/models/readme.js +38 -0
- package/lib/models/summary.js +199 -0
- package/lib/models/summaryArticle.js +169 -0
- package/lib/models/summaryPart.js +53 -0
- package/lib/models/templateBlock.js +230 -0
- package/lib/models/templateEngine.js +115 -0
- package/lib/models/templateOutput.js +36 -0
- package/lib/models/templateShortcut.js +65 -0
- package/lib/modifiers/config/__tests__/addPlugin.js +30 -0
- package/lib/modifiers/config/__tests__/removePlugin.js +29 -0
- package/lib/modifiers/config/__tests__/togglePlugin.js +28 -0
- package/lib/modifiers/config/addPlugin.js +27 -0
- package/lib/modifiers/config/editPlugin.js +13 -0
- package/lib/modifiers/config/getPluginConfig.js +22 -0
- package/lib/modifiers/config/hasPlugin.js +15 -0
- package/lib/modifiers/config/index.js +21 -0
- package/lib/modifiers/config/isDefaultPlugin.js +17 -0
- package/lib/modifiers/config/removePlugin.js +27 -0
- package/lib/modifiers/config/togglePlugin.js +32 -0
- package/lib/modifiers/index.js +11 -0
- package/lib/modifiers/summary/__tests__/editPartTitle.js +41 -0
- package/lib/modifiers/summary/__tests__/insertArticle.js +72 -0
- package/lib/modifiers/summary/__tests__/insertPart.js +56 -0
- package/lib/modifiers/summary/__tests__/mergeAtLevel.js +45 -0
- package/lib/modifiers/summary/__tests__/moveArticle.js +66 -0
- package/lib/modifiers/summary/__tests__/moveArticleAfter.js +75 -0
- package/lib/modifiers/summary/__tests__/removeArticle.js +54 -0
- package/lib/modifiers/summary/editArticleRef.js +20 -0
- package/lib/modifiers/summary/editArticleTitle.js +20 -0
- package/lib/modifiers/summary/editPartTitle.js +21 -0
- package/lib/modifiers/summary/index.js +27 -0
- package/lib/modifiers/summary/indexArticleLevels.js +21 -0
- package/lib/modifiers/summary/indexLevels.js +18 -0
- package/lib/modifiers/summary/indexPartLevels.js +25 -0
- package/lib/modifiers/summary/insertArticle.js +47 -0
- package/lib/modifiers/summary/insertPart.js +21 -0
- package/lib/modifiers/summary/mergeAtLevel.js +68 -0
- package/lib/modifiers/summary/moveArticle.js +27 -0
- package/lib/modifiers/summary/moveArticleAfter.js +59 -0
- package/lib/modifiers/summary/removeArticle.js +36 -0
- package/lib/modifiers/summary/removePart.js +18 -0
- package/lib/modifiers/summary/unshiftArticle.js +27 -0
- package/lib/output/__tests__/ebook.js +17 -0
- package/lib/output/__tests__/json.js +43 -0
- package/lib/output/__tests__/plugin-hooks.js +57 -0
- package/lib/output/__tests__/website.js +121 -0
- package/lib/output/callHook.js +51 -0
- package/lib/output/callPageHook.js +23 -0
- package/lib/output/createTemplateEngine.js +42 -0
- package/lib/output/ebook/getConvertOptions.js +69 -0
- package/lib/output/ebook/getCoverPath.js +30 -0
- package/lib/output/ebook/getPDFTemplate.js +40 -0
- package/lib/output/ebook/index.js +16 -0
- package/lib/output/ebook/onFinish.js +84 -0
- package/lib/output/ebook/onPage.js +23 -0
- package/lib/output/ebook/options.js +17 -0
- package/lib/output/generateAssets.js +26 -0
- package/lib/output/generateBook.js +167 -0
- package/lib/output/generatePage.js +90 -0
- package/lib/output/generatePages.js +52 -0
- package/lib/output/getModifiers.js +63 -0
- package/lib/output/helper/fileToOutput.js +30 -0
- package/lib/output/helper/fileToURL.js +30 -0
- package/lib/output/helper/index.js +3 -0
- package/lib/output/helper/resolveFileToURL.js +25 -0
- package/lib/output/helper/writeFile.js +26 -0
- package/lib/output/index.js +27 -0
- package/lib/output/json/index.js +14 -0
- package/lib/output/json/onFinish.js +39 -0
- package/lib/output/json/onPage.js +37 -0
- package/lib/output/json/options.js +11 -0
- package/lib/output/modifiers/__tests__/addHeadingId.js +23 -0
- package/lib/output/modifiers/__tests__/annotateText.js +39 -0
- package/lib/output/modifiers/__tests__/fetchRemoteImages.js +32 -0
- package/lib/output/modifiers/__tests__/highlightCode.js +48 -0
- package/lib/output/modifiers/__tests__/inlinePng.js +22 -0
- package/lib/output/modifiers/__tests__/inlineSvg.js +42 -0
- package/lib/output/modifiers/__tests__/resolveImages.js +39 -0
- package/lib/output/modifiers/__tests__/resolveLinks.js +81 -0
- package/lib/output/modifiers/__tests__/svgToImg.js +29 -0
- package/lib/output/modifiers/addHeadingId.js +26 -0
- package/lib/output/modifiers/annotateText.js +76 -0
- package/lib/output/modifiers/editHTMLElement.js +17 -0
- package/lib/output/modifiers/fetchRemoteImages.js +42 -0
- package/lib/output/modifiers/highlightCode.js +59 -0
- package/lib/output/modifiers/index.js +26 -0
- package/lib/output/modifiers/inlineAssets.js +29 -0
- package/lib/output/modifiers/inlinePng.js +43 -0
- package/lib/output/modifiers/inlineSvg.js +39 -0
- package/lib/output/modifiers/modifyHTML.js +27 -0
- package/lib/output/modifiers/resolveImages.js +30 -0
- package/lib/output/modifiers/resolveLinks.js +46 -0
- package/lib/output/modifiers/svgToImg.js +58 -0
- package/lib/output/page-cache.js +15 -0
- package/lib/output/prepareAssets.js +22 -0
- package/lib/output/preparePages.js +25 -0
- package/lib/output/preparePlugins.js +36 -0
- package/lib/output/testing/createMock.js +39 -0
- package/lib/output/testing/generateMock.js +55 -0
- package/lib/output/website/__tests__/i18n.js +40 -0
- package/lib/output/website/copyPluginAssets.js +92 -0
- package/lib/output/website/createTemplateEngine.js +136 -0
- package/lib/output/website/index.js +22 -0
- package/lib/output/website/listSearchPaths.js +20 -0
- package/lib/output/website/onAsset.js +29 -0
- package/lib/output/website/onFinish.js +35 -0
- package/lib/output/website/onInit.js +19 -0
- package/lib/output/website/onPage.js +73 -0
- package/lib/output/website/options.js +15 -0
- package/lib/output/website/prepareI18n.js +28 -0
- package/lib/output/website/prepareResources.js +49 -0
- package/lib/output/website/state.js +20 -0
- package/lib/parse/__tests__/listAssets.js +63 -0
- package/lib/parse/__tests__/parseBook.js +77 -0
- package/lib/parse/__tests__/parseGlossary.js +32 -0
- package/lib/parse/__tests__/parseIgnore.js +37 -0
- package/lib/parse/__tests__/parsePageFromString.js +34 -0
- package/lib/parse/__tests__/parseReadme.js +33 -0
- package/lib/parse/__tests__/parseSummary.js +30 -0
- package/lib/parse/findParsableFile.js +33 -0
- package/lib/parse/index.js +31 -0
- package/lib/parse/listAssets.js +36 -0
- package/lib/parse/lookupStructureFile.js +21 -0
- package/lib/parse/parseBook.js +68 -0
- package/lib/parse/parseConfig.js +52 -0
- package/lib/parse/parseGlossary.js +25 -0
- package/lib/parse/parseIgnore.js +43 -0
- package/lib/parse/parseLanguages.js +26 -0
- package/lib/parse/parsePage.js +21 -0
- package/lib/parse/parsePageFromString.js +25 -0
- package/lib/parse/parsePagesList.js +80 -0
- package/lib/parse/parseReadme.js +26 -0
- package/lib/parse/parseStructureFile.js +64 -0
- package/lib/parse/parseSummary.js +43 -0
- package/lib/parse/validateConfig.js +31 -0
- package/lib/parse/walkSummary.js +34 -0
- package/lib/parsers.js +60 -0
- package/lib/plugins/PluginResolver.js +84 -0
- package/lib/plugins/__tests__/findInstalled.js +25 -0
- package/lib/plugins/__tests__/listDependencies.js +28 -0
- package/lib/plugins/__tests__/sortDependencies.js +28 -0
- package/lib/plugins/__tests__/validatePlugin.js +99 -0
- package/lib/plugins/findInstalled.js +87 -0
- package/lib/plugins/index.js +17 -0
- package/lib/plugins/listBlocks.js +19 -0
- package/lib/plugins/listDependencies.js +33 -0
- package/lib/plugins/listDepsForBook.js +20 -0
- package/lib/plugins/listFilters.js +18 -0
- package/lib/plugins/listResources.js +44 -0
- package/lib/plugins/loadForBook.js +38 -0
- package/lib/plugins/loadPlugin.js +89 -0
- package/lib/plugins/package-name-util.js +48 -0
- package/lib/plugins/sortDependencies.js +30 -0
- package/lib/plugins/toNames.js +16 -0
- package/lib/plugins/validateConfig.js +60 -0
- package/lib/plugins/validatePlugin.js +36 -0
- package/lib/templating/__tests__/conrefsLoader.js +93 -0
- package/lib/templating/__tests__/postRender.js +52 -0
- package/lib/templating/__tests__/replaceShortcuts.js +27 -0
- package/lib/templating/conrefsLoader.js +88 -0
- package/lib/templating/index.js +19 -0
- package/lib/templating/listShortcuts.js +29 -0
- package/lib/templating/postRender.js +46 -0
- package/lib/templating/render.js +41 -0
- package/lib/templating/renderFile.js +39 -0
- package/lib/templating/replaceShortcuts.js +36 -0
- package/lib/templating/themesLoader.js +98 -0
- package/lib/utils/__tests__/git.js +47 -0
- package/lib/utils/__tests__/location.js +81 -0
- package/lib/utils/__tests__/path.js +19 -0
- package/lib/utils/command.js +104 -0
- package/lib/utils/error.js +88 -0
- package/lib/utils/fs.js +163 -0
- package/lib/utils/genKey.js +13 -0
- package/lib/utils/git.js +116 -0
- package/lib/utils/images.js +22 -0
- package/lib/utils/location.js +129 -0
- package/lib/utils/logger.js +158 -0
- package/lib/utils/mergeDefaults.js +18 -0
- package/lib/utils/path.js +62 -0
- package/lib/utils/promise.js +142 -0
- package/lib/utils/reducedObject.js +31 -0
- package/lib/utils/timing.js +90 -0
- package/package.json +112 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const is_1 = __importDefault(require("is"));
|
|
7
|
+
const util_1 = __importDefault(require("util"));
|
|
8
|
+
const bash_color_1 = __importDefault(require("bash-color"));
|
|
9
|
+
const immutable_1 = __importDefault(require("immutable"));
|
|
10
|
+
const LEVELS = immutable_1.default.Map({
|
|
11
|
+
DEBUG: 0,
|
|
12
|
+
INFO: 1,
|
|
13
|
+
WARN: 2,
|
|
14
|
+
ERROR: 3,
|
|
15
|
+
DISABLED: 10,
|
|
16
|
+
});
|
|
17
|
+
const COLORS = immutable_1.default.Map({
|
|
18
|
+
DEBUG: bash_color_1.default.purple,
|
|
19
|
+
INFO: bash_color_1.default.cyan,
|
|
20
|
+
WARN: bash_color_1.default.yellow,
|
|
21
|
+
ERROR: bash_color_1.default.red,
|
|
22
|
+
});
|
|
23
|
+
function Logger(write, logLevel) {
|
|
24
|
+
// @ts-expect-error ts-migrate(2350) FIXME: Only a void function can be called with the 'new' ... Remove this comment to see the full error message
|
|
25
|
+
if (!(this instanceof Logger))
|
|
26
|
+
return new Logger(write, logLevel);
|
|
27
|
+
this._write =
|
|
28
|
+
write ||
|
|
29
|
+
function (msg) {
|
|
30
|
+
if (process.stdout) {
|
|
31
|
+
process.stdout.write(msg);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
this.lastChar = "\n";
|
|
35
|
+
this.setLevel(logLevel || "info");
|
|
36
|
+
// Create easy-to-use method like "logger.debug.ln('....')"
|
|
37
|
+
LEVELS.forEach(function (level, levelKey) {
|
|
38
|
+
if (levelKey === "DISABLED") {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
levelKey = levelKey.toLowerCase();
|
|
42
|
+
this[levelKey] = this.log.bind(this, level);
|
|
43
|
+
this[levelKey].ln = this.logLn.bind(this, level);
|
|
44
|
+
this[levelKey].ok = this.ok.bind(this, level);
|
|
45
|
+
this[levelKey].fail = this.fail.bind(this, level);
|
|
46
|
+
this[levelKey].promise = this.promise.bind(this, level);
|
|
47
|
+
}, this);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
Change minimum level
|
|
51
|
+
|
|
52
|
+
@param {string} logLevel
|
|
53
|
+
*/
|
|
54
|
+
Logger.prototype.setLevel = function (logLevel) {
|
|
55
|
+
if (is_1.default.string(logLevel)) {
|
|
56
|
+
logLevel = logLevel.toUpperCase();
|
|
57
|
+
logLevel = LEVELS.get(logLevel);
|
|
58
|
+
}
|
|
59
|
+
this.logLevel = logLevel;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
Return minimum logging level
|
|
63
|
+
|
|
64
|
+
@return {number}
|
|
65
|
+
*/
|
|
66
|
+
Logger.prototype.getLevel = function (logLevel) {
|
|
67
|
+
return this.logLevel;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
Print a simple string
|
|
71
|
+
|
|
72
|
+
@param {string}
|
|
73
|
+
*/
|
|
74
|
+
Logger.prototype.write = function (msg) {
|
|
75
|
+
msg = msg.toString();
|
|
76
|
+
this.lastChar = msg[msg.length - 1];
|
|
77
|
+
return this._write(msg);
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
Format a string using the first argument as a printf-like format.
|
|
81
|
+
*/
|
|
82
|
+
Logger.prototype.format = function () {
|
|
83
|
+
return util_1.default.format.apply(util_1.default, arguments);
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
Print a line
|
|
87
|
+
|
|
88
|
+
@param {string}
|
|
89
|
+
*/
|
|
90
|
+
Logger.prototype.writeLn = function (msg) {
|
|
91
|
+
return this.write(`${msg || ""}\n`);
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
Log/Print a message if level is allowed
|
|
95
|
+
|
|
96
|
+
@param {number} level
|
|
97
|
+
*/
|
|
98
|
+
Logger.prototype.log = function (level) {
|
|
99
|
+
if (level < this.logLevel)
|
|
100
|
+
return;
|
|
101
|
+
const levelKey = LEVELS.findKey((v) => {
|
|
102
|
+
return v === level;
|
|
103
|
+
});
|
|
104
|
+
const args = Array.prototype.slice.apply(arguments, [1]);
|
|
105
|
+
let msg = this.format.apply(this, args);
|
|
106
|
+
if (this.lastChar == "\n") {
|
|
107
|
+
msg = `${COLORS.get(levelKey)(`${levelKey.toLowerCase()}:`)} ${msg}`;
|
|
108
|
+
}
|
|
109
|
+
return this.write(msg);
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
Log/Print a line if level is allowed
|
|
113
|
+
*/
|
|
114
|
+
Logger.prototype.logLn = function () {
|
|
115
|
+
if (this.lastChar != "\n")
|
|
116
|
+
this.write("\n");
|
|
117
|
+
const args = Array.prototype.slice.apply(arguments);
|
|
118
|
+
args.push("\n");
|
|
119
|
+
return this.log.apply(this, args);
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
Log a confirmation [OK]
|
|
123
|
+
*/
|
|
124
|
+
Logger.prototype.ok = function (level) {
|
|
125
|
+
const args = Array.prototype.slice.apply(arguments, [1]);
|
|
126
|
+
const msg = this.format.apply(this, args);
|
|
127
|
+
if (arguments.length > 1) {
|
|
128
|
+
this.logLn(level, bash_color_1.default.green(">> ") + msg.trim().replace(/\n/g, bash_color_1.default.green("\n>> ")));
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
this.log(level, bash_color_1.default.green("OK"), "\n");
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
Log a "FAIL"
|
|
136
|
+
*/
|
|
137
|
+
Logger.prototype.fail = function (level) {
|
|
138
|
+
return this.log(level, `${bash_color_1.default.red("ERROR")}\n`);
|
|
139
|
+
};
|
|
140
|
+
/**
|
|
141
|
+
Log state of a promise
|
|
142
|
+
|
|
143
|
+
@param {number} level
|
|
144
|
+
@param {Promise}
|
|
145
|
+
@return {Promise}
|
|
146
|
+
*/
|
|
147
|
+
Logger.prototype.promise = function (level, p) {
|
|
148
|
+
const that = this;
|
|
149
|
+
return p.then((st) => {
|
|
150
|
+
that.ok(level);
|
|
151
|
+
return st;
|
|
152
|
+
}, (err) => {
|
|
153
|
+
that.fail(level);
|
|
154
|
+
throw err;
|
|
155
|
+
});
|
|
156
|
+
};
|
|
157
|
+
Logger.LEVELS = LEVELS;
|
|
158
|
+
exports.default = Logger;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const immutable_1 = __importDefault(require("immutable"));
|
|
7
|
+
/**
|
|
8
|
+
* Merge
|
|
9
|
+
* @param {Object|Map} obj
|
|
10
|
+
* @param {Object|Map} src
|
|
11
|
+
* @return {Object}
|
|
12
|
+
*/
|
|
13
|
+
function mergeDefaults(obj, src) {
|
|
14
|
+
const objValue = immutable_1.default.fromJS(obj);
|
|
15
|
+
const srcValue = immutable_1.default.fromJS(src);
|
|
16
|
+
return srcValue.mergeDeep(objValue).toJS();
|
|
17
|
+
}
|
|
18
|
+
exports.default = mergeDefaults;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const path_1 = __importDefault(require("path"));
|
|
7
|
+
const error_1 = __importDefault(require("./error"));
|
|
8
|
+
// Normalize a filename
|
|
9
|
+
function normalizePath(filename) {
|
|
10
|
+
return path_1.default.normalize(filename);
|
|
11
|
+
}
|
|
12
|
+
// Return true if file path is inside a folder
|
|
13
|
+
function isInRoot(root, filename) {
|
|
14
|
+
root = path_1.default.normalize(root);
|
|
15
|
+
filename = path_1.default.normalize(filename);
|
|
16
|
+
if (root === ".") {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
if (root[root.length - 1] != path_1.default.sep) {
|
|
20
|
+
root = root + path_1.default.sep;
|
|
21
|
+
}
|
|
22
|
+
return filename.substr(0, root.length) === root;
|
|
23
|
+
}
|
|
24
|
+
// Resolve paths in a specific folder
|
|
25
|
+
// Throw error if file is outside this folder
|
|
26
|
+
function resolveInRoot(root) {
|
|
27
|
+
const args = Array.prototype.slice.call(arguments, 1);
|
|
28
|
+
const input = args.reduce((current, p) => {
|
|
29
|
+
// Handle path relative to book root ("/README.md")
|
|
30
|
+
if (p[0] == "/" || p[0] == "\\")
|
|
31
|
+
return p.slice(1);
|
|
32
|
+
return current ? path_1.default.join(current, p) : path_1.default.normalize(p);
|
|
33
|
+
}, "");
|
|
34
|
+
const result = path_1.default.resolve(root, input);
|
|
35
|
+
if (!isInRoot(root, result)) {
|
|
36
|
+
throw new error_1.default.FileOutOfScopeError({
|
|
37
|
+
filename: result,
|
|
38
|
+
root: root,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
// Chnage extension of a file
|
|
44
|
+
function setExtension(filename, ext) {
|
|
45
|
+
return path_1.default.join(path_1.default.dirname(filename), path_1.default.basename(filename, path_1.default.extname(filename)) + ext);
|
|
46
|
+
}
|
|
47
|
+
/*
|
|
48
|
+
Return true if a filename is relative.
|
|
49
|
+
|
|
50
|
+
@param {string}
|
|
51
|
+
@return {boolean}
|
|
52
|
+
*/
|
|
53
|
+
function isPureRelative(filename) {
|
|
54
|
+
return filename.indexOf("./") === 0 || filename.indexOf("../") === 0;
|
|
55
|
+
}
|
|
56
|
+
exports.default = {
|
|
57
|
+
isInRoot: isInRoot,
|
|
58
|
+
resolveInRoot: resolveInRoot,
|
|
59
|
+
normalize: normalizePath,
|
|
60
|
+
setExtension: setExtension,
|
|
61
|
+
isPureRelative: isPureRelative,
|
|
62
|
+
};
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.wrap = exports.some = exports.serie = exports.map = exports.reduce = exports.forEach = void 0;
|
|
7
|
+
const q_1 = __importDefault(require("q"));
|
|
8
|
+
const immutable_1 = __importDefault(require("immutable"));
|
|
9
|
+
// Debugging for long stack traces
|
|
10
|
+
if (process.env.DEBUG || process.env.CI) {
|
|
11
|
+
q_1.default.longStackSupport = true;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Reduce an array to a promise
|
|
15
|
+
*
|
|
16
|
+
* @param {Array|List} arr
|
|
17
|
+
* @param {Function(value, element, index)} iter
|
|
18
|
+
* @param {Array|List} base
|
|
19
|
+
* @return {Promise<Mixed>}
|
|
20
|
+
*/
|
|
21
|
+
function reduce(arr, iter, base) {
|
|
22
|
+
arr = immutable_1.default.Iterable.isIterable(arr) ? arr : immutable_1.default.List(arr);
|
|
23
|
+
return arr.reduce((prev, elem, key) => {
|
|
24
|
+
return prev.then((val) => {
|
|
25
|
+
return iter(val, elem, key);
|
|
26
|
+
});
|
|
27
|
+
}, q_1.default(base));
|
|
28
|
+
}
|
|
29
|
+
exports.reduce = reduce;
|
|
30
|
+
/**
|
|
31
|
+
* Iterate over an array using an async iter
|
|
32
|
+
*
|
|
33
|
+
* @param {Array|List} arr
|
|
34
|
+
* @param {Function(value, element, index)}
|
|
35
|
+
* @return {Promise}
|
|
36
|
+
*/
|
|
37
|
+
function forEach(arr, iter) {
|
|
38
|
+
// @ts-expect-error ts-migrate(2554) FIXME: Expected 3 arguments, but got 2.
|
|
39
|
+
return reduce(arr, (val, el, key) => {
|
|
40
|
+
return iter(el, key);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
exports.forEach = forEach;
|
|
44
|
+
/**
|
|
45
|
+
* Transform an array
|
|
46
|
+
*
|
|
47
|
+
* @param {Array|List} arr
|
|
48
|
+
* @param {Function(value, element, index)}
|
|
49
|
+
* @return {Promise}
|
|
50
|
+
*/
|
|
51
|
+
function serie(arr, iter, base) {
|
|
52
|
+
return reduce(arr, (before, item, key) => {
|
|
53
|
+
return q_1.default(iter(item, key)).then((r) => {
|
|
54
|
+
before.push(r);
|
|
55
|
+
return before;
|
|
56
|
+
});
|
|
57
|
+
}, []);
|
|
58
|
+
}
|
|
59
|
+
exports.serie = serie;
|
|
60
|
+
/**
|
|
61
|
+
* Iter over an array and return first result (not null)
|
|
62
|
+
*
|
|
63
|
+
* @param {Array|List} arr
|
|
64
|
+
* @param {Function(element, index)}
|
|
65
|
+
* @return {Promise<Mixed>}
|
|
66
|
+
*/
|
|
67
|
+
function some(arr, iter) {
|
|
68
|
+
arr = immutable_1.default.List(arr);
|
|
69
|
+
return arr.reduce((prev, elem, i) => {
|
|
70
|
+
return prev.then((val) => {
|
|
71
|
+
if (val)
|
|
72
|
+
return val;
|
|
73
|
+
return iter(elem, i);
|
|
74
|
+
});
|
|
75
|
+
}, q_1.default());
|
|
76
|
+
}
|
|
77
|
+
exports.some = some;
|
|
78
|
+
/**
|
|
79
|
+
* Map an array using an async (promised) iterator
|
|
80
|
+
*
|
|
81
|
+
* @param {Array|List} arr
|
|
82
|
+
* @param {Function(element, index)}
|
|
83
|
+
* @return {Promise<List>}
|
|
84
|
+
*/
|
|
85
|
+
function mapAsList(arr, iter) {
|
|
86
|
+
return reduce(arr, (prev, entry, i) => {
|
|
87
|
+
return q_1.default(iter(entry, i)).then((out) => {
|
|
88
|
+
prev.push(out);
|
|
89
|
+
return prev;
|
|
90
|
+
});
|
|
91
|
+
}, []);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Map an array or map
|
|
95
|
+
*
|
|
96
|
+
* @param {Array|List|Map|OrderedMap} arr
|
|
97
|
+
* @param {Function(element, key)}
|
|
98
|
+
* @return {Promise<List|Map|OrderedMap>}
|
|
99
|
+
*/
|
|
100
|
+
function map(arr, iter) {
|
|
101
|
+
if (immutable_1.default.Map.isMap(arr)) {
|
|
102
|
+
let type = "Map";
|
|
103
|
+
if (immutable_1.default.OrderedMap.isOrderedMap(arr)) {
|
|
104
|
+
type = "OrderedMap";
|
|
105
|
+
}
|
|
106
|
+
return mapAsList(arr, (value, key) => {
|
|
107
|
+
return q_1.default(iter(value, key)).then((result) => {
|
|
108
|
+
return [key, result];
|
|
109
|
+
});
|
|
110
|
+
}).then((result) => {
|
|
111
|
+
return immutable_1.default[type](result);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
return mapAsList(arr, iter).then((result) => {
|
|
116
|
+
return immutable_1.default.List(result);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
exports.map = map;
|
|
121
|
+
/**
|
|
122
|
+
* Wrap a function in a promise
|
|
123
|
+
*
|
|
124
|
+
* @param {Function} func
|
|
125
|
+
* @return {Funciton}
|
|
126
|
+
*/
|
|
127
|
+
function wrap(func) {
|
|
128
|
+
return function () {
|
|
129
|
+
const args = Array.prototype.slice.call(arguments, 0);
|
|
130
|
+
return q_1.default().then(() => {
|
|
131
|
+
return func.apply(null, args);
|
|
132
|
+
});
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
exports.wrap = wrap;
|
|
136
|
+
q_1.default.forEach = forEach;
|
|
137
|
+
q_1.default.reduce = reduce;
|
|
138
|
+
q_1.default.map = map;
|
|
139
|
+
q_1.default.serie = serie;
|
|
140
|
+
q_1.default.some = some;
|
|
141
|
+
q_1.default.wrap = wrap;
|
|
142
|
+
exports.default = q_1.default;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const immutable_1 = __importDefault(require("immutable"));
|
|
7
|
+
/**
|
|
8
|
+
* Reduce the difference between a map and its default version
|
|
9
|
+
* @param {Map} defaultVersion
|
|
10
|
+
* @param {Map} currentVersion
|
|
11
|
+
* @return {Map} The properties of currentVersion that differs from defaultVersion
|
|
12
|
+
*/
|
|
13
|
+
function reducedObject(defaultVersion, currentVersion) {
|
|
14
|
+
if (defaultVersion === undefined) {
|
|
15
|
+
return currentVersion;
|
|
16
|
+
}
|
|
17
|
+
return currentVersion.reduce((result, value, key) => {
|
|
18
|
+
const defaultValue = defaultVersion.get(key);
|
|
19
|
+
if (immutable_1.default.Map.isMap(value)) {
|
|
20
|
+
const diffs = reducedObject(defaultValue, value);
|
|
21
|
+
if (diffs.size > 0) {
|
|
22
|
+
return result.set(key, diffs);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (immutable_1.default.is(defaultValue, value)) {
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
return result.set(key, value);
|
|
29
|
+
}, immutable_1.default.Map());
|
|
30
|
+
}
|
|
31
|
+
exports.default = reducedObject;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const immutable_1 = __importDefault(require("immutable"));
|
|
7
|
+
const is_1 = __importDefault(require("is"));
|
|
8
|
+
const timers = {};
|
|
9
|
+
const startDate = Date.now();
|
|
10
|
+
/**
|
|
11
|
+
Mesure an operation
|
|
12
|
+
|
|
13
|
+
@parqm {string} type
|
|
14
|
+
@param {Promise} p
|
|
15
|
+
@return {Promise}
|
|
16
|
+
*/
|
|
17
|
+
function measure(type, p) {
|
|
18
|
+
timers[type] = timers[type] || {
|
|
19
|
+
type: type,
|
|
20
|
+
count: 0,
|
|
21
|
+
total: 0,
|
|
22
|
+
min: undefined,
|
|
23
|
+
max: 0,
|
|
24
|
+
};
|
|
25
|
+
const start = Date.now();
|
|
26
|
+
return p.fin(() => {
|
|
27
|
+
const end = Date.now();
|
|
28
|
+
const duration = end - start;
|
|
29
|
+
timers[type].count++;
|
|
30
|
+
timers[type].total += duration;
|
|
31
|
+
if (is_1.default.undefined(timers[type].min)) {
|
|
32
|
+
timers[type].min = duration;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
timers[type].min = Math.min(timers[type].min, duration);
|
|
36
|
+
}
|
|
37
|
+
timers[type].max = Math.max(timers[type].max, duration);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
Return a milliseconds number as a second string
|
|
42
|
+
|
|
43
|
+
@param {number} ms
|
|
44
|
+
@return {string}
|
|
45
|
+
*/
|
|
46
|
+
function time(ms) {
|
|
47
|
+
if (ms < 1000) {
|
|
48
|
+
return `${ms.toFixed(0)}ms`;
|
|
49
|
+
}
|
|
50
|
+
return `${(ms / 1000).toFixed(2)}s`;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
Dump all timers to a logger
|
|
54
|
+
|
|
55
|
+
@param {Logger} logger
|
|
56
|
+
*/
|
|
57
|
+
function dump(logger) {
|
|
58
|
+
const prefix = " > ";
|
|
59
|
+
let measured = 0;
|
|
60
|
+
const totalDuration = Date.now() - startDate;
|
|
61
|
+
// Enable debug logging
|
|
62
|
+
const logLevel = logger.getLevel();
|
|
63
|
+
logger.setLevel("debug");
|
|
64
|
+
immutable_1.default.Map(timers)
|
|
65
|
+
.valueSeq()
|
|
66
|
+
.sortBy((timer) => {
|
|
67
|
+
// @ts-expect-error ts-migrate(2339) FIXME: Property 'total' does not exist on type 'unknown'.
|
|
68
|
+
measured += timer.total;
|
|
69
|
+
// @ts-expect-error ts-migrate(2339) FIXME: Property 'total' does not exist on type 'unknown'.
|
|
70
|
+
return timer.total;
|
|
71
|
+
})
|
|
72
|
+
.forEach((timer) => {
|
|
73
|
+
// @ts-expect-error ts-migrate(2339) FIXME: Property 'total' does not exist on type 'unknown'.
|
|
74
|
+
const percent = (timer.total * 100) / totalDuration;
|
|
75
|
+
// @ts-expect-error ts-migrate(2339) FIXME: Property 'type' does not exist on type 'unknown'.
|
|
76
|
+
logger.debug.ln(`${percent.toFixed(1)}% of time spent in "${timer.type}" (${timer.count} times) :`);
|
|
77
|
+
// @ts-expect-error ts-migrate(2339) FIXME: Property 'total' does not exist on type 'unknown'.
|
|
78
|
+
logger.debug.ln(`${prefix}Total: ${time(timer.total)} | Average: ${time(timer.total / timer.count)}`);
|
|
79
|
+
// @ts-expect-error ts-migrate(2339) FIXME: Property 'min' does not exist on type 'unknown'.
|
|
80
|
+
logger.debug.ln(`${prefix}Min: ${time(timer.min)} | Max: ${time(timer.max)}`);
|
|
81
|
+
logger.debug.ln("---------------------------");
|
|
82
|
+
});
|
|
83
|
+
logger.debug.ln(`${time(totalDuration - measured)} spent in non-mesured sections`);
|
|
84
|
+
// Rollback to previous level
|
|
85
|
+
logger.setLevel(logLevel);
|
|
86
|
+
}
|
|
87
|
+
exports.default = {
|
|
88
|
+
measure: measure,
|
|
89
|
+
dump: dump,
|
|
90
|
+
};
|