rsf-zero 0.3.2 → 0.3.3

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/dev.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import "dotenv/config";
2
- import { RsfZeroConfig } from "../utils/export-types.js";
2
+ import { RsfZeroConfig } from "../utils/export-types.ts";
3
3
  export declare const dev: (options: RsfZeroConfig) => Promise<void>;
4
4
  //# sourceMappingURL=dev.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../src/cli/dev.ts"],"names":[],"mappings":"AAEA,OAAO,eAAe,CAAC;AAOvB,OAAO,EAAC,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAEvD,eAAO,MAAM,GAAG,GAAU,SAAS,aAAa,kBA+B/C,CAAA"}
1
+ {"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../src/cli/dev.ts"],"names":[],"mappings":"AAGA,OAAO,eAAe,CAAC;AAMvB,OAAO,EAAC,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAGvD,eAAO,MAAM,GAAG,GAAU,SAAS,aAAa,kBAiC/C,CAAA"}
package/dist/cli/dev.js CHANGED
@@ -4,7 +4,8 @@ import "dotenv/config";
4
4
  import { startVite } from "./dev/startVite.js";
5
5
  import { createActionRoute } from "./start/createActionRoute.js";
6
6
  import { debug } from "../utils/debug.js";
7
- import { customRoutes } from "../utils/customRoutes.js";
7
+ import { customRoutesHook } from "../utils/customRoutesHook.js";
8
+ import { onStartHook } from "../utils/onStartHook.js";
8
9
  export const dev = async (options) => {
9
10
  const app = express();
10
11
  const port = 3000;
@@ -22,11 +23,12 @@ export const dev = async (options) => {
22
23
  debug("Loaded action handler: " + action.name);
23
24
  };
24
25
  // - register custom routes
25
- await customRoutes(options, app);
26
+ await customRoutesHook(options, app);
26
27
  // Serve the frontend
27
28
  // - transform any actions found for the frontend
28
29
  // - and inform the onActionFound callback above
29
30
  const vite = await startVite({ app, onActionFound });
31
+ await onStartHook(options, app);
30
32
  app.listen(port, () => {
31
33
  console.log(`Server is running at http://localhost:${port}`);
32
34
  });
@@ -1 +1 @@
1
- {"version":3,"file":"start.d.ts","sourceRoot":"","sources":["../../src/cli/start.ts"],"names":[],"mappings":"AAIA,OAAO,eAAe,CAAC;AAGvB,OAAO,EAAC,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAKvD,eAAO,MAAM,KAAK,GAAU,SAAS,aAAa,kBAkCjD,CAAA"}
1
+ {"version":3,"file":"start.d.ts","sourceRoot":"","sources":["../../src/cli/start.ts"],"names":[],"mappings":"AAIA,OAAO,eAAe,CAAC;AAGvB,OAAO,EAAC,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAMvD,eAAO,MAAM,KAAK,GAAU,SAAS,aAAa,kBAoCjD,CAAA"}
package/dist/cli/start.js CHANGED
@@ -12,7 +12,8 @@ import morgan from "morgan";
12
12
  import "dotenv/config";
13
13
  import { createActionRoute } from "./start/createActionRoute.js";
14
14
  import { debug } from "../utils/debug.js";
15
- import { customRoutes } from "../utils/customRoutes.js";
15
+ import { customRoutesHook } from "../utils/customRoutesHook.js";
16
+ import { onStartHook } from "../utils/onStartHook.js";
16
17
  export const start = async (options) => {
17
18
  const app = express();
18
19
  const port = 3000;
@@ -27,7 +28,7 @@ export const start = async (options) => {
27
28
  // - register action handlers
28
29
  setActionRegistry(actionRegistry);
29
30
  // - register custom routes
30
- await customRoutes(options, app);
31
+ await customRoutesHook(options, app);
31
32
  // Client
32
33
  const staticPath = path.join(process.cwd(), 'dist/client/');
33
34
  debug('Serving static files from: ' + staticPath);
@@ -39,6 +40,7 @@ export const start = async (options) => {
39
40
  res.sendFile(path.join(process.cwd(), 'dist/client/index.html'));
40
41
  }
41
42
  });
43
+ await onStartHook(options, app);
42
44
  app.listen(port, () => {
43
45
  console.log(`Server is running at http://localhost:${port}`);
44
46
  });
@@ -0,0 +1,4 @@
1
+ import { Express } from "express";
2
+ import { RsfZeroConfig } from "./export-types.js";
3
+ export declare const customRoutesHook: (options: RsfZeroConfig, app: Express) => Promise<void>;
4
+ //# sourceMappingURL=customRoutesHook.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"customRoutesHook.d.ts","sourceRoot":"","sources":["../../src/utils/customRoutesHook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,SAAS,CAAC;AAEhC,OAAO,EAAC,aAAa,EAAC,MAAM,mBAAmB,CAAC;AAGhD,eAAO,MAAM,gBAAgB,GAAU,SAAS,aAAa,EAAE,KAAK,OAAO,kBAgC1E,CAAA"}
@@ -8,7 +8,7 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
8
8
  };
