Skip to content

Commit

Permalink
Merge pull request #216 from minggangw/fix-issue-211
Browse files Browse the repository at this point in the history
Remove the redundant code used to load an interface
  • Loading branch information
Minggang Wang authored Nov 30, 2017
2 parents d7f10f7 + 7639931 commit 518fdd8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
11 changes: 1 addition & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,7 @@ let rcl = {
* @return {object} - the object of the required package/interface.
*/
require(name) {
if (typeof (name.package) === 'string' && typeof (name.type) === 'string' && typeof (name.message) === 'string') {
return loader.loadInterface(name.package, name.type, name.message);
}

if (name.indexOf('/') !== -1) {
let [packageName, type, messageName] = name.split('/');
return loader.loadInterface(packageName, type, messageName);
}

return loader.loadInterfaceInPackage(name);
return loader.loadInterface(name);
},

/**
Expand Down
18 changes: 11 additions & 7 deletions lib/interface_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,22 @@ let interfaceLoader = {
return this.loadInterface(packageName, type, messageName);
}

// Suppose the name is a package, and traverse the path to collect the IDL files.
let packagePath = path.join(generator.generatedRoot, name);

// eslint-disable-next-line
let interfaces = fs.readdirSync(packagePath);
if (interfaces.length > 0) {
return this.loadInterfaceByPath(packagePath, interfaces);
}

throw new TypeError('A string argument in expected in "package/type/message" format');
},

loadInterfaceInPackage(packageName) {
let packagePath = path.join(generator.generatedRoot, packageName);
// The files under the package folder are limited, so it will not cost too
// much time and result in blocking the main thread.
// eslint-disable-next-line
let files = fs.readdirSync(packagePath);
loadInterfaceByPath(packagePath, interfaces) {
let interfaceInfos = [];

files.forEach((file) => {
interfaces.forEach((file) => {
let results = file.match(/\w+__(\w+)__(\w+).js$/);
let type = results[1];
let name = results[2];
Expand Down

0 comments on commit 518fdd8

Please sign in to comment.