How to use sane - 10 common examples

To help you get started, we’ve selected a few sane 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 phenomic / phenomic / packages / core / src / watch / index.js View on Github external
function createWatcher(options: {
  path: string,
  patterns: $ReadOnlyArray
}) {
  debug("path:", options.path);
  debug("extensions:", options.patterns);
  const watcher = sane(options.path, {
    watchman: canUseWatchman,
    glob: options.patterns
  });
  let subscribers = [];
  let ready = false;
  let closeMe = false;
  /* eslint-disable flowtype/no-mutable-array */
  const files: Array = globby
    .sync(options.patterns, { cwd: options.path })
    .map(file => toFile(options.path, file));
  debug("files", files.map(file => file.name));

  watcher.on("ready", () => {
    debug("watcher: ready");
    ready = true;
    if (closeMe) {
github jessieeeee / SimpleOne / node_modules / metro-bundler / node_modules / jest-haste-map / build / index.js View on Github external
_watch(
  hasteMap,
  hasteFS,
  moduleMap)
  {
    if (!this._options.watch) {
      return Promise.resolve();
    }

    // In watch mode, we'll only warn about module collisions and we'll retain
    // all files, even changes to node_modules.
    this._options.throwOnModuleCollision = false;
    this._options.retainAllFiles = true;

    const Watcher = canUseWatchman && this._options.useWatchman ?
    sane.WatchmanWatcher :
    sane.NodeWatcher;
    const extensions = this._options.extensions;
    const ignorePattern = this._options.ignorePattern;
    let changeQueue = Promise.resolve();
    let eventsQueue = [];
    // We only need to copy the entire haste map once on every "frame".
    let mustCopy = true;

    const createWatcher = root => {
      const watcher = new Watcher(root, {
        dot: false,
        glob: extensions.map(extension => '**/*.' + extension),
        ignored: ignorePattern });


      return new Promise((resolve, reject) => {
github jessieeeee / SimpleOne / node_modules / metro-bundler / node_modules / jest-haste-map / build / index.js View on Github external
hasteMap,
  hasteFS,
  moduleMap)
  {
    if (!this._options.watch) {
      return Promise.resolve();
    }

    // In watch mode, we'll only warn about module collisions and we'll retain
    // all files, even changes to node_modules.
    this._options.throwOnModuleCollision = false;
    this._options.retainAllFiles = true;

    const Watcher = canUseWatchman && this._options.useWatchman ?
    sane.WatchmanWatcher :
    sane.NodeWatcher;
    const extensions = this._options.extensions;
    const ignorePattern = this._options.ignorePattern;
    let changeQueue = Promise.resolve();
    let eventsQueue = [];
    // We only need to copy the entire haste map once on every "frame".
    let mustCopy = true;

    const createWatcher = root => {
      const watcher = new Watcher(root, {
        dot: false,
        glob: extensions.map(extension => '**/*.' + extension),
        ignored: ignorePattern });


      return new Promise((resolve, reject) => {
        const rejectTimeout = setTimeout(
github callstack / component-docs / src / serve.js View on Github external
github,
          logo,
          sheets: ['app.css'],
          scripts: scripts
            ? scripts.map(s => `scripts/${path.basename(s)}`)
            : [],
          colors,
        });
        return acc;
      }, {});
    } catch (e) {
      console.log(chalk.red(`Error building files: ${e.toString()}`));
    }
  };

  const watcher = sane(root, {
    watchman: true,
    glob: ['**/*.md', '**/*.mdx', '**/*.js', '**/*.ts', '**/*.tsx'],
    ignored: /node_modules/,
  });

  watcher.on('change', callback('change'));
  watcher.on('add', callback('add'));
  watcher.on('delete', callback('delete'));

  const cleanup = () => {
    watcher.close();
    process.exit();
  };

  const error = e => {
    console.log(e.stack || e.message);
github graphql-compose / graphql-compose-relay / resources / watch.js View on Github external
env: {
        ...process.env,
      },
      stdio: 'inherit'
    });
    child.on('exit', code => {
      if (code === 0) {
        resolve(true);
      } else {
        reject(new Error('Error code: ' + code));
      }
    });
  });
}

var watcher = sane(srcDir, { glob: ['**/*.js', '**/*.graphql'] })
  .on('ready', startWatch)
  .on('add', changeFile)
  .on('delete', deleteFile)
  .on('change', changeFile);

process.on('SIGINT', () => {
  console.log(CLEARLINE + yellow(invert('stopped watching')));
  watcher.close();
  process.exit();
});

var isChecking;
var needsCheck;
var toCheck = {};
var timeout;
github graphql / swapi-graphql / scripts / watch.js View on Github external
child.on('exit', function(code) {
      if (code === 0) {
        resolve(true);
      } else {
        reject(new Error('Error code: ' + code));
      }
    });
  });
}

