-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgenerate-gh-pages.mjs
61 lines (52 loc) · 1.79 KB
/
generate-gh-pages.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env zx
/**
* execution from monorepo:
* `npx zx scripts/generate-gh-pages.mjs`
*/
import { resolve } from 'path';
import { tmpdir } from 'os';
const currentVersion = require('../lerna.json').version;
const packageName = '@ovhcloud/ods-storybook';
const tmpDirName = 'ods-gh-pages';
const outDirName = 'docs';
(async () => {
await $`rm -rf dist`;
await $`mkdir -p dist`;
await $`echo "Documentation generated for version ${currentVersion} at ${new Date().toISOString()}" > dist/status.html`;
// clean tmp specific dir
const tmpOdsDir = resolve(tmpdir(), `${tmpDirName}`);
await $`rm -rf ${tmpOdsDir}/*`;
let versions = await $`npm view ${packageName} versions --json`;
versions = JSON.parse(versions);
for (let versionsKey in versions) {
const version = versions[versionsKey];
// create a dir for this version
const dir = resolve(tmpOdsDir, `${version}`);
await $`mkdir -p ${dir}`;
await $`ls -l ${dir}`;
// find the url and download
let tarball = await $`npm view ${packageName}@${version} dist.tarball`;
tarball = `${tarball.stdout.trim()}`;
const command = `curl -sS "${tarball}" | tar -xzf - -C ${dir} --strip 1`;
await $([command]);
try {
await $`mv ${dir}/dist dist/v${version}`;
} catch (e) {
console.error(`No dist dir found, ignoring the version`, e);
}
}
try {
// add the current build (released just done)
await $`cp -r packages/storybook/dist dist/v${currentVersion}`;
await $`ln -s v${currentVersion} dist/latest`;
} catch (e) {
console.error(`cannot add the current storybook build. ignore it`, e);
}
try {
// move all into out dir
await $`rm -rf ${outDirName}/v*`;
await $`mv dist/* ${outDirName}`;
} catch (e) {
console.error(`cannot move files into outDir.`, e);
}
})();