Code Monkey home page Code Monkey logo

visual-ts's Introduction

VisualTS

A powerful React/Next.js visual code generator for TypeScript projects. Built on top of the ts-generator package.

code-generator

Key Features

  • Module Parsing: Extract information about functions, variables, and types from TypeScript files.
  • Code Generation: Generate new TypeScript code based on parsed information.
  • Function Call Generation: Create TypeScript AST nodes for function calls, including async functions and Promises.
  • Variable Declaration Generation: Generate variable declarations with associated function calls.
  • Unique Variable Naming: Automatically generate unique variable names to avoid conflicts.
  • Type Extraction: Extract and process return types from functions, including Promise types.
  • Drag-and-drop Code Generation: Build custom functions by dragging and dropping functions from your codebase.
  • TypeScript and React Visualization: Visualize the structure and dependencies of TypeScript modules and React components.

Project Structure

  • packages/ts-generator: Core TypeScript utility package
  • apps/next: Next.js app showcasing ts-generator features
  • packages/ui: Shared component library
  • packages/eslint-config: ESLint configurations
  • packages/typescript-config: Shared TypeScript configurations

Installation

To use ts-generator in your project:

npm install @ozhanefe/ts-generator
# or
yarn add @ozhanefe/ts-generator
# or
pnpm add @ozhanefe/ts-generator
# or
bun add @ozhanefe/ts-generator

Note: This package requires TypeScript as a peer dependency.

Usage

Here's a basic example of how to use the ts-generator package:

import { parseFunctionsFromFile, generateCode } from "@ozhanefe/ts-generator";

// Parse functions from a TypeScript file
const { functionsInfo } = parseFunctionsFromFile("path/to/your/file.ts");

// Generate new code based on the parsed functions
const generatedCode = generateCode(functionsInfo);

console.log(generatedCode);

Development

To set up the project for development:

  1. Clone the repository: git clone https://github.com/ozhanefemeral/ts-generator
  2. Install dependencies: bun install
  3. Build all packages: bun build
  4. Start the development server: bun dev
  5. Open the Next.js app in your browser at http://localhost:3000

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Roadmap

Check out our roadmap to see what's coming next.

visual-ts's People

Contributors

ozhanefemeral avatar turbobot-temp avatar github-actions[bot] avatar

Stargazers

Murat Can Bayraktar avatar İbrahim Ödev avatar Melin Kan avatar Burak avatar Ali Osman avatar Umut Sirin avatar

Watchers

 avatar  avatar

visual-ts's Issues

Use TypeScript Compiler API for Creating Interfaces, Types, and Functions

Use TypeScript Compiler API for Creating Interfaces, Types, and Functions

Is your feature request related to a problem? Please describe.
Yes, currently we are dealing with strings to create interfaces, types, and functions, which is non-ideal and error-prone. It also makes it harder to use TypeScript's type-checking capabilities.

Describe the solution you'd like
We should use the TypeScript Compiler API to create interfaces, types, and functions. Specifically, we should utilize createFunctionDeclaration, createTypeAliasDeclaration, and other relevant factory functions.

Describe alternatives you've considered
There shouldn't be any alternative to this.

Additional context
The following file needs to be updated:

  • packages/code-generator/functions.ts

Checklist

  • Add unit tests for the new implementation.
  • Migrate existing string-based code generation to use TypeScript Compiler API.

Create a React SPA with Vite

We need to develop a React Single Page Application (SPA) using Vite for our ts-codegenerator. This will allow us to offer our visual TypeScript tools to users who prefer or require a standalone web application.

The SPA will use the shared component package we're creating and implement the CodeGenerator feature. We'll also integrate the codebase search feature using the JSON generation solution we're developing in a separate issue.

Checklist:

  • Wait for the shared component subpackage issue to be merged #19
  • Create a new Vite app in the monorepo /apps/react-spa
  • Set up TypeScript config for the Vite app
  • Configure ESLint for the Vite app
  • Configure Tailwind for the Vite app
  • Add the @visual-ts/react-components package as a dependency
  • Implement the CodeGenerator feature without search feature, only manual stuff

