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.

108 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. 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' || name.startsWith('@gitkraken')) continue;
  58. if (data.licenseFile == null) continue;
  59. let license;
  60. if (data.licenseFile.startsWith('https://')) {
  61. const response = await fetch(data.licenseFile);
  62. license = await response.text();
  63. } else {
  64. license = fs.readFileSync(data.licenseFile, 'utf8');
  65. }
  66. license = license.replace(/\r\n/g, '\n');
  67. packageOutputs.push(`${++count}. ${name}${version ? ` version ${version}` : ''} (${data.repository})`);
  68. licenseOutputs.push(
  69. `\n%% ${name} NOTICES AND INFORMATION BEGIN HERE\n=========================================\n${license}\n=========================================\nEND OF ${name} NOTICES AND INFORMATION`,
  70. );
  71. }
  72. const content = `GitLens\n\nTHIRD-PARTY SOFTWARE NOTICES AND INFORMATION\nThis project incorporates components from the projects listed below.\n\n${packageOutputs.join(
  73. '\n',
  74. )}\n${licenseOutputs.join('\n')}`;
  75. fs.writeFileSync(path.join(process.cwd(), 'ThirdPartyNotices.txt'), content, 'utf8');
  76. }
  77. async function generate() {
  78. const packages = await new Promise((resolve, reject) => {
  79. checker.init(
  80. {
  81. direct: 0,
  82. json: true,
  83. production: true,
  84. start: process.cwd(),
  85. },
  86. (err, packages) => {
  87. if (err) {
  88. reject(err);
  89. } else {
  90. resolve(packages);
  91. }
  92. },
  93. );
  94. });
  95. void generateThirdpartyNotices(packages);
  96. }
  97. void generate();