@ohos/hpm-cli
Version:
CLI for HarmonyOS package manager
100 lines (99 loc) • 14.3 kB
JavaScript
;
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
require("idempotent-babel-polyfill");
var _commander = _interopRequireDefault(require("commander"));
var _events = _interopRequireDefault(require("events"));
var _package = require("../package.json");
var _config = require("./utils/config");
var _semver = _interopRequireDefault(require("semver"));
var _i18n = _interopRequireWildcard(require("./i18n"));
var _helpers = require("./utils/helpers");
var _commands = require("./commands");
var _log = _interopRequireDefault(require("./core/log"));
var _pluginAPI = _interopRequireDefault(require("./plugin/pluginAPI"));
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t2 in e) "default" !== _t2 && {}.hasOwnProperty.call(e, _t2) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t2)) && (i.get || i.set) ? o(f, _t2, i) : f[_t2] = e[_t2]); return f; })(e, t); }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { if (r) i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n;else { var o = function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); }; o("next", 0), o("throw", 1), o("return", 2); } }, _regeneratorDefine2(e, r, n, t); }
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; } /*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
_events["default"].EventEmitter.defaultMaxListeners = 100;
function actionEntrance() {
return _actionEntrance.apply(this, arguments);
}
function _actionEntrance() {
_actionEntrance = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
var _args = arguments,
_t;
return _regenerator().w(function (_context) {
while (1) switch (_context.n) {
case 0:
if (!(_semver["default"].compare(process.version, '12.0.0') === -1)) {
_context.n = 1;
break;
}
process.exitCode = -1;
return _context.a(2, _i18n["default"].log('nodejs.version'));
case 1:
_context.p = 1;
_context.n = 2;
return (0, _commands.runAction)(this._name, _args, pluginAPI);
case 2:
_context.n = 4;
break;
case 3:
_context.p = 3;
_t = _context.v;
process.exitCode = -1;
_i18n["default"].log("".concat(this._name, ".error"), {
error: (0, _helpers.getErrorMessage)(_t)
});
_log["default"].debug(_t);
case 4:
return _context.a(2);
}
}, _callee, this, [[1, 3]]);
}));
return _actionEntrance.apply(this, arguments);
}
(0, _config.initConfig)();
_commander["default"].version(_package.version, '-V, --version', (0, _i18n.getI18nMessage)('help.version'));
_commander["default"].helpOption('-h, --help', (0, _i18n.getI18nMessage)('help.help'));
_commander["default"].addHelpCommand('help [command]', (0, _i18n.getI18nMessage)('help.help'));
_commander["default"].command('init').description((0, _i18n.getI18nMessage)('help.init')).option('-t, --template <template>', (0, _i18n.getI18nMessage)('help.initTemplate')).option('-d, --dirname <dirname>', (0, _i18n.getI18nMessage)('help.initDir')).option('-s, --scope <scopename>', (0, _i18n.getI18nMessage)('help.initScope')).arguments('[name]').action(actionEntrance);
_commander["default"].command('build').allowUnknownOption(true).description((0, _i18n.getI18nMessage)('help.build')).option('-p, --path <pathname>', (0, _i18n.getI18nMessage)('Target bundle.json path.')).option('-o, --os <osname>', (0, _i18n.getI18nMessage)('Os name such as linux, win, mac.')).option('-c, --cpu <cpuname>', (0, _i18n.getI18nMessage)('Cpu name such as x86, x64, arm.')).option('-dp, --defaultdeps <defaultDepsPath>', (0, _i18n.getI18nMessage)('Resolve defaultDeps path.')).option('-t, --test <testname>', (0, _i18n.getI18nMessage)('Build type')).action(actionEntrance);
_commander["default"].command('pack').description((0, _i18n.getI18nMessage)('help.pack')).option('-t, --target <targetname>', (0, _i18n.getI18nMessage)('pack component name.')).option('-o, --output <pathname>', (0, _i18n.getI18nMessage)('pack output path.')).option('-s, --snapshot', (0, _i18n.getI18nMessage)('pack snapshot version.')).action(actionEntrance);
_commander["default"].command('dist').allowUnknownOption(true).description((0, _i18n.getI18nMessage)('help.dist')).action(actionEntrance);
_commander["default"].command('install').alias('i').alias('add').arguments('[name]').description((0, _i18n.getI18nMessage)('help.install')).action(actionEntrance).option('-g, --global', (0, _i18n.getI18nMessage)('help.installGlobal')).option('-d, --save-dev', (0, _i18n.getI18nMessage)('help.installDev')).option('-f, --force', (0, _i18n.getI18nMessage)('help.forceInstall')).option('-dp, --defaultdeps <defaultDepsPath>', (0, _i18n.getI18nMessage)('Resolve defaultDeps path.'));
_commander["default"].command('uninstall').alias('rm').alias('remove').arguments('<name>').description((0, _i18n.getI18nMessage)('help.uninstall')).action(actionEntrance).option('-g, --global', (0, _i18n.getI18nMessage)('help.uninstallGlobal')).option('-d, --save-dev', (0, _i18n.getI18nMessage)('help.uninstallDev'));
_commander["default"].command('publish').description((0, _i18n.getI18nMessage)('help.publish')).option('-o, --old', (0, _i18n.getI18nMessage)('help.publishOld')).option('-s, --snapshot', (0, _i18n.getI18nMessage)('help.publishOld')).option('-t, --target <targetname>', (0, _i18n.getI18nMessage)('Publish component name.')).action(actionEntrance);
_commander["default"].command('run').allowUnknownOption(true).description((0, _i18n.getI18nMessage)('help.run')).arguments('<cmd>').action(actionEntrance);
_commander["default"].command('config').description((0, _i18n.getI18nMessage)('help.config')).action(actionEntrance).option('set <key> <value>', (0, _i18n.getI18nMessage)('help.configSet')).option('delete <key>', (0, _i18n.getI18nMessage)('help.configDelete')).option('get <key>', (0, _i18n.getI18nMessage)('help.configItem')).option('list', (0, _i18n.getI18nMessage)('help.configList')).option('-j, --json', (0, _i18n.getI18nMessage)('help.searchJson'));
_commander["default"].command('search').description((0, _i18n.getI18nMessage)('help.search')).option('-t, --type <type>', (0, _i18n.getI18nMessage)('help.searchType')).option('-j, --json', (0, _i18n.getI18nMessage)('help.searchJson')).option('-p, --pageSize <pageSize>', (0, _i18n.getI18nMessage)('help.searchPagesize')).option('-c, --currentPage <currentPage>', (0, _i18n.getI18nMessage)('help.searchCurrentpage')).option('-v, --ver <latest|all|semver>', (0, _i18n.getI18nMessage)('help.searchVersion')).option('-k, --kernel <kernel>', (0, _i18n.getI18nMessage)('help.searchKernel')).option('-b, --board <board>', (0, _i18n.getI18nMessage)('help.searchBoard')).option('-os, --osVersion <osVersion>', (0, _i18n.getI18nMessage)('help.searchOsVersion')).arguments('[name]').action(actionEntrance);
_commander["default"].command('update').alias('up').alias('upgrade').arguments('[name]').description((0, _i18n.getI18nMessage)('help.update')).action(actionEntrance).option('-g, --global', (0, _i18n.getI18nMessage)('help.updateGlobal')).option('--self', (0, _i18n.getI18nMessage)('help.updateSelf')).option('-f, --force', (0, _i18n.getI18nMessage)('help.forceUpdate'));
_commander["default"].command('check-update').description((0, _i18n.getI18nMessage)('help.checkUpdate')).action(actionEntrance).option('-g, --global', (0, _i18n.getI18nMessage)('help.checkUpdateGlobal')).option('-j, --json', (0, _i18n.getI18nMessage)('help.checkUpdateJson'));
_commander["default"].command('list').alias('ls').description((0, _i18n.getI18nMessage)('help.list')).option('-j, --json', (0, _i18n.getI18nMessage)('help.searchJson')).option('-g, --global', (0, _i18n.getI18nMessage)('help.listGlobal')).action(actionEntrance);
_commander["default"].command('gen-keys').description((0, _i18n.getI18nMessage)('help.genKeys')).action(actionEntrance);
_commander["default"].command('extract').alias('x').arguments('<source> [target]').description((0, _i18n.getI18nMessage)('help.extract')).action(actionEntrance);
_commander["default"].command('ui').description((0, _i18n.getI18nMessage)('help.ui')).option('-p, --port <port>', (0, _i18n.getI18nMessage)('help.uiPort')).option('-d, --daemon', (0, _i18n.getI18nMessage)('help.daemon')).action(actionEntrance);
_commander["default"].command('lang').arguments('[lang]').description((0, _i18n.getI18nMessage)('lang.lang')).action(actionEntrance);
_commander["default"].command('code').alias('segment').arguments('<action>').description((0, _i18n.getI18nMessage)('help.code')).action(actionEntrance);
_commander["default"].command('download').alias('d').arguments('<name>').description((0, _i18n.getI18nMessage)('help.download')).action(actionEntrance).option('-o, --output <dir>', (0, _i18n.getI18nMessage)('help.downLoadOutput'));
_commander["default"].command('fetch').description((0, _i18n.getI18nMessage)('help.fetch')).option('-p, --platform <platform>', (0, _i18n.getI18nMessage)('help.platform')).option('-z, --zip', (0, _i18n.getI18nMessage)('help.zip')).action(actionEntrance);
_commander["default"].command('docker').arguments('<action>').description('hpm docker').action(actionEntrance);
var pluginAPI = new _pluginAPI["default"](process.cwd(), _commands.runAction, _commander["default"]);
pluginAPI.registerPlugins();
_commander["default"].parse(process.argv);