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

workshopper-adventure

Package Overview
Dependencies
Maintainers
1
Versions
62
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

workshopper-adventure - npm Package Compare versions

Comparing version 3.4.0 to 3.4.1

189

adventure.js

@@ -11,4 +11,3 @@ const minimist = require('minimist')

/* jshint -W079 */
const showMenu = require('./exerciseMenu')
, showLanguageMenu = require('./languageMenu')
const createMenu = require('simple-terminal-menu')
, print = require('./print-text')

@@ -60,3 +59,3 @@ , util = require('./util')

this.defaultLang = options.defaultLang
this.menuOptions = options.menu
this.menuOptions = options.menu || {}
this.helpFile = options.helpFile

@@ -66,3 +65,11 @@ this.footer = options.footer

this.footerFile = [options.footerFile, path.join(__dirname, './i18n/footer/{lang}.md')]
this.width = typeof options.width == 'number' ? options.width : defaultWidth
if (typeof this.menuOptions.width !== 'number')
this.menuOptions.width = typeof options.width == 'number' ? options.width : defaultWidth
if (typeof this.menuOptions.x !== 'number')
this.menuOptions.x = 3
if (typeof this.menuOptions.y !== 'number')
this.menuOptions.y = 2

@@ -85,4 +92,3 @@ // an `onComplete` hook function *must* call the callback given to it when it's finished, async or not

if (Array.isArray(options.commands))
this.commands = options.commands
this.commands = Array.isArray(options.commands) ? options.commands : []

@@ -128,5 +134,8 @@ this.options = options

// backwards compatibility for title and subtitle
// backwards compatibility for title and subtitle and width
this.__defineGetter__('title', this.__.bind(this, 'title'))
this.__defineGetter__('subtitle', this.__.bind(this, 'subtitle'))
this.__defineGetter__('width', function () {
return this.menuOptions.width
}.bind(this))

@@ -222,54 +231,57 @@ this.current = this.getData('current')

