No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 3.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.ɵcodegenFunctionsDirectory = exports.ɵcodegenPublicDirectory = exports.build = exports.discover = exports.type = exports.support = exports.name = void 0;
  4. const fs_extra_1 = require("fs-extra");
  5. const promises_1 = require("fs/promises");
  6. const path_1 = require("path");
  7. const semver_1 = require("semver");
  8. const __1 = require("..");
  9. const utils_1 = require("../utils");
  10. exports.name = "Nuxt";
  11. exports.support = "experimental";
  12. exports.type = 4;
  13. const DEFAULT_BUILD_SCRIPT = ["nuxt build"];
  14. async function discover(dir) {
  15. if (!(await (0, fs_extra_1.pathExists)((0, path_1.join)(dir, "package.json"))))
  16. return;
  17. const nuxtDependency = (0, __1.findDependency)("nuxt", { cwd: dir, depth: 0, omitDev: false });
  18. const configFilesExist = await Promise.all([
  19. (0, fs_extra_1.pathExists)((0, path_1.join)(dir, "nuxt.config.js")),
  20. (0, fs_extra_1.pathExists)((0, path_1.join)(dir, "nuxt.config.ts")),
  21. ]);
  22. const anyConfigFileExists = configFilesExist.some((it) => it);
  23. if (!anyConfigFileExists && !nuxtDependency)
  24. return;
  25. return { mayWantBackend: true };
  26. }
  27. exports.discover = discover;
  28. async function build(root) {
  29. const { buildNuxt } = await (0, __1.relativeRequire)(root, "@nuxt/kit");
  30. const nuxtApp = await getNuxtApp(root);
  31. await (0, utils_1.warnIfCustomBuildScript)(root, exports.name, DEFAULT_BUILD_SCRIPT);
  32. await buildNuxt(nuxtApp);
  33. return { wantsBackend: true };
  34. }
  35. exports.build = build;
  36. async function getNuxtApp(cwd) {
  37. const { loadNuxt } = await (0, __1.relativeRequire)(cwd, "@nuxt/kit");
  38. return await loadNuxt({
  39. cwd,
  40. overrides: {
  41. nitro: { preset: "node" },
  42. },
  43. });
  44. }
  45. function isNuxt3(cwd) {
  46. const { version } = (0, __1.findDependency)("nuxt", { cwd, depth: 0, omitDev: false });
  47. return (0, semver_1.gte)(version, "3.0.0-0");
  48. }
  49. async function ɵcodegenPublicDirectory(root, dest) {
  50. const app = await getNuxtApp(root);
  51. const distPath = isNuxt3(root) ? (0, path_1.join)(root, ".output", "public") : app.options.generate.dir;
  52. await (0, fs_extra_1.copy)(distPath, dest);
  53. }
  54. exports.ɵcodegenPublicDirectory = ɵcodegenPublicDirectory;
  55. async function ɵcodegenFunctionsDirectory(sourceDir, destDir) {
  56. const packageJsonBuffer = await (0, promises_1.readFile)((0, path_1.join)(sourceDir, "package.json"));
  57. const packageJson = JSON.parse(packageJsonBuffer.toString());
  58. if (isNuxt3(sourceDir)) {
  59. const outputPackageJsonBuffer = await (0, promises_1.readFile)((0, path_1.join)(sourceDir, ".output", "server", "package.json"));
  60. const outputPackageJson = JSON.parse(outputPackageJsonBuffer.toString());
  61. await (0, fs_extra_1.copy)((0, path_1.join)(sourceDir, ".output", "server"), destDir);
  62. return { packageJson: Object.assign(Object.assign({}, packageJson), outputPackageJson), frameworksEntry: "nuxt3" };
  63. }
  64. else {
  65. const { options: { buildDir }, } = await getNuxtApp(sourceDir);
  66. await (0, fs_extra_1.copy)(buildDir, (0, path_1.join)(destDir, (0, path_1.basename)(buildDir)));
  67. return { packageJson };
  68. }
  69. }
  70. exports.ɵcodegenFunctionsDirectory = ɵcodegenFunctionsDirectory;