Usage of Assets within packages?


#1

I have a package that has the following directory structure.

products
├── README.md
├── collections.js
├── fixtures
│   ├── facts.json
│   └── products.json
├── package.js
├── publications.js
├── routes.js
└── seed.js

On startup, I want to get all the json in the fixtures directory and perform an operation.

Meteor.startup(function () {
  // insert static assets on startup.
  EJSON.parse(Assets.getText('fixtures/products.json')).forEach(product => {
    Products.upsert(product, { $set: product });
  });
});

However, it never seems to be able to do this. Is there a proper way to manage this?


#2

Don’t you need to put fixtures in a /private directory first?


#3

This is in a package, do you still need to do that?


#4

Try addAssets:

http://docs.meteor.com/#/full/PackageAPI-addAssets