|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | | -import { readFile, rm, writeFile, mkdir } from 'node:fs/promises'; |
| 3 | +import { cp, readFile, rm, writeFile } from 'node:fs/promises'; |
4 | 4 | import { join } from 'node:path'; |
5 | 5 |
|
6 | 6 | import HTMLMinifier from '@minify-html/node'; |
7 | 7 |
|
8 | 8 | import buildContent from './utils/buildContent.mjs'; |
9 | 9 | import dropdowns from './utils/buildDropdowns.mjs'; |
10 | | -import { safeCopy } from './utils/safeCopy.mjs'; |
11 | 10 | import tableOfContents from './utils/tableOfContents.mjs'; |
12 | 11 | import { groupNodesByModule } from '../../utils/generators.mjs'; |
13 | 12 | import { getRemarkRehype } from '../../utils/remark.mjs'; |
@@ -170,22 +169,31 @@ export default { |
170 | 169 | } |
171 | 170 |
|
172 | 171 | if (output) { |
173 | | - // Define the source folder for API docs assets |
174 | | - const srcAssets = join(baseDir, 'assets'); |
175 | | - |
176 | | - // Define the output folder for API docs assets |
177 | | - const assetsFolder = join(output, 'assets'); |
178 | | - |
179 | | - // Removes the current assets directory to copy the new assets |
180 | | - // and prevent stale assets from existing in the output directory |
181 | | - // If the path does not exists, it will simply ignore and continue |
182 | | - await rm(assetsFolder, { recursive: true, force: true, maxRetries: 10 }); |
183 | | - |
184 | | - // Creates the assets folder if it does not exist |
185 | | - await mkdir(assetsFolder, { recursive: true }); |
186 | | - |
187 | | - // Copy all files from assets folder to output, skipping unchanged files |
188 | | - await safeCopy(srcAssets, assetsFolder); |
| 172 | + try { |
| 173 | + // Define the output folder for API docs assets |
| 174 | + const assetsFolder = join(output, 'assets'); |
| 175 | + |
| 176 | + // Removes the current assets directory to copy the new assets |
| 177 | + // and prevent stale assets from existing in the output directory |
| 178 | + // If the path does not exists, it will simply ignore and continue |
| 179 | + await rm(assetsFolder, { |
| 180 | + recursive: true, |
| 181 | + force: true, |
| 182 | + maxRetries: 10, |
| 183 | + }); |
| 184 | + |
| 185 | + // We copy all the other assets to the output folder at the end of the process |
| 186 | + // to ensure that all latest changes on the styles are applied to the output |
| 187 | + // Note.: This is not meant to be used for DX/developer purposes. |
| 188 | + await cp(join(baseDir, 'assets'), assetsFolder, { |
| 189 | + recursive: true, |
| 190 | + force: true, |
| 191 | + }); |
| 192 | + } finally { |
| 193 | + // There's a chance that this step will fail when being run in parallel, since |
| 194 | + // the generators will all attempt to modify the same files at the same time. |
| 195 | + // In that scenario, we just want to ignore the potential failure. |
| 196 | + } |
189 | 197 | } |
190 | 198 |
|
191 | 199 | return generatedValues; |
|
0 commit comments