How to use the dir-compare.compareSync function in dir-compare

To help you get started, we’ve selected a few dir-compare 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 NekR / offline-plugin / tests / legacy / compare.js View on Github external
} else {
    log(chalk.inverse('Comparing: ' + path.basename(testDir)));
  }

  log('');

  var expectedFolder = path.join(testDir, '__expected', 'webpack' + webpackVersion.split('.')[0]);
  var outputFolder = path.join(testDir, '__output');

  try {
    fs.accessSync(expectedFolder);
  } catch (e) {
    return Promise.resolve();
  }

  var res = dircompare.compareSync(
    expectedFolder,
    outputFolder,
    options
  );

  if (isFix) {
    res.diffSet.forEach(function (entry) {
      var name1 = entry.name1 || '';
      var name2 = entry.name2 || '';

      if (entry.state === 'equal') {
        // Do nothing
      } else if (entry.state === 'left') {
        // Remove file from expected
        del.sync(path.join(entry.path1, name1));
        logFile(name1, chalk.red('[missing]'));
github electrode-io / electrode-native / system-tests / utils / sameDirContent.js View on Github external
module.exports = function(
  pathA,
  pathB,
  {
    excludeFilter, // File/directory name exclude filter. Comma separated minimatch patterns.
  } = {}
) {
  let result = true
  const directoriesDiff = dircompare.compareSync(pathA, pathB, {
    compareContent: true,
    excludeFilter,
  })
  for (const diff of directoriesDiff.diffSet) {
    if (diff.state === 'distinct') {
      console.log('A difference in content was found !')
      console.log(JSON.stringify(diff))
      let diffLine = jsdiff.diffLines(
        fs.readFileSync(path.join(diff.path1, diff.name1)).toString(),
        fs.readFileSync(path.join(diff.path2, diff.name2)).toString()
      )
      diffLine.forEach(part => {
        let color = part.added ? 'green' : part.removed ? 'red' : 'grey'
        process.stderr.write(part.value[color])
      })
      result = false
github AndyOGo / node-sync-glob / test / helpers.js View on Github external
export const compare = (done, source, target, options) => (event, data) => {
  if (event) {
    if (Array.isArray(data) && data.length === 2
      && typeof data[0] === 'string' && typeof data[1] === 'string') {
      // eslint-disable-next-line no-param-reassign
      [source, target] = data
    }

    const res = dirCompare.compareSync(source, target, {
      ...options,
      compareSize: true,
      compareContent: true,
    })

    expect(res.differences).toBe(0)
    expect(res.differencesFiles).toBe(0)
    expect(res.distinctFiles).toBe(0)
    expect(res.differencesDirs).toBe(0)
    expect(res.distinctDirs).toBe(0)

    if (done) {
      done()
    }
  }
}
github jondot / hygen / src / __tests__ / metaverse.spec.ts View on Github external
}
      }
      const res = await runner(cmd, config)
      res.actions.forEach(a => {
        a.timing = -1
        a.subject = a.subject.replace(/.*hygen\/src/, '')
      })
      expect(res).toMatchSnapshot(cmd.join(' '))
    }
    const givenDir = path.join(metaDir, 'given')
    const expectedDir = path.join(metaDir, 'expected')
    console.log('after', {
      [givenDir]: fs.readdirSync(givenDir),
      [expectedDir]: fs.readdirSync(expectedDir),
    })
    const res = dirCompare.compareSync(givenDir, expectedDir, opts)
    res.diffSet = res.diffSet.filter(d => d.state !== 'equal')
    if (!res.same) {
      console.log(res)
    }
    expect(res.same).toEqual(true)
  })
github DefinitelyTyped / tsd / test / nspec / cases-spec.js View on Github external
function assertDiff(expected, actual) {
    var res = dircompare.compareSync(expected, actual, {
        compareSize: true,
        compareContent: true
    });
    res.diffSet.forEach(function (entry) {
        var state = {
            'equal': '==',
            'left': '->',
            'right': '<-',
            'distinct': '<>'
        }[entry.state];
        var name1 = entry.name1 ? entry.name1 : '';
        var name2 = entry.name2 ? entry.name2 : '';
        var space = '                                ';
        console.log('        - ' + pad(space, name1 + '(' + entry.type1.cyan + ') ', true)
            + state + ' ' + pad(space, name2 + '(' + entry.type2.cyan + ')', true));
        if (entry.state === 'distinct') {
github hacksalot / HackMyResume / test / scripts / test-themes.js View on Github external
function foldersMatch( a, b ) {
  var ret;
  ret = dirCompare.compareSync(a, b, {compareSize: true, skipSubdirs: true});
  if( !ret.same ) return false;
  ret = dirCompare.compareSync(a, b, {compareContent: true, skipSubdirs: true});
  return ret.differences === 1;
}
github maxchehab / quickfix / lib / utils.js View on Github external
compare: function(name, root) {
    console.log("> Comparing...");

    //Creating cache and relative paths.
    const path1 = "/tmp/quickfix/" + name + "/node_modules";
    const path2 = root + "/node_modules";
    const options = {
      compareContent: true,
      excludeFilter: "package.json,.cache,.yarn-integrity"
    };

    //Compare cache and relative node_modules
    let res = dircompare.compareSync(path1, path2, options);

    //Populate changes with all entrys that are not equal.
    let changes = [];
    res.diffSet.forEach(function(entry) {
      if (entry.state != "equal" && entry.path2) {
        changes.push({
          absolutePath: entry.path2 + "/" + entry.name2,
          relativePath: entry.relativePath + "/" + entry.name2,
          changeID: uuid.v4()
        });
      }
    });
    return changes;
  },
  copyChanges: function(changes, root) {
github Gottwik / Enduro / libs / juicebox / juice_helpers.js View on Github external
function get_diff (folder) {
	var path1 = path.join(enduro.project_path, 'cms')
	var path2 = path.join(enduro.project_path, folder, 'cms')
	return dircompare.compareSync(path1, path2, {compareSize: true})
}
github liferay / alloy-editor / src / ui / react / gulp-tasks / fonts.js View on Github external
var shouldUpdateSkinIconFont = function(skin) {
    var updateIconFont = true;

    var skinFontDir = path.join(assetsDir, 'sass', 'skin', skin, '.font-cache');

    try {
        var iconDiffs = dircompare.compareSync(
            path.join(skinFontDir, 'icons'),
            path.join(skinFontDir, 'tmp', 'icons'),
            {
                compareContent: true,
                includeFilter: '*.svg'
            }
        );

        updateIconFont = !iconDiffs.same;

    } catch(err) { }

    return updateIconFont;
};
github abecms / abecms / src / cli / cms / templates / assets.js View on Github external
}

  try {
    const dirSource = fse.lstatSync(source)
    if (!dirSource.isDirectory() && !dirSource.isSymbolicLink()) {
      source = null
    }
  } catch (e) {
    source = null
  }

  directory = fse.lstatSync(dest)
  if (directory.isSymbolicLink()) dest = fse.readlinkSync(dest)

  if (source != null) {
    var res = dircompare.compareSync(source, dest, {
      compareDate: true
    })

    res.diffSet.forEach(function(entry) {
      var state = {
        equal: '==',
        left: '->',
        right: '<-',
        distinct: '<>'
      }[entry.state]

      var name1 = entry.name1 ? entry.name1 : ''
      var name2 = entry.name2 ? entry.name2 : ''

      let exclude = new RegExp(`.${config.files.templates.extension}$`)
      if (

dir-compare

Node JS directory compare

MIT
Latest version published 7 months ago

Package Health Score

70 / 100
Full package analysis