-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert component generator to TS #632
Merged
peterp
merged 12 commits into
redwoodjs:master
from
kimadeline:convert-component-generator-to-ts
Jun 3, 2020
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a2b9a6c
Extract prettify, expand transformTSToJS from #515
kimadeline fa1a201
Add --typescript, --ts, --javascript, --js args
kimadeline 09553cf
Update component.js + convert templates to tsx
kimadeline f54f6f0
Update component tests
kimadeline 8bccb07
yarn lint --fix
kimadeline ab22ea0
Fix most tests
kimadeline 2a308ca
Get the tests passing for now
kimadeline f1664d7
Update TS tests too
kimadeline 7668817
Merge branch 'master' into convert-component-generator-to-ts
peterp 4d912bc
Merge branch 'kimadeline-convert-component-generator-to-ts'
peterp cd07cf3
Fix test fixtures.
peterp 65b2753
Merge pull request #1 from redwoodjs/kimadeline-convert-component-gen…
kimadeline File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
43 changes: 0 additions & 43 deletions
43
packages/cli/src/commands/generate/component/__tests__/component.test.js
This file was deleted.
Oops, something went wrong.
85 changes: 85 additions & 0 deletions
85
packages/cli/src/commands/generate/component/__tests__/component.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
global.__dirname = __dirname | ||
import { loadGeneratorFixture } from 'src/lib/test' | ||
|
||
// TODO: Revert to import from '../component' when it gets types. | ||
import * as component from 'src/commands/generate/component/component' | ||
|
||
type WordFilesType = { [key: string]: string } | ||
|
||
let singleWordDefaultFiles: WordFilesType | ||
let multiWordDefaultFiles: WordFilesType | ||
let javascriptFiles: WordFilesType | ||
let typescriptFiles: WordFilesType | ||
|
||
beforeAll(() => { | ||
singleWordDefaultFiles = component.files({ name: 'User' }) | ||
multiWordDefaultFiles = component.files({ name: 'UserProfile' }) | ||
javascriptFiles = component.files({ | ||
name: 'JavascriptUser', | ||
javascript: true, | ||
}) | ||
typescriptFiles = component.files({ | ||
name: 'TypescriptUser', | ||
typescript: true, | ||
}) | ||
}) | ||
|
||
test('returns exactly 2 files', () => { | ||
expect(Object.keys(singleWordDefaultFiles).length).toEqual(2) | ||
}) | ||
|
||
test('creates a single word component', () => { | ||
expect( | ||
singleWordDefaultFiles['/path/to/project/web/src/components/User/User.tsx'] | ||
).toEqual(loadGeneratorFixture('component', 'singleWordComponent.tsx')) | ||
}) | ||
|
||
test('creates a single word component test', () => { | ||
expect( | ||
singleWordDefaultFiles[ | ||
'/path/to/project/web/src/components/User/User.test.tsx' | ||
] | ||
).toEqual(loadGeneratorFixture('component', 'singleWordComponent.test.tsx')) | ||
}) | ||
|
||
test('creates a multi word component', () => { | ||
expect( | ||
multiWordDefaultFiles[ | ||
'/path/to/project/web/src/components/UserProfile/UserProfile.tsx' | ||
] | ||
).toEqual(loadGeneratorFixture('component', 'multiWordComponent.tsx')) | ||
}) | ||
|
||
test('creates a multi word component test', () => { | ||
expect( | ||
multiWordDefaultFiles[ | ||
'/path/to/project/web/src/components/UserProfile/UserProfile.test.tsx' | ||
] | ||
).toEqual(loadGeneratorFixture('component', 'multiWordComponent.test.tsx')) | ||
}) | ||
|
||
test('creates JS component files if javacript = true', () => { | ||
expect( | ||
javascriptFiles[ | ||
'/path/to/project/web/src/components/JavascriptUser/JavascriptUser.js' | ||
] | ||
).not.toBeUndefined(); | ||
expect( | ||
javascriptFiles[ | ||
'/path/to/project/web/src/components/JavascriptUser/JavascriptUser.test.js' | ||
] | ||
).not.toBeUndefined(); | ||
}) | ||
|
||
test('creates TS component files if typescript = true', () => { | ||
expect( | ||
typescriptFiles[ | ||
'/path/to/project/web/src/components/TypescriptUser/TypescriptUser.tsx' | ||
] | ||
).not.toBeUndefined(); | ||
expect( | ||
typescriptFiles[ | ||
'/path/to/project/web/src/components/TypescriptUser/TypescriptUser.test.tsx' | ||
] | ||
).not.toBeUndefined(); | ||
}) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/cli/src/commands/generate/sdl/__tests__/fixtures/enumGeneratedSdl.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/cli/src/commands/generate/sdl/__tests__/fixtures/multiWordSdl.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import gql from 'graphql-tag' | ||
|
||
export const schema = gql` | ||
type UserProfile { | ||
id: Int! | ||
|
1 change: 1 addition & 0 deletions
1
packages/cli/src/commands/generate/sdl/__tests__/fixtures/multiWordSdlCrud.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import gql from 'graphql-tag' | ||
|
||
export const schema = gql` | ||
type UserProfile { | ||
id: Int! | ||
|
1 change: 1 addition & 0 deletions
1
packages/cli/src/commands/generate/sdl/__tests__/fixtures/singleWordSdl.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import gql from 'graphql-tag' | ||
|
||
export const schema = gql` | ||
type User { | ||
id: Int! | ||
|
1 change: 1 addition & 0 deletions
1
packages/cli/src/commands/generate/sdl/__tests__/fixtures/singleWordSdlCrud.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import gql from 'graphql-tag' | ||
|
||
export const schema = gql` | ||
type Post { | ||
id: Int! | ||
|
1 change: 1 addition & 0 deletions
1
packages/cli/src/commands/generate/service/__tests__/fixtures/multiWord.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import { db } from 'src/lib/db' | ||
|
||
export const userProfiles = () => { | ||
return db.userProfile.findMany() | ||
} |
1 change: 1 addition & 0 deletions
1
packages/cli/src/commands/generate/service/__tests__/fixtures/multiWord.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 8 additions & 9 deletions
17
packages/cli/src/commands/generate/service/__tests__/fixtures/multiWord_crud.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,30 @@ | ||
import { db } from 'src/lib/db' | ||
|
||
export const userProfiles = () => { | ||
return db.userProfile.findMany() | ||
} | ||
|
||
export const userProfile = ({ id }) => { | ||
return db.userProfile.findOne({ | ||
where: { | ||
id, | ||
}, | ||
where: { id }, | ||
}) | ||
} | ||
|
||
export const createUserProfile = ({ input }) => { | ||
return db.userProfile.create({ | ||
data: input, | ||
}) | ||
} | ||
|
||
export const updateUserProfile = ({ id, input }) => { | ||
return db.userProfile.update({ | ||
data: input, | ||
where: { | ||
id, | ||
}, | ||
where: { id }, | ||
}) | ||
} | ||
|
||
export const deleteUserProfile = ({ id }) => { | ||
return db.userProfile.delete({ | ||
where: { | ||
id, | ||
}, | ||
where: { id }, | ||
}) | ||
} |
1 change: 1 addition & 0 deletions
1
packages/cli/src/commands/generate/service/__tests__/fixtures/multiWord_crud.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/cli/src/commands/generate/service/__tests__/fixtures/singleWord.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import { db } from 'src/lib/db' | ||
|
||
export const users = () => { | ||
return db.user.findMany() | ||
} |
1 change: 1 addition & 0 deletions
1
packages/cli/src/commands/generate/service/__tests__/fixtures/singleWord.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 3 additions & 7 deletions
10
packages/cli/src/commands/generate/service/__tests__/fixtures/singleWord_belongsTo.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,10 @@ | ||
import { db } from 'src/lib/db' | ||
|
||
export const users = () => { | ||
return db.user.findMany() | ||
} | ||
|
||
export const User = { | ||
identity: (_obj, { root }) => | ||
db.user | ||
.findOne({ | ||
where: { | ||
id: root.id, | ||
}, | ||
}) | ||
.identity(), | ||
db.user.findOne({ where: { id: root.id } }).identity(), | ||
} |
17 changes: 8 additions & 9 deletions
17
packages/cli/src/commands/generate/service/__tests__/fixtures/singleWord_crud.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,30 @@ | ||
import { db } from 'src/lib/db' | ||
|
||
export const posts = () => { | ||
return db.post.findMany() | ||
} | ||
|
||
export const post = ({ id }) => { | ||
return db.post.findOne({ | ||
where: { | ||
id, | ||
}, | ||
where: { id }, | ||
}) | ||
} | ||
|
||
export const createPost = ({ input }) => { | ||
return db.post.create({ | ||
data: input, | ||
}) | ||
} | ||
|
||
export const updatePost = ({ id, input }) => { | ||
return db.post.update({ | ||
data: input, | ||
where: { | ||
id, | ||
}, | ||
where: { id }, | ||
}) | ||
} | ||
|
||
export const deletePost = ({ id }) => { | ||
return db.post.delete({ | ||
where: { | ||
id, | ||
}, | ||
where: { id }, | ||
}) | ||
} |
1 change: 1 addition & 0 deletions
1
packages/cli/src/commands/generate/service/__tests__/fixtures/singleWord_crud.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 alias!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯this should be default setup across generators for sure!