Skip to content

Commit c77336a

Browse files
committed
update async function
1 parent e57d27d commit c77336a

File tree

1 file changed

+28
-24
lines changed

1 file changed

+28
-24
lines changed

utils/update_info.js

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,35 @@ const {
88
namePrefix,
99
} = require(`${basePath}/src/config.js`);
1010

11-
// read json data
12-
let rawdata = fs.readFileSync(`${basePath}/build/json/_metadata.json`);
13-
let data = JSON.parse(rawdata);
14-
15-
console.log("Info will be updated using the config.js data.");
16-
const updateName = await yesno(`Update names?`);
17-
const updateDescription = await yesno(`Update descriptions?`);
18-
const updateBaseUri = await yesno(`Update images base URI?`);
19-
20-
data.forEach((item) => {
21-
if(updateName) item.name = `${namePrefix} #${item.edition}`;
22-
if(updateDescription) item.description = description;
23-
if(updateBaseUri) item.image = `${baseUri}/${item.edition}.png`;
24-
11+
(async () => {
12+
13+
// read json data
14+
let rawdata = fs.readFileSync(`${basePath}/build/json/_metadata.json`);
15+
let data = JSON.parse(rawdata);
16+
17+
console.log("Info will be updated using the config.js data.");
18+
const updateName = await yesno(`Update names?`);
19+
const updateDescription = await yesno(`Update descriptions?`);
20+
const updateBaseUri = await yesno(`Update images base URI?`);
21+
22+
data.forEach((item) => {
23+
if(updateName) item.name = `${namePrefix} #${item.edition}`;
24+
if(updateDescription) item.description = description;
25+
if(updateBaseUri) item.image = `${baseUri}/${item.edition}.png`;
26+
27+
fs.writeFileSync(
28+
`${basePath}/build/json/${item.edition}.json`,
29+
JSON.stringify(item, null, 2)
30+
);
31+
});
32+
2533
fs.writeFileSync(
26-
`${basePath}/build/json/${item.edition}.json`,
27-
JSON.stringify(item, null, 2)
34+
`${basePath}/build/json/_metadata.json`,
35+
JSON.stringify(data, null, 2)
2836
);
29-
});
3037

31-
fs.writeFileSync(
32-
`${basePath}/build/json/_metadata.json`,
33-
JSON.stringify(data, null, 2)
34-
);
38+
if(updateName) console.log(`Updated name prefix for images to ===> ${namePrefix}`);
39+
if(updateBaseUri) console.log(`Updated baseUri for images to ===> ${baseUri}`);
40+
if(updateDescription) console.log(`Updated description for images to ===> ${description}`);
3541

36-
if(updateName) console.log(`Updated name prefix for images to ===> ${namePrefix}`);
37-
if(updateBaseUri) console.log(`Updated baseUri for images to ===> ${baseUri}`);
38-
if(updateDescription) console.log(`Updated description for images to ===> ${description}`);
42+
})();

0 commit comments

Comments
 (0)