{"size": 1752, "ext": "js", "max_stars_repo_path": "scripts/gfm/classify.js", "max_stars_repo_name": "yozorajs/yozora", "max_stars_repo_stars_event_min_datetime": "2021-07-22T01:50:14.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-10T15:18:58.000Z", "max_issues_repo_path": "scripts/gfm/classify.js", "max_issues_repo_name": "yozorajs/yozora", "max_issues_repo_issues_event_min_datetime": "2021-06-11T07:00:39.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-10T01:11:58.000Z", "max_forks_repo_path": "scripts/gfm/classify.js", "max_forks_repo_name": "yozorajs/yozora", "max_forks_repo_forks_event_min_datetime": "2021-07-29T07:16:12.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-05T01:41:32.000Z"}
{"max_stars_count": 124, "max_issues_count": 5, "max_forks_count": 2, "avg_line_length": 30.7368421053, "max_line_length": 82, "alphanum_fraction": 0.6586757991}
/* eslint-disable import/no-extraneous-dependencies */
const chalk = require('chalk')
const fs = require('fs-extra')
const path = require('path')
const gfmClassifyData = require('./data.json')

class GFMExampleClassifier {
  constructor(gfmExamples) {
    this.gfmExamples = gfmExamples
    this.numberLength = gfmExamples.length.toString().length
  }

  classifyToPath(caseRootDir, groups) {
    const self = this
    for (const group of groups) {
      const excluded = group.excluded || []
      const groupDir = path.resolve(caseRootDir, group.name)
      if (!fs.existsSync(groupDir)) fs.mkdirpSync(groupDir)
      for (let i = group.start; i <= group.end; ++i) {
        if (excluded.includes(i)) continue
        const fileName = '#' + ('' + i).padStart(self.numberLength, '0') + '.json'
        const caseFilePath = path.join(groupDir, fileName)
        const gfmExample = self.gfmExamples[i]
        const data = self.mapGFMExampleDataToCase(gfmExample)
        const content = JSON.stringify(data, null, 2)
        fs.writeFileSync(caseFilePath, content, 'utf-8')
        console.log(chalk.green(`Add case ${caseFilePath}`))
      }
    }
    return self
  }

  mapGFMExampleDataToCase(gfmExample) {
    const result = {
      title: gfmExample.title,
      cases: [
        {
          description: gfmExample.description,
          input: gfmExample.content,
          htmlAnswer: gfmExample.expectedHtml,
        },
      ],
    }
    return result
  }
}

const classifier = new GFMExampleClassifier(gfmClassifyData)

const rootDir = path.resolve(__dirname, '../../')

// parser-gfm test cases
classifier.classifyToPath(
  path.resolve(rootDir, 'scaffolds/jest-for-tokenizer/fixtures/gfm'),
  require('./data-classify/parser-gfm.json'),
)
