Skip to content

Commit

Permalink
Create file watch for type def generation (#2614)
Browse files Browse the repository at this point in the history
* Add babel deps for parsing ast trees.

* Add code to abstract ast parsing.

* Find all the cells in a project.

* Add function to fetch all the cell files.

* Fix TS warning.

* Find all directory named imports in a project.

* Fix tests for Windows.

* Create mirror directory in getPaths.

* Partially convert fixture to TypeScript.

* Generate mirror types for Cells.

* Improve conditional checks for magic-modules.

* Clean up comments.

* Convert fixture api side to TypeScript.

* Generate directory named module mirror files.

* Remove whitespace in generated type.

* Remove "devtools" concept. Internal is always build time.

* Bump lock file.

* Fix test.

* Improve performance by removing import-time computation.

* Fix lint errors.

* Export fn to generate types.

* Add helpful alias for testing the CLI.

* Add command to generate types.

* Rename mirror types to generate types.

* Generate global types for imported pages.

* Replace glob with fast-glob.

* Remove pre-build-tasks and replace with generate-types.

* Add jsx ast tools.

* Clean up generate types.

* Bump yarn lock.

* Fix tests.

* Clean up some code.

* Fix lint and tests.

* Rename findFiles to files.

* Remove type generation from babel-plugins.

* Fix build script.

* Adjust generated paths.

* Prefix type definition templates.

* Add side prefix to generated includes.

* Remove unused mock from test.

* Add helper for creating type def include files.

* Generate all types.

* Add new ways to find files.

* Improve gen-type-def function names.

* Export file finders and type-def generators.

* Add file watcher stub.

* A note about process pages dir.

* Add some notes for outstanding things.

* Add is DirNamedModule check.

* Move file watcher.

* Fix some comments.

* Delete mirror directory for remove files.

* Move code-gen packages.

* Move GraphQL operation generation to internal.

* Make fixture app work again.

* Generate the GraphQL types.

* Lint.

* Find GraphQL schema files.

* Remove test matcher.

* Add graphql schema to paths.

* Add schema-ast.

* Keep todos count.

* Add way to generate graphql schema.

* Point graphql config to generated schema.

* Make generate types command do the work.

* Make watcher generate graphql schema and typedefs.

* Use rw-gen-watch command in dev.

* Clean up output.

* Fix windows tests?

* Update template tsconfigs.

* skipLibCheck already in compiler options config.
  • Loading branch information
peterp committed May 31, 2021
1 parent 9153749 commit dc4730b
Show file tree
Hide file tree
Showing 74 changed files with 12,762 additions and 4,862 deletions.
8 changes: 4 additions & 4 deletions __fixtures__/example-todo-main/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ yarn-error.log
.env
.DS_Store
.wip

api/prisma/dev.sqlite
packages/photon/runtime
packages/photon/index.js
packages/photon/index.d.ts

# Generated files
.redwood
api/types/
web/types/
9 changes: 0 additions & 9 deletions __fixtures__/example-todo-main/api/jsconfig.json

This file was deleted.

2 changes: 1 addition & 1 deletion __fixtures__/example-todo-main/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"name": "api",
"version": "0.0.0",
"dependencies": {
"@redwoodjs/api": "0.7.0"
"@redwoodjs/api": "0.32.2"
}
}
4 changes: 2 additions & 2 deletions __fixtures__/example-todo-main/api/src/functions/graphql.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import {
makeMergedSchema,
makeServices,
} from '@redwoodjs/api'

import schemas from 'src/graphql/**/*.{js,ts}'
import { db } from 'src/lib/db'
import services from 'src/services/**/*.{js,ts}'

import { db } from 'src/lib/db'

