1

Is there some workaround to generate ical files from meteor (javascript)?.

I've have found this https://github.com/sebbo2002/ical-generator but I don't know how to use it into a Meteor project. Thanks.

Felix
  • 3,058
  • 6
  • 43
  • 53

2 Answers2

1

If you have npm package installed, you can use it with Npm.require:

var ical = Npm.require('ical-generator')

Previously it was done with __meteor_bootstrap__, but it's outdated.

However, this will only work if you have ical-generator installed properly, and would require installing it manually every time you share project with someone. A better solution is to set a dependency in package.

To do so, create /packages/ical folder and /packages/ical/package.js file with the following content:

Package.describe({
  summary: "Write something meaningful here"
});

Npm.depends({'ical-generator': '0.1.1'});
Hubert OG
  • 19,314
  • 7
  • 45
  • 73
0

In the beginning you need to install npm module:

To install an npm module in a Meteor app :

  • cd .meteor/local/build/server
  • npm install ical-generator

Then use it:

var ical = __meteor_bootstrap__.require('ical-generator');

cal = ical();

cal.setDomain('example.com');

cal.addEvent({
    start: new Date(new Date().getTime() + 3600000),
    end: new Date(new Date().getTime() + 7200000),
    summary: 'Example Event',
    description: 'It works ;)',
    organizer: {
        name: 'Organizer\'s Name',
        email: 'organizer@example.com'
    },
    url: 'http://sebbo.net/'
});

console.log(cal.toString());

In case you would like to serve iCal file via http with cal.serve(res) method you have 2 ways to go, both are described here.

Community
  • 1
  • 1
Kuba Wyrobek
  • 5,273
  • 1
  • 24
  • 26
  • 3
    This is outdated, you no longer use `__meteor_bootstrap__.require`. Also, this will require to manually install `ical-generator` after every installation of the project, it won't fetch it automatically as it should. ALSO, I'm not convinced that `.meteor` is a good place for manually installing npm packages. – Hubert OG Jul 31 '13 at 07:02