create-nextly-app 0.0.2-alpha.74 → 0.0.2-alpha.76

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -42580,14 +42580,38 @@ const requireDeclaration = (createRequireName) => `// Resolves Nextly's cache ha
42580
42580
  const require = ${createRequireName}(import.meta.url);`;
42581
42581
  const REQUIRE_DECLARATION = requireDeclaration("createRequire");
42582
42582
  /**
42583
+ * Where a new app's config takes the crawlers that wait for the whole head,
42584
+ * and the files its deployed routes need beyond their traces.
42585
+ */
42586
+ const HTML_LIMITED_BOTS_IMPORT = "import { nextlyHtmlLimitedBots, nextlyTracingIncludes } from \"nextly/next\";";
42587
+ /**
42588
+ * The crawlers answered with each page's whole head in the first HTML rather
42589
+ * than streamed it: Next.js's own list, the main Googlebot and the AI
42590
+ * crawlers (`nextlyHtmlLimitedBots`).
42591
+ */
42592
+ const HTML_LIMITED_BOTS_LINE = ` // Search engines and AI crawlers read each page's whole head in the first
42593
+ // HTML, rather than metadata streamed in after it.
42594
+ htmlLimitedBots: nextlyHtmlLimitedBots,`;
42595
+ /**
42596
+ * The files Nextly loads at request time that a route's build trace leaves
42597
+ * out (`nextlyTracingIncludes`): without them, a host that deploys each route
42598
+ * with only its traced files (Vercel) fails the first request needing one.
42599
+ */
42600
+ const TRACING_INCLUDES_LINE = ` // Files Nextly loads at request time that the build's trace leaves out,
42601
+ // which a host deploying only traced files (Vercel) needs.
42602
+ outputFileTracingIncludes: { "/**": nextlyTracingIncludes() },`;
42603
+ /**
42583
42604
  * Render a complete next.config.ts file for the selected database.
42584
42605
  */