Generate JSON of scanned and parsed functions for SPA compatibility

We need to create a feature that generates a JSON file containing all scanned and parsed functions in the codebase as FunctionInfo. This will allow our SPA to have access to the codebase information without needing direct file system access.

This feature will be crucial for the upcoming React SPA project and will solve the challenge of codebase scanning in a client-side environment.

Checklist:

  • Modify the existing codebase scanning function to output a JSON file
  • Ensure the JSON structure matches the FunctionInfo interface
  • Create a script to generate this JSON file on-demand
  • Add documentation on how to use this feature
  • Update the ts-codegenerator package to include this new functionality
  • Test the JSON output with a variety of codebases to ensure accuracy and completeness

Create a shared React component subpackage

We need to migrate to a shared component package instead of developing components/hooks in the Next.js app. This way, we can use these pieces across any React environment, SPA, Remix or {insert technology}

The new package, @visual-ts/react-components, will contain the reusable components and hooks currently used in our Next.js app (and the ones we will create in the future 😄 )
Checklist:

  • Create a new subpackage in /packages (let's call it @visual-ts/react-components)
  • Set up TypeScript config for the new subpackage
  • Configure ESLint for the new subpackage
  • Set up Tailwind for the new subpackage
  • Move relevant components and hooks from the Next.js app to the new subpackage
  • Update package.json to include the new subpackage as a dependency
  • Update imports in the Next.js app to use the new subpackage
  • Test to ensure everything still works in the Next.js app

Grab declared variables for function params

Code Generator can declare a variable using a function call and that function may need parameters.

Code Generator should be smart enough to grab already declared variables; and use them as params when needed.

let data = await fetchData()
let parsedData = await parseData(data);

Right now we don't support this feature. That would be a great feature if we introduce it.

Fix `FunctionInfoPopover` click behaviour

Is your feature request related to a problem? Please describe.
The popover component that lets you view the function's code is not working. It worked before we implemented drag-and-drop functionality, but now it is broken.

Describe the solution you'd like
Make the FunctionInfoPopover function well again! and keep the drag-and-drop of course.

Additional context
You can find the FunctionList component in
packages/parser/src/components/project-functions/FunctionList.tsx

and the FunctionInfoPopover in
packages/parser/src/components/shared/FunctionInfoPopover.tsx

This is a good first issue! Feel free to contribute.

Adding Path Aliases for Local Imports within Packages

Is your feature request related to a problem? Please describe.
Yes, the current project structure makes it difficult to manage imports within packages. When importing modules or components from different directories within the same package, we have to use relative paths, which can become hard to maintain as the project grows. While we have successfully configured path aliases for imports across packages, we are facing challenges when it comes to local imports within the same package.

Describe the solution you'd like
The desired solution is to implement path aliases that allow us to import modules or components within the same package using a consistent and concise syntax. Instead of using relative paths like ../../../someModule, we could use an alias like @myPackage/someModule. This would improve code readability, maintainability, and make it easier to refactor code without breaking imports.

Describe alternatives you've considered
This PR (however this solution doesn't have autocomplete, and needs some investigation).

Another alternative is to use project-wide path aliases, but this approach may not be optimal for local imports within packages, as it could lead to naming conflicts or make it harder to reason about the import paths.

Additional context

Right now, our alias imports are autocompleted, but they fail when building:
Screenshot 2024-05-18 at 13 59 42

Screenshot 2024-05-18 at 13 59 13

Standardize ESLint Configuration Across the Project

Standardize ESLint Configuration Across the Project

Background

Currently, the ESLint configurations are inconsistent across the entire project. The following directories and packages are using different ESLint configurations:

  • apps/next
  • apps/docs
  • packages/ui
  • packages/code-generator
  • packages/parser

This inconsistency can lead to code style discrepancies and make it harder to maintain a consistent codebase across the project.

Additionally, there is an existing /eslint-config package in the packages directory, which can potentially be used as the main source for ESLint configuration across the project.

  • Find a eslint config that can be used in both apps and the packages
  • Update eslint-config package
  • Use it across the project
  • Add changes and rules to the documentation

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.