@vuepress/shared-utils
Advanced tools
Comparing version 1.0.0-alpha.23 to 1.0.0-alpha.24
@@ -1,7 +0,14 @@ | ||
const isDebug = process.argv.indexOf('--debug') !== -1 | ||
const isProduction = () => process.env.NODE_ENV === 'production' | ||
const isTest = () => process.env.NODE_ENV === 'test' | ||
class ENV { | ||
constructor () { | ||
this.isDebug = false | ||
this.isTest = false | ||
this.isProduction = false | ||
} | ||
exports.isDebug = isDebug | ||
exports.isTest = isTest | ||
exports.isProduction = isProduction | ||
setOptions (options) { | ||
Object.assign(this, options) | ||
} | ||
} | ||
module.exports = new ENV() | ||
@@ -0,56 +1,103 @@ | ||
'use strict' | ||
/** | ||
* Module dependencies. | ||
*/ | ||
const chalk = require('chalk') | ||
const env = require('./env') | ||
const logger = {} | ||
class Logger { | ||
constructor (options) { | ||
this.options = Object.assign( | ||
{ | ||
logLevel: process.argv.includes('--debug') | ||
? 4 | ||
: 3 | ||
}, | ||
options | ||
) | ||
} | ||
const logTypes = { | ||
success: { | ||
color: 'green', | ||
label: 'DONE' | ||
}, | ||
error: { | ||
color: 'red', | ||
label: 'FAIL' | ||
}, | ||
warn: { | ||
color: 'yellow', | ||
label: 'WARN' | ||
}, | ||
tip: { | ||
color: 'cyan', | ||
label: 'TIP' | ||
}, | ||
wait: { | ||
color: 'blue', | ||
label: 'WAIT' | ||
setOptions (options) { | ||
Object.assign(this.options, options) | ||
} | ||
} | ||
const getLoggerFn = (color, label) => (msg, log = true) => { | ||
let newLine = false | ||
if (msg.startsWith('\n')) { | ||
if (log) msg = msg.slice(1) | ||
newLine = true | ||
// level: 4 | ||
debug (...args) { | ||
if (this.options.logLevel < 4) { | ||
return | ||
} | ||
this.status('magenta', 'debug', ...args) | ||
} | ||
msg = chalk.reset.inverse.bold[color](` ${label} `) + ' ' + msg | ||
if (log) { | ||
console.log(newLine ? '\n' + msg : msg) | ||
} else { | ||
return msg | ||
// level: 2 | ||
warn (...args) { | ||
if (this.options.logLevel < 2) { | ||
return | ||
} | ||
console.warn(chalk.yellow('warning'), ...args) | ||
} | ||
} | ||
for (const type in logTypes) { | ||
const { color, label } = logTypes[type] | ||
logger[type] = getLoggerFn(color, label) | ||
} | ||
// level: 1 | ||
error (...args) { | ||
if (this.options.logLevel < 1) { | ||
return | ||
} | ||
process.exitCode = process.exitCode || 1 | ||
console.error(chalk.red('error'), ...args) | ||
} | ||
const debugFn = getLoggerFn('magenta', 'DEBUG') | ||
// level: 3 | ||
success (...args) { | ||
if (this.options.logLevel < 3) { | ||
return | ||
} | ||
this.status('green', 'success', ...args) | ||
} | ||
logger.debug = function (msg) { | ||
if (env.isDebug) { | ||
debugFn(msg) | ||
// level: 3 | ||
tip (...args) { | ||
if (this.options.logLevel < 3) { | ||
return | ||
} | ||
this.status('blue', 'tip', ...args) | ||
} | ||
// level: 3 | ||
info (...args) { | ||
if (this.options.logLevel < 3) { | ||
return | ||
} | ||
this.status('cyan', 'info', ...args) | ||
} | ||
wait (...args) { | ||
if (this.options.logLevel < 3) { | ||
return | ||
} | ||
this.status('cyan', 'wait', ...args) | ||
} | ||
// level: 3 | ||
status (color, label, ...args) { | ||
if (this.options.logLevel < 3) { | ||
return | ||
} | ||
console.log(chalk[color](label), ...args) | ||
} | ||
developer (...args) { | ||
if (process.env.VUEPRESS_ENV !== 'developer') { | ||
return | ||
} | ||
this.status('cyan', 'developer', ...args) | ||
} | ||
} | ||
module.exports = logger | ||
/** | ||
* Expose a logger instance. | ||
*/ | ||
module.exports = new Logger() | ||
@@ -45,3 +45,3 @@ // Midified from https://github.com/vuejs/vue-cli/blob/dev/packages/@0vue/cli-shared-utils/lib/module.js | ||
// when using 'require.resolve'. | ||
if (isTest() && request !== '@vuepress/theme-default') { | ||
if (isTest && request !== '@vuepress/theme-default') { | ||
resolvedPath = path.resolve(__dirname, '../../../../__mocks__', request) | ||
@@ -53,6 +53,7 @@ if (!fs.existsSync(`${resolvedPath}.js`) && !fs.existsSync(`${resolvedPath}/index.js`)) { | ||
} | ||
resolvedPath = resolve(request, { | ||
// module.paths is for globally install packages. | ||
paths: [context || process.cwd(), ...module.paths] | ||
}) | ||
// module.paths is for globally install packages. | ||
const paths = [context || process.cwd(), ...module.paths] | ||
resolvedPath = resolve(request, { paths }) | ||
return resolvedPath | ||
@@ -59,0 +60,0 @@ } |
{ | ||
"name": "@vuepress/shared-utils", | ||
"version": "1.0.0-alpha.23", | ||
"version": "1.0.0-alpha.24", | ||
"description": "shared-utils for vuepress", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
23139
766
7