{"library":"rollup-plugin-app-utils","title":"Rollup Plugin for Application Utilities","description":"The `rollup-plugin-app-utils` package provides a collection of common build utilities designed for Rollup-based projects. Currently stable at version 1.0.6, it does not specify a strict release cadence but appears to be a mature 1.x release. Its core functionalities include an i18n bundler capable of synchronizing translation keys across multiple locale files using a 'back-filling' mechanism, asset copying, dynamic directory preparation and cleanup, and HTML content injection. A key differentiator is its consolidation of these diverse utilities under a single plugin, with the i18n bundler offering intelligent key management. Developers should be aware that several of its file system operations, such as `copyAssets` and `emptyDirectories`, are synchronous, which can impact build performance on very large projects. The plugin is primarily consumed in `rollup.config.js` files, typically within an ESM context.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install rollup-plugin-app-utils"],"cli":null},"imports":["import Utils from 'rollup-plugin-app-utils'","import translations from 'i18n.translations'","const Utils = require('rollup-plugin-app-utils')"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import Utils from 'rollup-plugin-app-utils';\nimport path from 'path';\nimport fs from 'fs';\n\n// --- Setup: Create a temporary project structure for the demo ---\nconst projectRoot = path.resolve(__dirname, 'temp-rollup-project');\nconst localesDir = path.join(projectRoot, 'locales');\nconst outputDir = path.join(projectRoot, 'dist');\nconst srcDir = path.join(projectRoot, 'src');\n\n// Ensure a clean slate and create necessary directories\nUtils.emptyDirectories([projectRoot]); // Clean up previous runs\nfs.mkdirSync(path.join(localesDir, 'en'), { recursive: true });\nfs.mkdirSync(path.join(localesDir, 'es'), { recursive: true });\nfs.mkdirSync(srcDir, { recursive: true });\n\n// Create mock locale files\nfs.writeFileSync(path.join(localesDir, 'en', 'common.json'), JSON.stringify({\n  \"hello\": \"Hello\",\n  \"goodbye\": \"Goodbye from EN\",\n  \"greeting\": \"Welcome\"\n}, null, 2));\nfs.writeFileSync(path.join(localesDir, 'es', 'common.json'), JSON.stringify({\n  \"hello\": \"Hola\",\n  \"spanish_only\": \"Solo español\"\n}, null, 2)); // 'goodbye' and 'greeting' are missing here, will be back-filled\n\n// Create a mock source file that imports translations\nfs.writeFileSync(path.join(srcDir, 'main.js'), `\nimport translations from 'i18n.translations'; // Resolved by the plugin\n\nconsole.log('EN Hello:', translations.en.common.hello);\nconsole.log('ES Hello:', translations.es.common.hello);\nconsole.log('ES Goodbye (should be backfilled from EN):', translations.es.common.goodbye);\nconsole.log('ES Greeting (should be backfilled from EN):', translations.es.common.greeting);\nconsole.log('ES Spanish Only (should be removed by backfilling):', translations.es.common.spanish_only); // This key should be removed from ES as it's not in EN\n`);\n\n// --- Rollup Configuration ---\nexport default {\n  input: path.join(srcDir, 'main.js'),\n  output: {\n    dir: outputDir,\n    format: 'es',\n    entryFileNames: 'bundle.js',\n  },\n  plugins: [\n    // Clean the output directory before starting the build\n    Utils.emptyDirectories([outputDir]), \n    // Process and bundle i18n strings, performing back-filling\n    Utils.i18nBundler({\n      target: localesDir,\n      baseLanguage: 'en',\n      skipBackFilling: false, // Ensure back-filling happens (add missing, remove orphaned keys)\n      transformer: (lang, data) => data, // Simple passthrough transformer\n    })\n  ]\n};\n\n// To run this example:\n// 1. Save the above code as 'rollup.config.js' in an empty directory.\n// 2. Run 'npm install --save-dev rollup rollup-plugin-app-utils'.\n// 3. Execute 'npx rollup -c'.\n// 4. Inspect the 'temp-rollup-project/dist/bundle.js' and 'temp-rollup-project/locales' for processed output.\n","lang":"typescript","description":"This quickstart demonstrates how to configure `rollup-plugin-app-utils` in a `rollup.config.js` to use `emptyDirectories` for cleanup and `i18nBundler` for processing and back-filling internationalization strings. It sets up mock locale files to showcase the automatic synchronization of translation keys across languages.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}