<commit_before>'use strict';

const { join } = require('path');
const fs = require('hexo-fs');
const Promise = require('bluebird');
const chalk = require('chalk');

module.exports = ctx => {
  if (!ctx.env.init || ctx.env.safe) return;

  return loadModules(ctx).then(() => loadScripts(ctx));
};

function loadModuleList(ctx) {
  if (ctx.config && Array.isArray(ctx.config.plugins)) {
    return Promise.resolve(ctx.config.plugins).filter(item => typeof item === 'string');
  }

  const packagePath = join(ctx.base_dir, 'package.json');

  // Make sure package.json exists
  return fs.exists(packagePath).then(exist => {
    if (!exist) return [];

    // Read package.json and find dependencies
    return fs.readFile(packagePath).then(content => {
      const json = JSON.parse(content);
      const deps = Object.keys(json.dependencies || {});
      const devDeps = Object.keys(json.devDependencies || {});

      return deps.concat(devDeps);
    });
  }).filter(name => {
    // Ignore plugins whose name is not started with "hexo-"
    if (!/^hexo-|^@[^/]+\/hexo-/.test(name)) return false;

    // Make sure the plugin exists
    const path = ctx.resolvePlugin(name);
    return fs.exists(path);
  });
}

function loadModules(ctx) {
  return loadModuleList(ctx).map(name => {<commit_msg>Ignore plugins whose name is started with "@types/" (#3431)<commit_after>'use strict';

const { join } = require('path');
const fs = require('hexo-fs');
const Promise = require('bluebird');
const chalk = require('chalk');

module.exports = ctx => {
  if (!ctx.env.init || ctx.env.safe) return;

  return loadModules(ctx).then(() => loadScripts(ctx));
};

function loadModuleList(ctx) {
  if (ctx.config && Array.isArray(ctx.config.plugins)) {
    return Promise.resolve(ctx.config.plugins).filter(item => typeof item === 'string');
  }

  const packagePath = join(ctx.base_dir, 'package.json');

  // Make sure package.json exists
  return fs.exists(packagePath).then(exist => {
    if (!exist) return [];

    // Read package.json and find dependencies
    return fs.readFile(packagePath).then(content => {
      const json = JSON.parse(content);
      const deps = Object.keys(json.dependencies || {});
      const devDeps = Object.keys(json.devDependencies || {});

      return deps.concat(devDeps);
    });
  }).filter(name => {
    // Ignore plugins whose name is not started with "hexo-"
    if (!/^hexo-|^@[^/]+\/hexo-/.test(name)) return false;

    // Ignore typescript definition file that is started with "@types/"
    if (/^@types\//.test(name)) return false;

    // Make sure the plugin exists
    const path = ctx.resolvePlugin(name);
    return fs.exists(path);
  });
}

function loadModules(ctx) {
  return loadModuleList(ctx).map(name => {
{'fraction_non_alphanumeric': 0.1697564521992003, 'fraction_numerical': 0.0014540167211922936, 'mean_word_length': 3.5943238731218696, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, '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': '1517790', 'n_tokens_mistral': 868, 'n_tokens_neox': 845, 'n_words': 205}