コード例 #1
0
ファイル: workshopper.js プロジェクト: bojoer/workshopper
function onselect (name) {
  var exercise = this.loadExercise(name)

  if (!exercise)
    return error('No such exercise: ' + name)

  console.log(
      '\n ' + chalk.green.bold(this.title)
    + '\n' + chalk.green.bold(util.repeat('\u2500', chalk.stripColor(this.title).length + 2))
    + '\n ' + chalk.yellow.bold(exercise.name)
    + '\n ' + chalk.yellow.italic('Exercise', exercise.number, 'of', this.exercises.length)
    + '\n'
  )

  this.updateData('current', function () {
    return exercise.name
  })

  exercise.prepare(function (err) {
    if (err)
      return error('Error preparing exercise:', err.message || err)

    exercise.getExerciseText(function (err, type, exerciseText) {
      if (err)
        return error('Error loading exercise text:', err.message || err)

      printExercise.call(this, type, exerciseText)
    }.bind(this))
  }.bind(this))
}
コード例 #2
0
ファイル: CLIRunner.js プロジェクト: Becklyn/kaba-cli
            this.registeredTasks.forEach((task) => {
                const taskName = (this.DEFAULT_TASK_NAME === task)
                    ? `${chalk.yellow.italic("default task")}  (run without parameter)`
                    : chalk.yellow(task);

                console.log(`  • ${taskName}`);
            });
コード例 #3
0
function onselect (name) {
  var exercise = this.loadExercise(name)
    , afterPrepare

  if (!exercise)
    return error(this.__('error.exercise.missing', {name: name}))

  if (this.showHeader)
    console.log(
        '\n ' + chalk.green.bold(this.__('title'))
      + '\n' + chalk.green.bold(util.repeat('\u2500', chalk.stripColor(this.__('title')).length + 2))
      + '\n ' + chalk.yellow.bold(this.__('exercise.' + exercise.meta.name))
      + '\n ' + chalk.yellow.italic(this.__('progress.state', {count: exercise.meta.number, amount: this.exercises.length}))
      + '\n'
    )

  this.current = exercise.meta.name

  this.updateData('current', function () {
    return exercise.meta.name
  })

  afterPreparation = function (err) {
    if (err)
      return error(this.__('error.exercise.preparing', {err: err.message || err}))

    afterProblem = function() {
      var stream = require('combined-stream').create()
        , part
      if (exercise.problem)
        print.text(this.appName, this.appDir, exercise.problemType || 'txt', exercise.problem)
      else {
        part = print.localisedFileStream(this.appName, this.appDir,  path.resolve(__dirname, 'i18n/missing_problem/{lang}.md'), this.lang)
        if (part)
          stream.append(part)
      }

      if (exercise.footer || this.footer)
        print.text(this.appName, this.appDir, exercise.footer || this.footer, this.lang)
      else if (this.footerFile !== false) {
        part = print.localisedFirstFileStream(this.appName, this.appDir, this.footerFile || [], this.lang)
        if (part)
          stream.append(part)
      }

      stream.pipe(process.stdout)
    }.bind(this)

    if (!exercise.problem && typeof exercise.getExerciseText === 'function') {
      exercise.getExerciseText(function (err, type, exerciseText) {
        if (err)
          return error(this.__('error.exercise.loading', {err: err.message || err}))
        exercise.problem = exerciseText
        exercise.problemType = type
        afterProblem()
      }.bind(this))
    } else {
      afterProblem()
    }

  }.bind(this)

  if (typeof exercise.prepare === 'function') {
    exercise.prepare(afterPreparation)
  } else {
    afterPreparation(null)
  }
}