-
Notifications
You must be signed in to change notification settings - Fork 12
/
index.js
57 lines (46 loc) · 1.77 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
51
52
53
54
55
56
57
const path = require('path');
const { setLogger, setConfiguration, CompatibilityTypes } = require('@adguard/tsurlfilter');
const builder = require('./src/main/builder');
const schemaValidator = require('./src/main/json-validator');
const localesValidator = require('./src/main/locales-validator');
const logger = require('./src/main/utils/log');
// default platforms config
const platformsConfig = require('./src/main/platforms-config');
// Sets RuleConverter to use logger of current library
setLogger(logger);
// Sets configuration compatibility
setConfiguration({ compatibility: CompatibilityTypes.Corelibs });
const jsonSchemasConfigDir = path.join(__dirname, './schemas/');
process.on('unhandledRejection', (error) => {
throw error;
});
const compile = function (path, logPath, reportFile, platformsPath, whitelist, blacklist, customPlatformsConfig) {
if (customPlatformsConfig) {
logger.log('Using custom platforms configuration');
// eslint-disable-next-line no-restricted-syntax, guard-for-in
for (const platform in customPlatformsConfig) {
logger.log(`Redefining platform ${platform}`);
platformsConfig[platform] = customPlatformsConfig[platform];
}
}
return builder.build(
path,
logPath,
reportFile,
platformsPath,
platformsConfig,
whitelist,
blacklist,
);
};
const validateJSONSchema = function (platformsPath, requiredFiltersAmount) {
return schemaValidator.validate(platformsPath, jsonSchemasConfigDir, requiredFiltersAmount);
};
const validateLocales = function (localesDirPath, requiredLocales) {
return localesValidator.validate(localesDirPath, requiredLocales);
};
module.exports = {
compile,
validateJSONSchema,
validateLocales,
};