How to use file-system-cache - 3 common examples

To help you get started, we’ve selected a few file-system-cache examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github storybookjs / storybook / lib / core / src / server / build-dev.js View on Github external
import findCacheDir from 'find-cache-dir';
import open from 'open';
import boxen from 'boxen';
import semver from 'semver';
import dedent from 'ts-dedent';
import Table from 'cli-table3';
import prettyTime from 'pretty-hrtime';
import inquirer from 'inquirer';
import detectFreePort from 'detect-port';

import storybook from './dev-server';
import { getDevCli } from './cli';

const defaultFavIcon = require.resolve('./public/favicon.ico');
const cacheDir = findCacheDir({ name: 'storybook' });
const cache = Cache({
  basePath: cacheDir,
  ns: 'storybook', // Optional. A grouping namespace for items.
});

const writeStats = async (name, stats) => {
  await fs.writeFile(
    path.join(cacheDir, `${name}-stats.json`),
    JSON.stringify(stats.toJson(), null, 2),
    'utf8'
  );
};

const getFreePort = port =>
  detectFreePort(port).catch(error => {
    logger.error(error);
    process.exit(-1);
github storybookjs / storybook / lib / core / src / server / utils / load-storybook-metadata.js View on Github external
export async function cachedStorybookMetadata() {
  const cacheDir = findCacheDir({ name: 'storybook' });
  const cache = Cache({
    basePath: cacheDir,
    ns: 'storybook', // Optional. A grouping namespace for items.
  });

  const packagePath = await findUp('package.json');
  if (!packagePath) {
    throw new Error('No package.json');
  }
  const packageJson = JSON.parse(await fs.readFile(packagePath, 'utf-8'));
  const metadataCache = await cache.get('storybookMetadata', {});
  const storybookMetadata = await loadStorybookMetadata(packageJson, {
    cache: metadataCache,
    getPackageJson: async packageName => {
      const packageFile = require.resolve(`${packageName}/package.json`);
      return JSON.parse(await fs.readFile(packageFile, 'utf8'));
    },
github theenadayalank / lint-prepush / index.js View on Github external
(function() {
  const Listr = require("listr");
  const chalk = require("chalk");
  const debug = require("debug")("lint-prepush:index");
  const os = require('os');
  const Cache = require("file-system-cache").default;

  const cache = Cache({
    basePath: `${os.homedir()}/.lint-prepush`, // Path where cache files are stored.
    ns: process.cwd() // A grouping namespace for items.
  });

  const success = chalk.keyword("green");
  const error = chalk.keyword("red");
  const warning = chalk.keyword("yellow");

  const { log } = console;

  const { userConfig, execSyncProcess } = require("./utils/common");
  const resolveMainTask = require("./utils/resolveMainTask");
  const fetchGitDiff = require("./utils/fetchGitDiff");

  if(!userConfig) {
    process.exitCode = 1;

file-system-cache

A super-fast, promise-based cache that reads and writes to the file-system.

MIT
Latest version published 10 months ago

Package Health Score

73 / 100
Full package analysis

Popular file-system-cache functions