Skip to content

Commit f5d7f35

Browse files
authored
Merge pull request #4 from line/refactor/unnecessary-settings
Refactor: remove unnecessary setting
2 parents 09bae35 + ff8c29e commit f5d7f35

File tree

9 files changed

+28
-105
lines changed

9 files changed

+28
-105
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ node_modules
1111
dist
1212
dist-ssr
1313
*.local
14+
vite.config.ts.*
15+
16+
output.config.json
1417

1518
# Editor directories and files
1619
.vscode/*

.husky/pre-commit

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
. "$(dirname -- "$0")/_/husky.sh"
33

44
pnpm install
5+
pnpm configcheck
56
pnpm typecheck
67
pnpm lint
78
pnpm stylelint

README.md

+2-12
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ The `app.config.json` should be as below;
136136

137137
1. Prepare 16:9 ratio images
138138
2. Set image file name with rgb color with comma `rrr,ggg,bbb` between two dots, only if you need to set text color. (ex. 01.255,255,255.jpg)
139-
3. Add background image files into `public/backgrounds/**/*`. (or any other directory and set `backgroundsUri` as relative path.)
139+
3. Add background image files into `backgrounds/**/*`. (or any other directory and set `backgroundsUri` as relative path.)
140140
4. `pnpm run build` or `pnpm run dev`
141-
5. `app.config.json` 's `themes`'s `backgrounds` value will be changed automatically.
141+
5. `output.config.json` 's `themes`'s `backgrounds` value will be changed automatically.
142142

143143
- with CDN images
144144

@@ -308,16 +308,6 @@ With above structure, let say you want to override `themes` node for `office` th
308308
}
309309
]
310310
}
311-
],
312-
"backgrounds": [
313-
{
314-
"theme": "office",
315-
"src": "office/01.jpg"
316-
},
317-
{
318-
"theme": "office",
319-
"src": "office/02.jpg"
320-
}
321311
]
322312
}
323313
]

app.config.json

+3-84
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@
1919
"small": "3rem",
2020
"caption": "1.5rem"
2121
},
22-
"styles": [
23-
"LINE Seed"
24-
]
22+
"styles": ["LINE Seed"]
2523
},
2624
"defaultInputFields": [
2725
{
@@ -61,42 +59,7 @@
6159
],
6260
"themes": [
6361
{
64-
"name": "office",
65-
"backgrounds": [
66-
{
67-
"theme": "office",
68-
"src": "backgrounds/office/01.jpg"
69-
},
70-
{
71-
"theme": "office",
72-
"src": "backgrounds/office/02.jpg"
73-
},
74-
{
75-
"theme": "office",
76-
"src": "backgrounds/office/03.jpg"
77-
},
78-
{
79-
"theme": "office",
80-
"src": "backgrounds/office/04.jpg"
81-
},
82-
{
83-
"theme": "office",
84-
"src": "backgrounds/office/05.jpg"
85-
},
86-
{
87-
"theme": "office",
88-
"src": "backgrounds/office/06.jpg"
89-
},
90-
{
91-
"theme": "office",
92-
"src": "backgrounds/office/07.jpg"
93-
},
94-
{
95-
"theme": "office",
96-
"src": "backgrounds/office/08.255,255,255.jpg",
97-
"fontColor": "255,255,255"
98-
}
99-
]
62+
"name": "office"
10063
},
10164
{
10265
"name": "nature",
@@ -149,28 +112,6 @@
149112
}
150113
]
151114
}
152-
],
153-
"backgrounds": [
154-
{
155-
"theme": "nature",
156-
"src": "backgrounds/nature/01.jpg"
157-
},
158-
{
159-
"theme": "nature",
160-
"src": "backgrounds/nature/02.jpg"
161-
},
162-
{
163-
"theme": "nature",
164-
"src": "backgrounds/nature/03.jpg"
165-
},
166-
{
167-
"theme": "nature",
168-
"src": "backgrounds/nature/04.jpg"
169-
},
170-
{
171-
"theme": "nature",
172-
"src": "backgrounds/nature/05.jpg"
173-
}
174115
]
175116
},
176117
{
@@ -216,29 +157,7 @@
216157
}
217158
]
218159
}
219-
],
220-
"backgrounds": [
221-
{
222-
"theme": "texture",
223-
"src": "backgrounds/texture/01.jpg"
224-
},
225-
{
226-
"theme": "texture",
227-
"src": "backgrounds/texture/02.jpg"
228-
},
229-
{
230-
"theme": "texture",
231-
"src": "backgrounds/texture/03.jpg"
232-
},
233-
{
234-
"theme": "texture",
235-
"src": "backgrounds/texture/04.jpg"
236-
},
237-
{
238-
"theme": "texture",
239-
"src": "backgrounds/texture/05.jpg"
240-
}
241160
]
242161
}
243162
]
244-
}
163+
}

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
1111
"stylelint": "stylelint \"src/**/*.scss\"",
1212
"typecheck": "tsc --noEmit",
13+
"configcheck": "test -f output.config.json || cp app.config.json output.config.json",
1314
"format": "prettier --check \"./src/**/*.{js,cjs,mjs,ts,tsx,md,json}\"",
1415
"prepare": "husky install"
1516
},

src/App.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* under the License.
1515
*/
1616
import { CSSProperties, useEffect, useRef } from "react";
17-
import { keyColor, title } from "~/app.config.json";
17+
import { keyColor, title } from "~/output.config.json";
1818

1919
import {
2020
DownloadButton,

src/constants/font.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* License for the specific language governing permissions and limitations
1414
* under the License.
1515
*/
16-
import config from "~/app.config.json";
16+
import config from "~/output.config.json";
1717

1818
export const FontSizes: Record<string, string> = {} as const;
1919
Object.keys(config.fonts.sizes).forEach(

src/hooks/useAppConfiguration/AppContext.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
useEffect,
2323
useState,
2424
} from "react";
25-
import config from "~/app.config.json";
25+
import config from "~/output.config.json";
2626
import axios, { AxiosError } from "axios";
2727

2828
import { Image, InputFieldGroup, Theme } from "@/constants";
@@ -73,7 +73,6 @@ export const AppProvider = (props: PropsWithChildren) => {
7373
const { defaultInputFields } = config;
7474
const [themes, setThemes] = useState<Array<Theme>>([]);
7575
const [selectedImage, setSelectedImage] = useState<Image>({
76-
theme: "",
7776
src: "",
7877
});
7978
const [selectedTheme, setSelectedTheme] = useState("all");
@@ -86,7 +85,7 @@ export const AppProvider = (props: PropsWithChildren) => {
8685
case "filesystem":
8786
case "cdn":
8887
setThemes(config.themes as Array<Theme>);
89-
setSelectedImage(config.themes[0].backgrounds[0]);
88+
setSelectedImage((config.themes[0] as Theme)?.backgrounds[0] ?? []);
9089
break;
9190
case "github":
9291
try {

vite.config.ts

+14-4
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,22 @@ function copyBackgroundsForFileSystem() {
5151
const filteredFileContentsArray = fileContentsArray.filter(
5252
({ theme: fileTheme }) => fileTheme === theme,
5353
);
54-
config.themes[index].backgrounds = filteredFileContentsArray;
54+
config.themes[index]["backgrounds"] = filteredFileContentsArray.map(
55+
({ src, fontColor }) => (fontColor ? { src, fontColor } : { src }),
56+
);
5557
});
5658

57-
const configJsonPath = path.join(dir, "app.config.json");
59+
const configJsonPath = path.join(dir, "output.config.json");
5860
fs.writeFileSync(configJsonPath, JSON.stringify(config, null, 2));
5961

6062
return copy({
6163
targets: [{ src: sourceDirectory, dest: targetDirectory }],
6264
hook: "writeBundle",
6365
});
66+
} else {
67+
const dir = path.resolve();
68+
const configJsonPath = path.join(dir, "output.config.json");
69+
fs.writeFileSync(configJsonPath, JSON.stringify(config, null, 2));
6470
}
6571
}
6672

@@ -76,18 +82,22 @@ function readFilesRecursively(dir) {
7682

7783
sortedFiles.forEach((file) => {
7884
const filePath = path.join(dir, file);
85+
const theme = dir.replace(
86+
path.join(config.backgroundsUri.path, path.sep),
87+
"",
88+
);
7989

8090
if (fs.statSync(filePath).isDirectory()) {
8191
readFiles(filePath);
8292
} else if (isImageFile(filePath)) {
8393
const item = file.split(".")?.[2]
8494
? {
85-
theme: dir.replace(`${config.backgroundsUri.path}/`, ""),
95+
theme,
8696
src: filePath,
8797
fontColor: file.split(".")[1],
8898
}
8999
: {
90-
theme: dir.replace(`${config.backgroundsUri.path}/`, ""),
100+
theme,
91101
src: filePath,
92102
};
93103
fileContentsArray.push(item);

0 commit comments

Comments
 (0)