<commit_before>#!/usr/bin/env node

/**
 * Icon Cleaner
 * Description: Giving credit to creatives is easier than ever! Icon Cleaner collects attribution details from icons obtained from the awesome Noun Project and writes the data to a single file. Icon Cleaner also removes that information from the SVG and makes other aesthetic improvements to the SVG. 
 * URL: www.github.com/rashanjibowu/icon_cleaner
 * Copyright (c) 2016 <NAME>
 * License: MIT
 */

// Require necessary modules
var fs = require('fs');
var path = require('path');
var mkdirp = require('mkdirp');

// set the directory and paths
var directory = "icons/";
var attributionPath = "attribution.txt";

if (process.argv[2]) {
    directory = process.argv[2] + "/" + directory;
    attributionPath = process.argv[2] + "/" + attributionPath;
}

// set up variables
var preserveAspectRatio = 'preserveAspectRatio="xMidYMid meet"';
var viewBox = 'viewBox="0 0 100 100"';

// create the attribution file
var attribution = '';

// out path directory
var out = directory + "dist/";

// create the directory structure
mkdirp.sync(out);

fs.access(out, fs.R_OK | fs.W_OK, function(error) {
    if (error) {
        console.error(error);
        return;
    }

    console.log("%s was created!", out);
});

// Read in the contents
var files = fs.readdirSync(directory);

if (!files || files.length === 0) {
    console.error("No files found!");
    return;
}

// consider only SVG files
var svgFiles = files.filter(function(file) {
    return path.extname(file) === ".svg";
});

// set up regular expressions
var svgRE = /<svg/ig;
var viewBoxRE = /viewBox=".+?"/i;
var parRE = /preserveAspectRatio=".+?"/i;
var textRegex = /<text.*?>(.*?)<\/text>/ig;

console.log("We found %d SVG files", svgFiles.length);

// for each file, pull out the attribution detail, write it to a file, and clean up the image
svgFiles.forEach(function(file) {

    // construct file paths
    var fileName = directory + file;
    var newFileName = out + file;

    var fileContent = fs.readFileSync(fileName, "utf-8");

    if (!fileContent) {
        console.error("Unable to read the file: %s", file);
        return;
    }

    var newFile = '';
    var attributionNote = '';

    // find all text attributes
    // Assumes that attribution details appear in text elements
    // Assumes that all text elements contain attribution details
    var match;

    // initialize array of "edit points" to reconstruct the file later
    var editPoints = [];

    var lowY = 99999;
<commit_msg>Fixes bug with paths when installed globally. Fixes #7<commit_after>#!/usr/bin/env node

/**
 * Icon Cleaner
 * Description: Giving credit to creatives is easier than ever! Icon Cleaner collects attribution details from icons obtained from the awesome Noun Project and writes the data to a single file. Icon Cleaner also removes that information from the SVG and makes other aesthetic improvements to the SVG. 
 * URL: www.github.com/rashanjibowu/icon_cleaner
 * Copyright (c) 2016 <NAME>
 * License: MIT
 */

// Require necessary modules
var fs = require('fs');
var path = require('path');
var mkdirp = require('mkdirp');

// set the directory and paths
var current = path.resolve(".");
var directory = "icons/";
var attributionPath = "attribution.txt";

// Users can specify their own parent directory
if (process.argv[2]) {
    directory = process.argv[2] + "/" + directory;
    attributionPath = process.argv[2] + "/" + attributionPath;
}

directory = path.join(current, directory);
attributionPath = path.join(current, attributionPath);

// set up variables
var preserveAspectRatio = 'preserveAspectRatio="xMidYMid meet"';
var viewBox = 'viewBox="0 0 100 100"';

// create the attribution file
var attribution = '';

// out path directory
var out = path.join(directory, "dist");

// create the directory structure
mkdirp.sync(out);

fs.access(out, fs.R_OK | fs.W_OK, function(error) {
    if (error) {
        console.error(error);
        return;
    }

    console.log("%s was created!", out);
});

// Read in the contents
var files = fs.readdirSync(directory);

if (!files || files.length === 0) {
    console.error("No files found!");
    return;
}

// consider only SVG files
var svgFiles = files.filter(function(file) {
    return path.extname(file) === ".svg";
});

// set up regular expressions
var svgRE = /<svg/ig;
var viewBoxRE = /viewBox=".+?"/i;
var parRE = /preserveAspectRatio=".+?"/i;
var textRegex = /<text.*?>(.*?)<\/text>/ig;

console.log("We found %d SVG files", svgFiles.length);

// for each file, pull out the attribution detail, write it to a file, and clean up the image
svgFiles.forEach(function(file) {

    // construct file paths
    var fileName = path.join(directory, file);
    var newFileName = path.join(out, file);

    var fileContent = fs.readFileSync(fileName, "utf-8");

    if (!fileContent) {
        console.error("Unable to read the file: %s", file);
        return;
    }

    var newFile = '';
    var attributionNote = '';

    // find all text attributes
    // Assumes that attribution details appear in text elements
    // Assumes that all text elements contain attribution details
    var match;

    // initialize array of "edit points" to reconstruct the file later
    var editPoints = [];

    var lowY = 99999;

{'fraction_non_alphanumeric': 0.129202871174915, 'fraction_numerical': 0.008500188893086513, 'mean_word_length': 3.457070707070707, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '178938', 'n_tokens_mistral': 1659, 'n_tokens_neox': 1582, 'n_words': 554}