var flowServer = spawn(flowBinPath, ['server'], {
  cmd: cmd,
  env: process.env,
});

var watcher = sane(srcDir, { glob: ['**/*.*'] })
  .on('ready', startWatch)
  .on('add', changeFile)
  .on('delete', deleteFile)
  .on('change', changeFile);

process.on('SIGINT', function() {
  watcher.close();
  flowServer.kill();
  console.log(CLEARLINE + yellow(invert('stopped watching')));
  process.exit();
});

var isChecking;
var needsCheck;
var toCheck = {};
var timeout;
github graphql / graphql-relay-js / scripts / watch.js View on Github external
child.on('exit', function (code) {
      if (code === 0) {
        resolve(true);
      } else {
        reject(new Error('Error code: ' + code));
      }
    });
  });
}

var flowServer = spawn(flowBinPath, ['server'], {
  cmd: cmd,
  env: process.env
});

var watcher = sane(srcDir, { glob: ['**/*.*'] })
  .on('ready', startWatch)
  .on('add', changeFile)
  .on('delete', deleteFile)
  .on('change', changeFile);

process.on('SIGINT', function () {
  watcher.close();
  flowServer.kill();
  console.log(CLEARLINE + yellow(invert('stopped watching')));
  process.exit();
});

var isChecking;
var needsCheck;
var toCheck = {};
var timeout;
github graphql / graphiql / packages / codemirror-graphql / resources / watch.js View on Github external
child.on('exit', code => {
      if (code === 0) {
        resolve(true);
      } else {
        reject(new Error('Error code: ' + code));
      }
    });
  });
}

const flowServer = spawn(flowBinPath, ['server'], {
  cmd,
  env: process.env,
});

const watcher = sane(srcDir, { glob: ['**/*.js', '**/*.graphql'] })
  .on('ready', startWatch)
  .on('add', changeFile)
  .on('delete', deleteFile)
  .on('change', changeFile);

process.on('SIGINT', () => {
  watcher.close();
  flowServer.kill();
  console.log(CLEARLINE + yellow(invert('stopped watching')));
  process.exit();
});

let isChecking;
let needsCheck;
let toCheck = {};
let timeout;
github MattMcFarland / sequelize-relay / scripts / watch.js View on Github external
child.on('exit', function (code) {
      if (code === 0) {
        resolve(true);
      } else {
        reject(new Error('Error code: ' + code));
      }
    });
  });
}

var flowServer = spawn(flowBinPath, ['server'], {
  cmd: cmd,
  env: process.env
});

var watcher = sane(srcDir, { glob: ['**/*.*'] })
  .on('ready', startWatch)
  .on('add', changeFile)
  .on('delete', deleteFile)
  .on('change', changeFile);

process.on('SIGINT', function () {
  watcher.close();
  flowServer.kill();
  console.log(CLEARLINE + yellow(invert('stopped watching')));
  process.exit();
});

var isChecking;
var needsCheck;
var toCheck = {};
var timeout;
github MattMcFarland / reactathon / scripts / server.js View on Github external
var server = fork('lib/bin/server.js');

server.on('stdout', (m) => {
  console.log(blue(m));
})

/*
var server = spawn('node', ['--harmony', 'lib/bin/server.js'], {
  cmd: cmd,
  env: process.env,
  stdio: 'inherit'
});
*/
var watcher = sane(cmd, { glob: ['server/**/*.*', 'client/**/*.*'] })
  .on('ready', startWatch)
  .on('add', changeFile)
  .on('delete', deleteFile)
  .on('change', changeFile);

process.on('SIGINT', function () {
  console.log(CLEARLINE + yellow(invert('dev server killed')));
  bs.exit();
  flowServer.kill();
  server.kill();
  watcher.close();
  process.exit();
});

process.on('uncaughtException', (err) => {
  console.log(CLEARLINE + red(invert(`Caught exception: ${err}`)));

sane

Sane aims to be fast, small, and reliable file system watcher.

MIT
Latest version published 3 years ago

Package Health Score

74 / 100
Full package analysis