UNPKG

definition-tester

Version:
50 lines 1.91 kB
'use strict'; var child_process = require('child_process'); var path = require('path'); var Promise = require('bluebird'); var util = require('./util'); var GitChanges = (function () { function GitChanges(dtPath) { this.dtPath = dtPath; } GitChanges.prototype.readChanges = function () { var _this = this; var dir = path.join(this.dtPath, '.git'); return util.fileExists(dir).then(function (exists) { if (!exists) { throw new Error('cannot locate git-dir: ' + dir); } return new Promise(function (resolve, reject) { child_process.exec('git diff --name-only HEAD~1', { cwd: _this.dtPath }, function (err, stdout, stderr) { if (err) { reject(err); } else { var msg = stdout; resolve(msg.trim().split(/\r?\n/g)); } }); }); }); }; GitChanges.prototype.readChangedFolders = function () { var _this = this; return this.readChanges().then(function (changes) { return util.filterMapAsync(util.unique(changes.map(rootDirName)), function (folder) { if (folder === '.') { return undefined; } var full = path.join(_this.dtPath, folder); return util.fileExists(full).then(function (exists) { return exists ? full : undefined; }); }); }); }; return GitChanges; }()); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = GitChanges; function rootDirName(fileName) { var slash = fileName.indexOf('/'); return slash === -1 ? '.' : fileName.slice(0, slash); } //# sourceMappingURL=GitChanges.js.map