From 6813c5fef8f1c7cf04be1324a15d1a9a63457980 Mon Sep 17 00:00:00 2001 From: Philippe Ndiaye Date: Sat, 25 Feb 2023 21:11:48 +0100 Subject: [PATCH] Add support for copying the public assets all at once. --- .../addon-dev/src/rollup-public-reexports.ts | 32 +++++++++++++++++++ packages/addon-dev/src/rollup.ts | 5 +++ 2 files changed, 37 insertions(+) create mode 100644 packages/addon-dev/src/rollup-public-reexports.ts diff --git a/packages/addon-dev/src/rollup-public-reexports.ts b/packages/addon-dev/src/rollup-public-reexports.ts new file mode 100644 index 000000000..8f4f9f09c --- /dev/null +++ b/packages/addon-dev/src/rollup-public-reexports.ts @@ -0,0 +1,32 @@ +import { readJsonSync, writeJsonSync } from 'fs-extra'; +import walkSync from 'walk-sync'; +import type { Plugin } from 'rollup'; + +export default function publicAssets(opts: { exclude: string[] }): Plugin { + return { + name: 'public-assets-bundler', + generateBundle() { + let pkg = readJsonSync('package.json'); + let filenames; + + filenames = walkSync('public', { + directories: false, + ignore: opts.exclude || [], + }); + + const publicAssets: Record = filenames.reduce( + (acc: Record, v): Record => { + acc['./public/' + v] = ['/', pkg.name, '/', v].join(''); + return acc; + }, + {} + ); + + pkg['ember-addon'] = Object.assign({}, pkg['ember-addon'], { + 'public-assets': publicAssets, + }); + + writeJsonSync('package.json', pkg, { spaces: 2 }); + }, + }; +} diff --git a/packages/addon-dev/src/rollup.ts b/packages/addon-dev/src/rollup.ts index 381e69e95..6be2e0239 100644 --- a/packages/addon-dev/src/rollup.ts +++ b/packages/addon-dev/src/rollup.ts @@ -4,6 +4,7 @@ import { default as appReexports } from './rollup-app-reexports'; import { default as clean } from 'rollup-plugin-delete'; import { default as keepAssets } from './rollup-keep-assets'; import { default as dependencies } from './rollup-addon-dependencies'; +import { default as publicReexports } from './rollup-public-reexports'; import type { Plugin } from 'rollup'; export class Addon { @@ -83,4 +84,8 @@ export class Addon { dependencies() { return dependencies(); } + + publicAssets(opts: { exclude: string[] }) { + return publicReexports(opts); + } }