25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
2.8 KiB

  1. //@ts-check
  2. /* eslint-disable @typescript-eslint/no-var-requires */
  3. import * as fs from 'fs';
  4. import * as path from 'path';
  5. import fetch from 'node-fetch';
  6. import * as checker from 'license-checker-rseidelsohn';
  7. import { spawn } from 'child_process';
  8. /** @typedef { { licenses: string; repository: string; licenseFile: string } } PackageInfo **/
  9. /**
  10. * @param { { [key: string]: PackageInfo } } packages
  11. */
  12. async function generateThirdpartyNotices(packages) {
  13. /**
  14. * @type [string, PackageInfo][]
  15. */
  16. const codeOnlyPackages = [
  17. [
  18. 'microsoft/vscode',
  19. {
  20. licenses: 'MIT',
  21. repository: 'https://github.com/microsoft/vscode',
  22. licenseFile: 'https://raw.github.com/microsoft/vscode/main/LICENSE.txt',
  23. },
  24. ],
  25. [
  26. 'sindresorhus/string-width',
  27. {
  28. licenses: 'MIT',
  29. repository: 'https://github.com/sindresorhus/string-width',
  30. licenseFile: 'https://raw.github.com/sindresorhus/string-width/main/license',
  31. },
  32. ],
  33. [
  34. 'sindresorhus/is-fullwidth-code-point',
  35. {
  36. licenses: 'MIT',
  37. repository: 'https://github.com/sindresorhus/is-fullwidth-code-point',
  38. licenseFile: 'https://raw.github.com/sindresorhus/is-fullwidth-code-point/main/license',
  39. },
  40. ],
  41. ];
  42. const packageOutputs = [];
  43. const licenseOutputs = [];
  44. let count = 0;
  45. for (const [key, data] of Object.entries(packages)
  46. .concat(codeOnlyPackages)
  47. .sort(([a], [b]) => a.localeCompare(b))) {
  48. let name;
  49. let version;
  50. const index = key.lastIndexOf('@');
  51. if (index !== -1) {
  52. name = key.substr(0, index);
  53. version = key.substr(index + 1);
  54. } else {
  55. name = key;
  56. }
  57. if (name === 'gitlens') continue;
  58. let license;
  59. if (data.licenseFile.startsWith('https://')) {
  60. const response = await fetch(data.licenseFile);
  61. license = await response.text();
  62. } else {
  63. license = fs.readFileSync(data.licenseFile, 'utf8');
  64. }
  65. packageOutputs.push(`${++count}. ${name}${version ? ` version ${version}` : ''} (${data.repository})`);
  66. licenseOutputs.push(
  67. `\n%% ${name} NOTICES AND INFORMATION BEGIN HERE\n=========================================\n${license}\n=========================================\nEND OF ${name} NOTICES AND INFORMATION`,
  68. );
  69. }
  70. const content = `GitLens\n\nTHIRD-PARTY SOFTWARE NOTICES AND INFORMATION\nThis project incorporates components from the projects listed below.\n\n${packageOutputs.join(
  71. '\n',
  72. )}\n${licenseOutputs.join('\n')}`;
  73. fs.writeFileSync(path.join(process.cwd(), 'ThirdPartyNotices.txt'), content, 'utf8');
  74. }
  75. async function generate() {
  76. const packages = await new Promise((resolve, reject) => {
  77. checker.init(
  78. {
  79. direct: 0,
  80. json: true,
  81. production: true,
  82. start: process.cwd(),
  83. },
  84. (err, packages) => {
  85. if (err) {
  86. reject(err);
  87. } else {
  88. resolve(packages);
  89. }
  90. },
  91. );
  92. });
  93. void generateThirdpartyNotices(packages);
  94. }
  95. void generate();