@farm.js/cli 0.1.0-beta.5 → 0.1.0-beta.7

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/bin/farm.js CHANGED
@@ -80,6 +80,26 @@ program
80
80
  }
81
81
  });
82
82
 
83
+ const authCommand = program.command("auth").description("Manage Farm-native authentication");
84
+
85
+ authCommand
86
+ .command("migrate")
87
+ .description("Create or update the Farm Auth database schema")
88
+ .option("-r, --root <root>", "Root directory", process.cwd())
89
+ .option("-c, --config <config>", "Path to farm config file")
90
+ .action(async (options) => {
91
+ try {
92
+ const { migrateFarmAuth } = require("../dist/index.js");
93
+ await migrateFarmAuth({
94
+ root: options.root,
95
+ configPath: options.config,
96
+ });
97
+ } catch (error) {
98
+ console.error("Failed to migrate Farm Auth:", error);
99
+ process.exit(1);
100
+ }
101
+ });
102
+
83
103
  program
84
104
  .command("upgrade")
85
105
  .description("Upgrade installed Farm.js packages to a stable or beta release")
package/dist/index.js CHANGED
@@ -16,6 +16,8 @@ let node_timers_promises = require("node:timers/promises");
16
16
  let picocolors = require("picocolors");
17
17
  picocolors = require_add_integration.__toESM(picocolors);
18
18
  let croner = require("croner");
19
+ let node_module = require("node:module");
20
+ let node_url = require("node:url");
19
21
  //#region src/deploy.ts
20
22
  /**
21
23
  * Deploy Farm.js application
@@ -810,29 +812,16 @@ async function generateFarmArtifacts(options = {}) {
810
812
  ...userConfig
811
813
  }, "development");
812
814
  const extraRoutes = [...resolvedConfig.openapi?.enabled && resolvedConfig.openapi.route ? [resolvedConfig.openapi.route] : [], ...(0, _farm_js_core.getFarmDocsRouteTypeEntries)(resolvedConfig.docs)];
813
- await (0, _farm_js_core.generateRouteTypes)({
815
+ const typeArtifacts = await (0, _farm_js_core.generateFarmTypeArtifacts)({
814
816
  root: resolvedConfig.root,
815
817
  srcDir: resolvedConfig.srcDir,
818
+ configPath: options.configPath,
819
+ layers: resolvedConfig.layers,
816
820
  extraRoutes,
817
- suppressLintOnLink: resolvedConfig.suppressLintOnLink
821
+ suppressLintOnLink: resolvedConfig.suppressLintOnLink,
822
+ i18nConfig: resolvedConfig.i18n
818
823
  });
819
- await (0, _farm_js_core.generateEnvTypes)({
820
- root: resolvedConfig.root,
821
- srcDir: resolvedConfig.srcDir,
822
- configPath: options.configPath
823
- });
824
- const appDir = node_path.default.join(resolvedConfig.root, resolvedConfig.srcDir, "app");
825
- const apiGenerator = new _farm_js_core.APITypeGenerator(appDir);
826
- const apiRoutes = apiGenerator.scanAPIRoutes();
827
- const apiTypesPath = node_path.default.join(resolvedConfig.root, resolvedConfig.srcDir, "lib", "api.generated.ts");
828
- await (0, node_fs_promises.mkdir)(node_path.default.dirname(apiTypesPath), { recursive: true });
829
- await (0, node_fs_promises.writeFile)(apiTypesPath, apiGenerator.generateAPIRouter(apiRoutes), "utf8");
830
- if (resolvedConfig.i18n.enabled) await (0, _farm_js_core.generateFarmI18nTypes)({
831
- root: resolvedConfig.root,
832
- srcDir: resolvedConfig.srcDir,
833
- config: resolvedConfig.i18n
834
- });
835
- _farm_js_core.logger.success(`Generated route, API, env${resolvedConfig.i18n.enabled ? ", and i18n" : ""} types (${apiRoutes.length} API route${apiRoutes.length === 1 ? "" : "s"}).`);
824
+ _farm_js_core.logger.success(`Generated route, API, env${resolvedConfig.i18n.enabled ? ", and i18n" : ""} types (${typeArtifacts.apiRoutes.length} API route${typeArtifacts.apiRoutes.length === 1 ? "" : "s"}).`);
836
825
  const schemas = (0, _farm_js_core.getIntegrationSchemas)(resolvedConfig.integrations);
837
826
  const schemaEntries = Object.entries(schemas);
838
827
  if (!schemaEntries.length) {
@@ -2420,6 +2409,31 @@ function toPosix(value) {
2420
2409
  return value.split(node_path.default.sep).join("/");
2421
2410
  }
2422
2411
  //#endregion
2412
+ //#region src/auth.ts
2413
+ async function migrateFarmAuth(options = {}) {
2414
+ const root = node_path.default.resolve(options.root || process.cwd());
2415
+ const userConfig = await (0, _farm_js_core.loadConfig)(root, options.configPath, "production");
2416
+ if (!userConfig) throw new Error(`No farm.config file was found in ${root}.`);
2417
+ if (!(await (0, _farm_js_core.resolveConfig)({
2418
+ ...userConfig,
2419
+ root
2420
+ }, "production")).auth.enabled) throw new Error("Farm Auth is disabled. Add `auth: true` to farm.config.ts first.");
2421
+ const resolveFromApp = (0, node_module.createRequire)(node_path.default.join(root, "package.json"));
2422
+ let modulePath;
2423
+ try {
2424
+ modulePath = resolveFromApp.resolve("@farm.js/auth/internal");
2425
+ } catch {
2426
+ throw new Error("Install @farm.js/auth before running `farm auth migrate`.");
2427
+ }
2428
+ const runtime = await import(
2429
+ /* @vite-ignore */
2430
+ (0, node_url.pathToFileURL)(modulePath).href
2431
+ );
2432
+ _farm_js_core.logger.info("Applying the Farm Auth database schema...");
2433
+ await runtime.migrateFarmAuth();
2434
+ _farm_js_core.logger.success("Farm Auth database is ready.");
2435
+ }
2436
+ //#endregion
2423
2437
  //#region src/upgrade.ts
2424
2438
  const DEPENDENCY_SECTIONS = [
2425
2439
  "dependencies",
@@ -2615,6 +2629,7 @@ exports.listFarmCronJobs = listFarmCronJobs;
2615
2629
  exports.listFarmIntegrationProviders = require_add_integration.listFarmIntegrationProviders;
2616
2630
  exports.loadFarmCronConfig = loadFarmCronConfig;
2617
2631
  exports.migrateFarm = migrateFarm;
2632
+ exports.migrateFarmAuth = migrateFarmAuth;
2618
2633
  exports.parsePreviewPublicUrl = parsePreviewPublicUrl;
2619
2634
  exports.previewFarm = previewFarm;
2620
2635
  exports.resolveCloudflareAgentDeployPlan = resolveCloudflareAgentDeployPlan;