-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
51 lines (47 loc) · 1.29 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
#!/usr/bin/env node
import path from 'path';
import config from './lib/config.js';
import FsService from './lib/filesystem-service.js';
import WebService from './lib/web-service.js';
import {
helpText,
licenseFilesTargetFolder,
sourceToTargetFilename,
} from './lib/util.js';
(async () => {
if (config.help) {
console.log(helpText); // eslint-disable-line security-node/detect-crlf
return;
}
try {
const sourceFilename = config.source;
const json = await FsService.readJson(sourceFilename);
await WebService.addLicenseFilePath(
json,
config.httpRetryOptions,
config.githubToken,
);
const targetFilename = sourceToTargetFilename(
sourceFilename,
config.licDir,
);
FsService.createDirFromFilename(targetFilename);
await FsService.writeJson(json, targetFilename);
if (config.download) {
const sourceDirectory = path.dirname(sourceFilename);
const targetDirectory = licenseFilesTargetFolder(
config.licDir,
sourceDirectory,
);
await WebService.downloadLicenseFiles(
json,
targetDirectory,
config.httpRetryOptions,
config.githubToken,
);
}
} catch (e) {
console.error(e.message);
process.exit(1); // eslint-disable-line n/no-process-exit
}
})();