hg.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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) {
  14. return obj && obj.__esModule ? obj : {default: obj};
  15. }
  16. function _toConsumableArray(arr) {
  17. if (Array.isArray(arr)) {
  18. for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++)
  19. arr2[i] = arr[i];
  20. return arr2;
  21. } else {
  22. return Array.from(arr);
  23. }
  24. }
  25. function _asyncToGenerator(fn) {
  26. return function() {
  27. var gen = fn.apply(this, arguments);
  28. return new Promise(function(resolve, reject) {
  29. function step(key, arg) {
  30. try {
  31. var info = gen[key](arg);
  32. var value = info.value;
  33. } catch (error) {
  34. reject(error);
  35. return;
  36. }
  37. if (info.done) {
  38. resolve(value);
  39. } else {
  40. return Promise.resolve(value).then(
  41. function(value) {
  42. step('next', value);
  43. },
  44. function(err) {
  45. step('throw', err);
  46. }
  47. );
  48. }
  49. }
  50. return step('next');
  51. });
  52. };
  53. }
  54. /**
  55. * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
  56. *
  57. * This source code is licensed under the MIT license found in the
  58. * LICENSE file in the root directory of this source tree.
  59. *
  60. *
  61. */
  62. const env = Object.assign({}, process.env, {
  63. HGPLAIN: 1
  64. });
  65. const ANCESTORS = [
  66. // Parent commit to this one.
  67. '.^',
  68. // The first commit of my branch, only if we are not on the default branch.
  69. 'min(branch(.)) and not min(branch(default))',
  70. // Latest public commit.
  71. 'max(public())'
  72. ];
  73. const adapter = {
  74. findChangedFiles: (() => {
  75. var _ref = _asyncToGenerator(function*(cwd, options) {
  76. return new Promise(function(resolve, reject) {
  77. const includePaths = (options && options.includePaths) || [];
  78. const args = ['status', '-amnu'];
  79. if (options && options.withAncestor) {
  80. args.push('--rev', `ancestor(${ANCESTORS.join(', ')})`);
  81. } else if (options && options.changedSince) {
  82. args.push('--rev', `ancestor(., ${options.changedSince})`);
  83. } else if (options && options.lastCommit === true) {
  84. args.push('-A');
  85. }
  86. args.push.apply(args, _toConsumableArray(includePaths));
  87. const child = (_child_process || _load_child_process()).default.spawn(
  88. 'hg',
  89. args,
  90. {cwd: cwd, env: env}
  91. );
  92. let stdout = '';
  93. let stderr = '';
  94. child.stdout.on('data', function(data) {
  95. return (stdout += data);
  96. });
  97. child.stderr.on('data', function(data) {
  98. return (stderr += data);
  99. });
  100. child.on('error', function(error) {
  101. return reject(error);
  102. });
  103. child.on('close', function(code) {
  104. if (code === 0) {
  105. stdout = stdout.trim();
  106. if (stdout === '') {
  107. resolve([]);
  108. } else {
  109. resolve(
  110. stdout.split('\n').map(function(changedPath) {
  111. return (_path || _load_path()).default.resolve(
  112. cwd,
  113. changedPath
  114. );
  115. })
  116. );
  117. }
  118. } else {
  119. reject(new Error(code + ': ' + stderr));
  120. }
  121. });
  122. });
  123. });
  124. return function findChangedFiles(_x, _x2) {
  125. return _ref.apply(this, arguments);
  126. };
  127. })(),
  128. getRoot: (() => {
  129. var _ref2 = _asyncToGenerator(function*(cwd) {
  130. return new Promise(function(resolve) {
  131. try {
  132. let stdout = '';
  133. const child = (_child_process || _load_child_process()).default.spawn(
  134. 'hg',
  135. ['root'],
  136. {cwd: cwd, env: env}
  137. );
  138. child.stdout.on('data', function(data) {
  139. return (stdout += data);
  140. });
  141. child.on('error', function() {
  142. return resolve(null);
  143. });
  144. child.on('close', function(code) {
  145. return resolve(code === 0 ? stdout.trim() : null);
  146. });
  147. } catch (e) {
  148. resolve(null);
  149. }
  150. });
  151. });
  152. return function getRoot(_x3) {
  153. return _ref2.apply(this, arguments);
  154. };
  155. })()
  156. };
  157. exports.default = adapter;