42585
42606
  function buildNextConfigTemplate(database) {
42586
42607
  return `import type { NextConfig } from "next";
42608
+ ${HTML_LIMITED_BOTS_IMPORT}
42587
42609
 
42588
42610
  const nextConfig: NextConfig = {
42589
42611
  ${CACHE_COMPONENTS_ON}
42590
42612
  serverExternalPackages: ${packageListLiteral(database)},
42613
+ ${HTML_LIMITED_BOTS_LINE}
42614
+ ${TRACING_INCLUDES_LINE}
42591
42615
  };
42592
42616
 
42593
42617
  export default nextConfig;
@@ -42596,6 +42620,7 @@ export default nextConfig;
42596
42620
  /** The same config as a JavaScript module, for an app without TypeScript. */
42597
42621
  function buildNextConfigModule(database) {
42598
42622
  return `${REQUIRE_IMPORT}
42623
+ ${HTML_LIMITED_BOTS_IMPORT}
42599
42624
 
42600
42625
  ${REQUIRE_DECLARATION}
42601
42626
 
@@ -42603,6 +42628,8 @@ ${REQUIRE_DECLARATION}
42603
42628
  const nextConfig = {
42604
42629
  ${CACHE_COMPONENTS_ON}
42605
42630
  serverExternalPackages: ${packageListLiteral(database)},
42631
+ ${HTML_LIMITED_BOTS_LINE}
42632
+ ${TRACING_INCLUDES_LINE}
42606
42633
  };
42607
42634
 
42608
42635
  export default nextConfig;
@@ -47053,7 +47080,7 @@ async function copyTemplate(options) {
47053
47080
  if (await import_lib$1.default.pathExists(sharedSrc)) await import_lib$1.default.copy(sharedSrc, path.default.join(targetDir, "shared.ts"), { overwrite: true });
47054
47081
  }
47055
47082
  const templateMigrationsDir = path.default.join(typeDir, "migrations");
47056
- if (await import_lib$1.default.pathExists(templateMigrationsDir)) await import_lib$1.default.copy(templateMigrationsDir, path.default.join(targetDir, "migrations"), { overwrite: false });
47083
+ if (approach !== "code-first" && await import_lib$1.default.pathExists(templateMigrationsDir)) await import_lib$1.default.copy(templateMigrationsDir, path.default.join(targetDir, "migrations"), { overwrite: false });
47057
47084
  const templateScriptsDir = path.default.join(typeDir, "scripts");
47058
47085
  if (await import_lib$1.default.pathExists(templateScriptsDir)) await import_lib$1.default.copy(templateScriptsDir, path.default.join(targetDir, "scripts"), {
47059
47086
  overwrite: false,
@@ -48134,9 +48161,12 @@ function startNextly(configImport) {
48134
48161
  // Next.js writes its Cache Components setting into this file as it builds
48135
48162
  // it. Nextly, loaded from node_modules, cannot read that for itself. With
48136
48163
  // it off, Nextly warns at start; with it on, a cached read that finds no
48137
- // "use cache" read function says so.
48164
+ // "use cache" read function says so. The same holds for the build's newest
48165
+ // migration, which withNextly sets: a production start compares it with
48166
+ // the database's schema version and warns when the database is behind.
48138
48167
  await createRegister(config, {
48139
48168
  cacheComponents: process.env.__NEXT_CACHE_COMPONENTS,
48169
+ buildSchemaVersion: process.env.NEXTLY_BUILD_SCHEMA_VERSION,
48140
48170
  })();`;
48141
48171
  }
48142
48172
  /** The whole hook, as the blank template ships it. */
@@ -48748,6 +48778,73 @@ async function installWithYalc(cwd, pm, allPackages, pluginPackages) {
48748
48778
  for (const pkg of yalcPackages) await execa("yalc", ["add", pkg], { cwd });
48749
48779
  await execa(pm, ["install"], { cwd });
48750
48780
  }
48781
+ // src/installers/initial-migration.ts
48782
+ /**
48783
+ * A code-first project's first migration, written from its own config by the
48784
+ * `nextly migrate:create` the install brought.
48785
+ *
48786
+ * The build a template gives runs `nextly migrate`, which applies the files in
48787
+ * the folder the config reads and creates nothing else. A code-first blog's
48788
+ * schema is its config, the plugins it registers included, so its first
48789
+ * migration is generated from that config for the database the project was
48790
+ * scaffolded for, rather than copied from SQL written by hand for the visual
48791
+ * blog. The command needs the installed `nextly` and the project's `.env`, so
48792
+ * it runs after both.
48793
+ *
48794
+ * @module installers/initial-migration
48795
+ */
48796
+ /** The arguments to `nextly` that write the first migration. */
48797
+ const MIGRATE_CREATE_ARGS = ["migrate:create", "initial"];
48798
+ /**
48799
+ * Whether a new project gets its first migration written from its config: a
48800
+ * fresh project whose template has a code-first approach. A visual project
48801
+ * runs the template's own migration, and a template without approaches
48802
+ * (blank, plugin) declares nothing to migrate.
48803
+ */
48804
+ function writesInitialMigration(project) {
48805
+ return project.isFreshProject && project.projectType !== "plugin" && project.approach === "code-first";
48806
+ }
48807
+ /** The command, as the person runs it in the project with `packageManager`. */
48808
+ function initialMigrationCommand(packageManager) {
48809
+ return [
48810
+ binaryRunner(packageManager),
48811
+ "nextly",
48812
+ ...MIGRATE_CREATE_ARGS
48813
+ ].join(" ");
48814
+ }
48815
+ /**
48816
+ * Runs `nextly migrate:create initial` in `projectDir`. Resolves undefined
48817
+ * once it has written the migration, or with what went wrong, so the caller
48818
+ * can name the command to run by hand rather than stop a scaffold that is
48819
+ * otherwise whole.
48820
+ *
48821
+ * The shell's `DATABASE_URL`, `DB_DIALECT` and `NODE_ENV` are left out, so the
48822
+ * migration is written for the database the project's `.env` names, not one a
48823
+ * variable in the person's shell happens to name. Nothing is read from stdin:
48824
+ * a first migration has no rename to ask about.
48825
+ */
48826
+ async function writeInitialMigration(projectDir, packageManager) {
48827
+ const [file, ...runnerArgs] = binaryRunner(packageManager).split(" ");
48828
+ try {
48829
+ await execa(file, [
48830
+ ...runnerArgs,
48831
+ "nextly",
48832
+ ...MIGRATE_CREATE_ARGS
48833
+ ], {
48834
+ cwd: projectDir,
48835
+ env: {
48836
+ DATABASE_URL: void 0,
48837
+ DB_DIALECT: void 0,
48838
+ NODE_ENV: void 0
48839
+ },
48840
+ stdin: "ignore"
48841
+ });
48842
+ return;
48843
+ } catch (error) {
48844
+ const said = error.stderr;
48845
+ return typeof said === "string" && said.trim().length > 0 ? said.trim() : error.message;
48846
+ }
48847
+ }
48751
48848
  // ../../node_modules/.pnpm/tar@7.5.22/node_modules/tar/dist/esm/index.min.js
48752
48849
  var zr = Object.defineProperty;
48753
48850
  var Ur = (s, t) => {
@@ -53047,6 +53144,21 @@ async function createNextly(options = {}) {
53047
53144
  stopAtConfig(error, overallStartedAt);
53048
53145
  }
53049
53146
  }
53147
+ const initialMigration = writesInitialMigration({
53148
+ isFreshProject,
53149
+ projectType,
53150
+ approach
53151
+ });
53152
+ if (initialMigration && !skipInstall) {
53153
+ const s = be$1();
53154
+ s.start("Writing the first migration from your config...");
53155
+ const failed = await writeInitialMigration(cwd, projectInfo.packageManager);
53156
+ if (failed === void 0) s.stop("First migration written");
53157
+ else {
53158
+ s.stop("The first migration was not written");
53159
+ R$1.warn(`${failed}\nRun ${initialMigrationCommand(projectInfo.packageManager)} in the project before its first build.`);
53160
+ }
53161
+ }
53050
53162
  const pm = projectInfo.packageManager;
53051
53163
  const devCommand = `${scriptRunner(pm)} dev`;
53052
53164
  const lines = [];
@@ -53063,6 +53175,10 @@ async function createNextly(options = {}) {
53063
53175
  lines.push("");
53064
53176
  lines.push(` Use it in an app: add ${import_picocolors.default.dim("myPlugin()")} to ${import_picocolors.default.dim("plugins")} in nextly.config.ts.`);
53065
53177
  } else {
53178
+ if (initialMigration && skipInstall) {
53179
+ lines.push(` ${import_picocolors.default.bold(initialMigrationCommand(pm))}`);
53180
+ lines.push(` ${import_picocolors.default.dim("→ after installing: writes the first migration your build applies")}`);
53181
+ }
53066
53182
  lines.push(` ${import_picocolors.default.bold(devCommand)}`);
53067
53183
  lines.push("");
53068
53184
  if (databaseType === "sqlite") lines.push(` Your database (SQLite) is stored at ${import_picocolors.default.dim("./data/nextly.db")}`);
@@ -53150,4 +53266,4 @@ Object.defineProperty(exports, "validateTemplateName", {
53150
53266
  }
53151
53267
  });
53152
53268
 
53153
- //# sourceMappingURL=create-nextly-Decg8dye.cjs.map
53269
+ //# sourceMappingURL=create-nextly-CXsN4jfA.cjs.map