Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@architect/utils

Package Overview
Dependencies
Maintainers
6
Versions
124
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@architect/utils - npm Package Compare versions

Comparing version 2.0.5 to 2.1.0-RC.0

updater/methods.js

13

changelog.md

@@ -5,2 +5,15 @@ # Architect Utils changelog

## [2.1.0] 2021-05-13
### Added
- Added log levels to `updater`:
- Pass it a `logLevel` param with one of `normal` (default), `verbose`, or `debug`
- `verbose` outputs logs at its level and `normal`; `debug` outputs logs at all levels
- The `quiet` boolean flag still suppresses writing to `stdout`, but all relevant log data is still collected by the updater log buffer (see `get()` + `reset()` below)
- Added `updater.get()`, which returns the captured log buffer
- Added `updater.reset()` to clear the captured log buffer
---
## [2.0.5] 2021-03-05

@@ -7,0 +20,0 @@

8

package.json
{
"name": "@architect/utils",
"version": "2.0.5",
"version": "2.1.0-RC.0",
"description": "Common utility functions",

@@ -36,6 +36,6 @@ "main": "index.js",

"cross-env": "7.0.3",
"eslint": "7.22.0",
"husky": "^5.0.9",
"eslint": "7.26.0",
"husky": "^6.0.0",
"proxyquire": "^2.1.3",
"sinon": "^9.2.2",
"sinon": "^10.0.0",
"tap-spec": "^5.0.0",

@@ -42,0 +42,0 @@ "tape": "^5.0.1",

let chalk = require('chalk')
let chars = require('../chars')
let { printer, spinner } = require('./lib')
let { printer } = require('./lib')
let methods = require('./methods')
let data = ''

@@ -22,8 +23,9 @@ /**

*/
module.exports = function updater (name, params = {}) {
params.quiet = params.quiet || false
let quiet = () => process.env.ARC_QUIET || process.env.QUIET || params.quiet
module.exports = function statusUpdater (name, args = {}) {
let env = process.env
name = name ? chalk.grey(name) : 'Info'
let isCI = process.env.CI || process.stdout.isTTY === false
if (!quiet() && !isCI) {
let logLevel = args.logLevel || 'normal'
let quiet = env.ARC_QUIET || env.QUIET || args.quiet || false
let isCI = env.CI || process.stdout.isTTY === false
if (!quiet && !isCI) {
printer.hideCursor() // Disable cursor while updating

@@ -33,107 +35,40 @@ printer.restoreCursor() // Restore cursor on exit

let running = false
let { frames, timing } = spinner
function progressIndicator (info) {
// End-user progress mode
if (!running && !isCI && !quiet()) {
let i = 0
running = setInterval(function () {
printer.write(`${chalk.cyan(frames[i = ++i % frames.length])} ${info}`)
printer.reset()
}, timing)
}
// CI mode: updates console with status messages but not animations
else if (!running && isCI && !quiet()) {
console.log(`${chars.start} ${info}`)
}
let params = {
data,
isCI,
logLevel,
name,
printer,
quiet,
running,
}
// Optionally pass a message and/or post a multi-line supporting status update
function status (msg, ...more) {
msg = msg ? chalk.cyan(msg) : ''
let info = msg ? `${chars.start} ${name} ${msg}`.trim() : ''
if (running) cancel()
if (!quiet() && info) console.log(info) // Check for msg so as not to print an empty line
if (more.length) {
more.forEach(i => {
let add = chalk.dim(` | ${i}`)
if (!quiet()) console.log(add)
info += `\n${add}`
})
}
let updaters = {}
let logLevels = [ 'normal', 'verbose', 'debug' ]
if (!logLevels.includes(logLevel)) throw ReferenceError(`Invalid logLevel parameter, must be one of: ${logLevels.join(', ')}`)
return info
}
function start (msg) {
msg = msg ? chalk.cyan(msg) : ''
let info = `${name} ${msg}`.trim()
if (running) cancel()
progressIndicator(info)
return `${chars.start} ${info}`
}
function done (newName, msg) {
if (!msg) {
msg = newName
newName = ''
}
if (newName) newName = chalk.grey(newName)
if (msg) msg = chalk.cyan(msg)
cancel() // Maybe clear running status and reset
let info = `${chars.done} ${newName ? newName : name} ${msg ? msg : ''}`.trim()
if (!quiet()) console.log(info)
return info
}
function cancel () {
if (running) {
clearInterval(running)
printer.reset()
printer.clear()
running = false // Prevent accidental second done print
}
}
function err (error) {
if (running) cancel()
let isErr = error instanceof Error
let name = isErr ? error.name : 'Error'
let msg = isErr ? error.message : error
let info = `${chars.err} ${chalk.red(name + ':')} ${msg}`.trim()
if (isErr) {
info += '\n' + error.stack.split('\n').slice(1).join('\n')
}
console.log(info)
return info
}
function warn (warning) {
if (running) cancel()
if (warning instanceof Error) warning = warning.message
let info = `${chars.warn} ${chalk.yellow('Warning:')} ${warning}`.trim()
if (!quiet()) console.log(info)
return info
}
function raw (msg) {
if (!quiet()) console.log(msg)
return msg
}
logLevels.forEach(logMode => {
updaters[logMode] = {}
let args = { logMode, logLevels }
updaters[logMode].start = methods.start.bind({}, args, params)
updaters[logMode].status = methods.status.bind({}, args, params)
updaters[logMode].done = methods.done.bind({}, args, params)
updaters[logMode].cancel = methods.cancel.bind({}, args, params)
updaters[logMode].err = methods.err.bind({}, args, params)
updaters[logMode].warn = methods.warn.bind({}, args, params)
updaters[logMode].raw = methods.raw.bind({}, args, params)
// Aliases
updaters[logMode].update = updaters[logMode].start
updaters[logMode].stop = updaters[logMode].done
updaters[logMode].error = updaters[logMode].err
updaters[logMode].fail = updaters[logMode].err
updaters[logMode].warning = updaters[logMode].warn
})
return {
start,
update: start,
status,
done,
stop: done,
cancel,
err,
error: err,
fail: err,
warn,
warning: warn,
raw,
...updaters.normal,
get: methods.get.bind({}, {}, params),
reset: methods.reset.bind({}, params),
verbose: updaters.verbose,
debug: updaters.debug,
}

@@ -140,0 +75,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc