Giter Site home page Giter Site logo

ai-prompt-coder's Introduction

Introduction

ai-prompt-coder uses ChatGPT to write code based on .prompt files. It will build a prompt based on a set of rules applied to your directory structure. All rules are defined in .promptRules. Please see /examples for existing rules you can utilise.

Usage

Setting up

  • Install

    yarn add ai-prompt-coder
    
  • Create a .promptRules in your root directory. A basic rule that will be applied to all generated prompts looks as follows:

    -- src/**/*.prompt
    Project written in TypeScript with: React.
  • To exclude files, add them to an array after the glob pattern:

    -- **/components/**/*.tsx.prompt ["**/*.stories.tsx.prompt"]
    Rule applied to all components, excluding StoryBook examples.

A full example may look as follows:

-- src/**/*.prompt

This project uses: TypeScript, React, MUI, lodash, styled-components.

-- **/components/**/*.tsx.prompt ["**/*.stories.tsx.prompt"]

Follow the approach shown in this example:

```tsx
export interface IMyComponentProps {...}
export const MyComponent: React.FC<IMyComponentProps> = ({ ... }) => { ... }
```

No default export.
Include a class comment explaining the purpose of the component.
Use existing MUI components if necessary.

-- **/components/**/*.stories.tsx.prompt

Storybook example demonstrating all props.
Follow the approach shown in this example:

```ts
import React from "react";
import type { Meta, StoryFn } from "@storybook/react";
import { action } from "@storybook/addon-actions";
import { MyComponent, IMyComponentProps } from "./MyComponent";

const meta: Meta = {
  title: "Example/MyComponent",
  component: MyComponent,
  parameters: {
    layout: "centered"
  },
  argTypes: {
    onClick: { action: "clicked" }
  }
};

export default meta;

const Template: StoryFn<IMyComponentProps> = (args) => <MyComponent {...args} />;

export const Default = Template.bind({});
Default.args = {
  onClick: action("digit-click")
};
```

-- **/helpers/*.ts.prompt

Do not include any examples or tests in the code.
Ensure the function is exported.
Add a comment describing the purpose of the function.

-- **/helpers/**/*.spec.ts.prompt

Use Jest for testing.

Generating files

To generate a file:

  • Create a file called _prompts/OUTPUT_NAME.prompt. For example, create Timer.tsx.prompt with the following:

    Create a component named Timer that displays the ellapsed time since started.
  • Run using npx ai-prompt-coder. This will produce a Timer.tsx file.

  • If you are unhappy with the file, delete and run again.

  • You can embed other files using the markup [[./relative-path/filename]]. For example:

    Create a component that displays an Image [[../types/Image.ts]].

ai-prompt-coder's People

Contributors

torbensko avatar

Watchers

 avatar

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.