當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。