|
| 1 | +// The whole script is a hack to allow building Docusaurus in ESM project |
| 2 | +// https://github.com/facebook/docusaurus/issues/6520 |
| 3 | +// Should be just: `docusaurus build --out-dir ./websiteDist ./website` |
| 4 | + |
| 5 | +import fs from 'node:fs'; |
| 6 | +import os from 'node:os'; |
| 7 | +import path from 'node:path'; |
| 8 | + |
| 9 | +import { localRepoPath, npm, readPackageJSON } from './utils.js'; |
| 10 | + |
| 11 | +const tmpDir = path.join(os.tmpdir(), 'graphql-run-docusaurus'); |
| 12 | +fs.rmSync(tmpDir, { recursive: true, force: true }); |
| 13 | +fs.mkdirSync(tmpDir); |
| 14 | + |
| 15 | +const packageJSON = readPackageJSON(); |
| 16 | +delete packageJSON.type; |
| 17 | +fs.writeFileSync(tmpDirPath('package.json'), JSON.stringify(packageJSON)); |
| 18 | + |
| 19 | +copyToTmpDir('package-lock.json'); |
| 20 | +copyToTmpDir('tsconfig.json'); |
| 21 | +copyToTmpDir('src'); |
| 22 | +copyToTmpDir('website'); |
| 23 | + |
| 24 | +npm(['install', 'ci'], { cwd: tmpDir }); |
| 25 | + |
| 26 | +const env = { |
| 27 | + ...process.env, |
| 28 | + DOCUSAURUS_GENERATED_FILES_DIR_NAME: tmpDirPath('.docusaurus'), |
| 29 | +}; |
| 30 | +const docusaurusArgs = [ |
| 31 | + 'build', |
| 32 | + '--out-dir', |
| 33 | + localRepoPath('websiteDist'), |
| 34 | + tmpDirPath('website'), |
| 35 | +]; |
| 36 | +npm(['exec', 'docusaurus', '--', ...docusaurusArgs], { env, cwd: tmpDir }); |
| 37 | + |
| 38 | +function copyToTmpDir(relativePath: string) { |
| 39 | + fs.cpSync(localRepoPath(relativePath), tmpDirPath(relativePath), { |
| 40 | + recursive: true, |
| 41 | + }); |
| 42 | +} |
| 43 | + |
| 44 | +function tmpDirPath(...paths: ReadonlyArray<string>): string { |
| 45 | + return path.join(tmpDir, ...paths); |
| 46 | +} |
0 commit comments