I need to change all the files in the “templates” folder (according to ENV variable I passed) to the same files into sub-folder.
I have a lot of different themes, each theme has differences in markup this why I decided to use separate subfolder according to theme name. A theme name I’m passing before the build (e.g. THEME=theme1 && ember serve).
Is there a proper way to do this? I see the solution as create a node script which will change all the files in “template” copying them from a subfolder, but I do not like it.
Hi @trigger, welcome! What you want is a bit of broccoli code in your ember-cli-build.js. Ember uses broccoli as a major part of the build system to reduce your app from a tree of files into the final built assets via a series of transforms. Your use case is very simple, just you want to take some input templates and put them into a specific output location based on a flag.
There was actually a thread with a very similar question recently that might be worth checking out, as well as the docs for broccoli.js.
So you’re still ending up with a node script but it’s the “official” way to do stuff like this and should be much easier with broccoli than a lot of manual file management.
1 Like
Hi @dknutsen Many thanks for the link, this is exactly what I’m looking for.
What would be the changes if I need to replace everything except two folders? (the folders “components” and “services” in my case), thanks in advance.
app.options.trees.app = mergeTrees([
// copy "components" and "services" normally
new Funnel(appTree, { include: ["components", "services"] }), // srcDir and destDir are implicitly "."
// copy everything from some alternate directory
new Funnel(appTree, { srcDir: 'alternate-stuff' }) // destDir is implicitly "."
]);
Not sure, really depends on how your files are set up, but this is a rough guess.
1 Like