forked from teunmooij/github-versioned-release
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglob-patterns.ts
More file actions
46 lines (35 loc) · 1.15 KB
/
glob-patterns.ts
File metadata and controls
46 lines (35 loc) · 1.15 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
import fs from 'node:fs';
import type { Arguments } from './types';
const templates: Record<string, string[]> = {
'composite-action': ['action.{yml,yaml}', 'LICENSE', 'README{,.md}'],
'javascript-action': ['action.{yml,yaml}', 'dist/**', 'LICENSE', 'README{,.md}'],
};
const extractNames = (input: string) =>
input
.split('\n')
.map(name => {
const trimmed = name.trim();
if (trimmed.endsWith('/')) return trimmed + '**';
return trimmed;
})
.filter(name => name);
export const getIncludePatterns = ({ template, include }: Pick<Arguments, 'include' | 'template'>) => {
const list = [];
if (template) {
if (!templates[template]) throw new Error(`'${template}' is not a valid template`);
list.push(...templates[template]);
}
if (include) {
list.push(...extractNames(include));
}
if (list.length) return list;
return ['**/*'];
};
export const getExcludePatterns = async (exclude: string) => {
if (exclude) {
return extractNames(exclude);
}
if (!fs.existsSync('.gvrignore')) return [];
const ignoreFile = await fs.promises.readFile('.gvrignore', 'utf8');
return extractNames(ignoreFile);
};