当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript graceful-fs.existsSync函数代码示例

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


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

示例1: catch

const readCacheFile = (cachePath: Config.Path): string | null => {
  if (!fs.existsSync(cachePath)) {
    return null;
  }

  let fileData;
  try {
    fileData = fs.readFileSync(cachePath, 'utf8');
  } catch (e) {
    e.message =
      'jest: failed to read cache file: ' +
      cachePath +
      '\nFailure message: ' +
      e.message;
    removeFile(cachePath);
    throw e;
  }

  if (fileData == null) {
    // We must have somehow created the file but failed to write to it,
    // let's delete it and retry.
    removeFile(cachePath);
  }
  return fileData;
};
开发者ID:Volune,项目名称:jest,代码行数:25,代码来源:ScriptTransformer.ts

示例2:

const cacheWriteErrorSafeToIgnore = (
  e: Error & {code: string},
  cachePath: Config.Path,
) =>
  process.platform === 'win32' &&
  e.code === 'EPERM' &&
  fs.existsSync(cachePath);
开发者ID:Volune,项目名称:jest,代码行数:7,代码来源:ScriptTransformer.ts

示例3: expressInit

// function to initialize the express app
function expressInit(app) {

  //aditional app Initializations
  app.use(bodyParser.urlencoded({
    extended: false
  }));
  app.use(bodyParser.json());
  app.use(methodOverride());
  app.use(cookieParser());
  // Initialize passport and passport session
  app.use(passport.initialize());

  //initialize morgan express logger
  // NOTE: all node and custom module requests
  if (process.env.NODE_ENV !== 'test') {
    app.use(morgan('dev', {
      skip: function (req, res) { return res.statusCode < 400 }
    }));
  }

  // app.use(session({
  //   secret: config.sessionSecret,
  //   saveUninitialized: true,
  //   resave: false,
  //   store: new MongoStore({
  //     mongooseConnection: mongoose.connection
  //   })
  // }));

  //sets the routes for all the API queries
  routes(app);

  const dist = fs.existsSync('dist');

  //exposes the client and node_modules folders to the client for file serving when client queries "/"
  app.use('/node_modules', express.static('node_modules'));
  app.use('/custom_modules', express.static('custom_modules'));
  app.use(express.static(`${dist ? 'dist/client' : 'client'}`));
  app.use('/public', express.static('public'));

  //exposes the client and node_modules folders to the client for file serving when client queries anything, * is a wildcard
  app.use('*', express.static('node_modules'));
  app.use('*', express.static('custom_modules'));
  app.use('*', express.static(`${dist ? 'dist/client' : 'client'}`));
  app.use('*', express.static('public'));

  // starts a get function when any directory is queried (* is a wildcard) by the client, 
  // sends back the index.html as a response. Angular then does the proper routing on client side
  if (process.env.NODE_ENV !== 'development')
    app.get('*', function (req, res) {
      res.sendFile(path.join(process.cwd(), `/${dist ? 'dist/client' : 'client'}/index.html`));
    });

  return app;

};
开发者ID:projectSHAI,项目名称:expressgular2,代码行数:57,代码来源:express.ts

示例4:

 }>((result, sourcePath) => {
   if (
     coveredFiles.has(sourcePath) &&
     this._needsCoverageMapped.has(sourcePath) &&
     fs.existsSync(this._sourceMapRegistry[sourcePath])
   ) {
     result[sourcePath] = this._sourceMapRegistry[sourcePath];
   }
   return result;
 }, {});
开发者ID:Volune,项目名称:jest,代码行数:10,代码来源:index.ts

示例5: function

    return new Promise<string>((resolve, reject) => {
        let zipFileName = "datasheet_" + requestTimestamp.toString() + ".zip";
        let zipFilePath = config.get("save_path") + zipFileName;
        let zipStream = fs.createWriteStream(zipFilePath);
        let archive = archiver.create("zip", {});

        zipStream.on("close", function() {
            console.log("All files are zipped!");
            resolve(zipFileName);
        });

        archive.on("error", (err: any) => {
            reject(err);
        });

        archive.pipe(zipStream);

        for (let fileName of filesToZip) {
            let fileNameWithoutTimestamp = fileName.replace(/[0-9]/g, "");
            archive.append(fs.createReadStream(config.get("save_path") + fileName), { name: fileNameWithoutTimestamp });
        }
        
        if (downloadType === "Status and Intensity" && fs.existsSync(config.get("metadata_path") + "status_intensity_datafield_descriptions.xlsx")) {
            archive.append(fs.createReadStream(config.get("metadata_path") + "status_intensity_datafield_descriptions.xlsx"), { name: "status_intensity_datafield_descriptions.xlsx" });
        }
        else if (downloadType === "Site Phenometrics" && fs.existsSync(config.get("metadata_path") + "site_phenometrics_datafield_descriptions.xlsx")) {
            archive.append(fs.createReadStream(config.get("metadata_path") + "site_phenometrics_datafield_descriptions.xlsx"), { name: "site_phenometrics_datafield_descriptions.xlsx" });
        }
        else if (downloadType === "Individual Phenometrics" && fs.existsSync(config.get("metadata_path") + "individual_phenometrics_datafield_descriptions.xlsx")) {
            archive.append(fs.createReadStream(config.get("metadata_path") + "individual_phenometrics_datafield_descriptions.xlsx"), { name: "individual_phenometrics_datafield_descriptions.xlsx" });
        }else if (downloadType === "Magnitude Phenometrics" && fs.existsSync(config.get("metadata_path") + "magnitude_phenometrics_datafield_descriptions.xlsx")) {
            archive.append(fs.createReadStream(config.get("metadata_path") + "magnitude_phenometrics_datafield_descriptions.xlsx"), { name: "magnitude_phenometrics_datafield_descriptions.xlsx" });
        }
        
        if (filesToZip.length > 2 && fs.existsSync(config.get("metadata_path") + "ancillary_datafield_descriptions.xlsx")) {
            archive.append(fs.createReadStream(config.get("metadata_path") + "ancillary_datafield_descriptions.xlsx"), { name: "ancillary_datafield_descriptions.xlsx" });
        }
        archive.finalize();
    });
开发者ID:usa-npn,项目名称:pop-service,代码行数:39,代码来源:zipBuilder.ts

示例6: requireMock

  requireMock(from: Config.Path, moduleName: string) {
    const moduleID = this._resolver.getModuleID(
      this._virtualMocks,
      from,
      moduleName,
    );

    if (this._isolatedMockRegistry && this._isolatedMockRegistry[moduleID]) {
      return this._isolatedMockRegistry[moduleID];
    } else if (this._mockRegistry[moduleID]) {
      return this._mockRegistry[moduleID];
    }

    const mockRegistry = this._isolatedMockRegistry || this._mockRegistry;

    if (moduleID in this._mockFactories) {
      return (mockRegistry[moduleID] = this._mockFactories[moduleID]());
    }

    const manualMockOrStub = this._resolver.getMockModule(from, moduleName);
    let modulePath;
    if (manualMockOrStub) {
      modulePath = this._resolveModule(from, manualMockOrStub);
    } else {
      modulePath = this._resolveModule(from, moduleName);
    }

    let isManualMock =
      manualMockOrStub &&
      !this._resolver.resolveStubModuleName(from, moduleName);
    if (!isManualMock) {
      // If the actual module file has a __mocks__ dir sitting immediately next
      // to it, look to see if there is a manual mock for this file.
      //
      // subDir1/my_module.js
      // subDir1/__mocks__/my_module.js
      // subDir2/my_module.js
      // subDir2/__mocks__/my_module.js
      //
      // Where some other module does a relative require into each of the
      // respective subDir{1,2} directories and expects a manual mock
      // corresponding to that particular my_module.js file.

      const moduleDir = path.dirname(modulePath);
      const moduleFileName = path.basename(modulePath);
      const potentialManualMock = path.join(
        moduleDir,
        '__mocks__',
        moduleFileName,
      );
      if (fs.existsSync(potentialManualMock)) {
        isManualMock = true;
        modulePath = potentialManualMock;
      }
    }
    if (isManualMock) {
      const localModule: InitialModule = {
        children: [],
        exports: {},
        filename: modulePath,
        id: modulePath,
        loaded: false,
      };

      // Only include the fromPath if a moduleName is given. Else treat as root.
      const fromPath = moduleName ? from : null;
      this._execModule(localModule, undefined, mockRegistry, fromPath);
      mockRegistry[moduleID] = localModule.exports;
      localModule.loaded = true;
    } else {
      // Look for a real module to generate an automock from
      mockRegistry[moduleID] = this._generateMock(from, moduleName);
    }

    return mockRegistry[moduleID];
  }
开发者ID:Volune,项目名称:jest,代码行数:76,代码来源:index.ts


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