mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-13 15:14:52 +09:00
Move all functions and classes currently available through lib/name and libName to be under a single flat namespace in lib. This make reorganising the lib namespace much simpler as the location of symbols can move without breaking the consumers of lib. The multi-entrypoint design was already problematic for the web plugin system which couldn't effectively use it due to how webpack's shared module system is awkward to set up with multiple entrypoints per package.
41 lines
875 B
JavaScript
41 lines
875 B
JavaScript
"use strict";
|
|
|
|
/**
|
|
* Returns the root folder in the zip file
|
|
*
|
|
* Returns the name of the folder that all files in the zip file is
|
|
* contained in. Throws an error if there are multiple such folders.
|
|
*
|
|
* @param {JSZip} zip - Zip to search through.
|
|
* @returns {string} name of the root folder.
|
|
* @memberof module:lib
|
|
* @private
|
|
* @inner
|
|
*/
|
|
function findRoot(zip) {
|
|
let root = null;
|
|
zip.forEach((relativePath, file) => {
|
|
let index = relativePath.indexOf("/");
|
|
if (index === -1) {
|
|
throw new Error(`Zip contains file '${relativePath}' in root dir`);
|
|
}
|
|
|
|
let pathRoot = relativePath.slice(0, index);
|
|
if (root === null) {
|
|
root = pathRoot;
|
|
} else if (root !== pathRoot) {
|
|
throw new Error("Zip contains multiple root folders");
|
|
}
|
|
});
|
|
|
|
if (root === null) {
|
|
throw new Error("Empty zip file");
|
|
}
|
|
|
|
return root;
|
|
}
|
|
|
|
module.exports = {
|
|
findRoot,
|
|
};
|