Skip to content

Instantly share code, notes, and snippets.

@isaacs
Created January 16, 2020 22:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaacs/c3c870059fb26d3229f611b517c09ad2 to your computer and use it in GitHub Desktop.
Save isaacs/c3c870059fb26d3229f611b517c09ad2 to your computer and use it in GitHub Desktop.
const _progress = Symbol('_progress')
const npmlog = require('npmlog') // to be removed...
const procLog = require('./proc-log.js')
module.exports = cls => class Tracker extends cls {
constructor (options = {}) {
super(options)
this.log = options.log || npmlog || procLog
this[_progress] = new Map()
this.log.enableProgress() // to be removed...
}
addTracker (section, subsection = null) {
// this.addTracker('buildIdealTree') <-- starts parent tracker
// ... later ...
// this.addTracker('buildIdealTree', node.location)
// ... later ...
// this.finishTracker('buildIdealTree', node.location)
// ... all done ...
// this.finishTracker('buildIdealTree')
const tracker = this[_progress].get(section)
if (this[_progress].has(section) && !subsection) {
throw 'oh no'
}
// 0. no subsection, have existing tracker
// Error!
// 1. no subsection, no existing tracker
// create a new tracker from this.log
// 2. have subsection, no parent tracker
// ?error?
// 3. have subsection, have parent tracker, have subsection tracker
// Error!
// 4. have subsection, have parent tracker, no subsection tracker
// make new tracker in this[_progress] from parent tracker
// Q: how to store child trackers?
// this[_progress].set(someKindOfKey, tracker)
}
addTracker (tracker, name, size) {
if (tracker && tracker.newGroup) {
this.progress[name] = tracker.newGroup(name, size)
}
}
finishTracker (section, subSection) {
// if no subsection, finish all children? or error if open children?
// look up tracker by section/subsection, and call .finish() on it
// this[_progress].delete(trackerKey)
this.progress[name] && this.progress[name].finish()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment