orpc-file-based-router 0.0.18 → 0.1.0

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/index.cjs CHANGED
@@ -36,7 +36,7 @@ async function createRouter(routesDir) {
36
36
  return r.exports[e].route({ path: `${r.path}` });
37
37
  });
38
38
  }
39
- async function generateRouter(routesDir, outputFile) {
39
+ async function generateRouter(routesDir, outputFile, options) {
40
40
  const files = walkTree(
41
41
  routesDir
42
42
  );
@@ -48,14 +48,15 @@ async function generateRouter(routesDir, outputFile) {
48
48
  let routerContent = `// This file is auto-generated
49
49
 
50
50
  `;
51
- routerContent += importPaths.map((x, i) => `import { ${Object.keys(exports[i].exports).join(", ")} } from "./${x}"`).join("\n");
51
+ const extension = options?.importExtension || "";
52
+ routerContent += importPaths.map((x, i) => `import { ${Object.keys(exports[i].exports).join(", ")} } from "./${x}${extension}"`).join("\n");
52
53
  routerContent += "\n\nexport const router = ";
53
54
  routerContent += JSON.stringify(content, null, 2).replace(/"/g, "").replace(/(\s*)([a-zA-Z0-9]+-[a-zA-Z0-9-]+):/g, '$1"$2":');
54
55
  node_fs.writeFileSync(path.join(outputFile), routerContent);
55
56
  }
56
57
  function buildRoutePath(parsedFile) {
57
58
  const directory = parsedFile.dir === parsedFile.root ? "" : parsedFile.dir;
58
- const name = parsedFile.name.startsWith("index") ? parsedFile.name.replace("index", "") : `/${parsedFile.name}`;
59
+ const name = `/${parsedFile.name}`;
59
60
  return directory + name;
60
61
  }
61
62
  function buildRouter(routes, mapper) {
package/dist/index.d.cts CHANGED
@@ -1,5 +1,8 @@
1
1
  declare function createRouter(routesDir: string): Promise<Router>;
2
- declare function generateRouter(routesDir: string, outputFile: string): Promise<void>;
2
+ type GeneratorOptions = {
3
+ importExtension?: string;
4
+ };
5
+ declare function generateRouter(routesDir: string, outputFile: string, options?: GeneratorOptions): Promise<void>;
3
6
  type Router = Record<string, any>;
4
7
 
5
8
  export { createRouter, generateRouter };
package/dist/index.d.mts CHANGED
@@ -1,5 +1,8 @@
1
1
  declare function createRouter(routesDir: string): Promise<Router>;
2
- declare function generateRouter(routesDir: string, outputFile: string): Promise<void>;
2
+ type GeneratorOptions = {
3
+ importExtension?: string;
4
+ };
5
+ declare function generateRouter(routesDir: string, outputFile: string, options?: GeneratorOptions): Promise<void>;
3
6
  type Router = Record<string, any>;
4
7
 
5
8
  export { createRouter, generateRouter };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,8 @@
1
1
  declare function createRouter(routesDir: string): Promise<Router>;
2
- declare function generateRouter(routesDir: string, outputFile: string): Promise<void>;
2
+ type GeneratorOptions = {
3
+ importExtension?: string;
4
+ };
5
+ declare function generateRouter(routesDir: string, outputFile: string, options?: GeneratorOptions): Promise<void>;
3
6
  type Router = Record<string, any>;
4
7
 
5
8
  export { createRouter, generateRouter };
package/dist/index.mjs CHANGED
@@ -30,7 +30,7 @@ async function createRouter(routesDir) {
30
30
  return r.exports[e].route({ path: `${r.path}` });
31
31
  });
32
32
  }
33
- async function generateRouter(routesDir, outputFile) {
33
+ async function generateRouter(routesDir, outputFile, options) {
34
34
  const files = walkTree(
35
35
  routesDir
36
36
  );
@@ -42,14 +42,15 @@ async function generateRouter(routesDir, outputFile) {
42
42
  let routerContent = `// This file is auto-generated
43
43
 
44
44
  `;
45
- routerContent += importPaths.map((x, i) => `import { ${Object.keys(exports[i].exports).join(", ")} } from "./${x}"`).join("\n");
45
+ const extension = options?.importExtension || "";
46
+ routerContent += importPaths.map((x, i) => `import { ${Object.keys(exports[i].exports).join(", ")} } from "./${x}${extension}"`).join("\n");
46
47
  routerContent += "\n\nexport const router = ";
47
48
  routerContent += JSON.stringify(content, null, 2).replace(/"/g, "").replace(/(\s*)([a-zA-Z0-9]+-[a-zA-Z0-9-]+):/g, '$1"$2":');
48
49
  writeFileSync(join(outputFile), routerContent);
49
50
  }
50
51
  function buildRoutePath(parsedFile) {
51
52
  const directory = parsedFile.dir === parsedFile.root ? "" : parsedFile.dir;
52
- const name = parsedFile.name.startsWith("index") ? parsedFile.name.replace("index", "") : `/${parsedFile.name}`;
53
+ const name = `/${parsedFile.name}`;
53
54
  return directory + name;
54
55
  }
55
56
  function buildRouter(routes, mapper) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orpc-file-based-router",
3
- "version": "0.0.18",
3
+ "version": "0.1.0",
4
4
  "description": "File-based router plugin for oRPC - automatically generate oRPC router from your file structure",
5
5
  "author": "zeeeeby",
6
6
  "license": "MIT",
@@ -30,7 +30,8 @@
30
30
  ],
31
31
  "scripts": {
32
32
  "build": "npm run type-check && unbuild",
33
- "type-check": "tsc --noEmit"
33
+ "type-check": "tsc --noEmit",
34
+ "playground": "tsx playground/src/generator.ts"
34
35
  },
35
36
  "devDependencies": {
36
37
  "@orpc/client": "^1.8.5",
@@ -40,4 +41,4 @@
40
41
  "vitest": "^3.2.4",
41
42
  "zod": "^4.1.3"
42
43
  }
43
- }
44
+ }