Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

Context.js 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /**
  2. Licensed to the Apache Software Foundation (ASF) under one
  3. or more contributor license agreements. See the NOTICE file
  4. distributed with this work for additional information
  5. regarding copyright ownership. The ASF licenses this file
  6. to you under the Apache License, Version 2.0 (the
  7. "License"); you may not use this file except in compliance
  8. with the License. You may obtain a copy of the License at
  9. http://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing,
  11. software distributed under the License is distributed on an
  12. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  13. KIND, either express or implied. See the License for the
  14. specific language governing permissions and limitations
  15. under the License.
  16. */
  17. const path = require('path');
  18. const { CordovaError } = require('cordova-common');
  19. /**
  20. * Creates hook script context
  21. * @constructor
  22. * @param {String} hook The hook type
  23. * @param {Object} opts Hook options
  24. * @returns {Object} */
  25. function Context (hook, opts) {
  26. this.hook = hook;
  27. // create new object, to avoid affecting input opts in other places
  28. // For example context.opts.plugin = Object is done, then it affects by reference
  29. this.opts = Object.assign({}, opts);
  30. this.cmdLine = process.argv.join(' ');
  31. // Lazy-load cordova to avoid cyclical dependency
  32. Object.defineProperty(this, 'cordova', {
  33. get () { return this.requireCordovaModule('cordova-lib').cordova; }
  34. });
  35. }
  36. /**
  37. * Requires the specified Cordova module.
  38. *
  39. * This method should only be used to require packages named `cordova-*`.
  40. * Public modules of such a Cordova module can be required by giving their
  41. * full package path: `cordova-foo/bar` for example.
  42. *
  43. * @param {String} modulePath Module path as specified above
  44. * @returns {*} The required Cordova module
  45. */
  46. Context.prototype.requireCordovaModule = function (modulePath) {
  47. const [pkg, ...pkgPath] = modulePath.split('/');
  48. if (!pkg.match(/^cordova-[^/]+/)) {
  49. throw new CordovaError(
  50. 'Using "requireCordovaModule" to load non-cordova module ' +
  51. `"${modulePath}" is not supported. Instead, add this module to ` +
  52. 'your dependencies and use regular "require" to load it.'
  53. );
  54. }
  55. // We can only resolve `cordova-lib` by name if this module is installed as
  56. // a dependency of the current main module (e.g. when running `cordova`).
  57. // To handle `cordova-lib` paths correctly in all other cases too, we
  58. // require them using relative paths.
  59. return pkg === 'cordova-lib'
  60. ? require(path.posix.join('../..', ...pkgPath))
  61. : require(modulePath);
  62. };
  63. module.exports = Context;