Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

107 rindas
2.9 KiB

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