/
cordova-plugins
executable file
·94 lines (88 loc) · 3.38 KB
/
cordova-plugins
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
#!/usr/bin/env node
var path = require("path"),
fs = require("fs"),
exit = require("exit"),
nopt = require("nopt"),
clc = require('cli-color'),
shell = require("shelljs"),
// prompt = require( "prompt" ),
bootstrapdir = path.join(path.dirname(fs.realpathSync(__filename)), "../bootstrap"),
scriptsdir = path.join(path.dirname(fs.realpathSync(__filename)), "../scripts"),
tmp = shell.tempdir(),
pluginsfile = tmp + "plugins.json",
knownOpts = {
"dir" : path
},
shortHands = {
"d" : ["--dir", tmp ]
},
parsed = nopt(knownOpts, shortHands, process.argv, 2),
args = process.argv.splice(2);
function printPluginList(obj, filter) {
"use strict";
var plugin;
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
if (key !== '_updated') {
plugin = obj[key];
if (!filter || (filter && filter.trim() !== '' &&
((plugin.name.indexOf(filter) !== -1) || (plugin.description && plugin.description.indexOf(filter) !== -1))) ) {
shell.echo("Name: " + plugin.name.trim());
shell.echo("Description: " + (plugin.description ? plugin.description.trim() : "No description available."));
shell.echo("Version: " + plugin["dist-tags"].latest.trim());
shell.echo("Last Modified: " + new Date(plugin.time.modified));
shell.echo(clc.greenBright("Url: http://registry.cordova.io/" + key + "/-/" + key + "-" + plugin["dist-tags"].latest.trim() + ".tgz \n"));
}
}
}
}
}
function retrievePluginList() {
shell.exec("curl -s -o " + pluginsfile + " http://registry.cordova.io/-/all 2>&1");
var plugins = require(pluginsfile);
return plugins;
}
if (args.length === 0) {
// "se.sanitarium.cordova.exitapp":{
// "name":"se.sanitarium.cordova.exitapp",
// "description":"Implements navigator.app.exitApp on WP8",
// "dist-tags":{
// "latest":"1.0.0"
// },
// "maintainers":[
// {
// "name":"gaqzi",
// "email":"ba@sanitarium.se"
// }
// ],
// "time":{
// "modified":"2013-11-06T07:56:10.217Z"
// },
// "versions":{
// "1.0.0":"latest"
// },
// "keywords":[
// "cordova",
// "terminate"
// ]
// }
var list = retrievePluginList();
printPluginList(list || {});
}
else {
var directory = parsed.dir,
command = directory ? parsed.argv.remain[1] : parsed.argv.remain[0],
plugin = directory ? parsed.argv.remain[2] : parsed.argv.remain[1];
switch (command.toLowerCase()) {
case "search":
var list = retrievePluginList();
printPluginList(list || {}, plugin);
break;
case "get":
directory = directory || tmp;
shell.exec("curl -s -o " + directory + plugin.substring(plugin.lastIndexOf("/")) + " " + plugin + " 2>&1");
shell.echo( directory + plugin.substring(plugin.lastIndexOf("/")) );
break;
default:
}
}