wiki-builder
Advanced tools
Comparing version 1.0.2 to 1.0.5
134
lib/build.js
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -9,18 +8,10 @@ value: true | ||
exports["default"] = void 0; | ||
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")); | ||
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray")); | ||
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof")); | ||
var _fsExtra = _interopRequireDefault(require("fs-extra")); | ||
var _glob = _interopRequireDefault(require("glob")); | ||
var _shelljs = _interopRequireDefault(require("shelljs")); | ||
var _tracer = _interopRequireDefault(require("tracer")); | ||
var _default = { | ||
var _default = exports["default"] = { | ||
tempWikiDir: 'tempMdFiles', | ||
@@ -32,3 +23,2 @@ wikiConfigFileName: 'wikiConfig.json', | ||
console.log(data.output); | ||
_fsExtra["default"].appendFile('./wiki-build.log', "".concat(data.rawoutput, "\n"), function (err) { | ||
@@ -41,10 +31,8 @@ if (err) throw err; | ||
var _this = this; | ||
var wikiConfig = await this.getWikiConfigData(await this.findWikiConfigPath()["catch"](this.logger.error))["catch"](this.logger.error); | ||
var wikiDirPath = wikiConfig.wikiDirPath, | ||
ignoreMdTitles = wikiConfig.ignoreMdTitles, | ||
statsEnabled = wikiConfig.statsEnabled, | ||
plugins = wikiConfig.plugins, | ||
useLogger = wikiConfig.useLogger; | ||
ignoreMdTitles = wikiConfig.ignoreMdTitles, | ||
statsEnabled = wikiConfig.statsEnabled, | ||
plugins = wikiConfig.plugins, | ||
useLogger = wikiConfig.useLogger; | ||
if (!useLogger) { | ||
@@ -57,3 +45,2 @@ var logLevels = ['log', 'trace', 'debug', 'info', 'warn', 'error']; | ||
} | ||
await _fsExtra["default"].ensureDir(wikiDirPath)["catch"](this.logger.error); | ||
@@ -74,9 +61,6 @@ await this.removeMdFilesInWikiDir(wikiDirPath)["catch"](this.logger.error); | ||
var _this2 = this; | ||
plugins.forEach(function (plugin) { | ||
var pluginPath = _this2.getPluginPath(plugin); // eslint-disable-next-line | ||
var pluginPath = _this2.getPluginPath(plugin); | ||
// eslint-disable-next-line | ||
var pluginModule = require(pluginPath); | ||
var raStepArray = pluginModule.getStep(); | ||
@@ -90,7 +74,5 @@ raStepArray[1].push([pluginModule, plugin]); | ||
var _this3 = this; | ||
if (!Array.isArray(plugins) || plugins.length <= 0) { | ||
return []; | ||
} | ||
return plugins.map(function (plugin) { | ||
@@ -104,9 +86,6 @@ return _this3.getPluginPath(plugin); | ||
} | ||
var returnPluginPath = "".concat(process.cwd(), "/node_modules/").concat(pluginPath); | ||
if (pluginPath.endsWith('/')) { | ||
return returnPluginPath; | ||
} | ||
return "".concat(returnPluginPath, "/"); | ||
@@ -118,3 +97,2 @@ }, | ||
} | ||
var regex = new RegExp("".concat(this.wikiConfigFileName, "$"), 'g'); | ||
@@ -127,3 +105,2 @@ return _shelljs["default"].find('.').filter(function (file) { | ||
var _this4 = this; | ||
return _fsExtra["default"].readJson(wikiStringPath).then(function (wikiConfig) { | ||
@@ -133,3 +110,2 @@ return _this4.useGitignoredIfEnabled(_this4.cleanWikiConfigData(wikiConfig)); | ||
_this4.logger.error(err); | ||
return {}; | ||
@@ -154,3 +130,2 @@ }); | ||
var configPathReturn = configPath.trim(); | ||
if (configPathReturn.length === 0) { | ||
@@ -161,3 +136,2 @@ configPathReturn = defaultPath; | ||
} | ||
return configPathReturn; | ||
@@ -167,3 +141,2 @@ }, | ||
var configArrayReturn = configArray; | ||
if (!Array.isArray(configArray) && configArray) { | ||
@@ -175,6 +148,4 @@ if ((0, _typeof2["default"])(configArray) !== (0, _typeof2["default"])(true)) { | ||
} | ||
return configArrayReturn.map(function (file) { | ||
var fileReturn = String(file).trim(); | ||
if (caseFunc.toLowerCase() === 'lower') { | ||
@@ -185,3 +156,2 @@ fileReturn = fileReturn.toLowerCase(); | ||
} | ||
return fileReturn; | ||
@@ -197,7 +167,5 @@ }).filter(function (file) { | ||
} | ||
if (defaultValue && configBool === undefined) { | ||
return defaultValue; | ||
} | ||
return Boolean(configBool); | ||
@@ -208,7 +176,5 @@ }, | ||
var pathExists = await _fsExtra["default"].pathExists(wikiTempDir)["catch"](this.logger.error); | ||
if (pathExists) { | ||
return _fsExtra["default"].emptyDir(wikiTempDir); | ||
} | ||
return _fsExtra["default"].ensureDir(wikiTempDir); | ||
@@ -236,6 +202,5 @@ }, | ||
var _this5 = this; | ||
var wikiDirPath = wikiConfig.wikiDirPath, | ||
projectDirPath = wikiConfig.projectDirPath, | ||
ignoreMdFiles = wikiConfig.ignoreMdFiles; | ||
projectDirPath = wikiConfig.projectDirPath, | ||
ignoreMdFiles = wikiConfig.ignoreMdFiles; | ||
var mdFiles = await this.getMdFilesInDir(projectDirPath, 'project')["catch"](this.logger.error); | ||
@@ -256,3 +221,2 @@ mdFiles = mdFiles.filter(this.ignoreDirsFilterCallback(wikiConfig.ignoreDirs)); | ||
}); | ||
if (!ignoreMdSpecificFiles.some(function (ignore) { | ||
@@ -265,3 +229,2 @@ return file === ignore; | ||
} | ||
return ''; | ||
@@ -276,3 +239,2 @@ }); | ||
} | ||
var statsFile = "".concat(wikiDirPath, "/").concat(this.tempWikiDir, "/Stats.md"); | ||
@@ -286,3 +248,2 @@ var command = 'git diff --stat `git hash-object -t tree /dev/null`'; | ||
} | ||
resolve(stdout); | ||
@@ -295,3 +256,2 @@ }); | ||
var newFileData = data.toString().split('\n'); | ||
if (data.toString().length > 0) { | ||
@@ -301,18 +261,13 @@ newFileData.pop(); | ||
var numberMatches = fileCountLineCount.match(/\d+/g); | ||
if (numberMatches[1].length > 0) { | ||
newFileData.push("### Total Lines of Code: ".concat(numberMatches[1])); | ||
} | ||
if (numberMatches[0].length > 0) { | ||
newFileData.splice(0, 0, "### Number of Files: ".concat(numberMatches[0])); | ||
} | ||
newFileData.splice(0, 0, '# Stats'); | ||
} | ||
resolve(newFileData.join('\n\n')); | ||
}); | ||
})["catch"](this.logger.error); | ||
if (writeFileData.length > 0) { | ||
@@ -326,3 +281,2 @@ return new Promise(function (resolve, reject) { | ||
} | ||
await _fsExtra["default"].remove(statsFile)["catch"](this.logger.error); | ||
@@ -334,3 +288,2 @@ return 'Stats file removed because it was empty'; | ||
var gitIgnoreFound = await _fsExtra["default"].pathExists("".concat(wikiConfig.projectDirPath, ".gitignore"))["catch"](this.logger.error); | ||
if (wikiConfig.useGitignore && gitIgnoreFound) { | ||
@@ -342,3 +295,2 @@ var newWikiConfig = wikiConfig; | ||
var endOfPath = line.split('/').pop(); | ||
if (line.slice(-1) === '/') { | ||
@@ -352,3 +304,2 @@ newWikiConfig.ignoreDirs.push(line); | ||
} | ||
return wikiConfig; | ||
@@ -370,3 +321,2 @@ }, | ||
var safetyCounter = safety; | ||
if (!safetyCounter) { | ||
@@ -377,43 +327,33 @@ safetyCounter = 1; | ||
} | ||
safetyCounter += 1; // ------------- Get Functions and Extra Arguments for Next Section ------------- | ||
safetyCounter += 1; | ||
// ------------- Get Functions and Extra Arguments for Next Section ------------- | ||
var mapKeyValue = reduceActionSteps.entries().next().value; | ||
if (!mapKeyValue) { | ||
return new Error('No reduceActionSteps'); | ||
} | ||
var _mapKeyValue = (0, _slicedToArray2["default"])(mapKeyValue, 2), | ||
mapKey = _mapKeyValue[0], | ||
mapValue = _mapKeyValue[1]; | ||
mapKey = _mapKeyValue[0], | ||
mapValue = _mapKeyValue[1]; | ||
var _mapKey = (0, _slicedToArray2["default"])(mapKey, 2), | ||
specificFunc = _mapKey[0], | ||
extraSpecificArgs = _mapKey[1]; | ||
specificFunc = _mapKey[0], | ||
extraSpecificArgs = _mapKey[1]; | ||
var _mapValue = (0, _slicedToArray2["default"])(mapValue, 2), | ||
actionArray = _mapValue[0], | ||
moduleArray = _mapValue[1]; | ||
actionArray = _mapValue[0], | ||
moduleArray = _mapValue[1]; | ||
var _actionArray = (0, _slicedToArray2["default"])(actionArray, 2), | ||
actionOnReducedFunc = _actionArray[0], | ||
extraActionArgs = _actionArray[1]; | ||
actionOnReducedFunc = _actionArray[0], | ||
extraActionArgs = _actionArray[1]; | ||
var _moduleArray = (0, _slicedToArray2["default"])(moduleArray, 2), | ||
module = _moduleArray[0], | ||
moduleName = _moduleArray[1]; | ||
module = _moduleArray[0], | ||
moduleName = _moduleArray[1]; | ||
var reduceFuncName = this.findReduceFuncName(specificFunc, module); | ||
if (!reduceFuncName) { | ||
this.logger.error("A reduce function for ".concat(specificFunc.name, " was not found in ").concat(moduleName, ".\n") + '(The pattern is ...By{x} for the specific function and ...By{x}Reduce for the reduce function. ' + "In this case, x = '".concat(specificFunc.name.split('By').pop(), "'.)")); | ||
process.exit(1); | ||
} // ----------------------------- Read Reduce Action ----------------------------- | ||
} | ||
// ----------------------------- Read Reduce Action ----------------------------- | ||
var filesInTempDir = await this.readFilesInTempDir(wikiDirPath)["catch"](this.logger.error); | ||
var reduced = await module[reduceFuncName](filesInTempDir, extraSpecificArgs, specificFunc); | ||
await actionOnReducedFunc.apply(void 0, [reduced].concat((0, _toConsumableArray2["default"])(extraActionArgs))); // ------------------ Recursive Function Call or Termination -------------------- | ||
await actionOnReducedFunc.apply(void 0, [reduced].concat((0, _toConsumableArray2["default"])(extraActionArgs))); | ||
// ------------------ Recursive Function Call or Termination -------------------- | ||
if (reduceActionSteps.size !== 1) { | ||
@@ -423,3 +363,2 @@ reduceActionSteps["delete"](mapKey); | ||
} | ||
return undefined; | ||
@@ -429,3 +368,2 @@ }, | ||
var matchResults = specificFunc.name.match(/By(.*)/); | ||
if (matchResults) { | ||
@@ -437,7 +375,5 @@ var reduceNameSearch = "By".concat(matchResults[1]); | ||
} | ||
return false; | ||
}); | ||
} | ||
return undefined; | ||
@@ -450,3 +386,2 @@ }, | ||
var _this6 = this; | ||
var filesInTempDir = await this.getFilesInTempDir(wikiDirPath)["catch"](this.logger.error); | ||
@@ -467,3 +402,2 @@ var filePaths = filesInTempDir.map(function (file) { | ||
var _this7 = this; | ||
return filesInTempDir.reduce(async function (accumulator, fileObj) { | ||
@@ -479,7 +413,5 @@ var awaitedAccumulator = await accumulator["catch"](_this7.logger.error); | ||
var file = specificFunc.apply(void 0, [lines, fileObj].concat((0, _toConsumableArray2["default"])(extraArgs))); | ||
if (file !== false) { | ||
awaitedAccumulator.push(file); | ||
} | ||
return awaitedAccumulator; | ||
@@ -493,3 +425,2 @@ }, Promise.resolve([])); | ||
} | ||
return false; | ||
@@ -502,3 +433,2 @@ }, | ||
var wikiTitle = lines.shift(); | ||
if (wikiTitle) { | ||
@@ -509,3 +439,2 @@ var wikiFileName = wikiTitle.replace(/\b\w/g, function (word) { | ||
wikiFileName = wikiFileName.replace(/\s+/g, '-'); | ||
if (fileObj.filePath) { | ||
@@ -515,3 +444,2 @@ returnObj[fileObj.filePath] = "".concat(wikiFileName, ".md"); | ||
} | ||
return returnObj; | ||
@@ -543,3 +471,2 @@ }, | ||
var _this8 = this; | ||
var cleanedFilesToMove = filesToMove.filter(function (fileObj) { | ||
@@ -557,7 +484,4 @@ return Object.keys(fileObj).length > 0; | ||
var wikiFileName = fileObj[Object.keys(fileObj)[0]]; | ||
var _this8$getUniqueFileN = _this8.getUniqueFileName(wikiFileName, existingFileNames); | ||
var _this8$getUniqueFileN2 = (0, _slicedToArray2["default"])(_this8$getUniqueFileN, 2); | ||
wikiFileName = _this8$getUniqueFileN2[0]; | ||
@@ -574,5 +498,3 @@ existingFileNames = _this8$getUniqueFileN2[1]; | ||
} | ||
var safetyCounter = safety; | ||
if (!safetyCounter) { | ||
@@ -583,3 +505,2 @@ safetyCounter = 1; | ||
} | ||
safetyCounter += 1; | ||
@@ -590,3 +511,2 @@ var fileNameArray = fileName.split('.'); | ||
var newDupCount = dupCount; | ||
if (!newDupCount) { | ||
@@ -597,10 +517,7 @@ newDupCount = 1; | ||
} | ||
var lastDupCount = "-(".concat(newDupCount - 1, ")"); | ||
var fileNameNoExtensionArray = fileNameNoExtension.split(lastDupCount); | ||
if (fileNameNoExtensionArray.length > 1) { | ||
fileNameNoExtensionArray.pop(); | ||
} | ||
fileNameNoExtension = fileNameNoExtensionArray.join(lastDupCount); | ||
@@ -614,2 +531,1 @@ var newFileName = "".concat(fileNameNoExtension, "-(").concat(newDupCount, ").md"); | ||
}; | ||
exports["default"] = _default; |
{ | ||
"name": "wiki-builder", | ||
"version": "1.0.2", | ||
"version": "1.0.5", | ||
"description": "Build github wikis from markdown files", | ||
@@ -50,16 +50,16 @@ "private": false, | ||
"dependencies": { | ||
"fs-extra": "^10.0.1", | ||
"glob": "^7.2.0", | ||
"fs-extra": "^11.1.1", | ||
"glob": "^10.3.10", | ||
"shelljs": "^0.8.5", | ||
"tracer": "^1.1.5" | ||
"tracer": "^1.3.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "^7.17.6", | ||
"@babel/core": "^7.17.5", | ||
"@babel/preset-flow": "^7.16.7", | ||
"@babel/runtime": "^7.17.2", | ||
"ava": "^4.0.1", | ||
"@babel/cli": "^7.23.4", | ||
"@babel/core": "^7.23.3", | ||
"@babel/preset-flow": "^7.23.3", | ||
"@babel/runtime": "^7.23.4", | ||
"ava": "^5.3.1", | ||
"babel-eslint": "^10.1.0", | ||
"babel-preset-airbnb": "^5.0.0", | ||
"eslint": "^8.10.0", | ||
"eslint": "^8.54.0", | ||
"eslint-config-airbnb": "^19.0.4", | ||
@@ -69,6 +69,6 @@ "eslint-config-airbnb-base": "^15.0.0", | ||
"eslint-plugin-flowtype": "^8.0.3", | ||
"eslint-plugin-import": "^2.25.4", | ||
"eslint-plugin-jsx-a11y": "^6.5.1", | ||
"eslint-plugin-react": "^7.29.2", | ||
"underscore": "^1.13.2", | ||
"eslint-plugin-import": "^2.29.0", | ||
"eslint-plugin-jsx-a11y": "^6.8.0", | ||
"eslint-plugin-react": "^7.33.2", | ||
"underscore": "^1.13.6", | ||
"wiki_builder_test": "latest", | ||
@@ -75,0 +75,0 @@ "wiki_builder_test_plugin": "latest", |
@@ -51,3 +51,3 @@ [![Build Status](https://travis-ci.org/petekeller2/wiki-builder.svg?branch=master)](https://travis-ci.org/petekeller2/wiki-builder) | ||
in the same directory as the project's root, give the module | ||
(plugin) path instead of it's name. Example Usage: ["plugin-one", "plugin-two"]. | ||
(plugin) path instead of its name. Example Usage: ["plugin-one", "plugin-two"]. | ||
A list of existing plugins and a guide to creating new ones can | ||
@@ -54,0 +54,0 @@ be found in PLUGINS.md. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
487
28184
+ Added@isaacs/cliui@8.0.2(transitive)
+ Added@pkgjs/parseargs@0.11.0(transitive)
+ Addedansi-regex@5.0.16.1.0(transitive)
+ Addedansi-styles@4.3.06.2.1(transitive)
+ Addedbrace-expansion@2.0.1(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedcross-spawn@7.0.6(transitive)
+ Addedeastasianwidth@0.2.0(transitive)
+ Addedemoji-regex@8.0.09.2.2(transitive)
+ Addedforeground-child@3.3.0(transitive)
+ Addedfs-extra@11.2.0(transitive)
+ Addedglob@10.4.5(transitive)
+ Addedis-fullwidth-code-point@3.0.0(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedjackspeak@3.4.3(transitive)
+ Addedlru-cache@10.4.3(transitive)
+ Addedminimatch@9.0.5(transitive)
+ Addedminipass@7.1.2(transitive)
+ Addedpackage-json-from-dist@1.0.1(transitive)
+ Addedpath-key@3.1.1(transitive)
+ Addedpath-scurry@1.11.1(transitive)
+ Addedshebang-command@2.0.0(transitive)
+ Addedshebang-regex@3.0.0(transitive)
+ Addedsignal-exit@4.1.0(transitive)
+ Addedstring-width@4.2.35.1.2(transitive)
+ Addedstrip-ansi@6.0.17.1.0(transitive)
+ Addedwhich@2.0.2(transitive)
+ Addedwrap-ansi@7.0.08.1.0(transitive)
- Removedfs-extra@10.1.0(transitive)
Updatedfs-extra@^11.1.1
Updatedglob@^10.3.10
Updatedtracer@^1.3.0