Skip to content

Commit

Permalink
Merge pull request #1368 from phndiaye/public-tree-copy
Browse files Browse the repository at this point in the history
Add support for keeping public assets and ember-addon.public-assets meta in sync
  • Loading branch information
ef4 authored Feb 28, 2023
2 parents 565e9e5 + e4ee19d commit 01575a4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
36 changes: 36 additions & 0 deletions packages/addon-dev/src/rollup-public-assets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { readJsonSync, writeJsonSync } from 'fs-extra';
import walkSync from 'walk-sync';
import type { Plugin } from 'rollup';

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(path, {
directories: false,
globs: includeGlobPatterns,
ignore: excludedGlobPatterns,
});
const publicAssets: Record<string, string> = filenames.reduce(
(acc: Record<string, string>, v): Record<string, string> => {
acc[`./${path}/${v}`] = ['/', pkg.name, '/', path, '/', v].join('');
return acc;
},
{}
);

pkg['ember-addon'] = Object.assign({}, pkg['ember-addon'], {
'public-assets': publicAssets,
});

writeJsonSync('package.json', pkg, { spaces: 2 });
},
};
}
5 changes: 5 additions & 0 deletions packages/addon-dev/src/rollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 publicAssets } from './rollup-public-assets';
import type { Plugin } from 'rollup';

export class Addon {
Expand Down Expand Up @@ -83,4 +84,8 @@ export class Addon {
dependencies() {
return dependencies();
}

publicAssets(path: string, opts: { include: string[]; exclude: string[] }) {
return publicAssets(path, opts);
}
}

0 comments on commit 01575a4

Please sign in to comment.