<commit_before>import plugin from '@start/plugin/src/'

// https://docs.npmjs.com/cli/publish
export default (packagePath: string, userOptions?: {}) =>
  plugin('npmPublish', async ({ files }) => {
    const { default: execa } = await import('execa')

    const options = {
      registry: 'https://registry.npmjs.org/',
      ...userOptions
    }

    const cliOptions = Object.keys(options).reduce((result, key) => {
      return [...result, `--${key}=${options[key]}`]
    }, [])

    return execa('npm', ['publish', ...cliOptions, packagePath], {
      stdout: process.stdout,
      stderr: process.stderr,
      stripEof: false,
      env: {
        FORCE_COLOR: '1'
      }
    })
      .then(() => files)
      .catch(() => Promise.reject(null))
  })<commit_msg>🛠️ plugin-lib-npm-publish: handle more CLI args as options<commit_after>import plugin from '@start/plugin/src/'

type Options = {
  registry?: string,
  otp?: string,
  [key: string]: boolean | string
}

// https://docs.npmjs.com/cli/publish
export default (packagePath: string = '.', userOptions?: Options) =>
  plugin('npmPublish', async ({ files }) => {
    const { default: execa } = await import('execa')

    const options = {
      registry: 'https://registry.npmjs.org/',
      ...userOptions
    }
    const cliArgs = Object.keys(options).reduce((result, key) => {
      const value = options[key]

      if (typeof value === 'boolean') {
        return result.concat(`--${key}`)
      }

      if (typeof value === 'string') {
        return result.concat(`--${key}`, `${value}`)
      }

      return result
    }, [])

    return execa('npm', ['publish', ...cliArgs, packagePath], {
      stdout: process.stdout,
      stderr: process.stderr,
      stripEof: false,
      env: {
        FORCE_COLOR: '1'
      }
    })
      .then(() => files)
      .catch(() => Promise.reject(null))
  })
{'fraction_non_alphanumeric': 0.18609625668449198, 'fraction_numerical': 0.0010695187165775401, 'mean_word_length': 2.5570342205323193, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1272', 'n_tokens_mistral': 600, 'n_tokens_neox': 577, 'n_words': 129}