Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into darklua
Browse files Browse the repository at this point in the history
  • Loading branch information
vocksel committed Apr 12, 2024
2 parents f4a8b67 + 2a742e5 commit 235050c
Show file tree
Hide file tree
Showing 117 changed files with 149 additions and 44 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.luau linguist-language=Lua
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ jobs:

- uses: extractions/setup-just@v1

- name: Lint file extensions
run: ./bin/lint.sh

- name: Get model file name
run: |
name=$(jq -r .name default.project.json)
Expand Down
2 changes: 1 addition & 1 deletion bin/analyze.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ curl -s -O https://raw.githubusercontent.com/JohnnyMorganz/luau-lsp/master/scrip

rojo sourcemap tests.project.json -o sourcemap.json

luau-lsp analyze --sourcemap=sourcemap.json --defs=globalTypes.d.lua --defs=testez.d.lua --ignore=**/_Index/** src/
luau-lsp analyze --sourcemap=sourcemap.json --defs=globalTypes.d.lua --defs=testez.d.luau --ignore=**/_Index/** src/
exit_code=$?

rm globalTypes.d.lua
Expand Down
11 changes: 11 additions & 0 deletions bin/lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

set -euo pipefail

echo "Lint file extensions"
files=$(find src example -iname "*.lua")
if [[ -n "$files" ]]; then
echo "Error: one or more files are using the '.lua' extension. Please update these to '.luau' and try again"
echo "$files"
exit 1
fi
2 changes: 1 addition & 1 deletion bin/test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
rojo build tests.project.json -o tests.rbxl
run-in-roblox --place tests.rbxl --script tests/init.server.lua
run-in-roblox --place tests.rbxl --script tests/init.server.luau
rm tests.rbxl
2 changes: 1 addition & 1 deletion docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Then load a new Baseplate and open the flipbook plugin. Its storybook should now

## Testing

While developing, you should also be writing unit tests. Unit tests are written in `.spec.lua` files. You can see examples of this throughout the repository's codebase.
While developing, you should also be writing unit tests. Unit tests are written in `.spec.luau` files. You can see examples of this throughout the repository's codebase.

To run tests, simply start the experience in Studio. You will see in the output if tests are passing or failing.

Expand Down
16 changes: 8 additions & 8 deletions docs/migrating.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ This guide assumes you are using [Rojo](https://github.com/rojo-rbx/rojo/) to ma

The main difference in how flipbook and Hoarcekat handle stories is that flipbook requires a "storybook" file to know where your stories are. As such, to migrate over from Hoarcekat the first thing you should do is create a storybook for your project.

To do this, create a new `ProjectName.storybook.lua` file at the root of your project with the following contents:
To do this, create a new `ProjectName.storybook.luau` file at the root of your project with the following contents:

```lua
-- Make sure to adjust the path to Roact if needed
-- Make sure to adjust the path to Roact if needed
local Roact = require(script.Parent.Parent.Roact)

return {
roact = Roact,
storyRoots = {
storyRoots = {
script.Parent.Components
}
}
Expand All @@ -38,13 +38,13 @@ To fully benefit from the features flipbook has to offer, this section will guid
We will use the following component and story as an example:

```lua
-- HelloWorld.lua
-- HelloWorld.luau
type Props = {
name: string?
}

local function HelloWorld(props: Props)
local name = props.name or "World"
local name = props.name or "World"

return Roact.createElement("TextLabel", {
Text = ("Hello %s!"):format(name),
Expand All @@ -60,7 +60,7 @@ return HelloWorld
```

```lua
-- HelloWorld.story.lua
-- HelloWorld.story.luau
local Roact = require(script.Parent.Parent.Roact)
local HelloWorld = require(script.Parent.HelloWorld)

Expand All @@ -82,7 +82,7 @@ end
Converting a Hoarcekat story like this into one compatible with flipbook is quite easy. In fact, all that's needed from the above story is the call to `Roact.createElement`:

```lua
-- HelloWorld.story.lua
-- HelloWorld.story.luau
local Roact = require(script.Parent.Parent.Roact)
local HelloWorld = require(script.Parent.HelloWorld)

Expand Down Expand Up @@ -137,4 +137,4 @@ You are now equipped to migrate your other Hoarcekat stories over to flipbook!
## Further Reading

- [Writing Stories](writing-stories.md)
- [Story Format](story-format.md)
- [Story Format](story-format.md)
12 changes: 6 additions & 6 deletions docs/story-format.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ The only required prop is the `storyRoots` array, which tells flipbook which Ins
Example:

```lua
-- example/Example.storybook.lua
-- example/Example.storybook.luau
return {
name = "Example Storybook",
storyRoots = {
Expand All @@ -47,7 +47,7 @@ Support for Roblox's [Roact](https://github.com/Roblox/roact) library is built i
Example:

```lua
-- example/Button.story.lua
-- example/Button.story.luau
local Example = script:FindFirstAncestor("Example")

local Roact = require(Example.Parent.Packages.Roact)
Expand All @@ -68,7 +68,7 @@ return {
Example with controls:

```lua
-- example/ButtonWithControls.story.lua
-- example/ButtonWithControls.story.luau
local Example = script:FindFirstAncestor("Example")

local Roact = require(Example.Parent.Packages.Roact)
Expand Down Expand Up @@ -116,7 +116,7 @@ You can find React and ReactRoblox as part of the [CorePackages](https://github.
Example:

```lua
-- example/ReactCounter.story.lua
-- example/ReactCounter.story.luau
local Example = script:FindFirstAncestor("Example")

local React = require(Example.Parent.Packages.React)
Expand Down Expand Up @@ -160,7 +160,7 @@ A Functional story uses a function to create and mount UI. This is the most flex
Example:

```lua
-- example/Functional.story.lua
-- example/Functional.story.luau
local controls = {
text = "Functional Story",
}
Expand Down Expand Up @@ -206,7 +206,7 @@ See the [migration guide](migrating.md) for more info.
Example:

```lua
-- example/Hoarcekat.story.lua
-- example/Hoarcekat.story.luau
local Example = script:FindFirstAncestor("Example")

local Roact = require(Example.Parent.Packages.Roact)
Expand Down
16 changes: 8 additions & 8 deletions docs/writing-stories.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ flipbook uses the concept of "storybooks" and "stories." A storybook is used to

## Storybook

Every project needs a storybook, so to get started you will create a new `ProjectName.storybook.lua` file at the root of your project with the following contents:
Every project needs a storybook, so to get started you will create a new `ProjectName.storybook.luau` file at the root of your project with the following contents:

```lua
-- src/ProjectName.storybook.lua
-- src/ProjectName.storybook.luau

-- Make sure to adjust the path to Roact if needed
-- Make sure to adjust the path to Roact if needed
local Roact = require(path.to.Roact)

return {
roact = Roact,
storyRoots = {
storyRoots = {
script.Parent.Components
}
}
Expand All @@ -30,10 +30,10 @@ Right now you should see a single entry in flipbook's sidebar for this storybook

## Story

A story and its associated component should be in two separate files. Both files should share the same name, however the story will end with `.story`. To get started, let's create `Button.lua` and `Button.story.lua`:
A story and its associated component should be in two separate files. Both files should share the same name, however the story will end with `.story`. To get started, let's create `Button.luau` and `Button.story.luau`:

```lua
-- src/Components/Button.lua
-- src/Components/Button.luau

local Roact = require(path.to.Roact)

Expand Down Expand Up @@ -68,7 +68,7 @@ return Button
And now let's write the story to mount the Button component:

```lua
-- src/Components/Button.story.lua
-- src/Components/Button.story.luau

local Roact = require(path.to.Roact)
local Button = require(script.Parent.Button)
Expand Down Expand Up @@ -185,4 +185,4 @@ With this change, a new "Controls" panel will appear where you can toggle the `i

You have just been given an example of how to create a storybook and a story for a Button component that makes use of flipbook's controls feature. This document outlines the biggest features of flipbook, but there are other options you can play around with.

Check out [Story Format](story-format.md) next to learn about all the options you have available.
Check out [Story Format](story-format.md) next to learn about all the options you have available.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ local Sift = require("@pkg/Sift")
local Directory = require("./Directory")
local Story = require("./Story")
local types = require("@root/Explorer/types")
local getTreeDescendants = require("@root/Explorer/getTreeDescendants")
local filterComponentTreeNode = require("@root/Explorer/filterComponentTreeNode")

local e = React.createElement

Expand Down Expand Up @@ -58,22 +58,8 @@ local function Component(providedProps: Props)
end
end

if props.filter then
if props.node.icon == "story" and not props.node.name:lower():match(props.filter:lower()) then
return
end

local isEmpty = true
for _, descendant in getTreeDescendants(props.node) do
if descendant.name:lower():match(props.filter:lower()) then
isEmpty = false
break
end
end

if isEmpty then
return
end
if props.filter and filterComponentTreeNode(props.node, props.filter) then
return
end

return e("Frame", {
Expand Down
27 changes: 27 additions & 0 deletions src/Explorer/filterComponentTreeNode.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
local flipbook = script:FindFirstAncestor("flipbook")

local types = require(flipbook.Explorer.types)

local getTreeDescendants = require(script.Parent.getTreeDescendants)

local function filterComponentTreeNode(node: types.ComponentTreeNode, filter: string): boolean
if node.icon == "story" then
if not node.name:lower():match(filter:lower()) then
return true
end

return false
end

local isEmpty = true
for _, descendant in getTreeDescendants(node) do
if descendant.name:lower():match(filter:lower()) then
isEmpty = false
break
end
end

return isEmpty
end

return filterComponentTreeNode
77 changes: 77 additions & 0 deletions src/Explorer/filterComponentTreeNode.spec.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
local flipbook = script:FindFirstAncestor("flipbook")

local types = require(flipbook.Explorer.types)

return function()
local filterComponentTreeNode = require(script.Parent.filterComponentTreeNode)

it("should return true when the query does not match the story name", function()
local target: types.ComponentTreeNode = {
children = {},
name = "test",
icon = "story",
}
local query = "other"

local result = filterComponentTreeNode(target, query)
expect(result).to.equal(true)
end)

it("should return false the query matches the story name", function()
local target: types.ComponentTreeNode = {
children = {},
name = "test",
icon = "story",
}
local query = "tes"

local result = filterComponentTreeNode(target, query)
expect(result).to.equal(false)
end)

it("should return true when the filter does not match any of node in tree", function()
local target: types.ComponentTreeNode = {
children = {
{
children = {},
name = "test",
icon = "story",
},
{
children = {},
name = "folder",
icon = "folder",
},
},
name = "storybook",
icon = "storybook",
}
local query = "other"

local result = filterComponentTreeNode(target, query)
expect(result).to.equal(true)
end)

it("should return false when a filter match at least one of nodes in tree", function()
local target: types.ComponentTreeNode = {
children = {
{
children = {},
name = "test",
icon = "story",
},
{
children = {},
name = "folder",
icon = "folder",
},
},
name = "storybook",
icon = "storybook",
}
local query = "tes"

local result = filterComponentTreeNode(target, query)
expect(result).to.equal(false)
end)
end
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/Explorer/types.lua → src/Explorer/types.luau
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ type Storybook = storybookTypes.Storybook
export type ComponentTreeNode = {
name: string,
children: { ComponentTreeNode },
icon: string?,
icon: ("folder" | "story" | "storybook")?,
instance: Instance?,
storybook: Storybook?,
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tarmac.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ name = "flipbook"
[[inputs]]
glob = "img/**/*.png"
codegen = true
codegen-path = "src/assets.lua"
codegen-path = "src/assets.luau"
codegen-base-path = "img"
packable = true
File renamed without changes.
File renamed without changes.

0 comments on commit 235050c

Please sign in to comment.