Add images to assets manifest

This commit is contained in:
QWp6t
2016-11-06 03:49:41 -08:00
parent 0d38ab8391
commit c49793cd3d
9 changed files with 270 additions and 79 deletions

View File

@@ -1,3 +1,4 @@
const path = require('path');
/**
@@ -7,12 +8,12 @@ const path = require('path');
* @return {String} JSON
*/
module.exports = (assets) => {
const results = {};
const manifest = {};
Object.keys(assets).forEach((name) => {
Object.keys(assets[name]).forEach((ext) => {
const filename = `${path.dirname(assets[name][ext])}/${path.basename(`${name}.${ext}`)}`;
results[filename] = assets[name][ext];
manifest[filename] = assets[name][ext];
});
});
return JSON.stringify(results);
return manifest;
};

View File

@@ -0,0 +1,50 @@
'use strict'; // eslint-disable-line
const path = require('path');
const utils = require('loader-utils');
/**
* Generate output name from output pattern
*
* @link https://github.com/kevlened/copy-webpack-plugin/blob/323b1d74ef35ed2221637d8028b1bef854deb523/src/writeFile.js#L31-L65
* @param {string} pattern
* @param {string} relativeFrom
* @param {binary} content
* @return {string}
*/
module.exports = (pattern, relativeFrom, content) => {
let webpackTo = pattern;
let resourcePath = relativeFrom;
/* A hack so .dotted files don't get parsed as extensions */
const basename = path.basename(resourcePath);
let dotRemoved = false;
if (basename[0] === '.') {
dotRemoved = true;
resourcePath = path.join(path.dirname(resourcePath), basename.slice(1));
}
/**
* If it doesn't have an extension, remove it from the pattern
* ie. [name].[ext] or [name][ext] both become [name]
*/
if (!path.extname(resourcePath)) {
webpackTo = webpackTo.replace(/\.?\[ext]/g, '');
}
/**
* A hack because loaderUtils.interpolateName doesn't
* find the right path if no directory is defined
* ie. [path] applied to 'file.txt' would return 'file'
*/
if (resourcePath.indexOf('/') < 0) {
resourcePath = `/${resourcePath}`;
}
webpackTo = utils.interpolateName({ resourcePath }, webpackTo, { content });
if (dotRemoved) {
webpackTo = path.join(path.dirname(webpackTo), `.${path.basename(webpackTo)}`);
}
return webpackTo;
};

View File

@@ -0,0 +1,21 @@
/**
* Node-style asynchronous function.
*
* @callback nodeAsyncCallback
* @param {string|null} err
* @param {*} data
*/
/**
* Promisify node-style asynchronous functions
*
* @param {nodeAsyncCallback} fn - Function with node-style callback
* @param {this} [scope] - Scope to which the function should be bound. Default: fn
* @returns {Promise} - An instance of Promise
*/
module.exports = (fn, scope) => function callback() {
const args = [].slice.call(arguments);
return new Promise((resolve, reject) => {
args.push((err, data) => (err === null ? resolve(data) : reject(err)));
return fn.apply(scope || fn, args);
});
};