Comparing version 1.1.0 to 2.0.0
# CHANGELOG | ||
### 2.0.0 | ||
- Major: Upgraded to use the latest `@babel/*` 7.0 packages. | ||
### 1.1.0 | ||
@@ -4,0 +8,0 @@ |
const debug = require('diagnostics')('asset:list'); | ||
const table = require('markdown-table'); | ||
const EventEmitter = require('events'); | ||
const mkdirp = require('mkdirp'); | ||
const bytes = require('bytes'); | ||
const path = require('path'); | ||
const mkdirp = require('mkdirp'); | ||
const zlib = require('zlib'); | ||
@@ -8,0 +8,0 @@ const url = require('url'); |
151
lib/index.js
@@ -1,25 +0,50 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); } | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); } | ||
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); } | ||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
var debug = require('diagnostics')('asset:list'); | ||
var table = require('markdown-table'); | ||
var EventEmitter = require('events'); | ||
var mkdirp = require('mkdirp'); | ||
var bytes = require('bytes'); | ||
var path = require('path'); | ||
var mkdirp = require('mkdirp'); | ||
var zlib = require('zlib'); | ||
var url = require('url'); | ||
var fs = require('fs'); | ||
/** | ||
@@ -31,6 +56,7 @@ * Default options of the plugin. | ||
*/ | ||
var defaults = { | ||
separator: path.sep | ||
}; | ||
/** | ||
@@ -42,4 +68,4 @@ * Assets symbol. | ||
*/ | ||
var ASSETS = Symbol('ASSETS'); | ||
/** | ||
@@ -54,19 +80,24 @@ * Generates a markdown document that contains a listing of the various of | ||
var List = function (_EventEmitter) { | ||
var List = | ||
/*#__PURE__*/ | ||
function (_EventEmitter) { | ||
_inherits(List, _EventEmitter); | ||
function List(bundle, options) { | ||
var _this; | ||
_classCallCheck(this, List); | ||
var _this = _possibleConstructorReturn(this, (List.__proto__ || Object.getPrototypeOf(List)).call(this)); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(List).call(this)); | ||
_this.file = options.file; | ||
_this.bundle = bundle; | ||
_this.options = _extends({}, defaults, options); | ||
_this.generate = _this.generate.bind(_this); | ||
_this.options = _objectSpread({}, defaults, options); | ||
_this.generate = _this.generate.bind(_assertThisInitialized(_assertThisInitialized(_this))); | ||
_this.bundle.on('done', _this.generate); | ||
_this.on('done', _this.write); | ||
return _this; | ||
} | ||
/** | ||
@@ -81,7 +112,6 @@ * The name of the (bundle) documentation that we're generating. | ||
_createClass(List, [{ | ||
key: 'name', | ||
key: "name", | ||
value: function name() { | ||
return path.basename(this.file, path.extname(this.file)); | ||
} | ||
/** | ||
@@ -95,14 +125,11 @@ * Write the README file to disk. | ||
}, { | ||
key: 'write', | ||
key: "write", | ||
value: function write(readme) { | ||
var ext = path.extname(this.file); | ||
var out = this.file.slice(0, -Math.abs(ext.length)) + '.md'; | ||
debug('creating \'dist\' folder'); | ||
debug("creating 'dist' folder"); | ||
mkdirp.sync('dist'); | ||
debug('writing readme file to ' + out); | ||
debug("writing readme file to ".concat(out)); | ||
fs.writeFileSync(out, readme); | ||
} | ||
/** | ||
@@ -118,3 +145,3 @@ * The bundle process is done, so we can start generating the documentation. | ||
}, { | ||
key: 'generate', | ||
key: "generate", | ||
value: function generate(err, output, svgs) { | ||
@@ -124,20 +151,16 @@ if (err) { | ||
return this.emit('error', err); | ||
} | ||
// | ||
} // | ||
// Sort the svgs alphabetically based on the name of the asset. | ||
// | ||
svgs.sort(function sort(a, b) { | ||
if (a.name < b.name) return -1; | ||
if (a.name > b.name) return 1; | ||
return 0; | ||
}); | ||
var readme = ['# ' + path.basename(this.file), '', this.contents(svgs), '', this.details(output, svgs), '', '## Assets', ''].concat(_toConsumableArray(svgs.map(this.asset.bind(this)))).join('\n'); | ||
this.emit('done', readme); | ||
debug('done', readme); | ||
} | ||
/** | ||
@@ -152,3 +175,3 @@ * Generates an introduction header that contains some default information. | ||
}, { | ||
key: 'details', | ||
key: "details", | ||
value: function details(output, svgs) { | ||
@@ -158,6 +181,4 @@ var buffy = new Buffer(output); | ||
var name = this.name(); | ||
return '## Bundle details\n\n- **' + bytes(gzip.length) + '** compressed(gzip).\n- **' + bytes(buffy.length) + '** uncompressed.\n- Contains **' + svgs.length + '** asset' + (svgs.length > 1 ? 's' : '') + '.\n- Build according to specification **' + this.bundle.specification + '**\n\nThe bundle can be included using the `asset-provider` components:\n\n```js\nimport Provider, { Asset } from "asset-parser";\n\n<Provider uri="./' + name + '.svgs">\n <!-- Add the <Asset />\'s here -->\n</Provider>\n```\n\nLearn more about [asset-provider](https://github.com/godaddy/asset-system) components.'; | ||
return "## Bundle details\n\n- **".concat(bytes(gzip.length), "** compressed(gzip).\n- **").concat(bytes(buffy.length), "** uncompressed.\n- Contains **").concat(svgs.length, "** asset").concat(svgs.length > 1 ? 's' : '', ".\n- Build according to specification **").concat(this.bundle.specification, "**\n\nThe bundle can be included using the `asset-provider` components:\n\n```js\nimport Provider, { Asset } from \"asset-parser\";\n\n<Provider uri=\"./").concat(name, ".svgs\">\n <!-- Add the <Asset />'s here -->\n</Provider>\n```\n\nLearn more about [asset-provider](https://github.com/godaddy/asset-system) components."); | ||
} | ||
/** | ||
@@ -172,3 +193,3 @@ * Generates the documentation for a single Asset. | ||
}, { | ||
key: 'asset', | ||
key: "asset", | ||
value: function asset(svg) { | ||
@@ -183,6 +204,4 @@ // | ||
}; | ||
return ['### ' + svg.name, '', table([['name', 'width', 'height', 'preview'], [svg.name, size.width, size.height, this.embed(svg)]]), ''].concat(_toConsumableArray(this.example(svg, size)), ['']).join('\n'); | ||
return ["### ".concat(svg.name), '', table([['name', 'width', 'height', 'preview'], [svg.name, size.width, size.height, this.embed(svg)]]), ''].concat(_toConsumableArray(this.example(svg, size)), ['']).join('\n'); | ||
} | ||
/** | ||
@@ -197,10 +216,9 @@ * Embed a preview of the asset. | ||
}, { | ||
key: 'embed', | ||
key: "embed", | ||
value: function embed(svg) { | ||
var location = void 0; | ||
// | ||
var location; // | ||
// If we're supplied with a `hosted` property we're gonna assume that the | ||
// files are hosted in that said location. | ||
// | ||
if (this.options.hosted) { | ||
@@ -212,5 +230,4 @@ location = url.resolve(this.options.hosted, path.relative(process.cwd(), svg.loc)); | ||
return '<img src="' + location + '" />'; | ||
return "<img src=\"".concat(location, "\" />"); | ||
} | ||
/** | ||
@@ -226,7 +243,6 @@ * Generate the example code. | ||
}, { | ||
key: 'example', | ||
key: "example", | ||
value: function example(svg, size) { | ||
return ['```js', '<Asset name="' + svg.name + '" width={ ' + size.width + ' } height={ ' + size.height + ' } />', '```']; | ||
return ['```js', "<Asset name=\"".concat(svg.name, "\" width={ ").concat(size.width, " } height={ ").concat(size.height, " } />"), '```']; | ||
} | ||
/** | ||
@@ -241,3 +257,3 @@ * Generate categories for the assets based on the namespace. | ||
}, { | ||
key: 'categories', | ||
key: "categories", | ||
value: function categories(svgs) { | ||
@@ -247,3 +263,2 @@ var _this2 = this; | ||
var result = {}; | ||
svgs.map(function (svg) { | ||
@@ -253,3 +268,2 @@ return svg.name; | ||
var struc = result; | ||
name.split(_this2.options.separator).forEach(function (category, i, all) { | ||
@@ -261,10 +275,11 @@ if (!struc[category]) struc[category] = {}; | ||
if (!struc[ASSETS]) struc[ASSETS] = []; | ||
struc[ASSETS].push({ short: category, full: name }); | ||
struc[ASSETS].push({ | ||
short: category, | ||
full: name | ||
}); | ||
} | ||
}); | ||
}); | ||
return result; | ||
} | ||
/** | ||
@@ -279,3 +294,3 @@ * Generates the hash that github uses to link to headers. | ||
}, { | ||
key: 'link', | ||
key: "link", | ||
value: function link(name) { | ||
@@ -288,3 +303,2 @@ return name.replace(/[\.|\#]/g, '') // Remove dots and others. | ||
} | ||
/** | ||
@@ -299,3 +313,3 @@ * Generate a Table of Contents for the assets. | ||
}, { | ||
key: 'contents', | ||
key: "contents", | ||
value: function contents(svgs) { | ||
@@ -307,3 +321,2 @@ var _this3 = this; | ||
var indent = 3; | ||
/** | ||
@@ -315,8 +328,8 @@ * Generate link to the assets. | ||
*/ | ||
var item = function item(category) { | ||
category[ASSETS].forEach(function (item) { | ||
assets.push(Array(indent).join(' ') + ('- [' + item.short + '](#' + _this3.link(item.full) + ')')); | ||
assets.push(Array(indent).join(' ') + "- [".concat(item.short, "](#").concat(_this3.link(item.full), ")")); | ||
}); | ||
}; | ||
/** | ||
@@ -329,8 +342,9 @@ * Iterate the categories to generate an asset structure | ||
*/ | ||
var iterate = function iterate(what, keys) { | ||
keys.forEach(function (key) { | ||
var more = Object.keys(what[key]); | ||
if (ASSETS in what[key]) item(what[key]);else if (more.length) assets.push(Array(indent).join(' ') + "- ".concat(key)); | ||
if (ASSETS in what[key]) item(what[key]);else if (more.length) assets.push(Array(indent).join(' ') + ('- ' + key)); | ||
if (more.length) { | ||
@@ -342,9 +356,8 @@ indent = indent + 2; | ||
}); | ||
}; | ||
// | ||
}; // | ||
// Generate the categories. | ||
// | ||
iterate(categories, Object.keys(categories)); | ||
return ['## Table of Contents', '', '- [Bundle details](#bundle-details)', '- [Assets](#assets)'].concat(assets).join('\n'); | ||
@@ -355,5 +368,3 @@ } | ||
return List; | ||
}(EventEmitter); | ||
// | ||
}(EventEmitter); // | ||
// Expose the module. | ||
@@ -360,0 +371,0 @@ // |
{ | ||
"name": "asset-list", | ||
"version": "1.1.0", | ||
"version": "2.0.0", | ||
"description": "Automatically generate documentation for your generated asset-bundle's", | ||
@@ -10,3 +10,3 @@ "main": "./lib", | ||
"scripts": { | ||
"test:web": "mocha --colors --require babel-register test/*.test.js", | ||
"test:web": "mocha --colors --require setup-env test/*.test.js", | ||
"test": "nyc --reporter=text --reporter=lcov npm run test:web", | ||
@@ -24,7 +24,10 @@ "prepublishOnly": "npm run build", | ||
"devDependencies": { | ||
"@babel/cli": "^7.1.2", | ||
"@babel/core": "^7.1.2", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.0.0", | ||
"@babel/preset-env": "^7.1.0", | ||
"@babel/register": "^7.0.0", | ||
"asset-bundle": "latest", | ||
"asset-test": "latest", | ||
"assume": "^1.5.2", | ||
"babel-cli": "^6.26.0", | ||
"babel-plugin-transform-object-rest-spread": "^6.26.0", | ||
"babel-preset-es2015": "^6.24.1", | ||
"babel-register": "^6.26.0", | ||
"clone": "^2.1.1", | ||
@@ -36,10 +39,12 @@ "eslint": "^4.14.0", | ||
"mocha": "^4.1.0", | ||
"nyc": "^11.4.1" | ||
"nyc": "^11.4.1", | ||
"puppeteer": "^1.9.0", | ||
"setup-env": "^1.2.1" | ||
}, | ||
"babel": { | ||
"plugins": [ | ||
"transform-object-rest-spread" | ||
"@babel/plugin-proposal-object-rest-spread" | ||
], | ||
"presets": [ | ||
"babel-preset-es2015" | ||
"@babel/preset-env" | ||
] | ||
@@ -46,0 +51,0 @@ }, |
@@ -1,2 +0,3 @@ | ||
import Bundle from '../../bundle/index.js'; | ||
import { fixtures } from 'asset-test'; | ||
import Bundle from 'asset-bundle'; | ||
import List from '../index.js'; | ||
@@ -8,4 +9,2 @@ import assume from 'assume'; | ||
describe('List', function () { | ||
const fixtures = path.join(__dirname, '..', '..', '..', 'test', 'fixtures'); | ||
const godaddy = path.join(fixtures, 'godaddy.svg'); | ||
@@ -12,0 +11,0 @@ const tiger = path.join(fixtures, 'tiger.svg'); |
33404
729
17