export const handler = createGraphQLHandler({
schema: makeMergedSchema({
schemas,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const schema = gql`
type Query {
currentUser: JSON
}
`
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const schema = gql`
type Query {
todos: [Todo]
todosCount: Int!
}
type Mutation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ export const todos = () => db.todo.findMany()

export const createTodo = ({ body }) => db.todo.create({ data: { body } })

export const numTodos = () => 0

export const updateTodoStatus = ({ id, status }) =>
db.todo.update({
data: { status },
Expand Down
32 changes: 32 additions & 0 deletions __fixtures__/example-todo-main/api/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"compilerOptions": {
"noEmit": true,
"allowJs": true,
"esModuleInterop": true,
"target": "esnext",
"module": "esnext",
"moduleResolution": "node",
"baseUrl": "./",
"rootDirs": [
"./src",
"../.redwood/types/mirror/api/src"
],
"paths": {
"src/*": [
"./src/*",
"../.redwood/types/mirror/api/src/*"
],
"types/*": ["./types/*"]
},
"typeRoots": [
"../node_modules/@types",
"./node_modules/@types"
],
"types": ["jest"],
},
"include": [
"src",
"../.redwood/types/includes/all-*",
"../.redwood/types/includes/api-*",
]
}
5 changes: 3 additions & 2 deletions __fixtures__/example-todo-main/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
"private": true,
"workspaces": [
"api",
"web"
"web",
"../../packages/*"
],
"devDependencies": {
"@redwoodjs/core": "0.7.0"
"@redwoodjs/core": "0.32.2"
},
"eslintConfig": {
"extends": "@redwoodjs/eslint-config"
Expand Down
9 changes: 0 additions & 9 deletions __fixtures__/example-todo-main/web/jsconfig.json

This file was deleted.

8 changes: 4 additions & 4 deletions __fixtures__/example-todo-main/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"name": "web",
"version": "0.0.0",
"dependencies": {
"@redwoodjs/router": "0.7.0",
"@redwoodjs/web": "0.7.0",
"@redwoodjs/router": "0.32.2",
"@redwoodjs/web": "0.32.2",
"prop-types": "^15.7.2",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-is": "^16.8.0",
"styled-components": "^5.1.0"
}
Expand Down
17 changes: 17 additions & 0 deletions __fixtures__/example-todo-main/web/src/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { FatalErrorBoundary } from '@redwoodjs/web'
import { RedwoodApolloProvider } from '@redwoodjs/web/apollo'

import FatalErrorPage from 'src/pages/FatalErrorPage'
import Routes from './Routes'

import './index.css'

const App = () => (
<FatalErrorBoundary page={FatalErrorPage}>
<RedwoodApolloProvider>
<Routes />
</RedwoodApolloProvider>
</FatalErrorBoundary>
)

export default App
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default () => {
return (<>I am not a cell, I am a component that is named cell.</>)
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import styled from 'styled-components'
import TodoItem from 'src/components/TodoItem'

import { useMutation } from '@redwoodjs/web'

import TodoItem from 'src/components/TodoItem'

export const QUERY = gql`
query TodoListCell_GetTodos {
todos {
Expand Down
16 changes: 0 additions & 16 deletions __fixtures__/example-todo-main/web/src/index.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import styled from 'styled-components'

import AddTodo from 'src/components/AddTodo'
import TodoListCell from 'src/components/TodoListCell'

Expand Down
34 changes: 34 additions & 0 deletions __fixtures__/example-todo-main/web/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"compilerOptions": {
"noEmit": true,
"esModuleInterop": true,
"allowJs": true,
"target": "esnext",
"module": "esnext",
"moduleResolution": "node",
"baseUrl": "./",
"paths": {
"src/*": [
"./src/*",
"../.redwood/types/mirror/web/src/*"
]
},
"rootDirs": [
"./src",
"../.redwood/types/mirror/web/src"
],
"typeRoots": [
"../node_modules/@types",
"./node_modules/@types"
],
"types": [
"jest"
],
"jsx": "preserve",
},
"include": [
"src",
"../.redwood/types/includes/all-*",
"../.redwood/types/includes/web-*",
]
}
Loading

0 comments on commit dc4730b

Please sign in to comment.