{"size": 1116, "ext": "js", "max_stars_repo_path": "tool/update.js", "max_stars_repo_name": "flutter-academy/boxicons_flutter", "max_stars_repo_stars_event_min_datetime": "2018-11-23T15:01:48.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-13T17:23:16.000Z", "max_issues_repo_path": "tool/update.js", "max_issues_repo_name": "flutter-academy/boxicons_flutter", "max_issues_repo_issues_event_min_datetime": "2019-05-08T19:15:54.000Z", "max_issues_repo_issues_event_max_datetime": "2019-07-30T13:40:23.000Z", "max_forks_repo_path": "tool/update.js", "max_forks_repo_name": "flutter-academy/boxicons_flutter", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 6, "max_issues_count": 2, "max_forks_count": null, "avg_line_length": 34.875, "max_line_length": 107, "alphanum_fraction": 0.6962365591}
const { execSync } = require('child_process');
const fs = require('fs');
const os = require('os');
const path = require('path');
const Handlebars = require('handlebars');
const parser = require('fast-xml-parser');
const camelcase = require('camelcase');

function downloadFile(url, filename) {
  execSync(`curl ${url} -o ${filename} -s`);
}

const savedFile = path.join(os.tmpdir(), 'boxicons.svg');
const svgUrl = 'https://raw.githubusercontent.com/atisawd/boxicons/master/static/fonts/boxicons.svg';
downloadFile(svgUrl, savedFile);

const xml = fs.readFileSync(savedFile).toString();
const json = parser.parse(xml, {
  ignoreAttributes: false,
});
const icons = json.svg.defs.font.glyph
  .filter(glyph => glyph['@_unicode'] && glyph['@_glyph-name'])
  .map(glyph => ({
    codePoint: glyph['@_unicode'].substring(3, 7),
    name: camelcase(glyph['@_glyph-name']),
  }));

const outputFile = 'boxicons_flutter.dart';
const template = Handlebars.compile(fs.readFileSync(`./${outputFile}.hbs`).toString(), { noEscape: true });

const content = template({ icons });
fs.writeFileSync(`../lib/${outputFile}`, content);