Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best way to find all assets in a meteor application?

Tags:

meteor

I know it is possible to just read the program.json file, which lists all assets: https://github.com/meteor/meteor/issues/1328#issuecomment-22913769

But this sort of feels wrong, and I couldn't find out whether this will be supported going forward. The documentation on assets itself is still a little sparse in this regard (http://docs.meteor.com/#assets).

Is there a best practice on how to list all assets?

like image 349
Christian Fritz Avatar asked Oct 20 '22 20:10

Christian Fritz


1 Answers

I don't know if this is a best practice, but I got most of the way there by using meteor package https://github.com/peerlibrary/meteor-fs (which is a thin wrapper around https://nodejs.org/api/fs.html) and doing some poking around. Turns out the assets are put into a folder called app/.

Here's what my code looked like:

if (Meteor.isServer) {
    Meteor.startup(function() {
        // clear database and load everything in the articles folder
        fs.readdir("assets/app/", function(err, files) {
            if (err) throw err;
            files.forEach(function (val, ind, arr) {
                console.log(val);
            });
        });
    });
}
like image 80
outofambit Avatar answered Oct 23 '22 23:10

outofambit