Skip to content

Commit a2f3552

Browse files
Add watch mode with error resilience (#30)
- Added nodemon watch script for auto-rebuild on file changes - Changed forEach to Promise.all for proper async handling - Added per-entry error handling to prevent build crashes
1 parent f9e54f8 commit a2f3552

File tree

3 files changed

+380
-12
lines changed

3 files changed

+380
-12
lines changed

build/build.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,19 @@ import { makeLightBlogList } from './utils';
2020
await writeJson(buildConfig.distFolder + '/bloglist.json', blogListLight);
2121

2222
// replace README with entry.json for all blog posts
23-
blogList.forEach(async (entry) => {
24-
const entryDistFolder = `${buildConfig.distFolder}/${entry.slug}`;
25-
26-
await mkdirp(entryDistFolder);
27-
await copy(buildConfig.blogPostsFolder + '/' + entry.slug, entryDistFolder);
28-
await remove(`${entryDistFolder}/README.md`);
29-
30-
const entryJsonPath = `${entryDistFolder}/entry.json`;
31-
await writeJson(entryJsonPath, entry);
32-
console.log('Generated post file:', entryJsonPath);
33-
});
23+
await Promise.all(blogList.map(async (entry) => {
24+
try {
25+
const entryDistFolder = `${buildConfig.distFolder}/${entry.slug}`;
26+
27+
await mkdirp(entryDistFolder);
28+
await copy(buildConfig.blogPostsFolder + '/' + entry.slug, entryDistFolder);
29+
await remove(`${entryDistFolder}/README.md`);
30+
31+
const entryJsonPath = `${entryDistFolder}/entry.json`;
32+
await writeJson(entryJsonPath, entry);
33+
console.log('Generated post file:', entryJsonPath);
34+
} catch (error: any) {
35+
console.error(`Failed to process ${entry.slug}:`, error.message);
36+
}
37+
}));
3438
})();

0 commit comments

Comments
 (0)