-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpackage.js
157 lines (116 loc) · 4.43 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
var PackageVersion = require('./package-version-parser');
// Given a package constraint, check if the user has the latest version
//
// Returns true if output has been sent to the console
var checkPackage = function(packageConstraint) {
var splitString = packageConstraint.split('@');
var packageName = splitString[0];
var version = (splitString.length > 1) ? splitString[1] : null;
if (version) {
// This package has a version constraint
try {
var latestVersion = Version.getLatest(packageName);
if (latestVersion) {
if (PackageVersion.lessThan(version, latestVersion)) {
console.log(packageName + ' version ' + latestVersion + ' is available (' + version + ' currently specified).');
return true;
} else if (verbose) {
console.log(packageName + ' version ' + latestVersion + ' is up to date.');
return true;
}
} else {
console.log(packageName + ': version information not found. Run \'meteor show ' + packageName + '\' for more information.');
return true;
}
}
catch (e) {
// If we get an error trying to find a package version then just tell the user.
console.log(e);
return true;
}
} else {
// The package is unconstrained.
var used = Version.getVersionUsed(packageName);
try {
var latestVersion = Version.getLatest(packageName);
if (used && latestVersion && latestVersion !== 'local') {
if (PackageVersion.lessThan(used, latestVersion)) {
console.log(packageName + ' is not constrained. Version ' + latestVersion + ' is available (' + used + ' currently used by the project).');
return true;
} else if (verbose || unconstrained) {
console.log(packageName + ' is not constrained. The latest version (' + latestVersion + ') is being used by the project.');
return true;
}
} else if (verbose || unconstrained) {
console.log(packageName + ' does not have version contraint. The version currently used by the project cannot be determined.');
return true;
}
}
catch (e) {
// If we get an error trying to find a package version then just tell the user.
console.log(e);
return true;
}
}
return false;
};
// api object to be passed to the Package.onUse function
var api = {
// Define empty functions for parts of the API that don't interest us
versionsFrom: function() {},
imply: function() {},
export: function() {},
addFiles: function() {},
add_files: function() { if (warnings) console.log('Warning: Package uses deprecated \'add_files\' declaration. Use \'addFiles\' instead.'); },
addAssets: function() {},
mainModule: function() {},
// The `use` function is called with the list of packages that we need to check
use: function(packageConstraints) {
// The user can either pass an array or a string, we need to handle both cases
var output = false;
if (packageConstraints.constructor === Array) {
packageConstraints.forEach(function(packageConstraint) {
if (checkPackage(packageConstraint))
output = true;
});
} else {
if (checkPackage(packageConstraints))
output = true;
}
// Insert a blank link between packages if there were updates displayed
if (output)
Package.prevPackageDidOutput = true;
},
};
// We need to export our own Package object that will be called by the user's package.js script
var Package = {
describe: function(description) {
// If the previous package output to the console then we need to add a blank line.
if (Package.prevPackageDidOutput)
console.log('');
console.log('=> Checking package ' + description.name + '...');
Package.prevPackageDidOutput = false;
},
onUse: function(fn) {
try { fn(api); }
catch (e) { console.log(e); }
},
on_use: function(fn) {
if (warnings) console.log('Warning: Package uses deprecated \'on_use\' declaration. Use \'onUse\' instead.');
try { fn(api); }
catch (e) { console.log(e); }
},
onTest: function(fn) {
try { fn(api); }
catch (e) { console.log(e); }
},
on_test: function(fn) {
if (warnings) console.log('Warning: Package uses deprecated \'on_test\' declaration. Use \'onTest\' instead.');
try { fn(api); }
catch (e) { console.log(e); }
},
registerBuildPlugin: function(description) {
api.use(description.use);
},
};
module.exports = Package;