From 5abdb2339d7c7c25204b70ac3d531deb1aa071bf Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Fri, 10 Nov 2023 16:59:41 +0200 Subject: [PATCH] cs --- Gruntfile.js | 59 +++++++++++++++--------------- js/build-utils.js | 14 +++---- js/scripts/prepare-lib-original.js | 20 +++++----- js/scripts/prepare-lib.js | 10 ++--- 4 files changed, 51 insertions(+), 52 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 3ed3543cf3..661609b686 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -45,23 +45,23 @@ module.exports = grunt => { const originalLibDir = 'client/lib/original'; - let libsBundleFileList = [ + const libsBundleFileList = [ 'client/src/namespace.js', 'client/src/loader.js', ...buildUtils.getPreparedBundleLibList(libs), ]; - let bundleFileMap = {'client/lib/espo.js': libsBundleFileList}; + const bundleFileMap = {'client/lib/espo.js': libsBundleFileList}; - for (let name in bundleConfig.chunks) { - let namePart = 'espo-' + name; + for (const name in bundleConfig.chunks) { + const namePart = 'espo-' + name; bundleFileMap[`client/lib/${namePart}.js`] = originalLibDir + `/${namePart}.js` } - let copyJsFileList = buildUtils.getCopyLibDataList(libs); + const copyJsFileList = buildUtils.getCopyLibDataList(libs); - let minifyLibFileList = copyJsFileList + const minifyLibFileList = copyJsFileList .filter(item => item.minify) .map(item => { return { @@ -70,21 +70,21 @@ module.exports = grunt => { }; }); - let currentPath = path.dirname(fs.realpathSync(__filename)); + const currentPath = path.dirname(fs.realpathSync(__filename)); - let themeList = []; + const themeList = []; fs.readdirSync('application/Espo/Resources/metadata/themes').forEach(file => { themeList.push(file.substring(0, file.length - 5)); }); - let cssminFilesData = {}; - let lessData = {}; + const cssminFilesData = {}; + const lessData = {}; themeList.forEach(theme => { - let name = buildUtils.camelCaseToHyphen(theme); + const name = buildUtils.camelCaseToHyphen(theme); - let files = {}; + const files = {}; files['client/css/espo/'+name+'.css'] = 'frontend/less/'+name+'/main.less'; files['client/css/espo/'+name+'-iframe.css'] = 'frontend/less/'+name+'/iframe/main.less'; @@ -273,20 +273,20 @@ module.exports = grunt => { fs.mkdirSync(originalLibDir); } - let file = originalLibDir + `/${name}.js`; + const file = originalLibDir + `/${name}.js`; fs.writeFileSync(file, contents, 'utf8'); }; grunt.registerTask('bundle', () => { - let bundler = new Bundler(bundleConfig, libs); + const bundler = new Bundler(bundleConfig, libs); - let result = bundler.bundle(); + const result = bundler.bundle(); - for (let name in result) { + for (const name in result) { let contents = result[name]; - let key = 'espo-' + name; + const key = 'espo-' + name; if (name === 'main') { contents += '\n' + (new LayoutTypeBundler()).bundle(); @@ -297,7 +297,7 @@ module.exports = grunt => { }); grunt.registerTask('bundle-templates', () => { - let templateBundler = new TemplateBundler({ + const templateBundler = new TemplateBundler({ dirs: [ 'client/res/templates', 'client/modules/crm/res/templates', @@ -328,9 +328,9 @@ module.exports = grunt => { }); grunt.registerTask('chmod-multiple', () => { - let dirPath = 'build/EspoCRM-' + pkg.version; + const dirPath = 'build/EspoCRM-' + pkg.version; - let fileList = [ + const fileList = [ { name: '*.php', }, @@ -363,7 +363,7 @@ module.exports = grunt => { }, ]; - let dirReadableList = [ + const dirReadableList = [ 'public/install', 'public/portal', 'public/api', @@ -372,7 +372,7 @@ module.exports = grunt => { '.', ]; - let dirWritableList = [ + const dirWritableList = [ 'data', 'custom', 'custom/Espo', @@ -383,8 +383,8 @@ module.exports = grunt => { ]; fileList.forEach(item => { - let path = item.folder || '.'; - let name = item.name; + const path = item.folder || '.'; + const name = item.name; cp.execSync( `find ${path} -type f -iname "${name}" -exec chmod 644 {} +`, @@ -447,23 +447,22 @@ module.exports = grunt => { grunt.registerTask('zip', function () { // Don't change to arrow-function. const archiver = require('archiver'); - let resolve = this.async(); + const resolve = this.async(); - let folder = 'EspoCRM-' + pkg.version; - - let zipPath = 'build/' + folder +'.zip'; + const folder = 'EspoCRM-' + pkg.version; + const zipPath = 'build/' + folder + '.zip'; if (fs.existsSync(zipPath)) { fs.unlinkSync(zipPath); } - let archive = archiver('zip'); + const archive = archiver('zip'); archive.on('error', err => { grunt.fail.warn(err); }); - let zipOutput = fs.createWriteStream(zipPath); + const zipOutput = fs.createWriteStream(zipPath); zipOutput.on('close', () => { console.log("EspoCRM package has been built."); diff --git a/js/build-utils.js b/js/build-utils.js index d53364993a..72bc6fb1e6 100644 --- a/js/build-utils.js +++ b/js/build-utils.js @@ -26,9 +26,9 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -let BuildUtils = { +const BuildUtils = { getBundleLibList: function(libs) { - let list = []; + const list = []; libs.forEach(item => { if (!item.bundle) { @@ -57,7 +57,7 @@ let BuildUtils = { }, destToOriginalDest: function (dest) { - let path = dest.split('/'); + const path = dest.split('/'); return path.slice(0, -1) .concat('original') @@ -75,19 +75,19 @@ let BuildUtils = { * }[]} */ getCopyLibDataList: function (libs) { - let list = []; + const list = []; /** * @param {Object} item * @return {string} */ - let getItemDest = item => item.dest || 'client/lib/' + item.src.split('/').pop(); + const getItemDest = item => item.dest || 'client/lib/' + item.src.split('/').pop(); /** * @param {Object} item * @return {string} */ - let getItemOriginalDest = item => { + const getItemOriginalDest = item => { return BuildUtils.destToOriginalDest( getItemDest(item) ); @@ -98,7 +98,7 @@ let BuildUtils = { return; } - let minify = !!item.minify; + const minify = !!item.minify; if (item.files) { item.files.forEach(item => { diff --git a/js/scripts/prepare-lib-original.js b/js/scripts/prepare-lib-original.js index 9d32b5cbca..f88cf6d257 100644 --- a/js/scripts/prepare-lib-original.js +++ b/js/scripts/prepare-lib-original.js @@ -41,9 +41,9 @@ const originalLibCrmDir = './client/modules/crm/lib/original'; .filter(path => !fs.existsSync(path)) .forEach(path => fs.mkdirSync(path)); -let bundleFiles = Object.keys(bundleConfig.chunks) +const bundleFiles = Object.keys(bundleConfig.chunks) .map(name => { - let namePart = 'espo-' + name; + const namePart = 'espo-' + name; return namePart + '.js'; }); @@ -57,15 +57,15 @@ fs.readdirSync(originalLibCrmDir) const stripSourceMappingUrl = path => { /** @var {string} */ - let originalContents = fs.readFileSync(path, {encoding: 'utf-8'}); + const originalContents = fs.readFileSync(path, {encoding: 'utf-8'}); - let re = /^\/\/# sourceMappingURL.*/gm; + const re = /^\/\/# sourceMappingURL.*/gm; if (!originalContents.match(re)) { return; } - let contents = originalContents.replaceAll(re, ''); + const contents = originalContents.replaceAll(re, ''); fs.writeFileSync(path, contents, {encoding: 'utf-8'}); } @@ -97,8 +97,8 @@ const addSuppressAmd = path => { /** @var {string[]} */ const libSrcList = buildUtils.getBundleLibList(libs); -let amdIdMap = {}; -let suppressAmdMap = {}; +const amdIdMap = {}; +const suppressAmdMap = {}; libs.forEach(item => { if (!item.amdId || !item.bundle || item.files) { @@ -115,7 +115,7 @@ libs.forEach(item => { }); libSrcList.forEach(src => { - let dest = originalLibDir + '/' + src.split('/').slice(-1); + const dest = originalLibDir + '/' + src.split('/').slice(-1); fs.copyFileSync(src, dest); stripSourceMappingUrl(dest); @@ -124,7 +124,7 @@ libSrcList.forEach(src => { addSuppressAmd(dest); } - let key = amdIdMap[src]; + const key = amdIdMap[src]; if (key) { addLoadingSubject(dest, key); @@ -141,7 +141,7 @@ buildUtils.getCopyLibDataList(libs) addSuppressAmd(item.originalDest); } - let key = amdIdMap[item.src]; + const key = amdIdMap[item.src]; if (key) { addLoadingSubject(item.originalDest, key); diff --git a/js/scripts/prepare-lib.js b/js/scripts/prepare-lib.js index f28be5b67a..5acb15a090 100644 --- a/js/scripts/prepare-lib.js +++ b/js/scripts/prepare-lib.js @@ -31,20 +31,20 @@ const buildUtils = require('../build-utils'); const libs = require('./../../frontend/libs.json'); -let stripSourceMappingUrl = path => { +const stripSourceMappingUrl = path => { /** @var {string} */ - let originalContents = fs.readFileSync(path, {encoding: 'utf-8'}); + const originalContents = fs.readFileSync(path, {encoding: 'utf-8'}); - let re = /\/\/# sourceMappingURL.*/g; + const re = /\/\/# sourceMappingURL.*/g; if (!originalContents.match(re)) { return; } - let contents = originalContents.replaceAll(re, ''); + const contents = originalContents.replaceAll(re, ''); fs.writeFileSync(path, contents, {encoding: 'utf-8'}); -} +}; buildUtils.getCopyLibDataList(libs) .filter(item => !item.minify)