-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: Add Next.js codebase scanning and server action generation - Add Next.js specific types, scanner, and generator * feat: add type support for jest - Add new function `analyzeNextjsSourceFiles` to handle the source files - Update `scanNextjsCodebase` to call `analyzeNextjsSourceFiles` and return the result - Add tests * chore: bump version * switch to bun and update CI * chore: Update ESLint configuration and dependencies * chore: Update dependencies and add TypeScript support for Jest
- Loading branch information
1 parent
4ac1682
commit ae4b8ad
Showing
22 changed files
with
332 additions
and
88 deletions.
There are no files selected for viewing
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,5 @@ | ||
--- | ||
"@ozhanefe/ts-codegenerator": minor | ||
--- | ||
|
||
add eslint config |
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,5 @@ | ||
--- | ||
"@ozhanefe/ts-codegenerator": minor | ||
--- | ||
|
||
nextjs support |
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,5 @@ | ||
--- | ||
"@ozhanefe/ts-codegenerator": minor | ||
--- | ||
|
||
add nextjs parsing/generator features |
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,37 @@ | ||
const { resolve } = require("node:path"); | ||
|
||
const project = resolve(process.cwd(), "tsconfig.json"); | ||
|
||
/** @type {import("eslint").Linter.Config} */ | ||
module.exports = { | ||
root: true, | ||
extends: ["eslint:recommended", "prettier"], | ||
plugins: ["only-warn", "@typescript-eslint"], | ||
parser: "@typescript-eslint/parser", | ||
parserOptions: { | ||
project: "./tsconfig.json", | ||
tsconfigRootDir: __dirname, | ||
}, | ||
env: { | ||
node: true, | ||
}, | ||
settings: { | ||
"import/resolver": { | ||
typescript: { | ||
project, | ||
}, | ||
}, | ||
}, | ||
ignorePatterns: [".*.js", "node_modules/", "dist/"], | ||
overrides: [ | ||
{ | ||
files: ["*.js?(x)", "*.ts?(x)"], | ||
}, | ||
{ | ||
files: ["**/*.test.ts", "**/*.test.tsx"], | ||
env: { | ||
jest: true, | ||
}, | ||
}, | ||
], | ||
}; |
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,30 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- "**" | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: oven-sh/setup-bun@v1 | ||
with: | ||
bun-version: latest | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18.x | ||
|
||
- name: Install dependencies | ||
run: bun install | ||
|
||
- name: Lint | ||
run: bun run lint | ||
|
||
- name: Build | ||
run: bun run build | ||
|
||
- name: Test | ||
run: bun run test |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,36 @@ | ||
name: Release ts-codegenerator | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- "packages/ts-generator/**" | ||
|
||
jobs: | ||
release: | ||
name: Release | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Repo | ||
uses: actions/checkout@v3 | ||
with: | ||
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits | ||
fetch-depth: 0 | ||
|
||
- name: Setup Bun | ||
uses: oven-sh/setup-bun@v1 | ||
|
||
- name: Install Dependencies | ||
run: bun install | ||
|
||
- name: Create Release Pull Request or Publish to npm | ||
id: changesets | ||
uses: changesets/action@v1 | ||
with: | ||
# This expects your changesets to be in the root packages/ts-generator/.changeset | ||
cwd: ./packages/ts-generator | ||
publish: bun run release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
This file was deleted.
Oops, something went wrong.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export { getFunctionInfoFromNode } from "./parser"; | ||
export { getFunctionInfoFromNode, parseFunctionsFromText } from "./parser"; | ||
export { getFunctionVariables } from "./utils"; |
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,96 @@ | ||
import { Project } from "ts-morph"; | ||
import { | ||
analyzeNextjsSourceFiles, | ||
generateServerAction, | ||
ServerActionInfo, | ||
} from "../index"; | ||
|
||
describe("Next.js functionality", () => { | ||
let project: Project; | ||
|
||
beforeEach(() => { | ||
project = new Project({ useInMemoryFileSystem: true }); | ||
}); | ||
|
||
describe("analyzeNextjsSourceFiles", () => { | ||
it("should correctly identify and parse server actions", () => { | ||
const serverActionCode = ` | ||
"use server"; | ||
export async function submitForm(data: FormData) { | ||
// Server action logic | ||
} | ||
export async function deleteItem(id: string) { | ||
// Delete item logic | ||
} | ||
`; | ||
|
||
const sourceFile = project.createSourceFile( | ||
"app/actions.ts", | ||
serverActionCode | ||
); | ||
|
||
const result = analyzeNextjsSourceFiles([sourceFile]); | ||
|
||
expect(result.serverActions).toHaveLength(2); | ||
expect(result.serverActions[0]?.name).toBe("submitForm"); | ||
expect(result.serverActions[1]?.name).toBe("deleteItem"); | ||
}); | ||
|
||
it("should not identify non-server actions", () => { | ||
const regularCode = ` | ||
export function regularFunction() { | ||
// Regular function logic | ||
} | ||
`; | ||
|
||
const sourceFile = project.createSourceFile( | ||
"app/regular.ts", | ||
regularCode | ||
); | ||
|
||
const result = analyzeNextjsSourceFiles([sourceFile]); | ||
|
||
expect(result.serverActions).toHaveLength(0); | ||
}); | ||
}); | ||
|
||
describe("generateServerAction", () => { | ||
it("should generate correct server action code", () => { | ||
const serverActionInfo: ServerActionInfo = { | ||
name: "testAction", | ||
returnType: "Promise<string>", // This could be 'string' or 'Promise<string>', the function should handle both | ||
parameters: [ | ||
{ name: "data", type: "FormData" }, | ||
{ name: "userId", type: "string" }, | ||
], | ||
filePath: "app/actions.ts", | ||
}; | ||
|
||
const generatedCode = generateServerAction(serverActionInfo); | ||
|
||
expect(generatedCode).toContain('"use server";'); | ||
expect(generatedCode).toContain( | ||
"export async function testAction(data: FormData, userId: string): Promise<string>" | ||
); | ||
expect(generatedCode).toContain("// TODO: Implement server action logic"); | ||
expect(generatedCode).toContain('throw new Error("Not implemented");'); | ||
}); | ||
|
||
it("should handle non-Promise return types", () => { | ||
const serverActionInfo: ServerActionInfo = { | ||
name: "testAction", | ||
returnType: "void", | ||
parameters: [], | ||
filePath: "app/actions.ts", | ||
}; | ||
|
||
const generatedCode = generateServerAction(serverActionInfo); | ||
|
||
expect(generatedCode).toContain( | ||
"export async function testAction(): Promise<void>" | ||
); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.