Skip to content

Commit 8034065

Browse files
committed
Add --with-native-for-reason, --with-web-for-reason & remove --with-reason & --bs-module-path
1 parent 87a9e6a commit 8034065

24 files changed

+1200
-972
lines changed

README.md

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,43 +28,47 @@ Usage
2828
$ react-from-svg <sourcePath> <outputPath> [--with-native|--with-web]
2929

3030
Options
31-
--with-native, -native Output code for react-native-svg
32-
--with-web, -web Output code for DOM. If --with-native is also used, will be output as .web.js files
33-
--with-reason, -bs Output ReasonML bindings code
34-
--remove-fill, -rf Remove all 'fill' properties from SVGs, convenient for icons
35-
--remove-stroke, -rs Remove all 'stroke' properties from SVGs, convenient for icons
36-
--commonjs, -cjs Export as commonjs instead of es6 import/export
37-
--bs-module-path, -bsp Allow to customise ReasonML output path
31+
--with-native, -native Output code for react-native-svg
32+
--with-web, -web Output code for DOM. If --with-native is also used, will be output as .web.js files
33+
--with-native-for-reason, -bsnative Output code for @reason-react-native/svg
34+
--with-web-for-reason, -bsnweb Output code for reason-react
35+
--remove-fill, -rf Remove all 'fill' properties from SVGs, convenient for icons
36+
--remove-stroke, -rs Remove all 'stroke' properties from SVGs, convenient for icons
37+
--commonjs, -cjs Export as commonjs instead of es6 import/export
3838

