Skip to content

Commit 4139f20

Browse files
committed
add docs
1 parent afda40b commit 4139f20

74 files changed

Lines changed: 26352 additions & 2 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/bin/download.mjs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import fs from 'fs/promises';
2+
import path from 'node:path';
3+
import { spawn } from 'child_process';
4+
import { tmpdir } from 'node:os';
5+
6+
export async function createTempDir() {
7+
const name = await fs.mkdtemp(path.join(tmpdir(), 'normalize.css-'));
8+
return [name, async () => fs.rm(name, { recursive: true, force: true })];
9+
}
10+
11+
export async function curlDownloadAndExtract(url, dir) {
12+
await fs.mkdir(dir, { recursive: true });
13+
14+
const curl = spawn('curl', [url, '-o', path.join(dir, 'archive.tgz')]);
15+
await new Promise((resolve, reject) => {
16+
curl.on('close', (code) => {
17+
if (code === 0) {
18+
resolve();
19+
} else {
20+
reject(new Error(`curl exited with code ${code}`));
21+
}
22+
});
23+
});
24+
25+
const unzip = spawn('tar', ['-xzf', path.join(dir, 'archive.tgz'), '-C', dir, '--strip-components=1']);
26+
await new Promise((resolve, reject) => {
27+
unzip.on('close', (code) => {
28+
if (code === 0) {
29+
resolve();
30+
} else {
31+
reject(new Error(`tar exited with code ${code}`));
32+
}
33+
});
34+
});
35+
}

.github/bin/generate-gh-pages.mjs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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();

.github/bin/npm-data.mjs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export async function getPackageDataFromNPM() {
2+
const resp = await fetch(`https://registry.npmjs.org/@csstools/normalize.css`);
3+
if (resp.status === 404) {
4+
throw new Error(`Failed to fetch package metadata for @csstools/normalize.css, status code: ${resp.status} ${resp.statusText}`);
5+
}
6+
7+
if (!resp.ok) {
8+
throw new Error(`Failed to fetch package metadata for @csstools/normalize.css, status code: ${resp.status} ${resp.statusText}`);
9+
}
10+
11+
const data = await resp.json();
12+
13+
return data;
14+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import path from 'path';
2+
import fs from 'fs/promises';
3+
4+
export async function removeAllReleaseDirs() {
5+
const releaseDirs = await findAllReleaseDirs();
6+
7+
for (const dir of releaseDirs) {
8+
await fs.rm(dir, { recursive: true, force: true });
9+
}
10+
}
11+
12+
async function findAllReleaseDirs() {
13+
const dir = path.resolve('.');
14+
const dirents = await fs.readdir(dir, { withFileTypes: true });
15+
const releaseDirs = dirents.map((dirent) => {
16+
const res = path.resolve(dir, dirent.name);
17+
if (!res.startsWith(dir)) {
18+
return [];
19+
}
20+
21+
if (dirent.isSymbolicLink()) {
22+
return [];
23+
}
24+
25+
if (dirent.isDirectory()) {
26+
const basename = path.basename(res);
27+
if (/^\d+\.\d+\.\d+/.test(basename) && parseInt(basename.split('.')[0], 10) >= 8) {
28+
return [res];
29+
}
30+
31+
if (basename === 'latest') {
32+
return [res];
33+
}
34+
}
35+
36+
return [];
37+
});
38+
39+
return releaseDirs.flat();
40+
}

.github/workflows/pages.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Pages
2+
on:
3+
workflow_dispatch:
4+
5+
jobs:
6+
update-directory:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: check out
10+
uses: actions/checkout@v4
11+
with:
12+
fetch-depth: 1
13+
14+
- name: setup node
15+
uses: actions/[email protected]
16+
with:
17+
node-version: latest
18+
19+
- name: generate
20+
run: |
21+
node .github/bin/generate-gh-pages.mjs
22+
23+
- name: save
24+
run: |
25+
# Git config
26+
git config user.name github-actions[bot]
27+
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
28+
git add .
29+
git commit --allow-empty -m "Generate pages"
30+
git push --set-upstream origin main

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
node_modules
22
npm-debug.log
33
yarn.lock
4-
.*
54
!.editorconfig
65
!.gitignore
7-
!.travis.yml

docs/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.DS_Store
2+
*.orig
3+
*.swo
4+
*.swp
5+
node_modules

0 commit comments

Comments
 (0)