eachImport()

in lib/generator.js [162:196]


  eachImport(imports) {
    this.imports = {};
    if (imports.length === 0) {
      return;
    }
    if (!this.config.pkgDir) {
      throw new Error(`Must specific pkgDir when have imports`);
    }

    const lockPath = path.join(this.config.pkgDir, '.libraries.json');
    const lock = JSON.parse(fs.readFileSync(lockPath, 'utf8'));
    for (let i = 0; i < imports.length; i++) {
      const item = imports[i];
      const aliasId = item.lexeme;
      const moduleDir = this.config.libraries[aliasId];
      let targetPath = '';
      if (moduleDir.startsWith('./') || moduleDir.startsWith('../')) {
        targetPath = path.join(this.config.pkgDir, moduleDir);
      } else if (moduleDir.startsWith('/')) {
        targetPath = moduleDir;
      } else {
        targetPath = path.join(this.config.pkgDir, lock[moduleDir]);
      }
      const pkgPath = fs.existsSync(path.join(targetPath, 'Teafile')) ? path.join(targetPath, 'Teafile') : path.join(targetPath, 'Darafile');
      const pkg = JSON.parse(fs.readFileSync(pkgPath));
      const releaseJava = pkg.releases && pkg.releases.java;
      const javaPkg = pkg.java;
      if (!javaPkg) {
        throw new Error(`The '${aliasId}' has no Java supported.`);
      } else {
        javaPkg.release = releaseJava;
      }
      this.imports[aliasId] = javaPkg;
    }
  }