Server IP : 80.87.202.40 / Your IP : 216.73.216.169 Web Server : Apache System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64 User : bitrix ( 600) PHP Version : 8.2.27 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/bitrix/ext_www/rospirotorg.ru/bitrix/js/ui/linkify/.build-plugins/web-to-mobile/ |
Upload File : |
const fs = require('fs'); const path = require('path'); const fetchDependencies = require('./fetch-dependencies'); const makeDepsPhpContent = require('./make-deps-php-content'); const getExtensionsPath = require('./get-extensions-path'); /** * @param {{ * targetExtension: string, * replacements: Array<Array<pattern, replacement>>, * banner?: string, * }} options */ module.exports = function webToMobilePlugin(options) { const extensionDirectoryPath = path.join( getExtensionsPath(), ...options.targetExtension.split('/'), ); const extensionJsPath = path.join( extensionDirectoryPath, 'extension.js', ); return { name: 'web-to-mobile-plugin', generateBundle(bundle) { if (!fs.existsSync(extensionJsPath)) { fs.mkdirSync(extensionDirectoryPath, { recursive: true }); } let bundleContent = fs.readFileSync(bundle.file, 'utf8'); if (Array.isArray(options.replacements)) { options.replacements.forEach(([pattern, replacement]) => { bundleContent = bundleContent.replace(pattern, replacement); }); } const dependencies = fetchDependencies(bundleContent); if (dependencies.length > 0) { const depsPhpContent = makeDepsPhpContent(dependencies); const depsPhpPath = path.join(extensionDirectoryPath, 'deps.php'); fs.writeFileSync(depsPhpPath, depsPhpContent, 'utf8'); } if (typeof options.banner === 'string') { bundleContent = `${options.banner}\n${bundleContent}`; } fs.writeFileSync(extensionJsPath, bundleContent, 'utf8'); } } }