-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy pathlicensee.js
34 lines (31 loc) · 1.05 KB
/
licensee.js
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
// Copyright 2018 TODO Group. All rights reserved.
// Licensed under the Apache License, Version 2.0.
const { commandExists } = require('./command_exists')
const spawnSync = require('child_process').spawnSync
class Licensee {
/**
* Returns the license found for the project.
*
* Throws 'Licensee not installed' error if command line of 'licensee' is not available.
*
* @param {string} targetDir The directory to run licensee on
* @returns {Promise<string[]>} License identifiers
* @ignore
*/
async identifyLicense(targetDir) {
const command = await commandExists(['licensee', 'licensee.bat'])
if (command === null) {
throw new Error('Licensee not installed')
}
const licenseeOutput = spawnSync(command, ['detect', '--json', targetDir])
.stdout
if (licenseeOutput == null) {
throw new Error('Error executing licensee')
}
const json = licenseeOutput.toString()
return JSON.parse(json).licenses.map(function (license) {
return license.spdx_id
})
}
}
module.exports = new Licensee()