next-build.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #!/usr/bin/env node
  2. "use strict";
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.nextBuild = void 0;
  7. var _fs = require("fs");
  8. var _indexJs = _interopRequireDefault(require("next/dist/compiled/arg/index.js"));
  9. var Log = _interopRequireWildcard(require("../build/output/log"));
  10. var _build = _interopRequireDefault(require("../build"));
  11. var _utils = require("../server/lib/utils");
  12. var _isError = _interopRequireDefault(require("../lib/is-error"));
  13. var _getProjectDir = require("../lib/get-project-dir");
  14. function _interopRequireDefault(obj) {
  15. return obj && obj.__esModule ? obj : {
  16. default: obj
  17. };
  18. }
  19. function _getRequireWildcardCache() {
  20. if (typeof WeakMap !== "function") return null;
  21. var cache = new WeakMap();
  22. _getRequireWildcardCache = function() {
  23. return cache;
  24. };
  25. return cache;
  26. }
  27. function _interopRequireWildcard(obj) {
  28. if (obj && obj.__esModule) {
  29. return obj;
  30. }
  31. if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
  32. return {
  33. default: obj
  34. };
  35. }
  36. var cache = _getRequireWildcardCache();
  37. if (cache && cache.has(obj)) {
  38. return cache.get(obj);
  39. }
  40. var newObj = {};
  41. var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
  42. for(var key in obj){
  43. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  44. var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
  45. if (desc && (desc.get || desc.set)) {
  46. Object.defineProperty(newObj, key, desc);
  47. } else {
  48. newObj[key] = obj[key];
  49. }
  50. }
  51. }
  52. newObj.default = obj;
  53. if (cache) {
  54. cache.set(obj, newObj);
  55. }
  56. return newObj;
  57. }
  58. const nextBuild = (argv)=>{
  59. const validArgs = {
  60. // Types
  61. "--help": Boolean,
  62. "--profile": Boolean,
  63. "--debug": Boolean,
  64. "--no-lint": Boolean,
  65. // Aliases
  66. "-h": "--help",
  67. "-d": "--debug"
  68. };
  69. let args;
  70. try {
  71. args = (0, _indexJs).default(validArgs, {
  72. argv
  73. });
  74. } catch (error) {
  75. if ((0, _isError).default(error) && error.code === "ARG_UNKNOWN_OPTION") {
  76. return (0, _utils).printAndExit(error.message, 1);
  77. }
  78. throw error;
  79. }
  80. if (args["--help"]) {
  81. (0, _utils).printAndExit(`
  82. Description
  83. Compiles the application for production deployment
  84. Usage
  85. $ next build <dir>
  86. <dir> represents the directory of the Next.js application.
  87. If no directory is provided, the current directory will be used.
  88. Options
  89. --profile Can be used to enable React Production Profiling
  90. --no-lint Disable linting
  91. `, 0);
  92. }
  93. if (args["--profile"]) {
  94. Log.warn("Profiling is enabled. Note: This may affect performance");
  95. }
  96. if (args["--no-lint"]) {
  97. Log.warn("Linting is disabled");
  98. }
  99. const dir = (0, _getProjectDir).getProjectDir(args._[0]);
  100. // Check if the provided directory exists
  101. if (!(0, _fs).existsSync(dir)) {
  102. (0, _utils).printAndExit(`> No such directory exists as the project root: ${dir}`);
  103. }
  104. return (0, _build).default(dir, null, args["--profile"], args["--debug"], !args["--no-lint"]).catch((err)=>{
  105. console.error("");
  106. if ((0, _isError).default(err) && (err.code === "INVALID_RESOLVE_ALIAS" || err.code === "WEBPACK_ERRORS" || err.code === "BUILD_OPTIMIZATION_FAILED" || err.code === "EDGE_RUNTIME_UNSUPPORTED_API")) {
  107. (0, _utils).printAndExit(`> ${err.message}`);
  108. } else {
  109. console.error("> Build error occurred");
  110. (0, _utils).printAndExit(err);
  111. }
  112. });
  113. };
  114. exports.nextBuild = nextBuild;
  115. //# sourceMappingURL=next-build.js.map