UNPKG

@arc-fusion/cli

Version:

CLI for running Arc Fusion on your local machine

54 lines (48 loc) 1.72 kB
const fs = require('fs') const path = require('path') const { logMessage, TYPE_MESSAGE } = require('./logMessage') const { INFO } = TYPE_MESSAGE /** * Get the size of a file or directory. * * @param {string} filepath The path to the file or directory * @returns {number} */ function sizeSync (filepath) { try { const stat = fs.statSync(filepath) if (stat.isFile()) { return stat.size } else if (stat.isDirectory()) { return fs.readdirSync(filepath).reduce((a, e) => a + sizeSync(path.join(filepath, e)), 0) } else { return 4096 // can't take size of a stream/symlink/socket/etc, so return 1 block size } } catch (e) { // If the directory or file doesn't exist, return 0 bytes to handle missing bundle folders. return 0 } } const verifyBundleSize = () => { try { const artifactSize = sizeSync('.fusion/verify') const sourceCodeSize = sizeSync('./components') + sizeSync('./content') + sizeSync('./environment') + sizeSync('./properties') + sizeSync('./resources') + sizeSync('./scripts') const bundleSize = artifactSize + sourceCodeSize const bundleSizeInMB = bundleSize / (1024000) if (bundleSizeInMB >= 200) { logMessage(INFO, `WARNING: Your bundle source code is ${Math.round(bundleSizeInMB)}MB with dependencies and may not successfully deploy. [https://arcxp.com/go/fobsz] `) } else if (bundleSizeInMB >= 150) { logMessage(INFO, `WARNING: Your bundle source code is ${Math.round(bundleSizeInMB)}MB with dependencies. [https://arcxp.com/go/fobsz]`) } } catch (error) { console.error('Please run fusion verify from your project root.') } } module.exports = { verifyBundleSize }