Front end of the Slack clone application.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. 'use strict';
  2. var path = require('path');
  3. var loadJsonFile = require('load-json-file');
  4. var normalizePackageData = require('normalize-package-data');
  5. var pathType = require('path-type');
  6. module.exports = function (fp, opts) {
  7. if (typeof fp !== 'string') {
  8. opts = fp;
  9. fp = '.';
  10. }
  11. opts = opts || {};
  12. return pathType.dir(fp)
  13. .then(function (isDir) {
  14. if (isDir) {
  15. fp = path.join(fp, 'package.json');
  16. }
  17. return loadJsonFile(fp);
  18. })
  19. .then(function (x) {
  20. if (opts.normalize !== false) {
  21. normalizePackageData(x);
  22. }
  23. return x;
  24. });
  25. };
  26. module.exports.sync = function (fp, opts) {
  27. if (typeof fp !== 'string') {
  28. opts = fp;
  29. fp = '.';
  30. }
  31. opts = opts || {};
  32. fp = pathType.dirSync(fp) ? path.join(fp, 'package.json') : fp;
  33. var x = loadJsonFile.sync(fp);
  34. if (opts.normalize !== false) {
  35. normalizePackageData(x);
  36. }
  37. return x;
  38. };