snapshot of https://github.com/espocrm/espocrm.git (master, 2026-09-18; blobs > 131072B omitted)
Some checks failed
Test / Test on PHP 8.3 (push) Failing after 5s
Test / Test on PHP 8.4 (push) Failing after 4s
Test / Test on PHP 8.5 (push) Failing after 3s
TypeScript static analysis / TypeScript check (push) Failing after 14s
Test Integration on MySQL / Test on PHP 8.3 (push) Failing after 1s
Test Integration on MySQL / Test on PHP 8.5 (push) Failing after 1s
Test Integration on PostgreSQL / Test on PHP 8.4 fix (push) Failing after 1s
Test Integration on PostgreSQL / Test on PHP 8.4 master (push) Failing after 1s
Some checks failed
Test / Test on PHP 8.3 (push) Failing after 5s
Test / Test on PHP 8.4 (push) Failing after 4s
Test / Test on PHP 8.5 (push) Failing after 3s
TypeScript static analysis / TypeScript check (push) Failing after 14s
Test Integration on MySQL / Test on PHP 8.3 (push) Failing after 1s
Test Integration on MySQL / Test on PHP 8.5 (push) Failing after 1s
Test Integration on PostgreSQL / Test on PHP 8.4 fix (push) Failing after 1s
Test Integration on PostgreSQL / Test on PHP 8.4 master (push) Failing after 1s
This commit is contained in:
179
js/build-utils.js
Normal file
179
js/build-utils.js
Normal file
@@ -0,0 +1,179 @@
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2026 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
const BuildUtils = {
|
||||
/**
|
||||
* @param {{
|
||||
* src?: string,
|
||||
* dest?: string,
|
||||
* bundle?: boolean,
|
||||
* amdId?: string,
|
||||
* suppressAmd?: boolean,
|
||||
* minify?: boolean,
|
||||
* prepareCommand?: string,
|
||||
* name?: string,
|
||||
* files?: {
|
||||
* src: string,
|
||||
* dest: string,
|
||||
* }[],
|
||||
* }[]} libs
|
||||
* @param {boolean} [skipPreparable]
|
||||
* @return {{src: string, file: string}[]}
|
||||
*/
|
||||
getBundleLibList: function(libs, skipPreparable = false) {
|
||||
const list = [];
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {{amdId?: string, src: string}} item
|
||||
* @return {*|string}
|
||||
*/
|
||||
const getFile = item => {
|
||||
if (item.amdId) {
|
||||
if (item.amdId.startsWith('@')) {
|
||||
return item.amdId.slice(1).replace('/', '-') + '.js';
|
||||
}
|
||||
|
||||
return item.amdId + '.js';
|
||||
}
|
||||
|
||||
return item.src.split('/').slice(-1);
|
||||
};
|
||||
|
||||
libs.filter(item => item.bundle)
|
||||
.forEach(item => {
|
||||
if (item.prepareCommand && skipPreparable) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (item.files) {
|
||||
item.files.forEach(item => list.push({
|
||||
src: item.src,
|
||||
file: getFile(item),
|
||||
}));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!item.src) {
|
||||
return;
|
||||
}
|
||||
|
||||
list.push({
|
||||
src: item.src,
|
||||
file: getFile(item),
|
||||
});
|
||||
});
|
||||
|
||||
return list;
|
||||
},
|
||||
|
||||
getPreparedBundleLibList: function (libs) {
|
||||
const items = BuildUtils.getBundleLibList(libs);
|
||||
|
||||
return items.map(item => 'client/lib/original/' + item.file);
|
||||
},
|
||||
|
||||
destToOriginalDest: function (dest) {
|
||||
const path = dest.split('/');
|
||||
|
||||
return path.slice(0, -1)
|
||||
.concat('original')
|
||||
.concat(path.slice(-1))
|
||||
.join('/');
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Object[]} libs
|
||||
* @return {{
|
||||
* src: string,
|
||||
* dest: string,
|
||||
* originalDest: string|null,
|
||||
* minify: boolean,
|
||||
* }[]}
|
||||
*/
|
||||
getCopyLibDataList: function (libs) {
|
||||
const list = [];
|
||||
|
||||
/**
|
||||
* @param {Object} item
|
||||
* @return {string}
|
||||
*/
|
||||
const getItemDest = item => item.dest || 'client/lib/' + item.src.split('/').pop();
|
||||
|
||||
/**
|
||||
* @param {Object} item
|
||||
* @return {string}
|
||||
*/
|
||||
const getItemOriginalDest = item => {
|
||||
return BuildUtils.destToOriginalDest(
|
||||
getItemDest(item)
|
||||
);
|
||||
};
|
||||
|
||||
libs.forEach(item => {
|
||||
if (item.bundle) {
|
||||
return;
|
||||
}
|
||||
|
||||
const minify = !!item.minify;
|
||||
|
||||
if (item.files) {
|
||||
item.files.forEach(item => {
|
||||
list.push({
|
||||
src: item.src,
|
||||
dest: getItemDest(item),
|
||||
originalDest: minify ? getItemOriginalDest(item) : null,
|
||||
minify: minify,
|
||||
});
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!item.src) {
|
||||
return;
|
||||
}
|
||||
|
||||
list.push({
|
||||
src: item.src,
|
||||
dest: getItemDest(item),
|
||||
originalDest: minify ? getItemOriginalDest(item) : null,
|
||||
minify: minify,
|
||||
});
|
||||
});
|
||||
|
||||
return list;
|
||||
},
|
||||
|
||||
camelCaseToHyphen: function (string) {
|
||||
return string.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
|
||||
},
|
||||
}
|
||||
|
||||
module.exports = BuildUtils;
|
||||
996
js/diff.js
Normal file
996
js/diff.js
Normal file
@@ -0,0 +1,996 @@
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2026 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
const fs = require('fs');
|
||||
const cp = require('child_process');
|
||||
const archiver = require('archiver');
|
||||
const process = require('process');
|
||||
const buildUtils = require('./build-utils');
|
||||
|
||||
const bundleConfig = require('../frontend/bundle-config.json');
|
||||
|
||||
const exec = cp.exec;
|
||||
|
||||
/**
|
||||
* Builds upgrade packages.
|
||||
*/
|
||||
class Diff
|
||||
{
|
||||
constructor(espoPath, params) {
|
||||
this.espoPath = espoPath;
|
||||
this.params = params || {};
|
||||
}
|
||||
|
||||
_getTagList() {
|
||||
const dirInitial = process.cwd();
|
||||
|
||||
process.chdir(this.espoPath);
|
||||
|
||||
const tagsString = cp.execSync('git tag -l --sort=-v:refname').toString();
|
||||
const tagList = tagsString.trim().split("\n");
|
||||
|
||||
process.chdir(dirInitial);
|
||||
|
||||
return tagList;
|
||||
}
|
||||
|
||||
buildClosestUpgradePackages() {
|
||||
const versionFromList = this._getPreviousVersionList(true);
|
||||
|
||||
this.buildMultipleUpgradePackages(versionFromList);
|
||||
}
|
||||
|
||||
buildAllUpgradePackages() {
|
||||
const versionFromList = this._getPreviousVersionList();
|
||||
|
||||
this.buildMultipleUpgradePackages(versionFromList);
|
||||
}
|
||||
|
||||
_getPreviousVersionList(closest) {
|
||||
const dirInitial = process.cwd();
|
||||
|
||||
const version = (require(this.espoPath + '/package.json') || {}).version;
|
||||
|
||||
process.chdir(this.espoPath);
|
||||
|
||||
const tagList = this._getTagList();
|
||||
|
||||
const versionFromList = [];
|
||||
|
||||
const minorVersionNumber = version.split('.')[1];
|
||||
const hotfixVersionNumber = version.split('.')[2];
|
||||
const majorVersionNumber = version.split('.')[0];
|
||||
|
||||
for (let i = 0; i < tagList.length; i++) {
|
||||
const tag = tagList[i];
|
||||
|
||||
if (tag === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tag === version) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!~tag.indexOf('beta') && !~tag.indexOf('alpha')) {
|
||||
const minorVersionNumberI = tag.split('.')[1];
|
||||
|
||||
if (minorVersionNumberI !== minorVersionNumber) {
|
||||
versionFromList.push(tag);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (hotfixVersionNumber !== '0') {
|
||||
for (let i = 0; i < tagList.length; i++) {
|
||||
const tag = tagList[i];
|
||||
|
||||
const patchVersionNumberI = tag.split('.')[2];
|
||||
const minorVersionNumberI = tag.split('.')[1];
|
||||
const majorVersionNumberI = tag.split('.')[0];
|
||||
|
||||
if (
|
||||
closest &&
|
||||
(
|
||||
minorVersionNumberI !== minorVersionNumber ||
|
||||
majorVersionNumberI !== majorVersionNumber ||
|
||||
parseInt(patchVersionNumberI) !== parseInt(hotfixVersionNumber) - 1
|
||||
)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tag === version) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!~tag.indexOf('beta') && !~tag.indexOf('alpha')) {
|
||||
versionFromList.push(tag);
|
||||
|
||||
if (patchVersionNumberI === '0') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
process.chdir(dirInitial);
|
||||
|
||||
return versionFromList;
|
||||
}
|
||||
|
||||
buildMultipleUpgradePackages(versionFromList) {
|
||||
const params = this.params;
|
||||
const espoPath = this.espoPath;
|
||||
|
||||
async function buildMultiple() {
|
||||
for (const versionFrom of versionFromList) {
|
||||
const diff = new Diff(espoPath, params);
|
||||
|
||||
await diff.buildUpgradePackage(versionFrom);
|
||||
}
|
||||
}
|
||||
|
||||
buildMultiple();
|
||||
}
|
||||
|
||||
_versionExists(version) {
|
||||
return ~this._getTagList().indexOf(version);
|
||||
}
|
||||
|
||||
buildUpgradePackage(versionFrom) {
|
||||
const params = this.params;
|
||||
const espoPath = this.espoPath;
|
||||
|
||||
if (!this._versionExists(versionFrom)) {
|
||||
throw new Error('Version ' + versionFrom + ' does not exist.');
|
||||
}
|
||||
|
||||
return new Promise(resolve => {
|
||||
const acceptedVersionName = params.acceptedVersionName || versionFrom;
|
||||
const isDev = params.isDev;
|
||||
const withVendor = params.withVendor ?? true;
|
||||
const forceScripts = params.forceScripts;
|
||||
|
||||
const version = (require(espoPath + '/package.json') || {}).version;
|
||||
const composerData = require(espoPath + '/composer.json') || {};
|
||||
|
||||
const currentPath = espoPath;
|
||||
const buildRelPath = 'build/EspoCRM-' + version;
|
||||
const buildPath = currentPath + '/' + buildRelPath;
|
||||
const diffFilePath = currentPath + '/build/diff';
|
||||
const diffBeforeUpgradeFolderPath = currentPath + '/build/diffBeforeUpgrade';
|
||||
|
||||
const tempFolderPath = currentPath + '/build/upgradeTmp';
|
||||
const folderName = 'EspoCRM-upgrade-' + acceptedVersionName + '-to-' + version;
|
||||
const upgradePath = currentPath + '/build/' + folderName;
|
||||
const zipPath = currentPath + '/build/' + folderName + '.zip';
|
||||
let upgradeDataFolder = versionFrom + '-' + version;
|
||||
|
||||
|
||||
const isMinorVersion =
|
||||
versionFrom.split('.')[1] !== version.split('.')[1] ||
|
||||
versionFrom.split('.')[0] !== version.split('.')[0];
|
||||
|
||||
if (isMinorVersion) {
|
||||
upgradeDataFolder = version.split('.')[0] + '.' + version.split('.')[1];
|
||||
}
|
||||
|
||||
const upgradeDataFolderPath = currentPath + '/upgrades/' + upgradeDataFolder;
|
||||
const upgradeFolderExists = fs.existsSync(upgradeDataFolderPath);
|
||||
|
||||
let upgradeData = {};
|
||||
|
||||
if (upgradeFolderExists) {
|
||||
upgradeData = require(upgradeDataFolderPath + '/data.json') || {};
|
||||
}
|
||||
|
||||
const beforeUpgradeFileList = upgradeData.beforeUpgradeFiles || [];
|
||||
|
||||
deleteDirRecursively(diffFilePath);
|
||||
deleteDirRecursively(diffBeforeUpgradeFolderPath);
|
||||
deleteDirRecursively(upgradePath);
|
||||
deleteDirRecursively(tempFolderPath);
|
||||
|
||||
if (fs.existsSync(zipPath)) {
|
||||
fs.unlinkSync(zipPath);
|
||||
}
|
||||
|
||||
process.chdir(espoPath);
|
||||
|
||||
this._notifyIfBadBranch();
|
||||
|
||||
if (!fs.existsSync(buildPath)) {
|
||||
throw new Error(
|
||||
"EspoCRM is not built. You need to run 'grunt' before building an upgrade package."
|
||||
);
|
||||
}
|
||||
|
||||
if (!fs.existsSync(upgradePath)) {
|
||||
fs.mkdirSync(upgradePath);
|
||||
}
|
||||
|
||||
if (!fs.existsSync(upgradePath + '/files')) {
|
||||
fs.mkdirSync(upgradePath + '/files');
|
||||
}
|
||||
|
||||
if (fs.existsSync(upgradeDataFolderPath + '/beforeUpgradeFiles')) {
|
||||
cp.execSync(
|
||||
'cp -r ' + upgradeDataFolderPath + '/beforeUpgradeFiles ' + upgradePath + '/beforeUpgradeFiles'
|
||||
);
|
||||
}
|
||||
|
||||
if (beforeUpgradeFileList.length) {
|
||||
if (!fs.existsSync(upgradePath + '/beforeUpgradeFiles')) {
|
||||
fs.mkdirSync(upgradePath + '/beforeUpgradeFiles');
|
||||
}
|
||||
}
|
||||
|
||||
const libData = this._getLibData({
|
||||
versionFrom: versionFrom,
|
||||
currentPath: currentPath,
|
||||
});
|
||||
|
||||
const deleteFileList = this._getDeletedFileList(versionFrom)
|
||||
.concat(libData.filesToDelete)
|
||||
.filter((item, i, list) => list.indexOf(item) === i);
|
||||
|
||||
const tagList = this._getTagList();
|
||||
|
||||
process.chdir(buildPath);
|
||||
|
||||
let fileList = upgradeData.mandatoryFiles || [];
|
||||
|
||||
const stdout = cp.execSync('git diff --name-only ' + versionFrom).toString();
|
||||
|
||||
(stdout || '').trim().split('\n').forEach(file => {
|
||||
if (file === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
fileList.push(file);
|
||||
});
|
||||
|
||||
libData.filesToCopy.forEach(item => fileList.push(item));
|
||||
|
||||
fileList.push('application/Espo/Resources/defaults.php');
|
||||
|
||||
fileList.push('client/lib/espo.js');
|
||||
fileList.push('client/lib/espo.js.map');
|
||||
fileList.push('client/lib/templates.tpl');
|
||||
fileList.push('client/lib/original/espo.js');
|
||||
|
||||
Object.keys(bundleConfig.chunks)
|
||||
.map(name => {
|
||||
const namePart = `espo-${name}`;
|
||||
|
||||
fileList.push(`client/lib/${namePart}.js`);
|
||||
fileList.push(`client/lib/${namePart}.js.map`);
|
||||
fileList.push(`client/lib/original/${namePart}.js`);
|
||||
});
|
||||
|
||||
fs.readdirSync('client/css/espo/').forEach(file => {
|
||||
fileList.push('client/css/espo/' + file);
|
||||
});
|
||||
|
||||
fileList = fileList.filter(item => fs.existsSync(item));
|
||||
|
||||
fs.writeFileSync(diffFilePath, fileList.join('\n'));
|
||||
|
||||
if (beforeUpgradeFileList.length) {
|
||||
fs.writeFileSync(diffBeforeUpgradeFolderPath, beforeUpgradeFileList.join('\n'));
|
||||
}
|
||||
|
||||
if (beforeUpgradeFileList.length) {
|
||||
cp.execSync(
|
||||
'xargs -a ' + diffBeforeUpgradeFolderPath +
|
||||
' cp -p --parents -t ' + upgradePath + '/beforeUpgradeFiles'
|
||||
);
|
||||
}
|
||||
|
||||
if (!isDev || forceScripts) {
|
||||
if (fs.existsSync(upgradeDataFolderPath + '/scripts')) {
|
||||
cp.execSync('cp -r ' + upgradeDataFolderPath + '/scripts ' + upgradePath + '/scripts');
|
||||
}
|
||||
}
|
||||
|
||||
execute('xargs -a ' + diffFilePath + ' cp -p --parents -t ' + upgradePath + '/files' , () => {
|
||||
const date = this._getCurrentDate();
|
||||
|
||||
let versionList = [];
|
||||
|
||||
tagList.forEach(tag => {
|
||||
if (tag === versionFrom) {
|
||||
versionList.push(tag);
|
||||
}
|
||||
|
||||
/*if (!tag || tag === version) {
|
||||
return;
|
||||
}*/
|
||||
});
|
||||
|
||||
if (isDev) {
|
||||
versionList = [];
|
||||
}
|
||||
|
||||
const upgradeName = acceptedVersionName + " to " + version;
|
||||
|
||||
const manifestData = {
|
||||
"name": "EspoCRM Upgrade " + upgradeName,
|
||||
"type": "upgrade",
|
||||
"version": version,
|
||||
"acceptableVersions": versionList,
|
||||
"php": [composerData.require.php],
|
||||
"releaseDate": date,
|
||||
"author": "EspoCRM",
|
||||
"description": "",
|
||||
"delete": deleteFileList,
|
||||
};
|
||||
|
||||
const additionalManifestData = upgradeData.manifest || {};
|
||||
|
||||
for (const item in additionalManifestData) {
|
||||
if (Array.isArray(manifestData[item])) {
|
||||
manifestData[item] = manifestData[item].concat(additionalManifestData[item]);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
manifestData[item] = additionalManifestData[item];
|
||||
}
|
||||
|
||||
fs.writeFileSync(upgradePath + '/manifest.json', JSON.stringify(manifestData, null, ' '));
|
||||
|
||||
if (fs.existsSync(diffFilePath)) {
|
||||
fs.unlinkSync(diffFilePath);
|
||||
}
|
||||
|
||||
if (fs.existsSync(diffBeforeUpgradeFolderPath)) {
|
||||
fs.unlinkSync(diffBeforeUpgradeFolderPath);
|
||||
}
|
||||
|
||||
if (withVendor) {
|
||||
this._processVendor({
|
||||
versionFrom: versionFrom,
|
||||
currentPath: currentPath,
|
||||
tempFolderPath: tempFolderPath,
|
||||
upgradePath: upgradePath,
|
||||
});
|
||||
}
|
||||
|
||||
this._processArchive({
|
||||
upgradeName: upgradeName,
|
||||
zipPath: zipPath,
|
||||
upgradePath: upgradePath,
|
||||
})
|
||||
.then(() => resolve());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
_notifyIfBadBranch() {
|
||||
const currentBranch = cp.execSync('git rev-parse --abbrev-ref HEAD').toString().trim();
|
||||
|
||||
if (
|
||||
currentBranch !== 'master' &&
|
||||
currentBranch !== 'stable' &&
|
||||
currentBranch !== 'fix'
|
||||
) {
|
||||
console.log('\x1b[33m%s\x1b[0m', "Warning! You are on " + currentBranch + " branch.");
|
||||
}
|
||||
}
|
||||
|
||||
_getCurrentDate() {
|
||||
const d = new Date();
|
||||
|
||||
let monthN = ((d.getMonth() + 1).toString());
|
||||
monthN = monthN.length === 1 ? '0' + monthN : monthN;
|
||||
|
||||
let dateN = d.getDate().toString();
|
||||
dateN = dateN.length === 1 ? '0' + dateN : dateN;
|
||||
|
||||
return d.getFullYear().toString() + '-' + monthN + '-' + dateN.toString();
|
||||
}
|
||||
|
||||
_getDeletedFileList(versionFrom) {
|
||||
const dirInitial = process.cwd();
|
||||
|
||||
process.chdir(this.espoPath);
|
||||
|
||||
let deletedFileList = this._getRepositoryDeletedFileList(versionFrom);
|
||||
const previousAllFileList = this._getPreviousAllFileList(versionFrom);
|
||||
const actualAllFileList = this._getActualAllFileList();
|
||||
|
||||
previousAllFileList.forEach(file => {
|
||||
if (
|
||||
!~actualAllFileList.indexOf(file) &&
|
||||
!~deletedFileList.indexOf(file)
|
||||
) {
|
||||
deletedFileList.push(file);
|
||||
}
|
||||
});
|
||||
|
||||
deletedFileList = deletedFileList.filter(item => {
|
||||
if (
|
||||
item.indexOf('tests/') === 0 ||
|
||||
item.indexOf('upgrades/') === 0 ||
|
||||
item.indexOf('frontend/') === 0||
|
||||
item.indexOf('js/') === 0
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
process.chdir(dirInitial);
|
||||
|
||||
return deletedFileList;
|
||||
}
|
||||
|
||||
_getRepositoryDeletedFileList(versionFrom) {
|
||||
const deletedFileList = [];
|
||||
|
||||
const stdout = cp.execSync('git diff --name-only --diff-filter=D ' + versionFrom).toString();
|
||||
|
||||
(stdout || '').trim().split('\n').forEach(file => {
|
||||
if (file === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
deletedFileList.push(file);
|
||||
});
|
||||
|
||||
return deletedFileList;
|
||||
}
|
||||
|
||||
_getActualAllFileList() {
|
||||
const actualAllFileList = [];
|
||||
|
||||
const stdout = cp.execSync('git ls-tree -r --name-only HEAD').toString();
|
||||
|
||||
(stdout || '').trim().split('\n').forEach(file => {
|
||||
if (file === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
actualAllFileList.push(file);
|
||||
});
|
||||
|
||||
return actualAllFileList;
|
||||
}
|
||||
|
||||
_getPreviousAllFileList(versionFrom) {
|
||||
const previousAllFileList = [];
|
||||
|
||||
const stdout = cp.execSync('git ls-tree -r --name-only ' + versionFrom).toString();
|
||||
|
||||
(stdout || '').trim().split('\n').forEach(file => {
|
||||
if (file === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
previousAllFileList.push(file);
|
||||
});
|
||||
|
||||
return previousAllFileList;
|
||||
}
|
||||
|
||||
_deleteGitFolderInVendor(dir) {
|
||||
const folderList = fs.readdirSync(dir, {withFileTypes: true})
|
||||
.filter(dirent => dirent.isDirectory())
|
||||
.map(dirent => dirent.name);
|
||||
|
||||
folderList.forEach(folder => {
|
||||
const path = dir + '/' + folder;
|
||||
|
||||
const gitPath = path + '/.git';
|
||||
|
||||
if (fs.existsSync(gitPath)) {
|
||||
deleteDirRecursively(gitPath);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
_getLibData(dto) {
|
||||
const data = {
|
||||
filesToDelete: [],
|
||||
filesToCopy: [],
|
||||
};
|
||||
|
||||
const versionFrom = dto.versionFrom;
|
||||
const currentPath = dto.currentPath;
|
||||
|
||||
const output = cp.execSync("git show " + versionFrom + " --format=%H").toString();
|
||||
const commitHash = output.trim().split("\n")[3];
|
||||
|
||||
if (!commitHash) {
|
||||
throw new Error("Couldn't find commit hash.");
|
||||
}
|
||||
|
||||
const packageLockOldContents = cp.execSync("git show " + commitHash + ":package-lock.json").toString();
|
||||
const packageLockNewContents = cp.execSync("cat " + currentPath + "/package-lock.json").toString();
|
||||
|
||||
const depsOld = JSON.parse(packageLockOldContents).dependencies || {};
|
||||
const depsNew = JSON.parse(packageLockNewContents).dependencies || {};
|
||||
|
||||
if (packageLockOldContents === packageLockNewContents) {
|
||||
return data;
|
||||
}
|
||||
|
||||
let libOldDataList = [];
|
||||
let bundledOldDataList = [];
|
||||
|
||||
if (~this._getVersionAllFileList(versionFrom).indexOf('frontend/libs.json')) {
|
||||
libOldDataList = JSON
|
||||
.parse(
|
||||
cp.execSync("git show " + commitHash + ":frontend/libs.json").toString() || '[]'
|
||||
)
|
||||
.filter(item => !item.bundle);
|
||||
|
||||
bundledOldDataList = JSON
|
||||
.parse(
|
||||
cp.execSync("git show " + commitHash + ":frontend/libs.json").toString() || '[]'
|
||||
)
|
||||
.filter(item => item.bundle)
|
||||
.filter(item => item.src || item.files);
|
||||
}
|
||||
|
||||
const libNewDataList = require(this.espoPath + '/frontend/libs.json')
|
||||
.filter(item => !item.bundle);
|
||||
|
||||
const bundledNewDataList = require(this.espoPath + '/frontend/libs.json')
|
||||
.filter(item => item.bundle)
|
||||
.filter(item => item.src || item.files);
|
||||
|
||||
const resolveItemDest = item =>
|
||||
item.dest || 'client/lib/' + 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();
|
||||
};*/
|
||||
|
||||
const resolveItemName = item => {
|
||||
if (item.name) {
|
||||
return item.name;
|
||||
}
|
||||
|
||||
const src = /** @type string */item.src;
|
||||
|
||||
if (!src) {
|
||||
throw new Error("Bad lib data in `frontend/libs.json`.");
|
||||
}
|
||||
|
||||
const name = src.split('/')[1];
|
||||
|
||||
if (!name) {
|
||||
throw new Error("Bad lib data in `frontend/libs.json`.");
|
||||
}
|
||||
|
||||
if (name.startsWith('@')) {
|
||||
return src.split('/').slice(1, 3).join('/');
|
||||
}
|
||||
|
||||
return name;
|
||||
};
|
||||
|
||||
const changedLibList = [];
|
||||
const currentLibList = [];
|
||||
|
||||
const changedBundledList = [];
|
||||
const currentBundledList = [];
|
||||
|
||||
const toMinifyOldMap = {};
|
||||
const libOldDataMap = {};
|
||||
const bundledOldDataMap = {};
|
||||
|
||||
libOldDataList.forEach(item => {
|
||||
const name = resolveItemName(item);
|
||||
|
||||
toMinifyOldMap[name] = item.minify || false;
|
||||
libOldDataMap[name] = item;
|
||||
});
|
||||
|
||||
bundledOldDataList.forEach(item => {
|
||||
const name = resolveItemName(item);
|
||||
|
||||
bundledOldDataMap[name] = item;
|
||||
})
|
||||
|
||||
libNewDataList.forEach(item => {
|
||||
const name = resolveItemName(item);
|
||||
|
||||
const minify = item.minify || false;
|
||||
|
||||
if (!depsNew[name]) {
|
||||
throw new Error("Not installed lib '" + name + "' `frontend/libs.json`.");
|
||||
}
|
||||
|
||||
currentLibList.push(name);
|
||||
|
||||
const isAdded = !(name in depsOld);
|
||||
|
||||
const versionNew = depsNew[name].version || null;
|
||||
const versionOld = (depsOld[name] || {}).version || null;
|
||||
|
||||
const wasMinified = (toMinifyOldMap || {})[name];
|
||||
|
||||
const isDefsChanged = libOldDataMap[name] ?
|
||||
JSON.stringify(item) !== JSON.stringify(libOldDataMap[name]) :
|
||||
false;
|
||||
|
||||
if (
|
||||
!isAdded &&
|
||||
versionNew === versionOld &&
|
||||
minify === wasMinified &&
|
||||
!isDefsChanged
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
changedLibList.push(name);
|
||||
|
||||
if (item.files) {
|
||||
item.files.forEach(item =>
|
||||
data.filesToCopy.push(resolveItemDest(item))
|
||||
);
|
||||
|
||||
if (minify) {
|
||||
item.files.forEach(item => {
|
||||
data.filesToCopy.push(resolveItemDest(item) + '.map');
|
||||
data.filesToCopy.push(
|
||||
buildUtils.destToOriginalDest(resolveItemDest(item))
|
||||
);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
data.filesToCopy.push(resolveItemDest(item));
|
||||
|
||||
if (minify) {
|
||||
data.filesToCopy.push(resolveItemDest(item) + '.map');
|
||||
data.filesToCopy.push(
|
||||
buildUtils.destToOriginalDest(resolveItemDest(item))
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
libOldDataList.forEach(item => {
|
||||
const name = resolveItemName(item);
|
||||
|
||||
const minify = item.minify || false;
|
||||
|
||||
let toRemove = false;
|
||||
|
||||
if (
|
||||
~changedLibList.indexOf(name) ||
|
||||
!~currentLibList.indexOf(name)
|
||||
) {
|
||||
toRemove = true;
|
||||
}
|
||||
|
||||
if (!toRemove) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (item.files) {
|
||||
item.files.forEach(item =>
|
||||
data.filesToDelete.push(resolveItemDest(item))
|
||||
);
|
||||
|
||||
if (minify) {
|
||||
item.files.forEach(item => {
|
||||
data.filesToDelete.push(resolveItemDest(item) + '.map');
|
||||
data.filesToDelete.push(
|
||||
buildUtils.destToOriginalDest(resolveItemDest(item))
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
data.filesToDelete.push(resolveItemDest(item));
|
||||
|
||||
if (minify) {
|
||||
data.filesToDelete.push(resolveItemDest(item) + '.map');
|
||||
data.filesToDelete.push(
|
||||
buildUtils.destToOriginalDest(resolveItemDest(item))
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
bundledNewDataList.forEach(item => {
|
||||
const name = resolveItemName(item);
|
||||
|
||||
if (!depsNew[name]) {
|
||||
throw new Error("Not installed lib '" + name + "' `frontend/libs.json`.");
|
||||
}
|
||||
|
||||
currentBundledList.push(name);
|
||||
|
||||
const isAdded = !(name in depsOld);
|
||||
|
||||
const versionNew = depsNew[name].version || null;
|
||||
const versionOld = (depsOld[name] || {}).version || null;
|
||||
|
||||
const isDefsChanged = libOldDataMap[name] ?
|
||||
JSON.stringify(item) !== JSON.stringify(libOldDataMap[name]) :
|
||||
false;
|
||||
|
||||
if (
|
||||
!isAdded &&
|
||||
versionNew === versionOld &&
|
||||
!isDefsChanged
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
changedBundledList.push(name);
|
||||
|
||||
/*if (item.files) {
|
||||
item.files.forEach(item =>
|
||||
data.filesToCopy.push(resolveBundledItemDest(item))
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!item.src) {
|
||||
return;
|
||||
}
|
||||
|
||||
data.filesToCopy.push(resolveBundledItemDest(item));*/
|
||||
});
|
||||
|
||||
bundledOldDataList.forEach(item => {
|
||||
const name = resolveItemName(item);
|
||||
|
||||
let toRemove = false;
|
||||
|
||||
if (
|
||||
~changedBundledList.indexOf(name) ||
|
||||
!~currentBundledList.indexOf(name)
|
||||
) {
|
||||
toRemove = true;
|
||||
}
|
||||
|
||||
if (!toRemove) {
|
||||
// noinspection UnnecessaryReturnStatementJS
|
||||
return;
|
||||
}
|
||||
|
||||
/*if (item.files) {
|
||||
item.files.forEach(item =>
|
||||
data.filesToDelete.push(resolveBundledItemDest(item))
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!item.src) {
|
||||
return;
|
||||
}
|
||||
|
||||
data.filesToDelete.push(resolveBundledItemDest(item));*/
|
||||
});
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
_getVersionAllFileList(version) {
|
||||
const output = cp.execSync("git show " + version + " --format=%H").toString();
|
||||
const commitHash = output.trim().split("\n")[3];
|
||||
|
||||
const list = [];
|
||||
|
||||
cp.execSync("git ls-tree -r " + commitHash + " --name-only")
|
||||
.toString()
|
||||
.trim()
|
||||
.split('\n')
|
||||
.forEach(file => {
|
||||
if (file === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
list.push(file);
|
||||
});
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
_processVendor(dto) {
|
||||
const versionFrom = dto.versionFrom;
|
||||
const currentPath = dto.currentPath;
|
||||
const tempFolderPath = dto.tempFolderPath;
|
||||
const upgradePath = dto.upgradePath;
|
||||
|
||||
const output = cp.execSync("git show " + versionFrom + " --format=%H").toString();
|
||||
const commitHash = output.trim().split("\n")[3];
|
||||
|
||||
if (!commitHash) {
|
||||
throw new Error("Couldn't find commit hash.");
|
||||
}
|
||||
|
||||
const composerLockOldContents = cp.execSync("git show " + commitHash + ":composer.lock").toString();
|
||||
const composerOldContents = cp.execSync("git show " + commitHash + ":composer.json").toString();
|
||||
let composerLockNewContents = cp.execSync("cat " + currentPath + "/composer.lock").toString();
|
||||
let composerNewContents = cp.execSync("cat " + currentPath + "/composer.json").toString();
|
||||
|
||||
composerNewContents = composerNewContents.replace(/(\r\n)/g, '\n');
|
||||
composerLockNewContents = composerLockNewContents.replace(/(\r\n)/g, '\n');
|
||||
|
||||
if (
|
||||
composerLockNewContents === composerLockOldContents &&
|
||||
composerOldContents === composerNewContents
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
const newPackages = JSON.parse(composerLockNewContents).packages;
|
||||
const oldPackages = JSON.parse(composerLockOldContents).packages;
|
||||
|
||||
fs.mkdirSync(tempFolderPath);
|
||||
fs.mkdirSync(tempFolderPath + '/new');
|
||||
|
||||
const vendorPath = tempFolderPath + '/new/vendor/';
|
||||
|
||||
cp.execSync(`cp -r ${currentPath}/dev ${tempFolderPath}/new/dev`);
|
||||
|
||||
fs.writeFileSync(tempFolderPath + '/new/composer.lock', composerLockNewContents);
|
||||
fs.writeFileSync(tempFolderPath + '/new/composer.json', composerNewContents);
|
||||
|
||||
cp.execSync(
|
||||
"composer install --no-dev --ignore-platform-reqs",
|
||||
{
|
||||
cwd: tempFolderPath + "/new",
|
||||
stdio: 'ignore',
|
||||
}
|
||||
);
|
||||
|
||||
fs.mkdirSync(upgradePath + '/vendorFiles');
|
||||
|
||||
cp.execSync("mv " + vendorPath + "/autoload.php " + upgradePath + "/vendorFiles/autoload.php");
|
||||
cp.execSync("mv " + vendorPath + "/composer " + upgradePath + "/vendorFiles/composer");
|
||||
cp.execSync("mv " + vendorPath + "/bin "+ upgradePath + "/vendorFiles/bin");
|
||||
|
||||
const folderList = [];
|
||||
|
||||
for (const item of newPackages) {
|
||||
const name = item.name;
|
||||
|
||||
if (name.indexOf('composer/') === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let isFound = false;
|
||||
let toAdd = false;
|
||||
|
||||
for (const oItem of oldPackages) {
|
||||
if (oItem.name !== name) {
|
||||
continue;
|
||||
}
|
||||
|
||||
isFound = true;
|
||||
|
||||
if (item.version !== oItem.version) {
|
||||
toAdd = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isFound) {
|
||||
toAdd = true;
|
||||
}
|
||||
|
||||
if (toAdd) {
|
||||
const folder = name.split('/')[0];
|
||||
|
||||
if (!~folderList.indexOf(folder)) {
|
||||
folderList.push(folder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const folder of folderList) {
|
||||
this._deleteGitFolderInVendor(vendorPath + '/' + folder);
|
||||
|
||||
if (fs.existsSync(vendorPath + '/'+ folder)) {
|
||||
cp.execSync(
|
||||
'mv ' + vendorPath + '/' + folder + " " + upgradePath + '/vendorFiles/' + folder
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
deleteDirRecursively(tempFolderPath);
|
||||
}
|
||||
|
||||
_processArchive(dto) {
|
||||
const zipPath = dto.zipPath;
|
||||
const upgradePath = dto.upgradePath;
|
||||
const upgradeName = dto.upgradeName;
|
||||
|
||||
return new Promise(resolve => {
|
||||
const zipOutput = fs.createWriteStream(zipPath);
|
||||
|
||||
const archive = archiver('zip');
|
||||
|
||||
archive.on('error', err => {
|
||||
throw err;
|
||||
});
|
||||
|
||||
zipOutput.on('close', () => {
|
||||
console.log("Upgrade package has been built: " + upgradeName + "");
|
||||
|
||||
deleteDirRecursively(upgradePath);
|
||||
|
||||
resolve();
|
||||
});
|
||||
|
||||
archive.directory(upgradePath, false).pipe(zipOutput);
|
||||
archive.finalize();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function deleteDirRecursively(path) {
|
||||
if (fs.existsSync(path) && fs.lstatSync(path).isDirectory()) {
|
||||
fs.readdirSync(path).forEach(file => {
|
||||
const curPath = path + "/" + file;
|
||||
|
||||
if (fs.lstatSync(curPath).isDirectory()) {
|
||||
deleteDirRecursively(curPath);
|
||||
}
|
||||
else {
|
||||
fs.unlinkSync(curPath);
|
||||
}
|
||||
});
|
||||
|
||||
fs.rmdirSync(path);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (fs.existsSync(path) && fs.lstatSync(path).isFile()) {
|
||||
fs.unlinkSync(path);
|
||||
}
|
||||
}
|
||||
|
||||
function execute(command, callback) {
|
||||
exec(command, (error, stdout) => callback(stdout));
|
||||
}
|
||||
|
||||
module.exports = Diff;
|
||||
283
js/lang.js
Normal file
283
js/lang.js
Normal file
@@ -0,0 +1,283 @@
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2026 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
const fs = require('fs');
|
||||
const nodePath = require('path');
|
||||
const PO = require('pofile');
|
||||
const os = require('os');
|
||||
|
||||
/**
|
||||
* Builds language files from a PO file.
|
||||
*/
|
||||
class Lang
|
||||
{
|
||||
constructor (language, poPath, espoPath, onlyModuleName) {
|
||||
this.baseLanguage = 'en_US';
|
||||
this.language = language;
|
||||
this.poPath = poPath;
|
||||
|
||||
this.ignoreList = [
|
||||
'Global.options.language',
|
||||
];
|
||||
|
||||
this.espoPath = espoPath;
|
||||
|
||||
if (this.espoPath.slice(-1) !== '/') {
|
||||
this.espoPath += '/';
|
||||
}
|
||||
|
||||
this.moduleList = ['Crm'];
|
||||
|
||||
if (onlyModuleName) {
|
||||
this.moduleList = [onlyModuleName];
|
||||
}
|
||||
|
||||
const dirNames = this.dirNames = {};
|
||||
|
||||
const coreDir = this.espoPath + 'application/Espo/Resources/i18n/' + this.baseLanguage + '/';
|
||||
|
||||
let dirs = [coreDir];
|
||||
|
||||
dirNames[coreDir] = 'application/Espo/Resources/i18n/' + this.language + '/';
|
||||
|
||||
const installDir = this.espoPath + 'install/core/i18n/' + this.baseLanguage + '/';
|
||||
|
||||
dirs.push(installDir);
|
||||
dirNames[installDir] = 'install/core/i18n/' + this.language + '/';
|
||||
|
||||
const templatesDir = this.espoPath + 'application/Espo/Core/Templates/i18n/' + this.baseLanguage + '/';
|
||||
|
||||
dirs.push(templatesDir);
|
||||
dirNames[templatesDir] = 'application/Espo/Core/Templates/i18n/' + this.language + '/';
|
||||
|
||||
if (onlyModuleName) {
|
||||
dirs = [];
|
||||
}
|
||||
|
||||
this.moduleList.forEach(moduleName => {
|
||||
const path1 = this.espoPath + 'application/Espo/Modules/' + moduleName;
|
||||
const path2 = this.espoPath + 'custom/Espo/Modules/' + moduleName;
|
||||
|
||||
const baseDir = fs.existsSync(path1) ? path1 : path2;
|
||||
|
||||
const dir = baseDir + '/Resources/i18n/' + this.baseLanguage + '/';
|
||||
|
||||
dirs.push(dir);
|
||||
|
||||
dirNames[dir] = fs.existsSync(path1) ?
|
||||
'application/Espo/Modules/' + moduleName + '/Resources/i18n/' + this.language + '/' :
|
||||
'custom/Espo/Modules/' + moduleName + '/Resources/i18n/' + this.language + '/';
|
||||
});
|
||||
|
||||
this.dirs = dirs;
|
||||
|
||||
this.isWin = /^win/.test(os.platform());
|
||||
}
|
||||
|
||||
escape (string) {
|
||||
return string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
|
||||
}
|
||||
|
||||
run () {
|
||||
const translationData = {};
|
||||
const dirs = this.dirs;
|
||||
|
||||
const isWin = this.isWin;
|
||||
const language = this.language;
|
||||
|
||||
PO.load(this.poPath, (err, po) => {
|
||||
if (err) {
|
||||
throw new Error("Could not parse " + this.poPath + ".");
|
||||
}
|
||||
|
||||
po.items.forEach(item => {
|
||||
if (!item.msgctxt) {
|
||||
return;
|
||||
}
|
||||
|
||||
//let key = item.msgctxt + '__' + item.msgid;
|
||||
const file = item.msgctxt.split('.')[0];
|
||||
const path = item.msgctxt.split('.').slice(1);
|
||||
|
||||
const o = {
|
||||
stringOriginal: item.msgid,
|
||||
stringTranslated: item.msgstr[0],
|
||||
context: item.msgctxt,
|
||||
file: file,
|
||||
path: path,
|
||||
};
|
||||
|
||||
translationData[file] = translationData[file] || [];
|
||||
translationData[file].push(o);
|
||||
});
|
||||
|
||||
dirs.forEach(path => {
|
||||
const resDirPath = this.dirNames[path];
|
||||
const resPath = this.espoPath + 'build/' + language + '/' + resDirPath;
|
||||
|
||||
if (!fs.existsSync(resPath)) {
|
||||
let d = '';
|
||||
|
||||
resPath.split('/').forEach(f =>{
|
||||
if (!f) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isWin) {
|
||||
d = nodePath.join(d, f);
|
||||
} else {
|
||||
d += '/' + f;
|
||||
}
|
||||
|
||||
if (!fs.existsSync(d)) {
|
||||
fs.mkdirSync(d);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const list = fs.readdirSync(path);
|
||||
|
||||
list.forEach(fileName => {
|
||||
const filePath = path + fileName;
|
||||
const resFilePath = resPath + '/' + fileName;
|
||||
|
||||
let contents = fs.readFileSync(filePath, 'utf8');
|
||||
|
||||
const fileKey = fileName.split('.')[0];
|
||||
|
||||
const fileObject = JSON.parse(contents);
|
||||
const targetFileObject = {};
|
||||
|
||||
if (!(fileKey in translationData)) {
|
||||
return;
|
||||
}
|
||||
|
||||
translationData[fileKey].forEach(item => {
|
||||
let isArray = false;
|
||||
let isMet = true;
|
||||
let c = fileObject;
|
||||
const path = item.path.slice(0);
|
||||
|
||||
if (
|
||||
this.baseLanguage !== this.language &&
|
||||
~this.ignoreList.indexOf(fileKey + '.' + path.join('.'))
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const i in item.path) {
|
||||
const key = item.path[i];
|
||||
|
||||
if (key in c) {
|
||||
c = c[key];
|
||||
|
||||
if (Array.isArray(c)) {
|
||||
isArray = true;
|
||||
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
isMet = false;
|
||||
}
|
||||
}
|
||||
|
||||
const pathList = [];
|
||||
|
||||
if (isMet) {
|
||||
if (!isArray) {
|
||||
isMet = false;
|
||||
|
||||
for (const k in c) {
|
||||
if (c[k] === item.stringOriginal) {
|
||||
const p = path.slice(0);
|
||||
|
||||
p.push(k);
|
||||
|
||||
pathList.push(p);
|
||||
isMet = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
pathList.push(path);
|
||||
}
|
||||
}
|
||||
|
||||
if (!isMet) {
|
||||
return;
|
||||
}
|
||||
|
||||
let targetValue = item.stringTranslated;
|
||||
|
||||
if (targetValue === '') {
|
||||
return;
|
||||
}
|
||||
else {
|
||||
if (item.stringOriginal === item.stringTranslated) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (isArray) {
|
||||
try {
|
||||
targetValue = JSON.parse('[' + targetValue + ']');
|
||||
} catch (e) {
|
||||
targetValue = null;
|
||||
}
|
||||
}
|
||||
if (targetValue == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
pathList.forEach(path => {
|
||||
let c = targetFileObject;
|
||||
|
||||
path.forEach((pathKey, i) => {
|
||||
if (i < path.length - 1) {
|
||||
c[pathKey] = c[pathKey] || {};
|
||||
c = c[pathKey];
|
||||
} else {
|
||||
c[pathKey] = targetValue;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
contents = JSON.stringify(targetFileObject, null, ' ');
|
||||
|
||||
if (fs.existsSync(resFilePath)) {
|
||||
fs.unlinkSync(resFilePath);
|
||||
}
|
||||
|
||||
fs.writeFileSync(resFilePath, contents);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Lang;
|
||||
60
js/layout-template-bundler.js
Normal file
60
js/layout-template-bundler.js
Normal file
@@ -0,0 +1,60 @@
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2026 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
const fs = require('fs');
|
||||
const {globSync} = require('glob');
|
||||
|
||||
class LayoutTemplateBundler {
|
||||
|
||||
/**
|
||||
* @return {string}
|
||||
*/
|
||||
bundle() {
|
||||
const path = 'client/res/layout-types';
|
||||
|
||||
/** @var {string[]} */
|
||||
const files = globSync(path + '/*.tpl')
|
||||
.map(file => file.replaceAll('\\', '/'));
|
||||
|
||||
const map = {};
|
||||
|
||||
files.forEach(file => {
|
||||
const name = file
|
||||
.substring(path.length + 1)
|
||||
.slice(0, -4);
|
||||
|
||||
map[name] = fs.readFileSync(file, 'utf8');
|
||||
});
|
||||
|
||||
const mapPart = JSON.stringify(map);
|
||||
|
||||
return `\nEspo.layoutTemplates = ${mapPart};\n`;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = LayoutTemplateBundler;
|
||||
227
js/po.js
Normal file
227
js/po.js
Normal file
@@ -0,0 +1,227 @@
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2026 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
/**
|
||||
* Builds a PO file for a specific language or all languages.
|
||||
*/
|
||||
class PO
|
||||
{
|
||||
constructor (espoPath, language, onlyModuleName) {
|
||||
this.espoPath = espoPath;
|
||||
this.onlyModuleName = onlyModuleName;
|
||||
|
||||
this.espoPath = espoPath;
|
||||
if (this.espoPath.substr(-1) !== '/') {
|
||||
this.espoPath += '/';
|
||||
}
|
||||
|
||||
this.moduleList = ['Crm'];
|
||||
|
||||
if (onlyModuleName) {
|
||||
this.moduleList = [onlyModuleName];
|
||||
}
|
||||
|
||||
this.baseLanguage = 'en_US';
|
||||
this.language = language || this.baseLanguage;
|
||||
|
||||
this.outputFileName = 'espocrm-' + this.language;
|
||||
|
||||
if (onlyModuleName) {
|
||||
this.outputFileName += '-' + onlyModuleName;
|
||||
}
|
||||
|
||||
this.outputFileName += '.po';
|
||||
|
||||
let dirs = [
|
||||
this.espoPath + 'application/Espo/Resources/i18n/',
|
||||
this.espoPath + 'install/core/i18n/',
|
||||
this.espoPath + 'application/Espo/Core/Templates/i18n/'
|
||||
];
|
||||
|
||||
if (onlyModuleName) {
|
||||
dirs = [];
|
||||
}
|
||||
|
||||
this.moduleList.forEach(moduleName => {
|
||||
let path1 = this.espoPath + 'application/Espo/Modules/' + moduleName;
|
||||
let path2 = this.espoPath + 'custom/Espo/Modules/' + moduleName;
|
||||
|
||||
let dir = fs.existsSync(path1) ? path1 : path2;
|
||||
|
||||
dirs.push(dir + '/Resources/i18n/');
|
||||
});
|
||||
|
||||
this.dirs = dirs;
|
||||
|
||||
this.poContentHeader = 'msgid ""\n' +
|
||||
'msgstr ""\n' +
|
||||
'"Project-Id-Version: \\n"\n' +
|
||||
'"POT-Creation-Date: \\n"\n' +
|
||||
'"PO-Revision-Date: \\n"\n' +
|
||||
'"Last-Translator: \\n"\n' +
|
||||
'"MIME-Version: 1.0\\n"\n' +
|
||||
'"Content-Type: text/plain; charset=UTF-8\\n"\n' +
|
||||
'"Content-Transfer-Encoding: 8bit\\n"\n' +
|
||||
'"Language: ' + this.language + '\\n"\n\n';
|
||||
}
|
||||
|
||||
runAll () {
|
||||
let pathToLanguage = this.espoPath + '/application/Espo/Resources/i18n/';
|
||||
|
||||
let languageList = [];
|
||||
|
||||
fs.readdirSync(pathToLanguage).forEach(dir => {
|
||||
if (dir.indexOf('_') === 2) {
|
||||
languageList.push(dir);
|
||||
}
|
||||
});
|
||||
|
||||
languageList.forEach(language => {
|
||||
let po = new PO(this.espoPath, language, this.onlyModuleName);
|
||||
|
||||
po.run();
|
||||
});
|
||||
}
|
||||
|
||||
run () {
|
||||
let dirs = this.dirs;
|
||||
let messageData = {};
|
||||
let targetMessageData = {}
|
||||
|
||||
let poContents = this.poContentHeader;
|
||||
|
||||
dirs.forEach(path => {
|
||||
let dirPath = this.getDirPath(path, this.baseLanguage);
|
||||
|
||||
let list = fs.readdirSync(dirPath);
|
||||
|
||||
list.forEach(fileName => {
|
||||
let filePath = this.getDirPath(path, this.baseLanguage) + fileName;
|
||||
|
||||
this.populateMessageDataFromFile(filePath, messageData);
|
||||
|
||||
if (this.language !== this.baseLanguage) {
|
||||
let langFilePath = this.getDirPath(path, this.language) + fileName;
|
||||
|
||||
this.populateMessageDataFromFile(langFilePath, targetMessageData);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
if (this.language === this.baseLanguage) {
|
||||
targetMessageData = messageData;
|
||||
}
|
||||
|
||||
for (let key in messageData) {
|
||||
poContents += 'msgctxt "' + messageData[key].context + '"\n';
|
||||
poContents += 'msgid "' + messageData[key].value + '"\n';
|
||||
|
||||
let translatedValue = (targetMessageData[key] || {}).value || "";
|
||||
|
||||
poContents += 'msgstr "' + translatedValue + '"\n\n';
|
||||
}
|
||||
|
||||
let resFilePath = this.espoPath + 'build/' + this.outputFileName;
|
||||
|
||||
if (fs.existsSync(resFilePath)) {
|
||||
fs.unlinkSync(resFilePath);
|
||||
}
|
||||
|
||||
fs.writeFileSync(resFilePath, poContents);
|
||||
}
|
||||
|
||||
populateMessageDataFromFile (filePath, messageData) {
|
||||
if (!fs.existsSync(filePath)) {
|
||||
return messageData;
|
||||
}
|
||||
|
||||
let data = fs.readFileSync(filePath, 'utf8');
|
||||
|
||||
data = JSON.parse(data);
|
||||
|
||||
let fileName = filePath.split('\/').slice(-1).pop().split('.')[0];
|
||||
|
||||
this.populateMessageData(fileName, data, '', messageData);
|
||||
}
|
||||
|
||||
getDirPath (path, language) {
|
||||
return path + language + '/';
|
||||
}
|
||||
|
||||
populateMessageData (fileName, dataObject, prefix, messageData) {
|
||||
prefix = prefix || '';
|
||||
|
||||
for (let index in dataObject) {
|
||||
if (dataObject[index] === null || dataObject[index] === "") {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (typeof dataObject[index] === 'object' && !Array.isArray(dataObject[index])) {
|
||||
let nextPrefix = prefix + (prefix ? '.' : '') + index;
|
||||
|
||||
this.populateMessageData(fileName, dataObject[index], nextPrefix, messageData);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
let path = fileName + '.' + prefix;
|
||||
let key = path + '.' + index;
|
||||
let value = dataObject[index];
|
||||
|
||||
if (Array.isArray(value)) {
|
||||
value = '"' + value.join('", "') + '"';
|
||||
path = path + '.' + index;
|
||||
}
|
||||
|
||||
messageData[key] = {
|
||||
context: path,
|
||||
value: this.fixString(value)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
replaceAll (string, find, replace) {
|
||||
let escapedRegExp = find.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
|
||||
|
||||
return string.replace(new RegExp(escapedRegExp, 'g'), replace);
|
||||
}
|
||||
|
||||
fixString (savedString) {
|
||||
savedString = this.replaceAll(savedString, "\\", '\\\\');
|
||||
savedString = this.replaceAll(savedString, '"', '\\"');
|
||||
savedString = this.replaceAll(savedString, "\n", '\\n');
|
||||
savedString = this.replaceAll(savedString, "\t", '\\t');
|
||||
|
||||
return savedString;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = PO;
|
||||
66
js/scripts/postinstall-cleanup.js
Normal file
66
js/scripts/postinstall-cleanup.js
Normal file
@@ -0,0 +1,66 @@
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2026 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
function rmDir(path) {
|
||||
if (!fs.existsSync(path)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (fs.rm) {
|
||||
fs.rmSync(path, {recursive: true});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
fs.rmdirSync(path, {recursive: true});
|
||||
}
|
||||
|
||||
function rmFile(path) {
|
||||
if (!fs.existsSync(path)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
fs.unlinkSync(path);
|
||||
}
|
||||
|
||||
|
||||
// Can't be ignored by IntelliJ IDE, resort to removing.
|
||||
rmDir('./node_modules/vis/examples');
|
||||
rmDir('./node_modules/vis/lib');
|
||||
rmDir('./node_modules/vis/docs');
|
||||
|
||||
rmFile('./node_modules/vis/gulpfile.js');
|
||||
rmFile('./node_modules/vis/index.js');
|
||||
rmFile('./node_modules/vis/index-graph3d.js');
|
||||
rmFile('./node_modules/vis/index-network.js');
|
||||
rmFile('./node_modules/vis/index-timeline-graph2d.js');
|
||||
172
js/scripts/prepare-lib-original.js
Normal file
172
js/scripts/prepare-lib-original.js
Normal file
@@ -0,0 +1,172 @@
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2026 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
const fs = require('fs');
|
||||
const cp = require('child_process');
|
||||
const buildUtils = require('../build-utils');
|
||||
|
||||
// @todo Introduce libs-provider.
|
||||
/**
|
||||
* @type {{
|
||||
* src?: string,
|
||||
* dest?: string,
|
||||
* bundle?: boolean,
|
||||
* amdId?: string,
|
||||
* suppressAmd?: boolean,
|
||||
* minify?: boolean,
|
||||
* prepareCommand?: string,
|
||||
* name?: string,
|
||||
* files?: {
|
||||
* src: string,
|
||||
* dest: string,
|
||||
* }[],
|
||||
* }[]}
|
||||
*/
|
||||
const libs = require('./../../frontend/libs.json');
|
||||
|
||||
const bundleConfig = require('../../frontend/bundle-config.json');
|
||||
|
||||
const libDir = './client/lib';
|
||||
const originalLibDir = './client/lib/original';
|
||||
const libCrmDir = './client/modules/crm/lib';
|
||||
const originalLibCrmDir = './client/modules/crm/lib/original';
|
||||
|
||||
[libDir, originalLibDir, libCrmDir, originalLibCrmDir]
|
||||
.filter(path => !fs.existsSync(path))
|
||||
.forEach(path => fs.mkdirSync(path));
|
||||
|
||||
const bundleFiles = Object.keys(bundleConfig.chunks)
|
||||
.map(name => {
|
||||
const namePart = 'espo-' + name;
|
||||
|
||||
return namePart + '.js';
|
||||
});
|
||||
|
||||
fs.readdirSync(originalLibDir)
|
||||
.filter(file => !bundleFiles.includes(file))
|
||||
.forEach(file => fs.unlinkSync(originalLibDir + '/' + file));
|
||||
|
||||
fs.readdirSync(originalLibCrmDir)
|
||||
.forEach(file => fs.unlinkSync(originalLibCrmDir + '/' + file));
|
||||
|
||||
libs.filter(it => it.prepareCommand)
|
||||
.forEach(it => {
|
||||
cp.execSync(it.prepareCommand, {stdio: ['ignore', 'ignore', 'pipe']});
|
||||
});
|
||||
|
||||
const stripSourceMappingUrl = path => {
|
||||
/** @var {string} */
|
||||
const originalContents = fs.readFileSync(path, {encoding: 'utf-8'});
|
||||
|
||||
const re = /^\/\/# sourceMappingURL.*/gm;
|
||||
|
||||
if (!originalContents.match(re)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const contents = originalContents.replaceAll(re, '');
|
||||
|
||||
fs.writeFileSync(path, contents, {encoding: 'utf-8'});
|
||||
}
|
||||
|
||||
const addLoadingSubject = (path, subject) => {
|
||||
/** @var {string} */
|
||||
let contents = fs.readFileSync(path, {encoding: 'utf-8'});
|
||||
|
||||
contents =
|
||||
`Espo.loader.setContextId('${subject}');\n` +
|
||||
contents + '\n' +
|
||||
`Espo.loader.setContextId(null);\n`;
|
||||
|
||||
fs.writeFileSync(path, contents, {encoding: 'utf-8'});
|
||||
}
|
||||
|
||||
const addSuppressAmd = path => {
|
||||
/** @var {string} */
|
||||
let contents = fs.readFileSync(path, {encoding: 'utf-8'});
|
||||
|
||||
contents =
|
||||
`var _previousDefineAmd = define.amd; define.amd = false;\n` +
|
||||
contents + '\n' +
|
||||
`define.amd = _previousDefineAmd;\n`;
|
||||
|
||||
fs.writeFileSync(path, contents, {encoding: 'utf-8'});
|
||||
}
|
||||
|
||||
const amdIdMap = {};
|
||||
const suppressAmdMap = {};
|
||||
|
||||
libs.forEach(item => {
|
||||
if (!item.amdId || !item.bundle || item.files) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (item.suppressAmd) {
|
||||
suppressAmdMap[item.src] = true;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
amdIdMap[item.src] = 'lib!' + item.amdId;
|
||||
});
|
||||
|
||||
buildUtils.getBundleLibList(libs, true).forEach(item => {
|
||||
const src = item.src;
|
||||
|
||||
const dest = originalLibDir + '/' + item.file;
|
||||
|
||||
fs.copyFileSync(src, dest);
|
||||
stripSourceMappingUrl(dest);
|
||||
|
||||
if (suppressAmdMap[src]) {
|
||||
addSuppressAmd(dest);
|
||||
}
|
||||
|
||||
const key = amdIdMap[src];
|
||||
|
||||
if (key) {
|
||||
addLoadingSubject(dest, key);
|
||||
}
|
||||
});
|
||||
|
||||
buildUtils.getCopyLibDataList(libs)
|
||||
.filter(item => item.minify)
|
||||
.forEach(item => {
|
||||
fs.copyFileSync(item.src, item.originalDest);
|
||||
stripSourceMappingUrl(item.originalDest);
|
||||
|
||||
if (suppressAmdMap[item.src]) {
|
||||
addSuppressAmd(item.originalDest);
|
||||
}
|
||||
|
||||
const key = amdIdMap[item.src];
|
||||
|
||||
if (key) {
|
||||
addLoadingSubject(item.originalDest, key);
|
||||
}
|
||||
});
|
||||
69
js/scripts/prepare-lib.js
Normal file
69
js/scripts/prepare-lib.js
Normal file
@@ -0,0 +1,69 @@
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2026 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
const fs = require('fs');
|
||||
const buildUtils = require('../build-utils');
|
||||
|
||||
/**
|
||||
* @type {{
|
||||
* src?: string,
|
||||
* dest?: string,
|
||||
* bundle?: boolean,
|
||||
* amdId?: string,
|
||||
* suppressAmd?: boolean,
|
||||
* minify?: boolean,
|
||||
* prepareCommand?: string,
|
||||
* name?: string,
|
||||
* files?: {
|
||||
* src: string,
|
||||
* dest: string,
|
||||
* }[],
|
||||
* }[]}
|
||||
*/
|
||||
const libs = require('./../../frontend/libs.json');
|
||||
|
||||
const stripSourceMappingUrl = path => {
|
||||
/** @var {string} */
|
||||
const originalContents = fs.readFileSync(path, {encoding: 'utf-8'});
|
||||
|
||||
const re = /\/\/# sourceMappingURL.*/g;
|
||||
|
||||
if (!originalContents.match(re)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const contents = originalContents.replaceAll(re, '');
|
||||
|
||||
fs.writeFileSync(path, contents, {encoding: 'utf-8'});
|
||||
};
|
||||
|
||||
buildUtils.getCopyLibDataList(libs)
|
||||
.filter(item => !item.minify)
|
||||
.forEach(item => {
|
||||
stripSourceMappingUrl(item.dest);
|
||||
});
|
||||
59
js/transpile.js
Normal file
59
js/transpile.js
Normal file
@@ -0,0 +1,59 @@
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2026 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
const {Transpiler} = require('espo-frontend-build-tools');
|
||||
|
||||
let file;
|
||||
|
||||
let fIndex = process.argv.findIndex(item => item === '-f');
|
||||
|
||||
if (fIndex > 0) {
|
||||
file = process.argv.at(fIndex + 1);
|
||||
|
||||
if (!file) {
|
||||
throw new Error(`No file specified.`);
|
||||
}
|
||||
}
|
||||
|
||||
const transpiler1 = new Transpiler({
|
||||
file: file,
|
||||
});
|
||||
|
||||
const transpiler2 = new Transpiler({
|
||||
mod: 'crm',
|
||||
path: 'client/modules/crm',
|
||||
file: file,
|
||||
});
|
||||
|
||||
const result1 = transpiler1.process();
|
||||
const result2 = transpiler2.process();
|
||||
|
||||
let count = result1.transpiled.length + result2.transpiled.length;
|
||||
let copiedCount = result1.copied.length + result2.copied.length;
|
||||
|
||||
console.log(`\n transpiled: ${count}, copied: ${copiedCount}`)
|
||||
Reference in New Issue
Block a user