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.
package/dist/cli.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const require_create_nextly = require("./create-nextly-Decg8dye.cjs");
3
+ const require_create_nextly = require("./create-nextly-CXsN4jfA.cjs");
4
4
  // ../../node_modules/.pnpm/commander@14.0.2/node_modules/commander/lib/error.js
5
5
  var require_error = /* @__PURE__ */ require_create_nextly.__commonJSMin(((exports) => {
6
6
  /**
package/dist/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { a as getAvailableTemplateNames, c as init, d as __require, f as __toESM, i as validateTemplateName, l as shutdown, n as resolveProjectArg, o as packageVersion, r as validateProjectName, s as capture, t as createNextly, u as __commonJSMin } from "./create-nextly-ChHdzG83.mjs";
2
+ import { a as getAvailableTemplateNames, c as init, d as __require, f as __toESM, i as validateTemplateName, l as shutdown, n as resolveProjectArg, o as packageVersion, r as validateProjectName, s as capture, t as createNextly, u as __commonJSMin } from "./create-nextly-BmGN2BX8.mjs";
3
3
  // ../../node_modules/.pnpm/commander@14.0.2/node_modules/commander/lib/error.js
4
4
  var require_error = /* @__PURE__ */ __commonJSMin(((exports) => {
5
5
  /**
@@ -42567,14 +42567,38 @@ const requireDeclaration = (createRequireName) => `// Resolves Nextly's cache ha
42567
42567
  const require = ${createRequireName}(import.meta.url);`;
42568
42568
  const REQUIRE_DECLARATION = requireDeclaration("createRequire");
42569
42569
  /**
42570
+ * Where a new app's config takes the crawlers that wait for the whole head,
42571
+ * and the files its deployed routes need beyond their traces.
42572
+ */
42573
+ const HTML_LIMITED_BOTS_IMPORT = "import { nextlyHtmlLimitedBots, nextlyTracingIncludes } from \"nextly/next\";";
42574
+ /**
42575
+ * The crawlers answered with each page's whole head in the first HTML rather
42576
+ * than streamed it: Next.js's own list, the main Googlebot and the AI
42577
+ * crawlers (`nextlyHtmlLimitedBots`).
42578
+ */
42579
+ const HTML_LIMITED_BOTS_LINE = ` // Search engines and AI crawlers read each page's whole head in the first
42580
+ // HTML, rather than metadata streamed in after it.
42581
+ htmlLimitedBots: nextlyHtmlLimitedBots,`;
42582
+ /**
42583
+ * The files Nextly loads at request time that a route's build trace leaves
42584
+ * out (`nextlyTracingIncludes`): without them, a host that deploys each route
42585
+ * with only its traced files (Vercel) fails the first request needing one.
42586
+ */
42587
+ const TRACING_INCLUDES_LINE = ` // Files Nextly loads at request time that the build's trace leaves out,
42588
+ // which a host deploying only traced files (Vercel) needs.
42589
+ outputFileTracingIncludes: { "/**": nextlyTracingIncludes() },`;
42590
+ /**
42570
42591
  * Render a complete next.config.ts file for the selected database.
42571
42592
  */
42572
42593
  function buildNextConfigTemplate(database) {
42573
42594
  return `import type { NextConfig } from "next";
42595
+ ${HTML_LIMITED_BOTS_IMPORT}
42574
42596
 
42575
42597
  const nextConfig: NextConfig = {
42576
42598
  ${CACHE_COMPONENTS_ON}
42577
42599
  serverExternalPackages: ${packageListLiteral(database)},
42600
+ ${HTML_LIMITED_BOTS_LINE}
42601
+ ${TRACING_INCLUDES_LINE}
42578
42602
  };
42579
42603
 
42580
42604
  export default nextConfig;
@@ -42583,6 +42607,7 @@ export default nextConfig;
42583
42607
  /** The same config as a JavaScript module, for an app without TypeScript. */
42584
42608
  function buildNextConfigModule(database) {
42585
42609
  return `${REQUIRE_IMPORT}
42610
+ ${HTML_LIMITED_BOTS_IMPORT}
42586
42611
 
42587
42612
  ${REQUIRE_DECLARATION}
42588
42613
 
@@ -42590,6 +42615,8 @@ ${REQUIRE_DECLARATION}
42590
42615
  const nextConfig = {
42591
42616
  ${CACHE_COMPONENTS_ON}
42592
42617
  serverExternalPackages: ${packageListLiteral(database)},
42618
+ ${HTML_LIMITED_BOTS_LINE}
42619
+ ${TRACING_INCLUDES_LINE}
42593
42620
  };
42594
42621
 
42595
42622
  export default nextConfig;
@@ -47040,7 +47067,7 @@ async function copyTemplate(options) {
47040
47067
  if (await import_lib$1.default.pathExists(sharedSrc)) await import_lib$1.default.copy(sharedSrc, path.join(targetDir, "shared.ts"), { overwrite: true });
47041
47068
  }
47042
47069
  const templateMigrationsDir = path.join(typeDir, "migrations");
47043
- if (await import_lib$1.default.pathExists(templateMigrationsDir)) await import_lib$1.default.copy(templateMigrationsDir, path.join(targetDir, "migrations"), { overwrite: false });
47070
+ if (approach !== "code-first" && await import_lib$1.default.pathExists(templateMigrationsDir)) await import_lib$1.default.copy(templateMigrationsDir, path.join(targetDir, "migrations"), { overwrite: false });
47044
47071
  const templateScriptsDir = path.join(typeDir, "scripts");
47045
47072
  if (await import_lib$1.default.pathExists(templateScriptsDir)) await import_lib$1.default.copy(templateScriptsDir, path.join(targetDir, "scripts"), {
47046
47073
  overwrite: false,
@@ -48121,9 +48148,12 @@ function startNextly(configImport) {
48121
48148
  // Next.js writes its Cache Components setting into this file as it builds
48122
48149
  // it. Nextly, loaded from node_modules, cannot read that for itself. With
48123
48150
  // it off, Nextly warns at start; with it on, a cached read that finds no
48124
- // "use cache" read function says so.
48151
+ // "use cache" read function says so. The same holds for the build's newest
48152
+ // migration, which withNextly sets: a production start compares it with
48153
+ // the database's schema version and warns when the database is behind.
48125
48154
  await createRegister(config, {
48126
48155
  cacheComponents: process.env.__NEXT_CACHE_COMPONENTS,
48156
+ buildSchemaVersion: process.env.NEXTLY_BUILD_SCHEMA_VERSION,
48127
48157
  })();`;
48128
48158
  }
48129
48159
  /** The whole hook, as the blank template ships it. */
@@ -48735,6 +48765,73 @@ async function installWithYalc(cwd, pm, allPackages, pluginPackages) {
48735
48765
  for (const pkg of yalcPackages) await execa("yalc", ["add", pkg], { cwd });
48736
48766
  await execa(pm, ["install"], { cwd });
48737
48767
  }
48768
+ // src/installers/initial-migration.ts
48769
+ /**
48770
+ * A code-first project's first migration, written from its own config by the
48771
+ * `nextly migrate:create` the install brought.
48772
+ *
48773
+ * The build a template gives runs `nextly migrate`, which applies the files in
48774
+ * the folder the config reads and creates nothing else. A code-first blog's
48775
+ * schema is its config, the plugins it registers included, so its first
48776
+ * migration is generated from that config for the database the project was
48777
+ * scaffolded for, rather than copied from SQL written by hand for the visual
48778
+ * blog. The command needs the installed `nextly` and the project's `.env`, so
48779
+ * it runs after both.
48780
+ *
48781
+ * @module installers/initial-migration
48782
+ */
48783
+ /** The arguments to `nextly` that write the first migration. */
48784
+ const MIGRATE_CREATE_ARGS = ["migrate:create", "initial"];
48785
+ /**
48786
+ * Whether a new project gets its first migration written from its config: a
48787
+ * fresh project whose template has a code-first approach. A visual project
48788
+ * runs the template's own migration, and a template without approaches
48789
+ * (blank, plugin) declares nothing to migrate.
48790
+ */
48791
+ function writesInitialMigration(project) {
48792
+ return project.isFreshProject && project.projectType !== "plugin" && project.approach === "code-first";
48793
+ }
48794
+ /** The command, as the person runs it in the project with `packageManager`. */
48795
+ function initialMigrationCommand(packageManager) {
48796
+ return [
48797
+ binaryRunner(packageManager),
48798
+ "nextly",
48799
+ ...MIGRATE_CREATE_ARGS
48800
+ ].join(" ");
48801
+ }
48802
+ /**
48803
+ * Runs `nextly migrate:create initial` in `projectDir`. Resolves undefined
48804
+ * once it has written the migration, or with what went wrong, so the caller
48805
+ * can name the command to run by hand rather than stop a scaffold that is
48806
+ * otherwise whole.
48807
+ *
48808
+ * The shell's `DATABASE_URL`, `DB_DIALECT` and `NODE_ENV` are left out, so the
48809
+ * migration is written for the database the project's `.env` names, not one a
48810
+ * variable in the person's shell happens to name. Nothing is read from stdin:
48811
+ * a first migration has no rename to ask about.
48812
+ */
48813
+ async function writeInitialMigration(projectDir, packageManager) {
48814
+ const [file, ...runnerArgs] = binaryRunner(packageManager).split(" ");
48815
+ try {
48816
+ await execa(file, [
48817
+ ...runnerArgs,
48818
+ "nextly",
48819
+ ...MIGRATE_CREATE_ARGS
48820
+ ], {
48821
+ cwd: projectDir,
48822
+ env: {
48823
+ DATABASE_URL: void 0,
48824
+ DB_DIALECT: void 0,
48825
+ NODE_ENV: void 0
48826
+ },
48827
+ stdin: "ignore"
48828
+ });
48829
+ return;
48830
+ } catch (error) {
48831
+ const said = error.stderr;
48832
+ return typeof said === "string" && said.trim().length > 0 ? said.trim() : error.message;
48833
+ }
48834
+ }
48738
48835
  // ../../node_modules/.pnpm/tar@7.5.22/node_modules/tar/dist/esm/index.min.js
48739
48836
  var zr = Object.defineProperty;
48740
48837
  var Ur = (s, t) => {
@@ -53034,6 +53131,21 @@ async function createNextly(options = {}) {
53034
53131
  stopAtConfig(error, overallStartedAt);
53035
53132
  }
53036
53133
  }
53134
+ const initialMigration = writesInitialMigration({
53135
+ isFreshProject,
53136
+ projectType,
53137
+ approach
53138
+ });
53139
+ if (initialMigration && !skipInstall) {
53140
+ const s = be$1();
53141
+ s.start("Writing the first migration from your config...");
53142
+ const failed = await writeInitialMigration(cwd, projectInfo.packageManager);
53143
+ if (failed === void 0) s.stop("First migration written");
53144
+ else {
53145
+ s.stop("The first migration was not written");
53146
+ R.warn(`${failed}\nRun ${initialMigrationCommand(projectInfo.packageManager)} in the project before its first build.`);
53147
+ }
53148
+ }
53037
53149
  const pm = projectInfo.packageManager;
53038
53150
  const devCommand = `${scriptRunner(pm)} dev`;
53039
53151
  const lines = [];
@@ -53050,6 +53162,10 @@ async function createNextly(options = {}) {
53050
53162
  lines.push("");
53051
53163
  lines.push(` Use it in an app: add ${import_picocolors.default.dim("myPlugin()")} to ${import_picocolors.default.dim("plugins")} in nextly.config.ts.`);
53052
53164
  } else {
53165
+ if (initialMigration && skipInstall) {
53166
+ lines.push(` ${import_picocolors.default.bold(initialMigrationCommand(pm))}`);
53167
+ lines.push(` ${import_picocolors.default.dim("→ after installing: writes the first migration your build applies")}`);
53168
+ }
53053
53169
  lines.push(` ${import_picocolors.default.bold(devCommand)}`);
53054
53170
  lines.push("");
53055
53171
  if (databaseType === "sqlite") lines.push(` Your database (SQLite) is stored at ${import_picocolors.default.dim("./data/nextly.db")}`);
@@ -53072,4 +53188,4 @@ async function createNextly(options = {}) {
53072
53188
  }
53073
53189
  export { getAvailableTemplateNames as a, init as c, __require as d, __toESM$1 as f, validateTemplateName as i, shutdown as l, resolveProjectArg as n, packageVersion as o, validateProjectName as r, capture as s, createNextly as t, __commonJSMin$1 as u };
53074
53190
 
53075
- //# sourceMappingURL=create-nextly-ChHdzG83.mjs.map
53191
+ //# sourceMappingURL=create-nextly-BmGN2BX8.mjs.map