-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
50 lines (41 loc) · 2.1 KB
/
index.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const core = require('@actions/core');
const fs = require('fs')
const path = require('path');
async function run() {
try {
let dir = core.getInput('directory', { required: false });
const fileExtension = core.getInput('file_extension', { required: false }).toLowerCase();
const onlyStartsWith = core.getInput('only_files_starts_with', { required: false });
const onlyStartsWithDelimiter = core.getInput('only_files_starts_with_delimiter', { required: false });
const ignoreStartsWith = core.getInput('ignore_files_starts_with', { required: false });
const ignoreStartsWithDelimiter = core.getInput('ignore_files_starts_with_delimiter', { required: false });
dir = "./".concat(dir)
const content = fs.readdirSync(dir, { withFileTypes: true });
let files = content.filter(currentElement => currentElement.isFile())
.map(file => file.name);
if (fileExtension)
files = files.filter(currentFile => currentFile.toLowerCase().endsWith(`.${fileExtension}`))
if (onlyStartsWith) {
let onlyStartsFiles = new Array();
const onlyList = onlyStartsWith.split(onlyStartsWithDelimiter)
onlyList.forEach(currentOnlyStartsWith => {
onlyStartsFiles = onlyStartsFiles.concat(files.filter(currentFile => currentFile.startsWith(currentOnlyStartsWith)))
});
files = onlyStartsFiles
}
if (ignoreStartsWith) {
const ignoreList = ignoreStartsWith.split(ignoreStartsWithDelimiter)
ignoreList.forEach(currentIgnoreStartsWith => {
files = files.filter(currentFile => !currentFile.startsWith(currentIgnoreStartsWith))
});
}
const fileNames = files.map(file => path.parse(`${dir}/${file}`).name);
const filesJsonString = JSON.stringify(files)
const fileNamesJsonString = JSON.stringify(fileNames)
core.setOutput('files', filesJsonString);
core.setOutput('file_names', fileNamesJsonString);
} catch (error) {
core.setFailed(error.message);
}
}
run();