Skip to content

A Roblox Luau library for converting Instances into code snippets

Notifications You must be signed in to change notification settings

cxmeel/codify-lib

Repository files navigation

CodifyLib

A decoupled implementation of the Codify plugin's internal "Instance-to-snippet" conversion module.


Looking for the Codify plugin?

Purchase on Roblox Purchase on Itch.io

Codify converts Roblox Instances into code snippets in a flash. Whether you use vanilla Roblox Luau, TypeScript JSX, or a framework like React/Roact, Fusion, Vide or Rojo, Codify’s got you covered!


Contributors

The following individuals have contributed to the development of CodifyLib:

  • @boatbomber - Implemented original generators for Fusion and vanilla Roblox.
  • @PepeElToro41 - Implemented original JSX generator.

Example Usage

local CodifyLib = require("path/to/CodifyLib")
local Generators = CodifyLib.Generators

-- Setup the React generator with a custom config
local react = Generators.React({
    indentation = "  ",
    createMethod = "e",
    names = "all",
})

-- Generate the snippet, targeting the Baseplate
-- with a custom config
local snippet = CodifyLib.codify(workspace.Baseplate, {
    generator = react,
    caseFormat = "camel", -- Render keys/variables in camelCase
    userFormats = {
        color3 = "hex", -- Render Color3 values as hex
    },
})

print("Snippet:", snippet)

Generators

CodifyLib comes with a variety of generators to suit your needs:

Roblox

Generates vanilla Roblox Lua code (i.e. Instance.new).

type Config = {
    indentation: string?, -- default: "    "
    names: ("all" | "none" | "changed")?, -- default: "all"
}?

Fusion

Fusion is a reactive framework for Roblox Luau, created by @dphfox.
Learn more →

type Config = {
    indentation: string?, -- default: "    "
    createMethod: string?, -- default: "scope:New"
    childrenKey: string?, -- default: "Children"
    names: ("all" | "none" | "changed")?, -- default: "all"
}

React

React for Roblox is a translation of React17 from JavaScript to Lua by @roblox and @jsdotlua.
Learn more →

type Config = {
    indentation: string?, -- default: "    "
    createMethod: string?, -- default: "React.createElement"
    names: ("all" | "none" | "changed")?,
}

Jsx

JSX allows HTML-like syntax to be used in TypeScript for Roblox. It is part of the roblox-ts project.
Learn more →

type Config = {
    indentation: string?, -- default: "    "
    names: ("all" | "none" | "changed")?, -- default: "all"
    lowercaseKeyProp: boolean?, -- default: false
}

UserFormats

CodifyLib allows you to define the way datatypes are formatted in the resulting snippets. This can be useful for customizing the output to match your coding style.

The default for all values is "full".

type UserFormats = {
    color3: "full" | "hex" | "hsv" | "rgb",
    udim2: "full",
    numberRange: "full",
    enum: "full" | "number" | "string",
    normalId: "full",
    brickColor: "full" | "number" | "rgb",
    physicalProperties: "full",
    udim: "full",
    cframe: "full",
    vector2: "full",
    vector3: "full",
    font: "full",
    colorSequence: "full",
    numberSequence: "full",
}

Codify for Roblox Studio
Purchase on Roblox | Purchase on Itch.io | Learn more