-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathcommons.mjs
More file actions
52 lines (48 loc) · 1.23 KB
/
commons.mjs
File metadata and controls
52 lines (48 loc) · 1.23 KB
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
import 'zx/globals';
import assert from 'assert';
export const config = {
tmpDir: `./wcag-act-rules-tmp/`,
rulesDir: `./_rules/`,
glossaryDir: `./pages/glossary/`,
testAssetsDir: `./test-assets/`,
}
export async function cloneWcagActRules({ tmpDir }) {
await $`rm -rf ${tmpDir}`;
await $`git clone \
--no-single-branch \
--branch main \
https://github.com/w3c/wcag-act-rules.git ${tmpDir} \
--depth 1
`;
}
export async function createOrCheckoutBranch({ tmpDir }, branchName) {
assert(branchName, 'branchName must be defined');
cd(tmpDir);
try {
await $`git checkout ${branchName}`;
} catch {
await $`git checkout -b ${branchName}`;
} finally {
cd(`../`);
}
}
export async function commitAndPush({ tmpDir }, commitMessage) {
cd(tmpDir);
try {
const diff = (await $`git diff --name-status`).stdout;
if (diff.trim().length === 0) {
console.log('No changes detected, skipping git commit')
return;
}
await $`git add .`;
await $`git commit -m ${commitMessage}`;
try {
await $`git push`;
} catch {
const branchName = (await $`git branch --show-current`);
await $`git push --set-upstream origin ${branchName}`;
}
} finally {
cd(`../`);
}
}