|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +import { execSync } from 'child_process' |
| 4 | +import { existsSync, rmSync, renameSync, writeFileSync } from 'fs' |
| 5 | +import { join } from 'path' |
| 6 | + |
| 7 | +function banner() { |
| 8 | + console.log('*****************************************') |
| 9 | + console.log('** AWS Toolkit License Scanner **') |
| 10 | + console.log('*****************************************') |
| 11 | + console.log('') |
| 12 | +} |
| 13 | + |
| 14 | +function genAttribution() { |
| 15 | + console.log('') |
| 16 | + console.log(' == Generating Attribution Document ==') |
| 17 | + |
| 18 | + try { |
| 19 | + execSync('npm install -g oss-attribution-generator', { stdio: 'inherit' }) |
| 20 | + execSync('generate-attribution', { stdio: 'inherit' }) |
| 21 | + |
| 22 | + if (existsSync('oss-attribution')) { |
| 23 | + renameSync(join('oss-attribution', 'attribution.txt'), 'LICENSE-THIRD-PARTY') |
| 24 | + rmSync('oss-attribution', { recursive: true, force: true }) |
| 25 | + console.log('Attribution document generated: LICENSE-THIRD-PARTY') |
| 26 | + } else { |
| 27 | + console.log('Warning: oss-attribution directory not found') |
| 28 | + } |
| 29 | + } catch (error) { |
| 30 | + console.error('Error generating attribution:', error) |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | +function genFullLicenseReport() { |
| 35 | + console.log('') |
| 36 | + console.log(' == Generating Full License Report ==') |
| 37 | + |
| 38 | + try { |
| 39 | + execSync('npm install -g license-checker', { stdio: 'inherit' }) |
| 40 | + const licenseData = execSync('license-checker --json', { encoding: 'utf8' }) |
| 41 | + writeFileSync('licenses-full.json', licenseData) |
| 42 | + console.log('Full license report generated: licenses-full.json') |
| 43 | + } catch (error) { |
| 44 | + console.error('Error generating license report:', error) |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +function main() { |
| 49 | + banner() |
| 50 | + |
| 51 | + if (!existsSync('package.json')) { |
| 52 | + console.error('Error: package.json not found. Please run this script from the project root.') |
| 53 | + process.exit(1) |
| 54 | + } |
| 55 | + |
| 56 | + if (!existsSync('node_modules')) { |
| 57 | + console.log('node_modules not found. Running npm install...') |
| 58 | + try { |
| 59 | + execSync('npm install', { stdio: 'inherit' }) |
| 60 | + } catch (error) { |
| 61 | + console.error('Error running npm install:', error) |
| 62 | + process.exit(1) |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + console.log('Scanning licenses for AWS Toolkit VS Code project...') |
| 67 | + console.log(`Project root: ${process.cwd()}`) |
| 68 | + console.log('') |
| 69 | + |
| 70 | + genAttribution() |
| 71 | + genFullLicenseReport() |
| 72 | + |
| 73 | + console.log('') |
| 74 | + console.log('=== License Scan Complete ===') |
| 75 | + console.log('Generated files:') |
| 76 | + console.log(' - LICENSE-THIRD-PARTY (attribution document)') |
| 77 | + console.log(' - licenses-full.json (complete license data)') |
| 78 | + console.log('') |
| 79 | +} |
| 80 | + |
| 81 | +if (require.main === module) { |
| 82 | + main() |
| 83 | +} |
0 commit comments