log-loader
Advanced tools
Comparing version 0.1.2 to 0.1.3
var getParams = require('./params').getParams; | ||
var grey = require('colors/safe').grey; | ||
var getParams = require('./get-params'); | ||
var print = require('./print'); | ||
@@ -16,3 +16,3 @@ | ||
if (params.showSource) { | ||
console.log(source.grey) | ||
console.log(grey(source)) | ||
} | ||
@@ -33,3 +33,3 @@ | ||
if (params.showPitch) { | ||
print(this); | ||
print(this, true/*isPitch*/); | ||
} | ||
@@ -36,0 +36,0 @@ |
{ | ||
"name": "log-loader", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "loader for debugging", | ||
@@ -11,3 +11,4 @@ "main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"postversion": "git push origin HEAD && npm publish" | ||
}, | ||
@@ -14,0 +15,0 @@ "keywords": [], |
78
print.js
var colors = require('colors'); | ||
var h = require('./params'); | ||
var path = require('path'); | ||
var colors = require('colors/safe'); | ||
var getParams = require('./get-params'); | ||
@@ -11,7 +12,14 @@ var PAD_ID = 15; | ||
module.exports = function (loaderContext) { | ||
var params = h.getParams(loaderContext); | ||
var bold = colors.bold; | ||
var grey = colors.grey; | ||
var cyan = colors.cyan; | ||
var green = colors.green; | ||
var yellow = colors.yellow; | ||
var magenta = colors.magenta; | ||
module.exports = function (loaderContext, isPitch) { | ||
var params = getParams(loaderContext); | ||
// loader id | ||
var id = padLeftN(params.pad.id || PAD_ID, params.id); | ||
var id = padRightN(params.pad.id || PAD_ID, params.id); | ||
// relative path to the resource file (https://webpack.js.org/api/loaders/#resourcepath) | ||
@@ -22,12 +30,13 @@ var file = padRightN(params.pad.file || PAD_FILE, params.file); | ||
// previous loader package name | ||
var prevLoader = padLeftN(params.pad.loader || PAD_LOADER, h.getPrevLoader(loaderContext)); | ||
var prevLoader = padLeftN(params.pad.loader || PAD_LOADER, getPrevLoader(loaderContext)); | ||
// next loader package name | ||
var nextLoader = padLeftN(params.pad.loader || PAD_LOADER, h.getNextLoader(loaderContext)); | ||
var nextLoader = padLeftN(params.pad.loader || PAD_LOADER, getNextLoader(loaderContext)); | ||
console.log( | ||
params.showPrevLoader ? prevLoader.cyan.bold : '', | ||
file.bold, | ||
params.showIndex ? index.green.bold : '', | ||
id.magenta.bold, | ||
params.showNextLoader ? nextLoader.cyan.bold : '' | ||
params.showPrevLoader ? cyan(bold(prevLoader)) : '', | ||
isPitch ? grey(file) : bold(file), | ||
params.showIndex ? green(bold(index)) : '', | ||
magenta(bold(id)), | ||
params.showNextLoader ? cyan(bold(nextLoader)) : '', | ||
isPitch ? yellow('[pitch]') : '' | ||
); | ||
@@ -43,1 +52,46 @@ }; | ||
} | ||
/** | ||
* Return loader name by string like /abc/node_modules/log-loader/index.js | ||
* @param pathToIndexJs | ||
* @returns {String} | ||
*/ | ||
function getLoaderNameByPath(pathToIndexJs) { | ||
var loaderDir = path.relative('node_modules', pathToIndexJs); | ||
return loaderDir.split(path.sep).shift(); | ||
} | ||
/** | ||
* Return next loader name | ||
* @param loaderContext | ||
* @returns {String} | ||
*/ | ||
function getNextLoader(loaderContext) { | ||
var currentTndex = loaderContext.loaderIndex; | ||
var loaders = loaderContext.loaders; | ||
var nextLoader = loaders[currentTndex - 1] || null; | ||
if (nextLoader) { | ||
return ' -> ' + getLoaderNameByPath(nextLoader.path); | ||
} | ||
return ''; | ||
} | ||
/** | ||
* Return previous loader name | ||
* @param loaderContext | ||
* @returns {String} | ||
*/ | ||
function getPrevLoader(loaderContext) { | ||
var currentTndex = loaderContext.loaderIndex; | ||
var loaders = loaderContext.loaders; | ||
var prevLoader = loaders[currentTndex + 1] || null; | ||
if (prevLoader) { | ||
return getLoaderNameByPath(prevLoader.path)+ ' -> '; | ||
} | ||
return ''; | ||
} |
Sorry, the diff of this file is not supported yet
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
61504
18
133