<commit_before>import path       from 'path'
import readPkgUp  from 'read-pkg-up'

import npm          from 'npm-programmatic'
import pkgDir       from 'pkg-dir'
import semver       from 'semver'

import {
  Puppet,
  PuppetImplementation,
  PuppetOptions,
}                         from 'wechaty-puppet'

import {
  log,
}                       from './config'
import {
  PUPPET_DEPENDENCIES,
  PUPPET_NAME_DEFAULT,
  PuppetModuleName,
}                       from './puppet-config'
import {
  // Wechaty,
}                       from './wechaty'

export interface ResolveOptions {
  // wechaty        : Wechaty,
  puppet         : Puppet | PuppetModuleName,
  puppetOptions? : PuppetOptions,
}

export class PuppetManager {

  public static async resolve (
    options: ResolveOptions
  ): Promise<Puppet> {
    log.verbose('PuppetManager', 'resolve({wechaty: %s, puppet: %s, puppetOptions: %s})',
                                  // options.wechaty,
                                  options.puppet,
                                  JSON.stringify(options.puppetOptions),
                )

    let puppetInstance: Puppet

    if (options.puppet instanceof Puppet) {
      puppetInstance = await this.resolveInstance(options.puppet)
    } else {
      const MyPuppet = await this.resolveName(options.puppet)
      /**
       * We will meet the following error:
       *
       *  [ts] Cannot use 'new' with an expression whose type lacks a call or construct signature.
       *
       * When we have different puppet with different `constructor()` args.
       * For example: PuppetA allow `constructor()` but PuppetB requires `constructor(options)`<commit_msg>fix log<commit_after>import path       from 'path'
import readPkgUp  from 'read-pkg-up'

import npm          from 'npm-programmatic'
import pkgDir       from 'pkg-dir'
import semver       from 'semver'

import {
  Puppet,
  PuppetImplementation,
  PuppetOptions,
}                         from 'wechaty-puppet'

import {
  log,
}                       from './config'
import {
  PUPPET_DEPENDENCIES,
  PUPPET_NAME_DEFAULT,
  PuppetModuleName,
}                       from './puppet-config'
import {
  // Wechaty,
}                       from './wechaty'

export interface ResolveOptions {
  // wechaty        : Wechaty,
  puppet         : Puppet | PuppetModuleName,
  puppetOptions? : PuppetOptions,
}

export class PuppetManager {

  public static async resolve (
    options: ResolveOptions
  ): Promise<Puppet> {
    log.verbose('PuppetManager', 'resolve({puppet: %s, puppetOptions: %s})',
                                  // options.wechaty,
                                  options.puppet,
                                  JSON.stringify(options.puppetOptions),
                )

    let puppetInstance: Puppet

    if (options.puppet instanceof Puppet) {
      puppetInstance = await this.resolveInstance(options.puppet)
    } else {
      const MyPuppet = await this.resolveName(options.puppet)
      /**
       * We will meet the following error:
       *
       *  [ts] Cannot use 'new' with an expression whose type lacks a call or construct signature.
       *
       * When we have different puppet with different `constructor()` args.
       * For example: PuppetA allow `constructor()` but PuppetB requires `constructor(options)`
{'fraction_non_alphanumeric': 0.08904316329610625, 'fraction_numerical': 0.0, 'mean_word_length': 1.9909747292418774, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '197916', 'n_tokens_mistral': 1008, 'n_tokens_neox': 966, 'n_words': 248}