diff options
author | 2024-05-04 11:11:19 +0530 | |
---|---|---|
committer | 2024-05-04 11:11:19 +0530 | |
commit | d29479157c9eea4c0d1f36dc23e7fed55143f460 (patch) | |
tree | 2c2e7fb951d7c73249f6e6ff52f768805a15066c /scripts/package.js | |
parent | chore: change icons to reduce bundle (diff) | |
download | ferdium-recipes-d29479157c9eea4c0d1f36dc23e7fed55143f460.tar.gz ferdium-recipes-d29479157c9eea4c0d1f36dc23e7fed55143f460.tar.zst ferdium-recipes-d29479157c9eea4c0d1f36dc23e7fed55143f460.zip |
Replace 'await' calls with '*Sync' calls - which also removes eslint disables
Diffstat (limited to 'scripts/package.js')
-rw-r--r-- | scripts/package.js | 42 |
1 files changed, 18 insertions, 24 deletions
diff --git a/scripts/package.js b/scripts/package.js index 7ccb466..a28b01c 100644 --- a/scripts/package.js +++ b/scripts/package.js | |||
@@ -56,15 +56,15 @@ const compress = (src, dest) => | |||
56 | const outputFolder = path.join(repoRoot, 'archives'); | 56 | const outputFolder = path.join(repoRoot, 'archives'); |
57 | const allJson = path.join(repoRoot, 'all.json'); | 57 | const allJson = path.join(repoRoot, 'all.json'); |
58 | const featuredFile = path.join(repoRoot, 'featured.json'); | 58 | const featuredFile = path.join(repoRoot, 'featured.json'); |
59 | const featuredRecipes = await fs.readJSON(featuredFile); | 59 | const featuredRecipes = fs.readJSONSync(featuredFile); |
60 | let recipeList = []; | 60 | let recipeList = []; |
61 | let unsuccessful = 0; | 61 | let unsuccessful = 0; |
62 | 62 | ||
63 | await fs.ensureDir(outputFolder); | 63 | fs.ensureDirSync(outputFolder); |
64 | await fs.emptyDir(outputFolder); | 64 | fs.emptyDirSync(outputFolder); |
65 | await fs.ensureDir(tempFolder); | 65 | fs.ensureDirSync(tempFolder); |
66 | await fs.emptyDir(tempFolder); | 66 | fs.emptyDirSync(tempFolder); |
67 | await fs.remove(allJson); | 67 | fs.removeSync(allJson); |
68 | 68 | ||
69 | const git = await simpleGit(repoRoot); | 69 | const git = await simpleGit(repoRoot); |
70 | const isGitRepo = await git.checkIsRepo(); | 70 | const isGitRepo = await git.checkIsRepo(); |
@@ -84,8 +84,7 @@ const compress = (src, dest) => | |||
84 | // Check that each mandatory file exists | 84 | // Check that each mandatory file exists |
85 | for (const file of mandatoryFiles) { | 85 | for (const file of mandatoryFiles) { |
86 | const filePath = path.join(recipeSrc, file); | 86 | const filePath = path.join(recipeSrc, file); |
87 | // eslint-disable-next-line no-await-in-loop | 87 | if (!fs.pathExistsSync(filePath)) { |
88 | if (!(await fs.pathExists(filePath))) { | ||
89 | console.log( | 88 | console.log( |
90 | `⚠️ Couldn't package "${recipe}": Folder doesn't contain a "${file}".`, | 89 | `⚠️ Couldn't package "${recipe}": Folder doesn't contain a "${file}".`, |
91 | ); | 90 | ); |
@@ -110,8 +109,7 @@ const compress = (src, dest) => | |||
110 | 109 | ||
111 | // Check that user.js does not exist | 110 | // Check that user.js does not exist |
112 | const userJs = path.join(recipeSrc, 'user.js'); | 111 | const userJs = path.join(recipeSrc, 'user.js'); |
113 | // eslint-disable-next-line no-await-in-loop | 112 | if (fs.pathExistsSync(userJs)) { |
114 | if (await fs.pathExists(userJs)) { | ||
115 | console.log( | 113 | console.log( |
116 | `⚠️ Couldn't package "${recipe}": Folder contains a "user.js".`, | 114 | `⚠️ Couldn't package "${recipe}": Folder contains a "user.js".`, |
117 | ); | 115 | ); |
@@ -121,8 +119,7 @@ const compress = (src, dest) => | |||
121 | 119 | ||
122 | // Read package.json | 120 | // Read package.json |
123 | const packageJson = path.join(recipeSrc, 'package.json'); | 121 | const packageJson = path.join(recipeSrc, 'package.json'); |
124 | // eslint-disable-next-line no-await-in-loop | 122 | const config = fs.readJsonSync(packageJson); |
125 | const config = await fs.readJson(packageJson); | ||
126 | 123 | ||
127 | // Make sure it contains all required fields | 124 | // Make sure it contains all required fields |
128 | if (!config) { | 125 | if (!config) { |
@@ -276,8 +273,9 @@ const compress = (src, dest) => | |||
276 | } | 273 | } |
277 | 274 | ||
278 | if (configErrors.length > 0) { | 275 | if (configErrors.length > 0) { |
279 | console.log(`⚠️ Couldn't package "${recipe}": There were errors in the recipe's package.json: | 276 | console.log( |
280 | ${configErrors.reduce((str, err) => `${str}\n${err}`)}`); | 277 | `⚠️ Couldn't package "${recipe}": There were errors in the recipe's package.json: ${configErrors.reduce((str, err) => `${str}\n${err}`)}`, |
278 | ); | ||
281 | unsuccessful += 1; | 279 | unsuccessful += 1; |
282 | } | 280 | } |
283 | 281 | ||
@@ -289,29 +287,25 @@ const compress = (src, dest) => | |||
289 | } | 287 | } |
290 | 288 | ||
291 | // Copy recipe to temp folder | 289 | // Copy recipe to temp folder |
292 | // eslint-disable-next-line no-await-in-loop | 290 | fs.copySync(recipeSrc, path.join(tempFolder, config.id), { |
293 | await fs.copy(recipeSrc, path.join(tempFolder, config.id), { | ||
294 | filter: src => !src.endsWith('icon.svg'), | 291 | filter: src => !src.endsWith('icon.svg'), |
295 | }); | 292 | }); |
296 | 293 | ||
297 | if (!config.defaultIcon) { | 294 | if (!config.defaultIcon) { |
298 | // Check if icon.svg exists | 295 | // Check if icon.svg exists |
299 | // eslint-disable-next-line no-await-in-loop | 296 | if (!fs.existsSync(path.join(recipeSrc, 'icon.svg'))) { |
300 | if (!(await fs.exists(path.join(recipeSrc, 'icon.svg')))) { | ||
301 | console.log( | 297 | console.log( |
302 | `⚠️ Couldn't package "${recipe}": The recipe doesn't contain a "icon.svg" or "defaultIcon" in package.json`, | 298 | `⚠️ Couldn't package "${recipe}": The recipe doesn't contain a "icon.svg" or "defaultIcon" in package.json`, |
303 | ); | 299 | ); |
304 | unsuccessful += 1; | 300 | unsuccessful += 1; |
305 | } | 301 | } |
306 | 302 | ||
307 | // eslint-disable-next-line no-await-in-loop | 303 | const tempPackage = fs.readJSONSync( |
308 | const tempPackage = await fs.readJSON( | ||
309 | path.join(tempFolder, config.id, 'package.json'), | 304 | path.join(tempFolder, config.id, 'package.json'), |
310 | ); | 305 | ); |
311 | tempPackage.defaultIcon = `${repo}${config.id}/icon.svg`; | 306 | tempPackage.defaultIcon = `${repo}${config.id}/icon.svg`; |
312 | 307 | ||
313 | // eslint-disable-next-line no-await-in-loop | 308 | fs.writeJSONSync( |
314 | await fs.writeJSON( | ||
315 | path.join(tempFolder, config.id, 'package.json'), | 309 | path.join(tempFolder, config.id, 'package.json'), |
316 | tempPackage, | 310 | tempPackage, |
317 | // JSON.stringify(tempPackage, null, 2), | 311 | // JSON.stringify(tempPackage, null, 2), |
@@ -350,13 +344,13 @@ const compress = (src, dest) => | |||
350 | const textB = b.id.toLowerCase(); | 344 | const textB = b.id.toLowerCase(); |
351 | return textA < textB ? -1 : textA > textB ? 1 : 0; | 345 | return textA < textB ? -1 : textA > textB ? 1 : 0; |
352 | }); | 346 | }); |
353 | await fs.writeJson(allJson, recipeList, { | 347 | fs.writeJsonSync(allJson, recipeList, { |
354 | spaces: 2, | 348 | spaces: 2, |
355 | EOL: '\n', | 349 | EOL: '\n', |
356 | }); | 350 | }); |
357 | 351 | ||
358 | // Clean up | 352 | // Clean up |
359 | await fs.remove(tempFolder); | 353 | fs.removeSync(tempFolder); |
360 | 354 | ||
361 | // Capture the end time | 355 | // Capture the end time |
362 | const endTime = new Date(); | 356 | const endTime = new Date(); |