Skip to content

Commit

Permalink
Add a license report to build
Browse files Browse the repository at this point in the history
  • Loading branch information
e9gille committed Jan 17, 2023
1 parent ee74c5f commit 37e2033
Show file tree
Hide file tree
Showing 5 changed files with 540 additions and 21 deletions.
71 changes: 71 additions & 0 deletions generate-licenses.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
const generateLicenses = function generateLicenses(file) {
const checker = require('license-checker');
const fs = require('fs');
const path = require('path');
checker.init(
{
start: ".",
production: true,
excludePrivatePackages: true,
},
function (err, json) {
if (err) {
console.log(err); //Handle error
} else {
copyLicenseToText(json); //The sorted json data
}
}
);
function copyLicenseToText(json) {
const licenses = Object.keys(json).map((key) => {
let obj = json[key];
obj.module = key;
return obj;
})
.filter(item => !isMarkDown(item.licenseFile))
.reduce(
(r, v) => ((r[v.licenses] || (r[v.licenses] = [])).push(v), r),
{}
);
printLicenseSummary(licenses);
printLicenseDetails(licenses);
}
function printLicenseSummary(licenses) {
Object.keys(licenses).forEach((key) => {
const items = licenses[key];
fs.appendFileSync(file, "\n\n-------------------\n");
fs.appendFileSync(file, `${key} - License Summary\n`);
fs.appendFileSync(file, "--------------------\n\n");
items.forEach(item => {
fs.appendFileSync(file, `${item.module}\n`);
});
});
}
function printLicenseDetails(licenses) {
Object.keys(licenses).forEach(function (key) {
const items = licenses[key];
fs.appendFileSync(file, "\n\n----------------------\n");
fs.appendFileSync(file, `${key} - License Details \n`);
fs.appendFileSync(file, "------------------------\n\n");
items.forEach(copyLicense);
});
}
function copyLicense(item) {
try {
if (item.licenseFile && !isMarkDown(item.licenseFile)) {
const licenseFile = fs.readFileSync(`${item.licenseFile}`, "utf8");
fs.appendFileSync(file, "\n\n----------------------\n");
fs.appendFileSync(file, `${item.module} - ${item.licenses}\n`);
fs.appendFileSync(file, "-----------------------\n\n");
fs.appendFileSync(file, licenseFile);
}
} catch (err) {
console.error(err);
}
}
function isMarkDown(filepath) {
const filename = path.basename(filepath).toUpperCase();
return filename == "README.MD" || filename == "README.MARKDOWN";
}
};
module.exports.generateLicenses = generateLicenses;
2 changes: 1 addition & 1 deletion licence
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2016, Dyalog Ltd
Copyright (c) 2016-2023, Dyalog Ltd

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
22 changes: 2 additions & 20 deletions mk
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const fs = rq('fs');
const path = rq('path');
const { execSync } = rq('child_process');
const async = rq('async');
const { generateLicenses } = rq('./generate-licenses');
const sh = x => execSync(x, { encoding: 'utf8' }).replace(/[\r\n]/g, ''); // exec in shell
const rf = x => fs.readFileSync(x, 'utf8'); // read file
const wf = (x, y) => fs.writeFileSync(x, y); // write file
Expand Down Expand Up @@ -70,26 +71,6 @@ const pkg = (x, y, f) => {
buildVersion: isDyalogBuild ? process.env.APPVERSION : v,
appCategoryType: 'public.app-category.developer-tools',
extendInfo: isDyalogBuild ? 'CI/packagescripts/osx/Info.plist' : null,
/* afterCopy: [
(buildPath, electronVersion, platform, arch, cb) => {
if (!isDyalogBuild) return cb();
console.log(`Add Dyalog to ${buildPath}/../`);
execSync(`cp -r ${process.env.DYALOG_ROOT} ${buildPath}/../`);
console.log(`Add CEF to ${buildPath}/../../Frameworks`);
md(`${buildPath}/../../Frameworks/Chromium\ Embedded\ Framework.framework/Versions`);
const cef = 'Chromium\\ Embedded\\ Framework';
const cef_path = `${buildPath}/../../Frameworks/${cef}.framework/`;
execSync(`cp -r ${process.env.CEF_ROOT} ${cef_path}Versions/A`);
execSync(`ln -s ./A ${cef_path}Versions/Current`);
execSync(`ln -s ./Versions/Current/Libraries ${cef_path}Libraries`);
execSync(`ln -s ./Versions/Current/Resources ${cef_path}Resources`);
execSync(`ln -s ./Versions/Current/${cef} ${cef_path}${cef}`);
console.log(`Add symlink to Frameworks`);
execSync(`ln -s ../Frameworks ${buildPath}/../Frameworks`);
console.log("Dyalog and CEF added.");
cb();
}
],*/
win32metadata: { // ends up in Windows Explorer's right click > Properties
CompanyName: 'Dyalog Ltd',
FileDescription: 'Remote Integrated Development Environment for Dyalog APL',
Expand All @@ -101,6 +82,7 @@ const pkg = (x, y, f) => {
const d = `_/${pj.name}/${pj.productName}-${x}-${y}`;
rm(`${d}/version`);
fs.existsSync(`${d}/LICENSE`) && mv(`${d}/LICENSE`, `${d}/LICENSE.electron`);
generateLicenses(`${d}/LICENSES.node.txt`);
f();
}, e => f(e));
};
Expand Down
Loading

0 comments on commit 37e2033

Please sign in to comment.