mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
CLI: new licences command (#5690)
* new licences command * remove old licences command
This commit is contained in:
@@ -1,110 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
|
||||
var checker = require('license-checker');
|
||||
var spdxCodes = require('spdx-license-list');
|
||||
var ejs = require('ejs');
|
||||
var program = require('commander');
|
||||
|
||||
var templatePath = path.resolve(__dirname, 'templates', 'licensePage.ejs');
|
||||
|
||||
const nonStandardLicenses = {
|
||||
'public domain': 'PDDL-1.0',
|
||||
'apache': 'Apache-2.0',
|
||||
'bsd': 'BSD-2-Clause'
|
||||
};
|
||||
|
||||
const missingRepos = {
|
||||
'@alfresco/adf-testing': 'https://github.com/Alfresco/alfresco-ng2-components',
|
||||
'@webassemblyjs/helper-api-error': 'https://github.com/xtuc/webassemblyjs',
|
||||
'@webassemblyjs/helper-fsm': 'https://github.com/xtuc/webassemblyjs',
|
||||
'@webassemblyjs/ieee754': 'https://github.com/xtuc/webassemblyjs',
|
||||
'@webassemblyjs/leb128': 'https://github.com/xtuc/webassemblyjs',
|
||||
'adf-tslint-rules': 'https://github.com/Alfresco/alfresco-ng2-components',
|
||||
'adf-monaco-extension': 'https://github.com/eromano/aca-monaco-extension',
|
||||
'indexof': 'https://github.com/component/indexof',
|
||||
'rxjs-compat': 'https://github.com/ReactiveX/rxjs/tree/master/compat',
|
||||
};
|
||||
|
||||
program
|
||||
.usage('<versionNumber>')
|
||||
.parse(process.argv);
|
||||
|
||||
var packageJson = JSON.parse(fs.readFileSync(path.resolve('./','package.json')));
|
||||
|
||||
if (!packageJson) {
|
||||
console.error('Move in the path where you have the package.json');
|
||||
throw '';
|
||||
}
|
||||
|
||||
console.log(path.resolve('./','package.json'));
|
||||
|
||||
checker.init({
|
||||
start: './',
|
||||
production: true,
|
||||
failOn: 'GPL'
|
||||
}, function (err, packages) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
} else {
|
||||
for (var packageName in packages) {
|
||||
var pack = packages[packageName];
|
||||
pack['licenseExp'] = pack['licenses'].toString()
|
||||
.replace(/\*/, '')
|
||||
.replace(/[a-zA-Z0-9\-\.]+/g, match => {
|
||||
var lowerMatch = match.toLowerCase();
|
||||
|
||||
if ((lowerMatch !== 'and') && (lowerMatch !== 'or') && (lowerMatch !== 'with')) {
|
||||
return licenseWithMDLinks(match);
|
||||
} else {
|
||||
return match;
|
||||
}
|
||||
});
|
||||
|
||||
if (!pack['repository']) {
|
||||
var lastAtSignPos = packageName.lastIndexOf('@');
|
||||
var mainName = packageName.substring(0, lastAtSignPos);
|
||||
|
||||
if (missingRepos[mainName]) {
|
||||
pack['repository'] = missingRepos[mainName];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ejs.renderFile(templatePath, {
|
||||
packages: packages,
|
||||
projVersion: packageJson.version,
|
||||
projName: packageJson.description
|
||||
}, {}, (err, mdText) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
} else {
|
||||
fs.writeFileSync(`license-info-${packageJson.version}.md`, mdText);
|
||||
console.log(`Wrote license`);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
function licenseWithMDLinks(licenseExp) {
|
||||
var licenseUrl = '';
|
||||
|
||||
if (spdxCodes[licenseExp] && spdxCodes[licenseExp]['url']) {
|
||||
licenseUrl = spdxCodes[licenseExp]['url'];
|
||||
} else {
|
||||
var substituteLicString = nonStandardLicenses[licenseExp.toLowerCase()];
|
||||
|
||||
if (spdxCodes[substituteLicString] && spdxCodes[substituteLicString]['url']) {
|
||||
licenseUrl = spdxCodes[substituteLicString]['url'];
|
||||
}
|
||||
}
|
||||
|
||||
if (licenseUrl) {
|
||||
return `[${licenseExp}](${licenseUrl})`;
|
||||
} else {
|
||||
return licenseExp;
|
||||
}
|
||||
}
|
28
lib/cli/bin/doc/templates/licensePage.ejs
vendored
28
lib/cli/bin/doc/templates/licensePage.ejs
vendored
@@ -1,28 +0,0 @@
|
||||
---
|
||||
Title: License info, <%= projName %> <%= projVersion %>
|
||||
---
|
||||
|
||||
# License information for <%= projName %> <%= projVersion %>
|
||||
|
||||
This page lists all third party libraries that ADF <%= projVersion %> depends on.
|
||||
|
||||
## Libraries
|
||||
|
||||
| Name | Version | License |
|
||||
| --- | --- | --- |
|
||||
<% for (var packageName in packages) {
|
||||
var lastAtSignPos = packageName.lastIndexOf('@');
|
||||
|
||||
var name = packageName.substring(0, lastAtSignPos);
|
||||
var version = packageName.substring(lastAtSignPos + 1);
|
||||
var pack = packages[packageName];
|
||||
var licenses = pack['licenseExp'] || 'N/A';
|
||||
var repo = pack['repository'];
|
||||
var linkedName = name;
|
||||
|
||||
if (repo) {
|
||||
linkedName = `[${name}](${repo})`
|
||||
}
|
||||
-%>
|
||||
| <%= linkedName %> | <%= version %> | <%= licenses %> |
|
||||
<% } %>
|
Reference in New Issue
Block a user