libs without src support
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
namespace Espo\Core\Utils\Client;
|
||||
|
||||
use Espo\Core\Utils\File\Manager as FileManager;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* @internal Also used by the installer w/o DI.
|
||||
@@ -61,38 +62,40 @@ class DevModeJsFileListProvider
|
||||
$list = array_merge(
|
||||
$list,
|
||||
array_map(
|
||||
fn($item) => self::prepareBundleLibFilePath($item),
|
||||
$this->getLibFileListFromItems($files)
|
||||
fn ($item) => self::prepareBundleLibFilePath($item),
|
||||
$files
|
||||
)
|
||||
);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$list[] = self::prepareBundleLibFilePath($item->src);
|
||||
if (!isset($item->src)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$list[] = self::prepareBundleLibFilePath($item);
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \stdClass[] $items
|
||||
* @return string[]
|
||||
*/
|
||||
private function getLibFileListFromItems(array $items): array
|
||||
{
|
||||
$list = [];
|
||||
|
||||
foreach ($items as $item) {
|
||||
$list[] = $item->src;
|
||||
private function prepareBundleLibFilePath(object $item): string
|
||||
{
|
||||
$amdId = $item->amdId ?? null;
|
||||
|
||||
if ($amdId) {
|
||||
return 'client/lib/original/' . $amdId . '.js';
|
||||
}
|
||||
|
||||
return $list;
|
||||
$src = $item->src ?? null;
|
||||
|
||||
if (!$src) {
|
||||
throw new RuntimeException("Missing 'src' in bundled lib definition.");
|
||||
}
|
||||
|
||||
private function prepareBundleLibFilePath(string $path): string
|
||||
{
|
||||
$arr = explode('/', $path);
|
||||
$arr = explode('/', $src);
|
||||
|
||||
return 'client/lib/original/' . array_slice($arr, -1)[0];
|
||||
}
|
||||
|
||||
@@ -125,6 +125,10 @@
|
||||
"bundle": true,
|
||||
"amdId": "intl-tel-input-utils"
|
||||
},
|
||||
{
|
||||
"bundle": true,
|
||||
"amdId": "intl-tel-input-globals"
|
||||
},
|
||||
{
|
||||
"src": "node_modules/summernote/dist/summernote.js",
|
||||
"amdId": "summernote",
|
||||
|
||||
+23
-8
@@ -27,25 +27,40 @@
|
||||
************************************************************************/
|
||||
|
||||
const BuildUtils = {
|
||||
/**
|
||||
* @param {Array} libs
|
||||
* @return {{src: string, file: string}[]}
|
||||
*/
|
||||
getBundleLibList: function(libs) {
|
||||
const list = [];
|
||||
|
||||
libs.forEach(item => {
|
||||
if (!item.bundle) {
|
||||
return;
|
||||
const getFile = item => {
|
||||
if (item.amdId) {
|
||||
return item.amdId + '.js';
|
||||
}
|
||||
|
||||
return item.src.split('/').slice(-1);
|
||||
};
|
||||
|
||||
libs.filter(item => item.bundle)
|
||||
.forEach(item => {
|
||||
if (item.files) {
|
||||
item.files.forEach(item => list.push(item.src));
|
||||
item.files.forEach(item => list.push({
|
||||
src: item.src,
|
||||
file: getFile(item),
|
||||
}));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!item.src) {
|
||||
throw new Error("No lib src.");
|
||||
return;
|
||||
}
|
||||
|
||||
list.push(item.src);
|
||||
list.push({
|
||||
src: item.src,
|
||||
file: getFile(item),
|
||||
});
|
||||
});
|
||||
|
||||
return list;
|
||||
@@ -53,7 +68,7 @@ const BuildUtils = {
|
||||
|
||||
getPreparedBundleLibList: function (libs) {
|
||||
return BuildUtils.getBundleLibList(libs)
|
||||
.map(file => 'client/lib/original/' + file.split('/').slice(-1));
|
||||
.map(item => 'client/lib/original/' + item.file);
|
||||
},
|
||||
|
||||
destToOriginalDest: function (dest) {
|
||||
@@ -114,7 +129,7 @@ const BuildUtils = {
|
||||
}
|
||||
|
||||
if (!item.src) {
|
||||
throw new Error("No lib src.");
|
||||
return;
|
||||
}
|
||||
|
||||
list.push({
|
||||
|
||||
+19
-3
@@ -556,19 +556,27 @@ class Diff
|
||||
.parse(
|
||||
cp.execSync("git show " + commitHash + ":frontend/libs.json").toString() || '[]'
|
||||
)
|
||||
.filter(item => item.bundle);
|
||||
.filter(item => item.bundle)
|
||||
.filter(item => item.src || item.files);
|
||||
}
|
||||
|
||||
let libNewDataList = require(this.espoPath + '/frontend/libs.json')
|
||||
.filter(item => !item.bundle);
|
||||
|
||||
let bundledNewDataList = require(this.espoPath + '/frontend/libs.json')
|
||||
.filter(item => item.bundle);
|
||||
.filter(item => item.bundle)
|
||||
.filter(item => item.src || item.files);
|
||||
|
||||
let resolveItemDest = item =>
|
||||
item.dest || 'client/lib/' + item.src.split('/').pop();
|
||||
|
||||
let resolveBundledItemDest = item => 'client/lib/original/' + item.src.split('/').pop();
|
||||
const resolveBundledItemDest = item => {
|
||||
if (item.amdId) {
|
||||
return `'client/lib/original/${item.amdId}.js`;
|
||||
}
|
||||
|
||||
return 'client/lib/original/' + item.src.split('/').pop();
|
||||
};
|
||||
|
||||
let resolveItemName = item => {
|
||||
if (item.name) {
|
||||
@@ -759,6 +767,10 @@ class Diff
|
||||
return;
|
||||
}
|
||||
|
||||
if (!item.src) {
|
||||
return;
|
||||
}
|
||||
|
||||
data.filesToCopy.push(resolveBundledItemDest(item));
|
||||
});
|
||||
|
||||
@@ -786,6 +798,10 @@ class Diff
|
||||
return;
|
||||
}
|
||||
|
||||
if (!item.src) {
|
||||
return;
|
||||
}
|
||||
|
||||
data.filesToDelete.push(resolveBundledItemDest(item));
|
||||
});
|
||||
|
||||
|
||||
@@ -94,8 +94,7 @@ const addSuppressAmd = path => {
|
||||
fs.writeFileSync(path, contents, {encoding: 'utf-8'});
|
||||
}
|
||||
|
||||
/** @var {string[]} */
|
||||
const libSrcList = buildUtils.getBundleLibList(libs);
|
||||
const bundleLibDataList = buildUtils.getBundleLibList(libs);
|
||||
|
||||
const amdIdMap = {};
|
||||
const suppressAmdMap = {};
|
||||
@@ -114,8 +113,10 @@ libs.forEach(item => {
|
||||
amdIdMap[item.src] = 'lib!' + item.amdId;
|
||||
});
|
||||
|
||||
libSrcList.forEach(src => {
|
||||
const dest = originalLibDir + '/' + src.split('/').slice(-1);
|
||||
bundleLibDataList.forEach(item => {
|
||||
const src = item.src;
|
||||
|
||||
const dest = originalLibDir + '/' + item.file;
|
||||
|
||||
fs.copyFileSync(src, dest);
|
||||
stripSourceMappingUrl(dest);
|
||||
|
||||
Reference in New Issue
Block a user