/** * Imports all modules from a given directory. * * @param {String} path Directory path. If starts with //, the path will be absolute. * If starts with /, the path will be relative to a project directory (the one with package.json file). * @returns {Object} Module file name -> loaded module map object. */ requireDirectory(path) { let path0 = path; if (s.startsWith(path, '//')) { path0 = path0.substr(1); } else if (path0[0] == '/') { path0 = appRootPath + path0; } return requireDir(path0); }
/** * Helper function to correctly import modules in different processes with * different directory layout. If a module path ends with /, imports the whole * directory. If a module path starts with //, lookup will be made by absolute path. * If a module path starts with /, lookup will be made relative to project root. * * @param {String} modulePath Path of the module to import. If starts with /, a module * is searched relative to project directory. * @returns {*} Module import result. */ require(modulePath) { if (modulePath[0] != '/' && modulePath[0] != '.') { return globalRequire(modulePath); } else if (_.last(modulePath) == '/') { return this.requireDirectory(modulePath); } else if (s.startsWith(modulePath, '//')) { return globalRequire(modulePath.substr(common.isWindows() ? 2 : 1)); } else { return globalRequire(appRootPath + modulePath); } }
/** * Serializes a given class-defined actor behaviour. * * @param {Function} def Class-defined actor behaviour. * @returns {String} Serialized actor behaviour. * @private */ _serializeClassDefinition(def) { // Get a base class for behaviour class. let base = Object.getPrototypeOf(def); let baseBehaviour = ''; if (base && base.name) { // Have a user-defined super class. Serialize it as well. baseBehaviour = this._serializeClassDefinition(base); } let selfString = def.toString(); if (s.startsWith(selfString, 'function')) { selfString = this._serializeEs5ClassDefinition(def, selfString, base.name); } else if (s.startsWith(selfString, 'class')) { selfString += '; ' + def.name + ';'; } return baseBehaviour + selfString; }