Skip to content

Commit 50e0e81

Browse files
committed
Automatically create JS versions of our TS code
1 parent eb55821 commit 50e0e81

File tree

7 files changed

+2260
-1046
lines changed

7 files changed

+2260
-1046
lines changed

web/docs/advanced/apis.md

+8-33
Original file line numberDiff line numberDiff line change
@@ -136,48 +136,23 @@ For example, if your app is running at `https://example.com` then from the above
136136

137137
To use the API from your client, including with auth support, you can import the Axios wrapper from `wasp/client/api` and invoke a call. For example:
138138

139-
<Tabs groupId="js-ts">
140-
<TabItem value="js" label="JavaScript">
141-
142-
```jsx title="src/pages/SomePage.jsx"
143-
import React, { useEffect } from "react";
144-
import { api } from "wasp/client/api";
139+
```tsx title="src/pages/SomePage.tsx" auto-js with-hole
140+
import React, { useEffect } from 'react'
141+
import { api } from 'wasp/client/api'
145142

146143
async function fetchCustomRoute() {
147-
const res = await api.get("/foo/bar");
148-
console.log(res.data);
144+
const res = await api.get('/foo/bar')
145+
console.log(res.data)
149146
}
150147

151148
export const Foo = () => {
152149
useEffect(() => {
153-
fetchCustomRoute();
154-
}, []);
155-
156-
return <>// ...</>;
157-
};
158-
```
159-
</TabItem>
160-
<TabItem value="ts" label="TypeScript">
161-
162-
```tsx title="src/pages/SomePage.tsx"
163-
import React, { useEffect } from "react";
164-
import { api } from "wasp/client/api";
150+
fetchCustomRoute()
151+
}, [])
165152

166-
async function fetchCustomRoute() {
167-
const res = await api.get("/foo/bar");
168-
console.log(res.data);
153+
return <>{hole}</>
169154
}
170-
171-
export const Foo = () => {
172-
useEffect(() => {
173-
fetchCustomRoute();
174-
}, []);
175-
176-
return <>// ...</>;
177-
};
178155
```
179-
</TabItem>
180-
</Tabs>
181156

182157
#### Making Sure CORS Works
183158

web/docs/auth/social-auth/google.md

+1-54
Original file line numberDiff line numberDiff line change
@@ -394,56 +394,6 @@ For an up to date info about the data received from Google, please refer to the
394394

395395
<OverrideExampleIntro />
396396

397-
<Tabs groupId="js-ts">
398-
<TabItem value="js" label="JavaScript">
399-
400-
```wasp title="main.wasp"
401-
app myApp {
402-
wasp: {
403-
version: "{latestWaspVersion}"
404-
},
405-
title: "My App",
406-
auth: {
407-
userEntity: User,
408-
methods: {
409-
google: {
410-
// highlight-next-line
411-
configFn: import { getConfig } from "@src/auth/google.js",
412-
// highlight-next-line
413-
userSignupFields: import { userSignupFields } from "@src/auth/google.js"
414-
}
415-
},
416-
onAuthFailedRedirectTo: "/login"
417-
},
418-
}
419-
```
420-
421-
```prisma title="schema.prisma"
422-
model User {
423-
id Int @id @default(autoincrement())
424-
username String @unique
425-
displayName String
426-
}
427-
428-
// ...
429-
```
430-
431-
```js title=src/auth/google.js
432-
export const userSignupFields = {
433-
username: () => 'hardcoded-username',
434-
displayName: (data) => data.profile.name,
435-
}
436-
437-
export function getConfig() {
438-
return {
439-
scopes: ['profile', 'email'],
440-
}
441-
}
442-
```
443-
444-
</TabItem>
445-
<TabItem value="ts" label="TypeScript">
446-
447397
```wasp title="main.wasp"
448398
app myApp {
449399
wasp: {
@@ -475,7 +425,7 @@ model User {
475425
// ...
476426
```
477427

478-
```ts title=src/auth/google.ts
428+
```ts title=src/auth/google.ts auto-js
479429
import { defineUserSignupFields } from 'wasp/server/auth'
480430

481431
export const userSignupFields = defineUserSignupFields({
@@ -492,9 +442,6 @@ export function getConfig() {
492442

493443
<GetUserFieldsType />
494444

495-
</TabItem>
496-
</Tabs>
497-
498445
## Using Auth
499446

500447
<UsingAuthNote />

web/docusaurus.config.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ const lightCodeTheme = require('prism-react-renderer/themes/github')
33
const autoImportTabs = require('./src/remark/auto-import-tabs')
44
const fileExtSwitcher = require('./src/remark/file-ext-switcher')
55
const searchAndReplace = require('./src/remark/search-and-replace')
6+
const autoJSCode = require('./src/remark/auto-js-code')
7+
const codeWithHole = require('./src/remark/code-with-hole')
68

79
const includeCurrentVersion =
810
process.env.DOCS_INCLUDE_CURRENT_VERSION === 'true'
@@ -155,7 +157,13 @@ module.exports = {
155157
sidebarPath: require.resolve('./sidebars.js'),
156158
sidebarCollapsible: true,
157159
editUrl: 'https://github.com/wasp-lang/wasp/edit/release/web',
158-
remarkPlugins: [autoImportTabs, fileExtSwitcher, searchAndReplace],
160+
remarkPlugins: [
161+
autoJSCode,
162+
autoImportTabs,
163+
fileExtSwitcher,
164+
searchAndReplace,
165+
codeWithHole,
166+
],
159167

160168
// ------ Configuration for multiple docs versions ------ //
161169

0 commit comments

Comments
 (0)