Adventure.prototype.add = function (name_or_object, fn_or_object) {
var meta
, dir
, stat
Adventure.prototype.add = function (name_or_object, fn_or_object, fn) {
var meta
, dir
, stat
meta = (typeof name_or_object === 'object')
? name_or_object
: (typeof fn_or_object === 'object')
? fn_or_object
: { name: name_or_object }
meta = (typeof name_or_object === 'object')
? name_or_object
: (typeof fn_or_object === 'object')
? fn_or_object
: { name: name_or_object }
if (typeof name_or_object === 'string')
meta.name = name_or_object
if (typeof name_or_object === 'string')
meta.name = name_or_object
if (/^\/\//.test(meta.name))
return
if (/^\/\//.test(meta.name))
return
if (!meta.id)
meta.id = util.idFromName(meta.name)
if (!meta.id)
meta.id = util.idFromName(meta.name)
if (!meta.dir)
meta.dir = this.dirFromName(meta.name)
if (!meta.dir)
meta.dir = this.dirFromName(meta.name)
if (meta.dir && !meta.exerciseFile)
meta.exerciseFile = path.join(meta.dir, './exercise.js')
if (meta.dir && !meta.exerciseFile)
meta.exerciseFile = path.join(meta.dir, './exercise.js')
if (typeof fn_or_object === 'function')
meta.fn = fn_or_object
if (typeof fn_or_object === 'function')
meta.fn = fn_or_object
if (!meta.fn && meta.exerciseFile) {
try {
stat = fs.statSync(meta.exerciseFile)
} catch (err) {
return error(this.__('error.exercise.missing_file', {exerciseFile: meta.exerciseFile}))
}
if (typeof fn === 'function')
meta.fn = fn
if (!stat || !stat.isFile())
return error(this.__('error.exercise.missing_file', {exerciseFile: meta.exerciseFile}))
meta.fn = (function () {
return require(meta.exerciseFile)
}).bind(meta)
if (!meta.fn && meta.exerciseFile) {
try {
stat = fs.statSync(meta.exerciseFile)
} catch (err) {
return error(this.__('error.exercise.missing_file', {exerciseFile: meta.exerciseFile}))
}
if (!meta.fn)
return error(this.__('error.exercise.not_a_workshopper', {exerciseFile: meta.exerciseFile}))
if (!stat || !stat.isFile())
return error(this.__('error.exercise.missing_file', {exerciseFile: meta.exerciseFile}))
meta.fn = (function () {
return require(meta.exerciseFile)
}).bind(meta)
}
this.exercises.push(meta.name)
this._meta[meta.id] = meta
meta.number = this.exercises.length
return this
if (!meta.fn)
return error(this.__('error.exercise.not_a_workshopper', {exerciseFile: meta.exerciseFile}))
this.exercises.push(meta.name)
this._meta[meta.id] = meta
meta.number = this.exercises.length
return this
}

@@ -461,13 +473,23 @@

Adventure.prototype.printLanguageMenu = function () {
var menu = showLanguageMenu({
name : this.appName
, languages : this.i18n.languages
, lang : this.lang
, width : this.width
, menu : this.menuOptions
}, this.i18n)
var __ = this.i18n.__
, menu = createMenu(this.menuOptions)
, completed = this.getData('completed') || []
menu.on('select', this.selectLanguage.bind(this))
menu.on('cancel', this.printMenu.bind(this))
menu.on('exit', this._exit.bind(this))
menu.writeLine(chalk.bold(__('title')))
if (this.i18n.has('subtitle'))
menu.writeLine(chalk.italic(__('subtitle')))
menu.writeSeparator()
this.i18n.languages.forEach(function (language) {
var label = chalk.bold('»') + ' ' + __('language.' + language)
, marker = (this.lang === language) ? '[' + __('language._current') + ']' : ''
menu.add(label, marker, this.selectLanguage.bind(this, language))
}.bind(this))
menu.writeSeparator()
menu.add(chalk.bold(__('menu.cancel')), this.printMenu.bind(this))
menu.add(chalk.bold(__('menu.exit')), this._exit.bind(this))
}

@@ -480,30 +502,33 @@

Adventure.prototype.printMenu = function () {
var menu = showMenu({
name : this.appName
, languages : this.i18n.languages
, width : this.width
, completed : this.getData('completed') || []
, exercises : this.exercises
, extras : this.commands && this.commands
.filter(function (item) {
return item.menu !== false
})
.map(function (item) {
return item.name.toLowerCase()
})
, menu : this.menuOptions
}, this.i18n)
var __ = this.i18n.__
, menu = createMenu(this.menuOptions)
, completed = this.getData('completed') || []
menu.on('select', onselect.bind(this))
menu.on('exit', this._exit.bind(this))
menu.on('language', this.printLanguageMenu.bind(this))
menu.on('help', this._printHelp.bind(this))
menu.writeLine(chalk.bold(__('title')))
if (this.commands) {
this.commands.forEach(function (item) {
menu.on('extra-' + item.name, function () {
item.handler(this)
}.bind(this))
}.bind(this))
}
if (this.i18n.has('subtitle'))
menu.writeLine(chalk.italic(__('subtitle')))
menu.writeSeparator()
this.exercises.forEach(function (exercise) {
var label = chalk.bold('»') + ' ' + __('exercise.' + exercise)
, marker = (completed.indexOf(exercise) >= 0) ? '[' + __('menu.completed') + ']' : ''
menu.add(label, marker, onselect.bind(this, exercise))
}.bind(this))
menu.writeSeparator()
menu.add(chalk.bold(__('menu.help')), this._printHelp.bind(this))
if (this.i18n.languages && this.i18n.languages.length > 1)
menu.add(chalk.bold(__('menu.language')), this.printLanguageMenu.bind(this))
this.commands.filter(function (extra) {
return extra.menu !== false
}).forEach(function (extra) {
menu.add(chalk.bold(__('menu.' + extra.name)), extra.handler.bind(extra, this))
}.bind(this))
menu.add(chalk.bold(__('menu.exit')), this._exit.bind(this))
}

@@ -510,0 +535,0 @@

{
"name": "workshopper-adventure",
"version": "3.4.0",
"version": "3.4.1",
"description": "A terminal workshop runner framework (adventure compatible)",

@@ -21,2 +21,3 @@ "main": "./index.js",

"msee": "~0.1.1",
"simple-terminal-menu": "^1.0.0",
"terminal-menu": "^2.1.1",

@@ -23,0 +24,0 @@ "through": "^2.3.7",

@@ -7,7 +7,2 @@ const path = require('path')

function repeat (ch, sz) {
return new Array(sz + 1).join(ch)
}
function idFromName (id) {

@@ -34,10 +29,2 @@ return id.toLowerCase()

function applyTextMarker (text, marker, size) {
var availableSpace = size - vw.width(marker, true)
text = vw.truncate(text, availableSpace, '...', true)
return text + repeat(' ', availableSpace - vw.width(text, true)) + marker
}
function getFsObject(type, file, base) {

@@ -63,4 +50,2 @@ var stat

, dirFromName: dirFromName
, repeat: repeat
, applyTextMarker: applyTextMarker
, getDir: getFsObject.bind(null, 'dir')

@@ -67,0 +52,0 @@ , getFile: getFsObject.bind(null, 'file')

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