bootstrap.js 1.4 KB

1234567891011121314151617181920212223242526272829303132
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.detectLocalCLI = exports.ERROR_VERSION_TOO_OLD = exports.ERROR_LOCAL_CLI_NOT_FOUND = exports.ERROR_BASE_DIRECTORY_NOT_FOUND = void 0;
  4. const tslib_1 = require("tslib");
  5. const node_1 = require("@ionic/cli-framework/utils/node");
  6. const debug_1 = require("debug");
  7. const path = tslib_1.__importStar(require("path"));
  8. const semver = tslib_1.__importStar(require("semver"));
  9. const color_1 = require("./lib/color");
  10. const debug = (0, debug_1.debug)('ionic:bootstrap');
  11. exports.ERROR_BASE_DIRECTORY_NOT_FOUND = 'BASE_DIRECTORY_NOT_FOUND';
  12. exports.ERROR_LOCAL_CLI_NOT_FOUND = 'LOCAL_CLI_NOT_FOUND';
  13. exports.ERROR_VERSION_TOO_OLD = 'VERSION_TOO_OLD';
  14. async function detectLocalCLI() {
  15. let pkgPath;
  16. try {
  17. pkgPath = require.resolve('ionic/package', { paths: (0, node_1.compileNodeModulesPaths)(process.cwd()) });
  18. }
  19. catch (e) {
  20. // ignore
  21. }
  22. if (pkgPath && process.env.IONIC_CLI_LIB !== path.dirname(pkgPath)) {
  23. const pkg = await (0, node_1.readPackageJsonFile)(pkgPath);
  24. debug(`local CLI ${(0, color_1.strong)(pkg.version)} found at ${(0, color_1.strong)(pkgPath)}`);
  25. if (semver.lt(pkg.version, '4.0.0')) {
  26. throw exports.ERROR_VERSION_TOO_OLD;
  27. }
  28. return path.dirname(pkgPath);
  29. }
  30. throw exports.ERROR_LOCAL_CLI_NOT_FOUND;
  31. }
  32. exports.detectLocalCLI = detectLocalCLI;