From b267bfc9cc6bdad512d4f49f5fcc02075dae7c7c Mon Sep 17 00:00:00 2001 From: Austin Andrews Date: Thu, 12 Apr 2018 23:50:26 -0500 Subject: [PATCH] Publish @mdi/util --- package.json | 19 +++++++++++++++++++ util.js | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 package.json create mode 100644 util.js diff --git a/package.json b/package.json new file mode 100644 index 0000000..950410d --- /dev/null +++ b/package.json @@ -0,0 +1,19 @@ +{ + "name": "@mdi/util", + "version": "0.1.0", + "description": "Util helpers for support builds.", + "main": "util.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/Templarian/MaterialDesign-Util.git" + }, + "author": "Austin Andrews (@Templarian)", + "license": "MIT", + "bugs": { + "url": "https://github.com/Templarian/MaterialDesign-Util/issues" + }, + "homepage": "https://github.com/Templarian/MaterialDesign-Util#readme" +} diff --git a/util.js b/util.js new file mode 100644 index 0000000..5369d67 --- /dev/null +++ b/util.js @@ -0,0 +1,34 @@ +const fs = require('fs'); + +const encoding = "utf8"; +const folder = `${__dirname}/../svg`; + +exports.getVersion = () => { + const file = fs.readFileSync(`${folder}/package.json`, { encoding }); + return JSON.parse(file).version; +}; + +exports.getMeta = (withPaths) => { + const file = fs.readFileSync(`${folder}/meta.json`, { encoding }); + const meta = JSON.parse(file); + if (withPaths) { + const total = meta.length; + meta.forEach((icon, i) => { + const svg = fs.readFileSync(`${folder}/svg/${icon.name}.svg`, { encoding }); + icon.path = svg.match(/d="([^"]+)"/)[1]; + }); + } + return meta; +}; + +exports.write = (file, data) => { + fs.writeFileSync(file, data); +}; + +exports.read = (file, data) => { + fs.readFileSync(file); +}; + +exports.exists = (file) => { + return fs.exists(file); +};