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
|
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only
import * as path from 'path';
import * as fs from 'fs';
import { program } from 'commander';
import { execSync } from 'child_process';
function main() {
program.option('-d, --dir <string>', 'Path to target extension root');
program.option('-e, --exclude <string>', 'Exclude packages');
program.parse(process.argv);
const options = program.opts();
const extensionRoot = path.resolve(__dirname, '../');
const targetExtensionRoot = path.join(extensionRoot, options.dir as string);
const exclude = options.exclude as string;
const temp = path.join(targetExtensionRoot, 'ThirdPartyNotices_temp.txt');
let isCatchedError = false;
try {
console.log('Checking licenses...');
const previousFile = path.join(
targetExtensionRoot,
'ThirdPartyNotices.txt'
);
if (!fs.existsSync(previousFile)) {
throw new Error(`${previousFile} file not found`);
}
process.chdir(targetExtensionRoot);
console.log('temp file:', temp);
execSync(
`npm run generateLicenses -- --output="${temp}" --dir="${targetExtensionRoot}" --exclude="${exclude}, qt-lib"`,
{
cwd: extensionRoot,
stdio: 'inherit'
}
);
const tempText = fs.readFileSync(temp, 'utf-8');
const previousText = fs.readFileSync(previousFile, 'utf-8');
if (tempText === previousText) {
console.log('ThirdPartyNotices.txt is up to date.');
} else {
const errorMessage =
`ThirdPartyNotices.txt is out of date.` +
`Please run 'npm run generateLicenses' to update it.`;
throw new Error(errorMessage);
}
} catch (error) {
console.error(error);
isCatchedError = true;
} finally {
fs.rmSync(temp, { force: true });
if (isCatchedError) {
process.exit(1);
}
}
}
main();
|