-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgetAceBuilds.js
70 lines (56 loc) · 1.81 KB
/
getAceBuilds.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* eslint-disable no-unused-vars */
const path = require('path');
const fs = require('fs');
const _ = require('lodash');
module.exports = (aceDirectory) => {
const allModes = [];
const allThemes = [];
const otherFiles = [];
const files = fs.readdirSync(path.join(path.dirname(require.resolve('ace-builds')), '..', aceDirectory));
if (!files) {
throw new Error('Did you install `ace-builds` npm package yet?');
} else if (files) {
let modes = new RegExp('(mode)-((?!snippets)[\\w]+)(.js)');
let others = new RegExp(`(?!.*${path.posix.sep})(?!.*${path.posix.sep})(.*)`, 'i');
let themes = new RegExp('(theme)-([\\w]+)(.js)');
// Get All Modes
allModes
.push(...files
.filter((file) => file.match(modes))
.map((filteredFile) => {
const found = filteredFile.match(/(?<mode>[mode]+)-(?<filename>[\w]+)(?<extension>.js)/);
if (found) {
return found.groups.filename;
}
return null;
})
.filter(Boolean));
otherFiles
.push(...files
.filter((file) => file.match(others))
.map((filteredFile) => {
const found = filteredFile.match(/(?!.*\/)(?:(?!mode-|theme-|ace.js|snippets)(.*))*/i);
if (!_.isUndefined(found[0]) && found[0].length > 0) {
return found[0];
}
return null;
})
.filter(Boolean));
// Get All Themes
allThemes
.push(...files
.filter((file) => file.match(themes))
.map((filteredFile) => {
const found = filteredFile.match(/(?<theme>[theme]+)-(?<filename>[\w]+)(?<extension>.js)/);
if (found) {
return found.groups.filename;
}
return null;
}).filter(Boolean));
}
return {
allModes,
allThemes,
otherFiles
};
};