9
9
  import path from 'path';
10
10
  import { debug } from "./debug.js";
11
- export const customRoutes = async (options, app) => {
11
+ export const customRoutesHook = async (options, app) => {
12
12
  if (options.routes) {
13
13
  debug(`Routes config option found`);
14
14
  if (!Array.isArray(options.routes)) {
@@ -3,5 +3,6 @@ export type { ActionRegistry } from "../types.ts";
3
3
  export type RsfZeroConfig = {
4
4
  startStatic?: serveStatic.ServeStaticOptions;
5
5
  routes?: string[];
6
+ onStart?: string;
6
7
  };
7
8
  //# sourceMappingURL=export-types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"export-types.d.ts","sourceRoot":"","sources":["../../src/utils/export-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,cAAc,CAAC;AAE5C,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,MAAM,MAAM,aAAa,GAAG;IAC1B,WAAW,CAAC,EAAE,WAAW,CAAC,kBAAkB,CAAC;IAC7C,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB,CAAA"}
1
+ {"version":3,"file":"export-types.d.ts","sourceRoot":"","sources":["../../src/utils/export-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,cAAc,CAAC;AAE5C,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,MAAM,MAAM,aAAa,GAAG;IAC1B,WAAW,CAAC,EAAE,WAAW,CAAC,kBAAkB,CAAC;IAC7C,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAA"}
@@ -0,0 +1,4 @@
1
+ import { Express } from "express";
2
+ import { RsfZeroConfig } from "./export-types.js";
3
+ export declare const onStartHook: (options: RsfZeroConfig, app: Express) => Promise<void>;
4
+ //# sourceMappingURL=onStartHook.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"onStartHook.d.ts","sourceRoot":"","sources":["../../src/utils/onStartHook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,SAAS,CAAC;AAEhC,OAAO,EAAC,aAAa,EAAC,MAAM,mBAAmB,CAAC;AAGhD,eAAO,MAAM,WAAW,GAAU,SAAS,aAAa,EAAE,KAAK,OAAO,kBA+BrE,CAAA"}
@@ -0,0 +1,35 @@
1
+ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
2
+ if (typeof path === "string" && /^\.\.?\//.test(path)) {
3
+ return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
4
+ return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
5
+ });
6
+ }
7
+ return path;
8
+ };
9
+ import path from 'path';
10
+ import { debug } from "./debug.js";
11
+ export const onStartHook = async (options, app) => {
12
+ const { onStart } = options;
13
+ if (onStart) {
14
+ debug(`onStart config option found`);
15
+ if (typeof onStart !== 'string') {
16
+ throw new Error('Invalid onStart option. Must be a string.');
17
+ }
18
+ const absolutePath = path.isAbsolute(onStart)
19
+ ? onStart
20
+ : path.join(process.cwd(), onStart);
21
+ debug(`Loading onStart from: ${absolutePath}`);
22
+ const module = await import(__rewriteRelativeImportExtension(absolutePath));
23
+ const exportNames = Object.keys(module);
24
+ if (exportNames.length !== 1) {
25
+ throw new Error(`File ${absolutePath} must contain a single export.`);
26
+ }
27
+ const [firstExportName] = exportNames;
28
+ const firstExport = module[firstExportName];
29
+ if (!(typeof firstExport === 'function')) {
30
+ throw new Error(`File ${absolutePath} must export a function`);
31
+ }
32
+ firstExport(app);
33
+ debug(`onStart loaded successfully: ${absolutePath}`);
34
+ }
35
+ };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "A minimal micro-framework with React Server Functions support",
4
4
  "author": "Igor Nadj",
5
5
  "type": "module",
6
- "version": "0.3.2",
6
+ "version": "0.3.3",
7
7
  "repository": {
8
8
  "type": "git",
9
9
  "url": "https://github.com/IgorNadj/rsf-zero.git",
@@ -1,4 +0,0 @@
1
- import { Express } from "express";
2
- import { RsfZeroConfig } from "./export-types.js";
3
- export declare const customRoutes: (options: RsfZeroConfig, app: Express) => Promise<void>;
4
- //# sourceMappingURL=customRoutes.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"customRoutes.d.ts","sourceRoot":"","sources":["../../src/utils/customRoutes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,SAAS,CAAC;AAEhC,OAAO,EAAC,aAAa,EAAC,MAAM,mBAAmB,CAAC;AAGhD,eAAO,MAAM,YAAY,GAAU,SAAS,aAAa,EAAE,KAAK,OAAO,kBAgCtE,CAAA"}