|
| 1 | +import fs from "fs/promises"; |
| 2 | +import path from "path"; |
| 3 | +import { createTempDir, curlDownloadAndExtract } from "./download.mjs"; |
| 4 | +import { getPackageDataFromNPM } from "./npm-data.mjs"; |
| 5 | +import { removeAllReleaseDirs } from "./remove-all-current-release-dirs.mjs"; |
| 6 | + |
| 7 | +await fs.copyFile(path.join('.', 'test.html'), path.join('docs', 'test.html')); |
| 8 | + |
| 9 | +await removeAllReleaseDirs(); |
| 10 | + |
| 11 | +const npmData = await getPackageDataFromNPM(); |
| 12 | +const [tmpDir, cleanup] = await createTempDir(); |
| 13 | + |
| 14 | +for (const version in npmData.versions) { |
| 15 | + const versionData = npmData.versions[version]; |
| 16 | + const tarBallURL = versionData.dist.tarball; |
| 17 | + const tmpDirForVersion = path.join(tmpDir, version); |
| 18 | + |
| 19 | + await curlDownloadAndExtract(tarBallURL, tmpDirForVersion); |
| 20 | + |
| 21 | + await fs.mkdir(path.join('docs', version)); |
| 22 | + await fs.copyFile(path.join(tmpDirForVersion, 'normalize.css'), path.join('docs', version, 'normalize.css')); |
| 23 | + await fs.copyFile(path.join('docs', 'test.html'), path.join('docs', version, 'test.html')); |
| 24 | +} |
| 25 | + |
| 26 | +for (const distTag in npmData['dist-tags']) { |
| 27 | + const version = npmData['dist-tags'][distTag]; |
| 28 | + const versionData = npmData.versions[version]; |
| 29 | + if (!versionData) { |
| 30 | + continue; |
| 31 | + } |
| 32 | + |
| 33 | + const tarBallURL = versionData.dist.tarball; |
| 34 | + const tmpDirForVersion = path.join(tmpDir, distTag); |
| 35 | + |
| 36 | + await curlDownloadAndExtract(tarBallURL, tmpDirForVersion); |
| 37 | + |
| 38 | + await fs.mkdir(path.join('docs', distTag)); |
| 39 | + await fs.copyFile(path.join(tmpDirForVersion, 'normalize.css'), path.join('docs', distTag, 'normalize.css')); |
| 40 | + await fs.copyFile(path.join('docs', 'test.html'), path.join('docs', distTag, 'test.html')); |
| 41 | +} |
| 42 | + |
| 43 | +await cleanup(); |
0 commit comments