• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript fs-promise.exists函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中fs-promise.exists函数的典型用法代码示例。如果您正苦于以下问题:TypeScript exists函数的具体用法?TypeScript exists怎么用?TypeScript exists使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了exists函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: loadModels

  /**
   * Load all models from plugins.
   *
   * @param sequelize {Sequelize}
   *
   * @returns {Promise}
   */
  public async loadModels(sequelize: Sequelize) {
    if (this.order.length === 0) {
      this.determinateOrder();
    }

    for (let id of this.order) {
      if (this.plugins[id].directory) {
        var modelDirectory = path.normalize(this.plugins[id].directory + '/models/');
        var exists = await fs.exists(modelDirectory);
        if (! exists) {
          modelDirectory = path.normalize(this.plugins[id].directory + '/Models/');
          exists = await fs.exists(modelDirectory);
          if (! exists) continue;
        }

        try {
          let list = glob.sync(modelDirectory + '*.js');

          if (list.length > 0) {
            for (let file of list) {
              // Import sequelize model.
              let model: any = sequelize.import(file);

              // Set in the plugin.
              if (! this.plugins[id].models) {
                this.plugins[id].models = {};
              }
              this.plugins[id].models[model.name] = model;

              // Set in the global models.
              if (! this.app.models.hasOwnProperty(id)) {
                this.app.models[id] = {};
              }
              this.app.models[id][model.name] = model;
            }
          }
        } catch (err) {
          this.app.log.warn('Warning, can\'t load models for plugin ' + id, err.stack);
        }
      }
    }
  }
开发者ID:tomvlk,项目名称:ManiaJS,代码行数:49,代码来源:PluginManager.ts


示例2: createFromFile

    /**
     * Creates a server and database from reading a settings file.
     * 
     * @param filePath   Path to the settings file.
     * @returns A promise for a new running server.
     */
    public static async createFromFile(filePath: string): Promise<Server> {
        const settings: IAssassinsSettings = await fsp.exists(filePath)
            .then(exists => {
                if (!exists) {
                    throw new Error(`'${filePath}' not found.\nMake sure you copied '${filePath.replace(".json", ".default.json")}' to '${filePath}'.`);
                }
            })
            .then(() => fsp.readFile(filePath))
            .then((data: Buffer) => JSON.parse(data.toString()));

        return await Server.createFromSettings(settings);
    }
开发者ID:juliusl,项目名称:intern-assassins,代码行数:18,代码来源:server.ts


示例3: locateElectronPrebuilt

(async () => {
  const electronPrebuiltPath = argv.e ? path.resolve(process.cwd(), argv.e) : locateElectronPrebuilt();
  let electronPrebuiltVersion = argv.v; 

  if (!electronPrebuiltVersion) {
    try {
      if (!electronPrebuiltPath) throw new Error("electron-prebuilt not found");
      const pkgJson = require(path.join(electronPrebuiltPath, 'package.json'));

      electronPrebuiltVersion = pkgJson.version;
    } catch (e) {
      throw new Error('Unable to find electron-prebuilt\'s version number, either install it or specify an explicit version');
    }
  }

  let rootDirectory = argv.m;

  if (!rootDirectory) {
    // NB: We assume here that we're going to rebuild the immediate parent's
    // node modules, which might not always be the case but it's at least a
    // good guess
    rootDirectory = path.resolve(__dirname, '../../..');
    if (!await fs.exists(rootDirectory) || !await fs.exists(path.resolve(rootDirectory, 'package.json'))) {
      // Then we try the CWD
      rootDirectory = process.cwd();
      if (!await fs.exists(rootDirectory) || !await fs.exists(path.resolve(rootDirectory, 'package.json'))) {
        throw new Error('Unable to find parent node_modules directory, specify it via --module-dir, E.g. "--module-dir ." for the current directory');
      }
    }
  } else {
    rootDirectory = path.resolve(process.cwd(), rootDirectory);
  }
  
  let modulesDone = 0;
  let moduleTotal = 0;
  const rebuildSpinner = ora('Searching dependency tree').start();
  let lastModuleName: string;

  const redraw = (moduleName?: string) => {
    if (moduleName) lastModuleName = moduleName;
    if (argv.p) {
      rebuildSpinner.text = `Building modules: ${modulesDone}/${moduleTotal}`;
    } else {
      rebuildSpinner.text = `Building module: ${lastModuleName}, Completed: ${modulesDone}`;
    }
  }

  const rebuilder = rebuild(rootDirectory, electronPrebuiltVersion, argv.a || process.arch, argv.w ? argv.w.split(',') : [], argv.f, argv.d, argv.t ? argv.t.split(',') : ['prod', 'dev'], argv.p ? 'parallel' : (argv.s ? 'sequential' : undefined));

  const lifecycle = rebuilder.lifecycle;

  lifecycle.on('module-found', (moduleName: string) => {
    moduleTotal += 1;
    redraw(moduleName);
  });

  lifecycle.on('module-done', () => {
    modulesDone += 1;
    redraw();
  });

  try {
    await rebuilder;
  } catch (err) {
    rebuildSpinner.text = 'Rebuild Failed';
    rebuildSpinner.fail();
    throw err;
  }

  rebuildSpinner.text = 'Rebuild Complete';
  rebuildSpinner.succeed();
})();
开发者ID:our-city-app,项目名称:mobicage-desktop-client,代码行数:72,代码来源:cli.ts


示例4: it

 it('should not have rebuilt top level devDependencies', async () => {
   const forgeMeta = path.resolve(testModulePath, 'node_modules', 'ffi', 'build', 'Release', '.forge-meta');
   expect(await fs.exists(forgeMeta), 'ffi build meta should not exist').to.equal(false);
 });
开发者ID:our-city-app,项目名称:mobicage-desktop-client,代码行数:4,代码来源:rebuild.ts



注:本文中的fs-promise.exists函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript fs-promise.mkdirs函数代码示例发布时间:2022-05-25
下一篇:
TypeScript fs-promise.copy函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap