-
Notifications
You must be signed in to change notification settings - Fork 39
/
package.js
74 lines (64 loc) · 3.06 KB
/
package.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Package metadata file for Meteor.js. Maintainer: @dandv.
'use strict';
var packageName = 'webix:webix'; // https://atmospherejs.com/webix/webix
var gitHubPath = 'webix-hub/tracker'; // https://github.com/webix-hub/tracker
/* All of the below is just to get the version number of the 3rd party library.
* First we'll try to read it from package.json. This works when publishing or testing the package
* but not when running an example app that uses a local copy of the package because the current
* directory will be that of the app, and it won't have package.json. Finding the path of a file is hard:
* http://stackoverflow.com/questions/27435797/how-do-i-obtain-the-path-of-a-file-in-a-meteor-package
* Therefore, we'll fall back to GitHub, because Bower doesn't have a REST API, and Webix isn't on NPM -
* http://forum.webix.com/discussion/4947/add-webix-to-npm-npmjs-com
*
* We also don't have the HTTP package at this stage, and if we use Package.* in the request() callback,
* it will error that it must be run in a Fiber. So we'll use Node futures.
*/
var request = Npm.require('request');
var Future = Npm.require('fibers/future');
var semver = Npm.require('semver'); // to compare versions
var fut = new Future;
var version;
if (!version) try {
var packageJson = JSON.parse(Npm.require('fs').readFileSync('webix/bower.json'));
version = packageJson.version;
} catch (e) {
// if the file was not found, fall back to GitHub
console.warn('Could not find webix/bower.json to read version number from; trying GitHub...');
var url = 'https://api.github.com/repos/' + gitHubPath + '/tags';
request.get({
url: url,
headers: {
'User-Agent': 'request' // GitHub requires it
}
}, function (error, response, body) {
if (!error && response.statusCode === 200) {
var versions = JSON.parse(body).sort(function (v1, v2) {
return semver.compare(v2.name, v1.name); // sort descending
});
fut.return(versions[0].name);
} else {
fut.throw('Could not get version information from ' + url + ' either (rate limit reached or incorrect package name?):\n' + (response && response.statusCode || '') + (response && response.body || '') + (error || ''));
}
});
version = fut.wait();
}
// Now that we finally have an accurate version number...
Package.describe({
name: packageName,
version: version,
summary: 'Reactive Webix UI widgets bound to Meteor collections: table/grid, list etc.',
git: 'https://github.com/dandv/meteor-webix',
documentation: 'README.md'
});
Package.onUse(function (api) {
api.addFiles('webix/codebase/webix_debug.js', 'client');
// the Meteor proxy connector
api.addFiles('webix-meteor-data/codebase/meteor-data.js', 'client');
api.export('webix', 'client');
});
Package.onTest(function(api) {
api.use(packageName, 'client'); // yes, our package tests have to explicitly use our package - https://github.com/meteor/meteor/issues/1620
api.use('webix:skin-flat', 'client'); // use a skin for the visual check
api.use(['tinytest', 'http'], 'client');
api.addFiles('tests/visual.js', 'client');
});