Sha256: 034f005f84e136bd1f4fbdf313fd59ae6c3c00305d82f5e7a9845e406d9e2f74

Contents?: true

Size: 1.78 KB

Versions: 23

Compression:

Stored size: 1.78 KB

Contents

var grapher = require('sass-graph'),
  clonedeep = require('lodash/cloneDeep'),
  path = require('path'),
  config = {},
  watcher = {},
  graph = null;

watcher.reset = function(opts) {
  config = clonedeep(opts || config || {});
  var options = {
    loadPaths: config.includePath,
    extensions: ['scss', 'sass', 'css'],
    follow: config.follow,
  };

  if (config.directory) {
    graph = grapher.parseDir(config.directory, options);
  } else {
    graph = grapher.parseFile(config.src, options);
  }

  return Object.keys(graph.index);
};

watcher.changed = function(absolutePath) {
  var files = {
    added: [],
    changed: [],
    removed: [],
  };

  this.reset();

  if (absolutePath && path.basename(absolutePath)[0] !== '_') {
    files.changed.push(absolutePath);
  }

  graph.visitAncestors(absolutePath, function(parent) {
    if (path.basename(parent)[0] !== '_') {
      files.changed.push(parent);
    }
  });

  graph.visitDescendents(absolutePath, function(child) {
    files.added.push(child);
  });

  return files;
};

watcher.added = function(absolutePath) {
  var files = {
    added: [],
    changed: [],
    removed: [],
  };

  this.reset();

  if (Object.keys(graph.index).indexOf(absolutePath) === -1) {
    files.added.push(absolutePath);
  }

  graph.visitDescendents(absolutePath, function(child) {
    files.added.push(child);
  });

  return files;
};

watcher.removed = function(absolutePath) {
  var files = {
    added: [],
    changed: [],
    removed: [],
  };

  graph.visitAncestors(absolutePath, function(parent) {
    if (path.basename(parent)[0] !== '_') {
      files.changed.push(parent);
    }
  });

  if (Object.keys(graph.index).indexOf(absolutePath) !== -1) {
    files.removed.push(absolutePath);
  }

  this.reset();

  return files;
};

module.exports = watcher;

Version data entries

23 entries across 21 versions & 9 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/@rails/webpacker/node_modules/node-sass/lib/watcher.js
optimacms-0.1.61 spec/dummy/node_modules/node-sass/lib/watcher.js
disco_app-0.18.0 test/dummy/node_modules/node-sass/lib/watcher.js
disco_app-0.18.2 test/dummy/node_modules/node-sass/lib/watcher.js
tang-0.2.1 spec/tang_app/node_modules/node-sass/lib/watcher.js
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/node-sass/lib/watcher.js
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/node-sass/lib/watcher.js
ruby2js-4.0.4 lib/tasks/testrails/node_modules/node-sass/lib/watcher.js
ruby2js-4.0.3 lib/tasks/testrails/node_modules/node-sass/lib/watcher.js
tang-0.2.0 spec/tang_app/node_modules/node-sass/lib/watcher.js
tang-0.1.0 spec/tang_app/node_modules/node-sass/lib/watcher.js
tang-0.0.9 spec/tang_app/node_modules/node-sass/lib/watcher.js
enju_library-0.3.8 spec/dummy/node_modules/node-sass/lib/watcher.js
ilog-0.4.1 node_modules/node-sass/lib/watcher.js
ilog-0.4.0 node_modules/node-sass/lib/watcher.js
ilog-0.3.3 node_modules/node-sass/lib/watcher.js
jester-data-8.0.0 node_modules/node-sass/lib/watcher.js
ezii-os-5.2.1 node_modules/node-sass/lib/watcher.js
ezii-os-2.0.1 node_modules/node-sass/lib/watcher.js
ezii-os-1.1.0 node_modules/node-sass/lib/watcher.js