Skip to content

Commit 5f34751

Browse files
committed
rescript parser WIP
1 parent 0878c64 commit 5f34751

File tree

11 files changed

+237
-0
lines changed

11 files changed

+237
-0
lines changed

src/parser/.bsb.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
49528

src/parser/.merlin

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
####{BSB GENERATED: NO EDIT
2+
FLG -ppx '/Users/dielduarte/localhost/animate-css-styled-components/src/parser/node_modules/rescript/darwin/bsc.exe -as-ppx '
3+
S /Users/dielduarte/localhost/animate-css-styled-components/src/parser/node_modules/rescript/lib/ocaml
4+
B /Users/dielduarte/localhost/animate-css-styled-components/src/parser/node_modules/rescript/lib/ocaml
5+
FLG -w +a-4-9-20-40-41-42-50-61-102
6+
S src
7+
B lib/bs/src
8+
S src/bindings
9+
B lib/bs/src/bindings
10+
####BSB GENERATED: NO EDIT}

src/parser/bsconfig.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "your-project-name",
3+
"sources": [
4+
{
5+
"dir": "src",
6+
"subdirs": true
7+
}
8+
],
9+
"package-specs": [
10+
{
11+
"module": "commonjs",
12+
"in-source": true
13+
}
14+
],
15+
"suffix": ".bs.js",
16+
"bs-dependencies": []
17+
}

src/parser/package-lock.json

Lines changed: 83 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/parser/package.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "parser",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1",
8+
"re:build": "rescript",
9+
"re:start": "rescript build -w"
10+
},
11+
"keywords": [],
12+
"author": "",
13+
"license": "ISC",
14+
"devDependencies": {
15+
"rescript": "^9.1.2"
16+
},
17+
"dependencies": {
18+
"css-tree": "^1.1.3"
19+
}
20+
}

src/parser/src/AnimatedComponent.bs.js

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/parser/src/AnimatedComponent.res

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
let generateAnimatedComponent = (~animationCode, ~componentName) => {
2+
let result = "
3+
import styled, { keyframes } from 'styled-components';
4+
import BaseAnimation from '../BaseAnimation';
5+
6+
const ${componentName}Animation = keyframes`
7+
${animationCode}
8+
`;
9+
10+
const ${componentName} = styled(BaseAnimation)`
11+
animation-name: ${${componentName}Animation};
12+
`;
13+
14+
export default ${componentName};
15+
"
16+
17+
let replaceComponentName = Js.String.replaceByRe(%re("/\${componentName}/g"), componentName)
18+
let replaceAnimationCode = Js.String.replaceByRe(%re("/\${animationCode}/g"), animationCode)
19+
20+
result->replaceComponentName->replaceAnimationCode
21+
}

src/parser/src/bindings/CssTree.bs.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/parser/src/bindings/CssTree.res

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
type node = {
2+
"type": string,
3+
@set
4+
"name": string,
5+
"block": {"type": string, "children": array<string>},
6+
}
7+
8+
@module("css-tree")
9+
external parse: string => 'a = "parse"
10+
11+
@module("css-tree")
12+
external generate: 'a => string = "generate"
13+
14+
@module("css-tree")
15+
external walk: ('a, node => unit) => unit = "walk"

src/parser/src/index.bs.js

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/parser/src/index.res

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
let ast = CssTree.parse("@keyframes zoomInLeft {
2+
from {
3+
opacity: 0;
4+
transform: scale3d(0.1, 0.1, 0.1) translate3d(-1000px, 0, 0);
5+
animation-timing-function: cubic-bezier(0.55, 0.055, 0.675, 0.19);
6+
}
7+
8+
60% {
9+
opacity: 1;
10+
transform: scale3d(0.475, 0.475, 0.475) translate3d(10px, 0, 0);
11+
animation-timing-function: cubic-bezier(0.175, 0.885, 0.32, 1);
12+
}
13+
}
14+
15+
.zoomInLeft {
16+
animation-name: zoomInLeft;
17+
}")
18+
19+
CssTree.walk(ast, node => {
20+
if node["type"] === "Atrule" {
21+
AnimatedComponent.generateAnimatedComponent(
22+
~animationCode=CssTree.generate(node["block"]),
23+
~componentName="NameOne",
24+
)->Js.log
25+
}
26+
})
27+
28+
// @TODO
29+
// - get animation name
30+
// - get Animation extra styles
31+
// - import animation file
32+
// - script to clone animate css and read files
33+
// - script to generate a new animat-css-library version

0 commit comments

Comments
 (0)