Add more instance types
This commit is contained in:
@@ -12,7 +12,6 @@ This transformer automatically converts constructor-style instance creation (`ne
|
||||
- 🔍 Full TypeScript type safety
|
||||
- ⚡ Zero runtime overhead (transforms at compile-time)
|
||||
- 🔄 Supports all creatable Roblox instance types
|
||||
- 📦 Easy to install and use
|
||||
|
||||
## Installation
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "rbxts-transformer-instances",
|
||||
"version": "1.0.0",
|
||||
"version": "1.0.1",
|
||||
"description": "Enable the use of instance constructors, reducing boilerplate.",
|
||||
"main": "out/index.js",
|
||||
"author": "evilbocchi",
|
||||
|
||||
@@ -128,6 +128,26 @@ declare const CreatableInstancesWithConstructors: CreatableInstancesWithConstruc
|
||||
return content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the instance-classes.ts file content
|
||||
* @param {string[]} classNames List of creatable instance class names
|
||||
* @returns {string} The content for the instance-classes.ts file
|
||||
*/
|
||||
function generateInstanceClassesFile(classNames) {
|
||||
return `/**
|
||||
* This file is auto-generated by the generate-instance-classes script.
|
||||
* Do not modify manually.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Array of all creatable Roblox instance class names
|
||||
* Used by the transformer to identify constructor calls
|
||||
*/
|
||||
export const CREATABLE_INSTANCES = [
|
||||
${classNames.map(name => `"${name}"`).join(",\n ")}
|
||||
];`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Main function
|
||||
*/
|
||||
@@ -135,12 +155,17 @@ function main() {
|
||||
const classNames = getCreatableInstanceNames();
|
||||
console.log(`Found ${classNames.length} creatable instance types`);
|
||||
|
||||
// Generate and write declarations file
|
||||
const declarationsContent = generateDeclarations(classNames);
|
||||
const outputPath = path.join(__dirname, '..', 'index.d.ts');
|
||||
const declarationsPath = path.join(__dirname, '..', 'index.d.ts');
|
||||
fs.writeFileSync(declarationsPath, declarationsContent, 'utf-8');
|
||||
console.log(`Successfully generated declarations in ${declarationsPath}`);
|
||||
|
||||
// Write to file
|
||||
fs.writeFileSync(outputPath, declarationsContent, 'utf-8');
|
||||
console.log(`Successfully generated declarations in ${outputPath}`);
|
||||
// Generate and write instance-classes.ts
|
||||
const instanceClassesContent = generateInstanceClassesFile(classNames);
|
||||
const instanceClassesPath = path.join(__dirname, '..', 'src', 'instance-classes.ts');
|
||||
fs.writeFileSync(instanceClassesPath, instanceClassesContent, 'utf-8');
|
||||
console.log(`Successfully generated instance classes in ${instanceClassesPath}`);
|
||||
|
||||
console.log('Example declarations:');
|
||||
const examples = classNames.slice(0, 5);
|
||||
|
||||
@@ -0,0 +1,301 @@
|
||||
/**
|
||||
* This file is auto-generated by the generate-instance-classes script.
|
||||
* Do not modify manually.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Array of all creatable Roblox instance class names
|
||||
* Used by the transformer to identify constructor calls
|
||||
*/
|
||||
export const CREATABLE_INSTANCES = [
|
||||
"Accessory",
|
||||
"AccessoryDescription",
|
||||
"Accoutrement",
|
||||
"Actor",
|
||||
"AdGui",
|
||||
"AdPortal",
|
||||
"AirController",
|
||||
"AlignOrientation",
|
||||
"AlignPosition",
|
||||
"AngularVelocity",
|
||||
"Animation",
|
||||
"AnimationConstraint",
|
||||
"AnimationController",
|
||||
"AnimationRigData",
|
||||
"Animator",
|
||||
"Annotation",
|
||||
"ArcHandles",
|
||||
"Atmosphere",
|
||||
"AtmosphereSensor",
|
||||
"Attachment",
|
||||
"AudioAnalyzer",
|
||||
"AudioChannelMixer",
|
||||
"AudioChannelSplitter",
|
||||
"AudioChorus",
|
||||
"AudioCompressor",
|
||||
"AudioDeviceInput",
|
||||
"AudioDeviceOutput",
|
||||
"AudioDistortion",
|
||||
"AudioEcho",
|
||||
"AudioEmitter",
|
||||
"AudioEqualizer",
|
||||
"AudioFader",
|
||||
"AudioFilter",
|
||||
"AudioFlanger",
|
||||
"AudioLimiter",
|
||||
"AudioListener",
|
||||
"AudioPitchShifter",
|
||||
"AudioPlayer",
|
||||
"AudioReverb",
|
||||
"AudioSearchParams",
|
||||
"AudioTextToSpeech",
|
||||
"AuroraScript",
|
||||
"Backpack",
|
||||
"BallSocketConstraint",
|
||||
"Beam",
|
||||
"BillboardGui",
|
||||
"BindableEvent",
|
||||
"BindableFunction",
|
||||
"BlockMesh",
|
||||
"BloomEffect",
|
||||
"BlurEffect",
|
||||
"BodyAngularVelocity",
|
||||
"BodyColors",
|
||||
"BodyForce",
|
||||
"BodyGyro",
|
||||
"BodyPartDescription",
|
||||
"BodyPosition",
|
||||
"BodyThrust",
|
||||
"BodyVelocity",
|
||||
"Bone",
|
||||
"BoolValue",
|
||||
"BoxHandleAdornment",
|
||||
"Breakpoint",
|
||||
"BrickColorValue",
|
||||
"BubbleChatMessageProperties",
|
||||
"BuoyancySensor",
|
||||
"CFrameValue",
|
||||
"Camera",
|
||||
"CanvasGroup",
|
||||
"CharacterMesh",
|
||||
"ChorusSoundEffect",
|
||||
"ClickDetector",
|
||||
"ClimbController",
|
||||
"Clouds",
|
||||
"Color3Value",
|
||||
"ColorCorrectionEffect",
|
||||
"ColorGradingEffect",
|
||||
"CompressorSoundEffect",
|
||||
"ConeHandleAdornment",
|
||||
"Configuration",
|
||||
"ControllerManager",
|
||||
"ControllerPartSensor",
|
||||
"CornerWedgePart",
|
||||
"CurveAnimation",
|
||||
"CustomLog",
|
||||
"CylinderHandleAdornment",
|
||||
"CylinderMesh",
|
||||
"CylindricalConstraint",
|
||||
"DataStoreGetOptions",
|
||||
"DataStoreIncrementOptions",
|
||||
"DataStoreOptions",
|
||||
"DataStoreSetOptions",
|
||||
"Decal",
|
||||
"DepthOfFieldEffect",
|
||||
"Dialog",
|
||||
"DialogChoice",
|
||||
"DistortionSoundEffect",
|
||||
"DoubleConstrainedValue",
|
||||
"DragDetector",
|
||||
"Dragger",
|
||||
"EchoSoundEffect",
|
||||
"EqualizerSoundEffect",
|
||||
"EulerRotationCurve",
|
||||
"ExperienceInviteOptions",
|
||||
"ExplorerFilter",
|
||||
"Explosion",
|
||||
"FaceControls",
|
||||
"FileMesh",
|
||||
"Fire",
|
||||
"FlangeSoundEffect",
|
||||
"FloatCurve",
|
||||
"FloorWire",
|
||||
"FluidForceSensor",
|
||||
"Folder",
|
||||
"ForceField",
|
||||
"Frame",
|
||||
"GetTextBoundsParams",
|
||||
"Glue",
|
||||
"GroundController",
|
||||
"Handles",
|
||||
"HapticEffect",
|
||||
"Hat",
|
||||
"HiddenSurfaceRemovalAsset",
|
||||
"Highlight",
|
||||
"HingeConstraint",
|
||||
"Hole",
|
||||
"Humanoid",
|
||||
"HumanoidController",
|
||||
"HumanoidDescription",
|
||||
"HumanoidRigDescription",
|
||||
"IKControl",
|
||||
"ImageButton",
|
||||
"ImageHandleAdornment",
|
||||
"ImageLabel",
|
||||
"InputAction",
|
||||
"InputBinding",
|
||||
"InputContext",
|
||||
"IntConstrainedValue",
|
||||
"IntValue",
|
||||
"InternalSyncItem",
|
||||
"IntersectOperation",
|
||||
"Keyframe",
|
||||
"KeyframeMarker",
|
||||
"KeyframeSequence",
|
||||
"LineForce",
|
||||
"LineHandleAdornment",
|
||||
"LinearVelocity",
|
||||
"LocalScript",
|
||||
"LocalizationTable",
|
||||
"ManualGlue",
|
||||
"ManualWeld",
|
||||
"MarkerCurve",
|
||||
"MaterialVariant",
|
||||
"MeshPart",
|
||||
"Model",
|
||||
"ModuleScript",
|
||||
"Motor",
|
||||
"Motor6D",
|
||||
"MotorFeature",
|
||||
"NegateOperation",
|
||||
"NoCollisionConstraint",
|
||||
"Noise",
|
||||
"NumberPose",
|
||||
"NumberValue",
|
||||
"ObjectValue",
|
||||
"OperationGraph",
|
||||
"Pants",
|
||||
"Part",
|
||||
"PartOperation",
|
||||
"ParticleEmitter",
|
||||
"Path2D",
|
||||
"PathfindingLink",
|
||||
"PathfindingModifier",
|
||||
"PitchShiftSoundEffect",
|
||||
"Plane",
|
||||
"PlaneConstraint",
|
||||
"PluginCapabilities",
|
||||
"PointLight",
|
||||
"Pose",
|
||||
"PrismaticConstraint",
|
||||
"ProximityPrompt",
|
||||
"RTAnimationTracker",
|
||||
"RayValue",
|
||||
"RelativeGui",
|
||||
"RemoteEvent",
|
||||
"RemoteFunction",
|
||||
"ReverbSoundEffect",
|
||||
"RigidConstraint",
|
||||
"RocketPropulsion",
|
||||
"RodConstraint",
|
||||
"RopeConstraint",
|
||||
"Rotate",
|
||||
"RotateP",
|
||||
"RotateV",
|
||||
"RotationCurve",
|
||||
"ScreenGui",
|
||||
"Script",
|
||||
"ScrollingFrame",
|
||||
"Seat",
|
||||
"SelectionBox",
|
||||
"SelectionPartLasso",
|
||||
"SelectionPointLasso",
|
||||
"SelectionSphere",
|
||||
"Shirt",
|
||||
"ShirtGraphic",
|
||||
"SkateboardController",
|
||||
"SkateboardPlatform",
|
||||
"Sky",
|
||||
"Smoke",
|
||||
"Snap",
|
||||
"Sound",
|
||||
"SoundGroup",
|
||||
"Sparkles",
|
||||
"SpawnLocation",
|
||||
"SpecialMesh",
|
||||
"SphereHandleAdornment",
|
||||
"SpotLight",
|
||||
"SpringConstraint",
|
||||
"StarterGear",
|
||||
"StringValue",
|
||||
"StudioAttachment",
|
||||
"StudioCallout",
|
||||
"StyleDerive",
|
||||
"StyleLink",
|
||||
"StyleRule",
|
||||
"StyleSheet",
|
||||
"SunRaysEffect",
|
||||
"SurfaceAppearance",
|
||||
"SurfaceGui",
|
||||
"SurfaceLight",
|
||||
"SurfaceSelection",
|
||||
"SwimController",
|
||||
"Team",
|
||||
"TeleportOptions",
|
||||
"TerrainDetail",
|
||||
"TerrainRegion",
|
||||
"TextBox",
|
||||
"TextButton",
|
||||
"TextChannel",
|
||||
"TextChatCommand",
|
||||
"TextChatMessageProperties",
|
||||
"TextLabel",
|
||||
"Texture",
|
||||
"Tool",
|
||||
"Torque",
|
||||
"TorsionSpringConstraint",
|
||||
"TrackerStreamAnimation",
|
||||
"Trail",
|
||||
"TremoloSoundEffect",
|
||||
"TrussPart",
|
||||
"UIAspectRatioConstraint",
|
||||
"UICorner",
|
||||
"UIDragDetector",
|
||||
"UIFlexItem",
|
||||
"UIGradient",
|
||||
"UIGridLayout",
|
||||
"UIListLayout",
|
||||
"UIPadding",
|
||||
"UIPageLayout",
|
||||
"UIScale",
|
||||
"UISizeConstraint",
|
||||
"UIStroke",
|
||||
"UITableLayout",
|
||||
"UITextSizeConstraint",
|
||||
"UnionOperation",
|
||||
"UniversalConstraint",
|
||||
"UnreliableRemoteEvent",
|
||||
"Vector3Curve",
|
||||
"Vector3Value",
|
||||
"VectorForce",
|
||||
"VehicleController",
|
||||
"VehicleSeat",
|
||||
"VelocityMotor",
|
||||
"VideoDeviceInput",
|
||||
"VideoDisplay",
|
||||
"VideoFrame",
|
||||
"VideoPlayer",
|
||||
"ViewportFrame",
|
||||
"VisualizationMode",
|
||||
"VisualizationModeCategory",
|
||||
"WedgePart",
|
||||
"Weld",
|
||||
"WeldConstraint",
|
||||
"Wire",
|
||||
"WireframeHandleAdornment",
|
||||
"WorkspaceAnnotation",
|
||||
"WorldModel",
|
||||
"WrapDeformer",
|
||||
"WrapLayer",
|
||||
"WrapTarget"
|
||||
];
|
||||
+3
-9
@@ -1,4 +1,5 @@
|
||||
import ts from "typescript";
|
||||
import { CREATABLE_INSTANCES } from "./instance-classes";
|
||||
|
||||
/**
|
||||
* This is the transformer's configuration, the values are passed from the tsconfig.
|
||||
@@ -40,15 +41,8 @@ function visitExpression(context: TransformContext, node: ts.Expression): ts.Exp
|
||||
if (ts.isIdentifier(expression)) {
|
||||
const className = expression.text;
|
||||
|
||||
// Check if it's an Instance-derived class (assuming basic Roblox classes for now)
|
||||
const instanceClasses = [
|
||||
"Part", "Model", "Folder", "Script", "LocalScript", "ModuleScript",
|
||||
"Frame", "TextLabel", "TextButton", "ImageLabel", "ImageButton",
|
||||
"Sound", "Animation", "BoolValue", "StringValue", "NumberValue",
|
||||
// Add more Roblox classes as needed
|
||||
];
|
||||
|
||||
if (instanceClasses.includes(className)) {
|
||||
// Use the imported list of creatable instances
|
||||
if (CREATABLE_INSTANCES.includes(className)) {
|
||||
const { factory } = context;
|
||||
|
||||
// Create new Instance("ClassName") expression
|
||||
|
||||
Vendored
Reference in New Issue
Block a user