1 | 'use strict';
|
2 |
|
3 | function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
4 |
|
5 | var command = require('@pagedip/lib-command');
|
6 | var command__default = _interopDefault(command);
|
7 | var inquirer = _interopDefault(require('inquirer'));
|
8 | var libLicenseTools = require('@pagedip/lib-license-tools');
|
9 | var updateNotifier = _interopDefault(require('update-notifier'));
|
10 | var fs = _interopDefault(require('mz/fs'));
|
11 |
|
12 | var name = "pagedip";
|
13 |
|
14 | var version = "5.2.1";
|
15 |
|
16 | var main$1 = "Usage: pagedip <command> [--debug] [--silent] [--dev] [--help]\n [--version]\n\n The Pagedip CLI tool.\n\nCommands\n install Install a Pagedip package by name.\n run Run a Pagedip app.\n start, server, ee Start a basic Pagedip Enterprise server.\n register Register this host with a Pagedip License key.\n license Verify and print information about a Pagedip license\n key.\n\n This is the main Pagedip CLI tool. With this tool you can install Pagedip\n packages, run servers, and more.\n\n The following app names can be used as commands directly: api, auth,\n couchdb-setup, editor, enterprise-edition, iis-install, live, setup, theme,\n theme-server\n\n Run --help on any command for further help documentation.\n\nOptions\n --debug Show debug messages.\n -s, --silent All logs will be hidden.\n --dev Run in development mode.\n -h, -H, --help Shows this message.\n -v, -V, --version Prints the version and exits.";
|
17 |
|
18 | var register = "Usage: pagedip register [license] [--help]\n\n Register this host with a Pagedip License key.\n\n Register a machine with a valid license to interact with various restricted\n Pagedip services.\n\nOptions\n -h, -H, --help Shows this message.";
|
19 |
|
20 | var install = "Usage: pagedip install [<pkgname>...] [--help]\n\n Install Pagedip packages.\n\n This will install Pagedip packages and apps from the Pagedip registry. This\n host should already be registered with a valid license key before installing\n packages.\n\n One or more packages can be installed at once. Postfix the package name with\n @version to install a specific version.\n\nOptions\n -h, -H, --help Shows this message.";
|
21 |
|
22 | var license = "Usage: pagedip license [license] [--help]\n\n Verify and print information about a Pagedip license key.\n\n This will verify a license key and print some basic information about it. If\n you do not pass a license key, this will display info on the installed key.\n\nOptions\n -h, -H, --help Shows this message.";
|
23 |
|
24 | var apps = [".babelrc", ".template", "api", "auth", "couchdb-setup", "editor", "enterprise-edition", "iis-install", "live", "setup", "theme", "theme-server"];
|
25 |
|
26 | var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
27 |
|
28 | function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
|
29 |
|
30 |
|
31 | updateNotifier({
|
32 | pkg: { name: name, version: version }
|
33 | }).notify();
|
34 |
|
35 | var internalCommands = {
|
36 | "install": ["i"],
|
37 | "run": ["app"],
|
38 | "enterprise-edition": ["start", "server", "ee"],
|
39 | "setup": [],
|
40 | "register": [],
|
41 | "license": []
|
42 | };
|
43 |
|
44 | var resolveCommandName = function resolveCommandName(n) {
|
45 | if (typeof n !== "string" || !n) return;
|
46 |
|
47 | n = n.toLowerCase();
|
48 |
|
49 | for (var k in internalCommands) {
|
50 | if (k.toLowerCase() === n) return n;
|
51 |
|
52 | var a = internalCommands[k];
|
53 | if (Array.isArray(a) && a.includes(n)) return k;
|
54 | }
|
55 |
|
56 | return n;
|
57 | };
|
58 |
|
59 | var cli = command__default("pagedip", {
|
60 | module: module
|
61 | }, function () {
|
62 | var _ref = _asyncToGenerator(function* (args, config, logger) {
|
63 | var ocmd = args.shift();
|
64 | var cmdname = resolveCommandName(ocmd);
|
65 | var showVersion = this.version();
|
66 |
|
67 | if (ocmd !== cmdname) {
|
68 | logger.debug("resolved command %s -> %s", logger.color.blue(ocmd), logger.color.blue(cmdname));
|
69 | }
|
70 |
|
71 | if (cmdname && !showVersion) {
|
72 | var cmd = command.get("pagedip-" + cmdname);
|
73 | if (cmd) {
|
74 | yield this.run(cmd, args, logger);
|
75 | return;
|
76 | }
|
77 | }
|
78 |
|
79 | if (apps.includes(cmdname)) {
|
80 | yield this.run("pagedip-run", [cmdname].concat(args), logger);
|
81 | return;
|
82 | }
|
83 |
|
84 | if (showVersion) {
|
85 | logger.info(name + " " + version);
|
86 | } else {
|
87 | logger.info(main$1);
|
88 | }
|
89 | });
|
90 |
|
91 | return function (_x, _x2, _x3) {
|
92 | return _ref.apply(this, arguments);
|
93 | };
|
94 | }());
|
95 |
|
96 | command__default("pagedip-install", {
|
97 | help: install,
|
98 | alias: {
|
99 | tag: "t"
|
100 | }
|
101 | }, function () {
|
102 | var _ref2 = _asyncToGenerator(function* (args, config, logger) {
|
103 | if (!args.length) {
|
104 | logger.info(install);
|
105 | return;
|
106 | }
|
107 |
|
108 | var opts = config.pick("tag");
|
109 |
|
110 | yield require("./").install(args, _extends({}, opts, { logger: logger }));
|
111 | });
|
112 |
|
113 | return function (_x4, _x5, _x6) {
|
114 | return _ref2.apply(this, arguments);
|
115 | };
|
116 | }());
|
117 |
|
118 | command__default("pagedip-run", {}, function () {
|
119 | var _ref3 = _asyncToGenerator(function* (args, config, logger) {
|
120 | if (!args.length) {
|
121 | logger.info(undefined);
|
122 | return;
|
123 | }
|
124 |
|
125 | var _require = require("./"),
|
126 | load = _require.load;
|
127 |
|
128 | var cmd = void 0;
|
129 |
|
130 | try {
|
131 | cmd = yield load(args[0], { logger: logger });
|
132 | } catch (e) {
|
133 | if (e.code !== "MODULE_NOT_FOUND") throw e;
|
134 |
|
135 | var _ref4 = yield inquirer.prompt([{
|
136 | type: "confirm",
|
137 | name: "confirm",
|
138 | message: "Could not locate a package named '" + args[0] + "'. Do you want to attempt to install it?",
|
139 | default: true
|
140 | }]),
|
141 | confirm = _ref4.confirm;
|
142 |
|
143 | if (!confirm) throw e;
|
144 |
|
145 | yield this.run("pagedip-install", [args[0]], logger);
|
146 | cmd = yield load(args[0], { logger: logger });
|
147 | }
|
148 |
|
149 | yield this.run(cmd, args.slice(1), logger);
|
150 | });
|
151 |
|
152 | return function (_x7, _x8, _x9) {
|
153 | return _ref3.apply(this, arguments);
|
154 | };
|
155 | }());
|
156 |
|
157 | function printLicense(data, logger) {
|
158 | logger.log("%s\nID: %s\nRegistered To: %s\nIssued: %s\nExpires: %s", logger.color.white.bgGreen("Valid Pagedip license key."), data.id, data.user, new Date(data.issued).toString(), new Date(data.ttl).toString());
|
159 | logger.log("\n%s\n", data.payload);
|
160 | }
|
161 |
|
162 | command__default("pagedip-license", {
|
163 | help: license
|
164 | }, function () {
|
165 | var _ref5 = _asyncToGenerator(function* (args, config, logger) {
|
166 | var data = yield libLicenseTools.verify(libLicenseTools.getLicense(args[0]));
|
167 | printLicense(data, logger);
|
168 | });
|
169 |
|
170 | return function (_x10, _x11, _x12) {
|
171 | return _ref5.apply(this, arguments);
|
172 | };
|
173 | }());
|
174 |
|
175 | command__default("pagedip-register", {
|
176 | help: register,
|
177 | alias: {
|
178 | "file": "f"
|
179 | }
|
180 | }, function () {
|
181 | var _ref6 = _asyncToGenerator(function* (args, config, logger) {
|
182 | var key = void 0;
|
183 | var keyFile = config.get("file");
|
184 |
|
185 | if (args.length) {
|
186 | key = args[0];
|
187 | } else if (keyFile) {
|
188 | key = yield fs.readFile(keyFile, "utf-8");
|
189 | } else {
|
190 | var result = yield inquirer.prompt([{
|
191 | type: "input",
|
192 | name: "key",
|
193 | message: "License Key (paste the raw license contents here)",
|
194 | validate: function validate(v) {
|
195 | return Boolean(v.length);
|
196 | }
|
197 | }]);
|
198 |
|
199 | key = result.key;
|
200 | }
|
201 |
|
202 | if (!key) {
|
203 | logger.info(register);
|
204 | return;
|
205 | }
|
206 |
|
207 | var data = yield libLicenseTools.verifyInstall(key);
|
208 | logger.log("");
|
209 | printLicense(data, logger);
|
210 | logger.log(logger.color.green("Thank you for registering! You can now download and use Pagedip packages. \uD83C\uDF89\n"));
|
211 | });
|
212 |
|
213 | return function (_x13, _x14, _x15) {
|
214 | return _ref6.apply(this, arguments);
|
215 | };
|
216 | }());
|
217 |
|
218 | module.exports = cli;
|