-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
75 lines (67 loc) · 2.65 KB
/
index.ts
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
71
72
73
74
75
import * as path from 'path';
import {
createRepositoryLoader,
FailedLoadHandler,
} from './src/repository-loader';
import {createMemorySource} from './src/repository-loader/sources';
import {createLoggerFactory, loggerFactory, nullWriter} from './src/logger';
import {createMockDefinitions} from './src/repository-loader/__fixtures__';
import {createYamlSource} from './src/repository-loader/sources';
import {filter, map} from 'rxjs/operators';
import {createSecurityAlertTaskProducer} from './src/repository-task/tasks/security-alert';
import {createDependencyReportTaskProducer} from './src/repository-task/tasks/dependency-report';
import {isDefined} from './src/util';
import {createRepositoryTaskLoader} from './src/repository-task/createRepositoryTaskLoader';
(async () => {
const logger = loggerFactory.createLogger();
const sources = [
// createMemorySource(createMockDefinitions(10)),
createYamlSource(path.join(__dirname, 'repositories'), loggerFactory),
];
const onFailedLoad: FailedLoadHandler = (source, e) =>
logger.error(`An error occurred loading from source ${source.id()}`, e);
const repositoryLoader = createRepositoryLoader(sources, onFailedLoad);
const taskLoader = createRepositoryTaskLoader(
createDependencyReportTaskProducer(loggerFactory),
repositoryLoader
);
// const taskLoader = createRepositoryTaskLoader(
// createSecurityAlertTaskProducer(loggerFactory),
// repositoryLoader
// );
taskLoader.subscribe(task => logger.info(task.uuid));
})();
// Security alert.
// (async () => {
// const logger = loggerFactory.createLogger();
// const git: IGit = createGitService(createExecutable, loggerFactory);
//
// const definitionsPath = path.join(__dirname, 'repositories');
// const destinationPath = path.join(__dirname, 'gitRepos/');
// const repositories = await getRepositories(definitionsPath, destinationPath);
//
// for (const repo of repositories) {
// if (!(await git.clone(repo))) {
// continue;
// }
//
// if (repo.isSecurityAlertEnabled()) {
// const auditCmd = `cd ${repo.cloneDestination()} && npm audit --json`;
// const audit: Executable = createExecutable(auditCmd);
// const auditResult: IExecutionResult = await audit();
//
// if (isExecutionSuccessful(auditResult) || auditResult.code === 1) {
// logger.info(
// `Results for ${repo.name()}`,
// JSON.parse(auditResult.output).metadata.vulnerabilities
// );
// } else {
// logger.error(
// `An error occurred for ${repo.name()}`,
// auditResult.error,
// auditResult.output
// );
// }
// }
// }
// })();