Skip to content
This repository was archived by the owner on Dec 8, 2023. It is now read-only.

chore: try it #177

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .grit/workflows/extract_colors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import * as grit from '@getgrit/api';

export async function execute() {
const tokens = await grit.stdlib.apply(
{
query: `engine marzano(0.1)
language js

js"colors = { $colors }" where {
$dunk = js"thing",
$colors <: some bubble($alias) js"$name: theme.$label" where {
// Build the next rewrite inline
// $alias += js"\`'$name'\` => \`'$label'\`, "
}
}`,
extract: ['$dunk'],
},
{},
);
if (!tokens.success) return tokens;
console.log('got back', tokens);
// const rewrites = tokens.outputs.find((o) => o.name === '$alias').content;
// const query = `engine marzano
// language js

// js"color($color)" where { $color <: or { ${rewrites} }`;
// console.log(query);
// const colors = await grit.stdlib.apply(
// {
// query,
// },
// {},
// );

return {
success: true,
message: `Success.`,
};
}
23 changes: 23 additions & 0 deletions colors.grit
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
engine marzano(0.1)
language js

files(files = and {
$alias_list = [],
// First we gather everything up by looking for our colors file
some bubble($alias_list) { file($body) where {
$body <: contains js"colors = { $colors }",
$colors <: some bubble($alias_list) $alias where { $alias_list += $alias }
} },
// Then we actually use it
some bubble($alias_list) { file($body) where {
$body <: contains js"color($color)" where {
$alias_list <: some bubble($color, $value) js"$name: theme.$label" where {
// Cast it to a string
$literal = js"'$name'",
$color <: $literal,
$value = js"'$label'"
},
$color => js"$value"
}
}}
})
9 changes: 9 additions & 0 deletions samples/tokenize-colors/scheme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const theme = {
blueOne: '#1E88E5',
blueTwo: '#1976D2',
};

export const colors = {
bg: theme.blueOne,
fg: theme.blueTwo,
};
3 changes: 3 additions & 0 deletions samples/tokenize-colors/usage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const Component = styled.div`
color: ${color('bg')};
`;