hg.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _path;
  6. function _load_path() {
  7. return _path = _interopRequireDefault(require('path'));
  8. }
  9. var _child_process;
  10. function _load_child_process() {
  11. return _child_process = _interopRequireDefault(require('child_process'));
  12. }
  13. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  14. function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } /**
  15. * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
  16. *
  17. * This source code is licensed under the MIT license found in the
  18. * LICENSE file in the root directory of this source tree.
  19. *
  20. *
  21. */
  22. const env = Object.assign({}, process.env, {
  23. HGPLAIN: 1
  24. });
  25. const ANCESTORS = [
  26. // Parent commit to this one.
  27. '.^',
  28. // The first commit of my branch, only if we are not on the default branch.
  29. 'min(branch(.)) and not min(branch(default))',
  30. // Latest public commit.
  31. 'max(public())'];
  32. const adapter = {
  33. findChangedFiles: (() => {
  34. var _ref = _asyncToGenerator(function* (cwd, options) {
  35. return new Promise(function (resolve, reject) {
  36. let args = ['status', '-amnu'];
  37. if (options && options.withAncestor) {
  38. args.push('--rev', `ancestor(${ANCESTORS.join(', ')})`);
  39. } else if (options && options.changedSince) {
  40. args.push('--rev', `ancestor(., ${options.changedSince})`);
  41. } else if (options && options.lastCommit === true) {
  42. args = ['tip', '--template', '{files%"{file}\n"}'];
  43. }
  44. const child = (_child_process || _load_child_process()).default.spawn('hg', args, { cwd, env });
  45. let stdout = '';
  46. let stderr = '';
  47. child.stdout.on('data', function (data) {
  48. return stdout += data;
  49. });
  50. child.stderr.on('data', function (data) {
  51. return stderr += data;
  52. });
  53. child.on('error', function (error) {
  54. return reject(error);
  55. });
  56. child.on('close', function (code) {
  57. if (code === 0) {
  58. stdout = stdout.trim();
  59. if (stdout === '') {
  60. resolve([]);
  61. } else {
  62. resolve(stdout.split('\n').map(function (changedPath) {
  63. return (_path || _load_path()).default.resolve(cwd, changedPath);
  64. }));
  65. }
  66. } else {
  67. reject(new Error(code + ': ' + stderr));
  68. }
  69. });
  70. });
  71. });
  72. return function findChangedFiles(_x, _x2) {
  73. return _ref.apply(this, arguments);
  74. };
  75. })(),
  76. getRoot: (() => {
  77. var _ref2 = _asyncToGenerator(function* (cwd) {
  78. return new Promise(function (resolve) {
  79. try {
  80. let stdout = '';
  81. const child = (_child_process || _load_child_process()).default.spawn('hg', ['root'], { cwd, env });
  82. child.stdout.on('data', function (data) {
  83. return stdout += data;
  84. });
  85. child.on('error', function () {
  86. return resolve(null);
  87. });
  88. child.on('close', function (code) {
  89. return resolve(code === 0 ? stdout.trim() : null);
  90. });
  91. } catch (e) {
  92. resolve(null);
  93. }
  94. });
  95. });
  96. return function getRoot(_x3) {
  97. return _ref2.apply(this, arguments);
  98. };
  99. })()
  100. };
  101. exports.default = adapter;