forked from adobe-experience-league/exlm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
preview.js
27 lines (20 loc) · 788 Bytes
/
preview.js
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
import util from 'node:util';
import { exec } from 'child_process';
import open from 'open';
const execAsync = util.promisify(exec);
let ref = await execAsync('git branch --show-current');
ref = ref.stdout.replace(/\//g, '-');
const [url = '/docs/authoring-guide-exl/using/markdown/cheatsheet', branch = ref] = process.argv.slice(2);
const owner = 'adobe-experience-league';
const repo = 'exlm';
const apiUrl = `https://admin.hlx.page/preview/${owner}/${repo}/${branch}${url}`;
// eslint-disable-next-line no-console
console.log('\x1b[32m', `Previewing: ${apiUrl}\n`);
const res = await fetch(apiUrl, { method: 'POST' });
if (res.ok) {
const data = await res.json();
await open(data.preview.url);
} else {
// eslint-disable-next-line no-console
console.log('API error');
}