Skip to content

Commit 273285f

Browse files
authored
Merge pull request #4 from laravel/inertia-helpers
Add Inertia Helpers
2 parents ec81431 + dc5a05b commit 273285f

File tree

5 files changed

+27
-6
lines changed

5 files changed

+27
-6
lines changed

.gitignore

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
node_modules/
2-
dist/
3-
npm-debug.log
4-
package-lock.json
1+
/node_modules/
2+
/dist/
3+
/inertia-helpers/
4+
/npm-debug.log
5+
/package-lock.json

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
"main": "dist/index.js",
1818
"types": "dist/index.d.ts",
1919
"scripts": {
20-
"build": "tsc",
20+
"build": "npm run build-plugin && npm run build-inertia-helpers",
21+
"build-plugin": "rm -rf dist && tsc",
22+
"build-inertia-helpers": "rm -rf inertia-helpers && tsc --project tsconfig.inertia-helpers.json",
2123
"lint": "eslint --ext .ts ./src ./tests",
2224
"test": "vitest run"
2325
},

src/inertia-helpers/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export function resolvePageComponent<T>(path: string, pages: Record<string, () => Promise<T>>) {
2+
if (typeof pages[path] === 'undefined') {
3+
throw new Error(`Page not found: ${path}`)
4+
}
5+
6+
return pages[path]()
7+
}

tsconfig.inertia-helpers.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "inertia-helpers",
5+
"target": "ES2020",
6+
"module": "ES2020",
7+
},
8+
"include": [
9+
"./src/inertia-helpers/index.ts"
10+
]
11+
}

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
"esModuleInterop": true
1111
},
1212
"include": [
13-
"./src/*.ts"
13+
"./src/index.ts"
1414
]
1515
}

0 commit comments

Comments
 (0)