From 6813c5fef8f1c7cf04be1324a15d1a9a63457980 Mon Sep 17 00:00:00 2001 From: Philippe Ndiaye Date: Sat, 25 Feb 2023 21:11:48 +0100 Subject: [PATCH 1/4] 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); + } } From fc94ad2dbc55de6f37b41095c46a3bafa8904db9 Mon Sep 17 00:00:00 2001 From: Philippe Ndiaye Date: Sat, 25 Feb 2023 22:08:50 +0100 Subject: [PATCH 2/4] nit: declare untouched variable straight as const --- packages/addon-dev/src/rollup-public-reexports.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/addon-dev/src/rollup-public-reexports.ts b/packages/addon-dev/src/rollup-public-reexports.ts index 8f4f9f09c..e91e76173 100644 --- a/packages/addon-dev/src/rollup-public-reexports.ts +++ b/packages/addon-dev/src/rollup-public-reexports.ts @@ -7,13 +7,10 @@ export default function publicAssets(opts: { exclude: string[] }): Plugin { name: 'public-assets-bundler', generateBundle() { let pkg = readJsonSync('package.json'); - let filenames; - - filenames = walkSync('public', { + const filenames = walkSync('public', { directories: false, - ignore: opts.exclude || [], + ignore: opts?.exclude || [], }); - const publicAssets: Record = filenames.reduce( (acc: Record, v): Record => { acc['./public/' + v] = ['/', pkg.name, '/', v].join(''); From 5db5ee708c84fe4d83954e4d9204b05c383a868f Mon Sep 17 00:00:00 2001 From: Philippe Ndiaye Date: Mon, 27 Feb 2023 21:03:53 +0100 Subject: [PATCH 3/4] Add support for include glob pattern option & allow the asset path to passed down instead of forcing it to public --- ...ublic-reexports.ts => rollup-public-assets.ts} | 15 +++++++++++---- packages/addon-dev/src/rollup.ts | 6 +++--- 2 files changed, 14 insertions(+), 7 deletions(-) rename packages/addon-dev/src/{rollup-public-reexports.ts => rollup-public-assets.ts} (63%) diff --git a/packages/addon-dev/src/rollup-public-reexports.ts b/packages/addon-dev/src/rollup-public-assets.ts similarity index 63% rename from packages/addon-dev/src/rollup-public-reexports.ts rename to packages/addon-dev/src/rollup-public-assets.ts index e91e76173..6856624d1 100644 --- a/packages/addon-dev/src/rollup-public-reexports.ts +++ b/packages/addon-dev/src/rollup-public-assets.ts @@ -2,18 +2,25 @@ import { readJsonSync, writeJsonSync } from 'fs-extra'; import walkSync from 'walk-sync'; import type { Plugin } from 'rollup'; -export default function publicAssets(opts: { exclude: string[] }): Plugin { +export default function publicAssets( + path: string, + opts: { include: string[]; exclude: string[] } +): Plugin { + const includeGlobPatterns = opts?.include; + const excludedGlobPatterns = opts?.exclude || []; + return { name: 'public-assets-bundler', generateBundle() { let pkg = readJsonSync('package.json'); - const filenames = walkSync('public', { + const filenames = walkSync(path, { directories: false, - ignore: opts?.exclude || [], + globs: includeGlobPatterns, + ignore: excludedGlobPatterns, }); const publicAssets: Record = filenames.reduce( (acc: Record, v): Record => { - acc['./public/' + v] = ['/', pkg.name, '/', v].join(''); + acc[`./${path}/${v}`] = ['/', pkg.name, '/', path, '/', v].join(''); return acc; }, {} diff --git a/packages/addon-dev/src/rollup.ts b/packages/addon-dev/src/rollup.ts index 6be2e0239..89a4121ab 100644 --- a/packages/addon-dev/src/rollup.ts +++ b/packages/addon-dev/src/rollup.ts @@ -4,7 +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 { default as publicAssets } from './rollup-public-assets'; import type { Plugin } from 'rollup'; export class Addon { @@ -85,7 +85,7 @@ export class Addon { return dependencies(); } - publicAssets(opts: { exclude: string[] }) { - return publicReexports(opts); + publicAssets(path: string, opts: { include: string[], exclude: string[] }) { + return publicAssets(path, opts); } } From e4ee19d6b301687aac06b85db5ca946101e00416 Mon Sep 17 00:00:00 2001 From: Philippe Ndiaye Date: Tue, 28 Feb 2023 10:31:37 +0100 Subject: [PATCH 4/4] Fix prettier linting issue --- packages/addon-dev/src/rollup.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/addon-dev/src/rollup.ts b/packages/addon-dev/src/rollup.ts index 89a4121ab..5c49149ce 100644 --- a/packages/addon-dev/src/rollup.ts +++ b/packages/addon-dev/src/rollup.ts @@ -85,7 +85,7 @@ export class Addon { return dependencies(); } - publicAssets(path: string, opts: { include: string[], exclude: string[] }) { + publicAssets(path: string, opts: { include: string[]; exclude: string[] }) { return publicAssets(path, opts); } }