3939
Example
40-
$ react-from-svg assets/svgs src/Svgs --remove-fill
40+
$ react-from-svg assets/svgs src/Svgs --with-native --remove-fill
4141
```
4242

43-
### Examples
43+
## Requirements
4444

45-
#### React DOM, no options
45+
### `--with-web`
4646

47-
```console
48-
react-from-svg assets/svgs src/Svgs --with-web
49-
```
47+
Need you to install have:
5048

51-
#### React Native with fill svg props removed
49+
- [React](https://reactjs.org)
5250

53-
```console
54-
react-from-svg assets/svgs src/Svgs --with-native --remove-fill
55-
```
51+
### `--with-web-for-reason`
5652

57-
#### React Native + ReasonML bindings SVGs
53+
Need you to install have:
5854

59-
```console
60-
react-from-svg assets/svgs src/Svgs --with-native --with-reason
61-
```
55+
- [React](https://reactjs.org)
56+
- [`reason-react`](https://reasonml.github.io/reason-react/)
6257

63-
#### React Native + ReasonML bindings SVGs and absolute path
58+
### `--with-native`
6459

65-
It's usefull if you defined a webpack alias and you don't generate your
66-
bucklescript output `"in-source"`
60+
Need you to install have:
6761

68-
```console
69-
react-from-svg assets/svgs src/Svgs --with-reason --reason-module-path=./src/components
70-
```
62+
- [React](https://reactjs.org)
63+
- [React Native](https://reactnative.dev) (or an alternative platform like
64+
[React Native Web](https://github.com/necolas/react-native-web))
65+
- [`react-native-svg`](https://github.com/react-native-community/react-native-svg)
66+
67+
### `--with-native-for-reason`
68+
69+
In addition to `--with-native` requirements, you need to install & add as
70+
`bs-dependencies` in your `bsconfig.json`:
71+
72+
- [`reason-react`](https://reasonml.github.io/reason-react/)
73+
- [`reason-react-native`](https://reason-react-native.github.io)
74+
- [`@reason-react-native/svg`](https://github.com/reason-react-native/svg)

__tests__/TransformNative.re

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
open Node.Fs;
2+
3+
open Jest;
4+
open Expect;
5+
6+
let fixtures = "./__tests__/__fixtures__";
7+
8+
let snap = (svg, ~removeFill, ~removeStroke) => {
9+
svg
10+
->Transformer.transformSvg(
11+
~removeFill,
12+
~removeStroke,
13+
~js=true,
14+
~pascalCaseTag=true,
15+
~template=Templates.native(~commonjs=false),
16+
)
17+
->expect
18+
->toMatchSnapshot;
19+
};
20+
21+
let testAll = svg => {
22+
test("all options", () =>
23+
svg->snap(~removeFill=true, ~removeStroke=true)
24+
);
25+
test("remove-fill", () =>
26+
svg->snap(~removeFill=true, ~removeStroke=false)
27+
);
28+
test("remove-stroke", () =>
29+
svg->snap(~removeFill=false, ~removeStroke=true)
30+
);
31+
};
32+
33+
describe("simple svg", () =>
34+
readFileSync(fixtures ++ "/simple.svg", `utf8)->testAll
35+
);
36+
37+
describe("edge case width svg", () =>
38+
readFileSync(fixtures ++ "/edge-case-width.svg", `utf8)->testAll
39+
);
40+
41+
describe("clean & minimal svg", () =>
42+
readFileSync(fixtures ++ "/clean.svg", `utf8)->testAll
43+
);
44+
45+
describe("sketch export", () =>
46+
readFileSync(fixtures ++ "/sketch-export.svg", `utf8)->testAll
47+
);
48+
49+
describe("with fill", () =>
50+
readFileSync(fixtures ++ "/with-fill.svg", `utf8)->testAll
51+
);
52+
53+
describe("with stroke", () =>
54+
readFileSync(fixtures ++ "/with-stroke.svg", `utf8)->testAll
55+
);

__tests__/Test.re renamed to __tests__/TransformNativeForReason.re

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ open Node.Fs;
33
open Jest;
44
open Expect;
55

6+
let fixtures = "./__tests__/__fixtures__";
7+
68
let snap = (svg, ~removeFill, ~removeStroke) => {
79
svg
810
->Transformer.transformSvg(
911
~removeFill,
1012
~removeStroke,
11-
~commonjs=false,
13+
~js=false,
1214
~pascalCaseTag=true,
13-
~template=Templates.native,
15+
~template=Templates.nativeForReason,
1416
)
1517
->expect
1618
->toMatchSnapshot;
@@ -29,25 +31,25 @@ let testAll = svg => {
2931
};
3032

3133
describe("simple svg", () =>
32-
readFileSync("./__tests__/fixtures/simple.svg", `utf8)->testAll
34+
readFileSync(fixtures ++ "/simple.svg", `utf8)->testAll
3335
);
3436

3537
describe("edge case width svg", () =>
36-
readFileSync("./__tests__/fixtures/edge-case-width.svg", `utf8)->testAll
38+
readFileSync(fixtures ++ "/edge-case-width.svg", `utf8)->testAll
3739
);
3840

3941
describe("clean & minimal svg", () =>
40-
readFileSync("./__tests__/fixtures/clean.svg", `utf8)->testAll
42+
readFileSync(fixtures ++ "/clean.svg", `utf8)->testAll
4143
);
4244

4345
describe("sketch export", () =>
44-
readFileSync("./__tests__/fixtures/sketch-export.svg", `utf8)->testAll
46+
readFileSync(fixtures ++ "/sketch-export.svg", `utf8)->testAll
4547
);
4648

4749
describe("with fill", () =>
48-
readFileSync("./__tests__/fixtures/with-fill.svg", `utf8)->testAll
50+
readFileSync(fixtures ++ "/with-fill.svg", `utf8)->testAll
4951
);
5052

5153
describe("with stroke", () =>
52-
readFileSync("./__tests__/fixtures/with-stroke.svg", `utf8)->testAll
54+
readFileSync(fixtures ++ "/with-stroke.svg", `utf8)->testAll
5355
);

__tests__/TransformWeb.re

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
open Node.Fs;
2+
3+
open Jest;
4+
open Expect;
5+
6+
let fixtures = "./__tests__/__fixtures__";
7+
8+
let snap = (svg, ~removeFill, ~removeStroke) => {
9+
svg
10+
->Transformer.transformSvg(
11+
~removeFill,
12+
~removeStroke,
13+
~js=true,
14+
~pascalCaseTag=false,
15+
~template=Templates.web(~commonjs=false),
16+
)
17+
->expect
18+
->toMatchSnapshot;
19+
};
20+
21+
let testAll = svg => {
22+
test("all options", () =>
23+
svg->snap(~removeFill=true, ~removeStroke=true)
24+
);
25+
test("remove-fill", () =>
26+
svg->snap(~removeFill=true, ~removeStroke=false)
27+
);
28+
test("remove-stroke", () =>
29+
svg->snap(~removeFill=false, ~removeStroke=true)
30+
);
31+
};
32+
33+
describe("simple svg", () =>
34+
readFileSync(fixtures ++ "/simple.svg", `utf8)->testAll
35+
);
36+
37+
describe("edge case width svg", () =>
38+
readFileSync(fixtures ++ "/edge-case-width.svg", `utf8)->testAll
39+
);
40+
41+
describe("clean & minimal svg", () =>
42+
readFileSync(fixtures ++ "/clean.svg", `utf8)->testAll
43+
);
44+
45+
describe("sketch export", () =>
46+
readFileSync(fixtures ++ "/sketch-export.svg", `utf8)->testAll
47+
);
48+
49+
describe("with fill", () =>
50+
readFileSync(fixtures ++ "/with-fill.svg", `utf8)->testAll
51+
);
52+
53+
describe("with stroke", () =>
54+
readFileSync(fixtures ++ "/with-stroke.svg", `utf8)->testAll
55+
);

__tests__/TransformWebForReason.re

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
open Node.Fs;
2+
3+
open Jest;
4+
open Expect;
5+
6+
let fixtures = "./__tests__/__fixtures__";
7+
8+
let snap = (svg, ~removeFill, ~removeStroke) => {
9+
svg
10+
->Transformer.transformSvg(
11+
~removeFill,
12+
~removeStroke,
13+
~js=false,
14+
~pascalCaseTag=false,
15+
~template=Templates.webForReason,
16+
)
17+
->expect
18+
->toMatchSnapshot;
19+
};
20+
21+
let testAll = svg => {
22+
test("all options", () =>
23+
svg->snap(~removeFill=true, ~removeStroke=true)
24+
);
25+
test("remove-fill", () =>
26+
svg->snap(~removeFill=true, ~removeStroke=false)
27+
);
28+
test("remove-stroke", () =>
29+
svg->snap(~removeFill=false, ~removeStroke=true)
30+
);
31+
};
32+
33+
describe("simple svg", () =>
34+
readFileSync(fixtures ++ "/simple.svg", `utf8)->testAll
35+
);
36+
37+
describe("edge case width svg", () =>
38+
readFileSync(fixtures ++ "/edge-case-width.svg", `utf8)->testAll
39+
);
40+
41+
describe("clean & minimal svg", () =>
42+
readFileSync(fixtures ++ "/clean.svg", `utf8)->testAll
43+
);
44+
45+
describe("sketch export", () =>
46+
readFileSync(fixtures ++ "/sketch-export.svg", `utf8)->testAll
47+
);
48+
49+
describe("with fill", () =>
50+
readFileSync(fixtures ++ "/with-fill.svg", `utf8)->testAll
51+
);
52+
53+
describe("with stroke", () =>
54+
readFileSync(fixtures ++ "/with-stroke.svg", `utf8)->testAll
55+
);
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)