kiwiirc-custom/build/webpack/exports-loader.js
Georg b3dd3db30b
Adding show_password_box
Signed-off-by: Georg <georg@lysergic.dev>
2021-06-25 07:28:29 +02:00

36 lines
1.1 KiB
JavaScript

const path = require('path');
const entry = 'window._kiwi_exports';
function accesorString(value) {
const childProperties = value.split('.');
let propertyString = entry;
let result = '';
for (let i = 0; i < childProperties.length; i++) {
if (i > 0) result += `if(!${propertyString}) ${propertyString} = {};\n`;
propertyString += `[${JSON.stringify(childProperties[i])}]`;
}
result += `${propertyString}`;
return result;
}
module.exports = function(source) {
if (source.indexOf('\'kiwi public\'') > -1) {
let resource = this.resourcePath;
let pos = resource.lastIndexOf(path.sep + 'src' + path.sep);
resource = resource.substr(pos + 5);
resource = resource.split(path.sep).join('.');
resource = resource.replace(/\.(vue|js)$/, '');
let a = '\r\n';
a += `${entry} = ${entry} || {};\r\n`;
a += accesorString(resource);
a += `\r\n${entry}.${resource} = exports.default ? exports.default : exports;\r\n`;
source += a;
}
return source;
};