Merge pull request #271 from CesiumGS/ThirdParty.json

This commit is contained in:
Shehzan Mohammed 2022-05-13 12:13:29 -04:00 committed by GitHub
commit 0c9083a542
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 146 additions and 1 deletions

58
ThirdParty.json Normal file
View File

@ -0,0 +1,58 @@
[
{
"name": "bluebird",
"license": [
"MIT"
],
"version": "3.7.2",
"url": "https://www.npmjs.com/package/bluebird"
},
{
"name": "cesium",
"license": [
"Apache-2.0"
],
"version": "1.93.0",
"url": "https://www.npmjs.com/package/cesium"
},
{
"name": "fs-extra",
"license": [
"MIT"
],
"version": "10.1.0",
"url": "https://www.npmjs.com/package/fs-extra"
},
{
"name": "jpeg-js",
"license": [
"BSD-3-Clause"
],
"version": "0.4.3",
"url": "https://www.npmjs.com/package/jpeg-js"
},
{
"name": "mime",
"license": [
"MIT"
],
"version": "2.6.0",
"url": "https://www.npmjs.com/package/mime"
},
{
"name": "pngjs",
"license": [
"MIT"
],
"version": "6.0.0",
"url": "https://www.npmjs.com/package/pngjs"
},
{
"name": "yargs",
"license": [
"MIT"
],
"version": "17.4.1",
"url": "https://www.npmjs.com/package/yargs"
}
]

View File

@ -11,6 +11,7 @@ const open = require("open");
const path = require("path"); const path = require("path");
const yargs = require("yargs"); const yargs = require("yargs");
const defaultValue = Cesium.defaultValue;
const defined = Cesium.defined; const defined = Cesium.defined;
const argv = yargs.argv; const argv = yargs.argv;
@ -33,6 +34,7 @@ module.exports = {
"test-watch": testWatch, "test-watch": testWatch,
coverage: coverage, coverage: coverage,
cloc: cloc, cloc: cloc,
"generate-third-party": generateThirdParty,
}; };
function test(done) { function test(done) {
@ -117,3 +119,87 @@ function cloc() {
}); });
}); });
} }
function getLicenseDataFromPackage(packageName, override) {
override = defaultValue(override, defaultValue.EMPTY_OBJECT);
const packagePath = path.join("node_modules", packageName, "package.json");
if (!fsExtra.existsSync(packagePath)) {
throw new Error(`Unable to find ${packageName} license information`);
}
const contents = fsExtra.readFileSync(packagePath);
const packageJson = JSON.parse(contents);
let licenseField = override.license;
if (!licenseField) {
licenseField = [packageJson.license];
}
if (!licenseField && packageJson.licenses) {
licenseField = packageJson.licenses;
}
if (!licenseField) {
console.log(`No license found for ${packageName}`);
licenseField = ["NONE"];
}
let version = packageJson.version;
if (!packageJson.version) {
console.log(`No version information found for ${packageName}`);
version = "NONE";
}
return {
name: packageName,
license: licenseField,
version: version,
url: `https://www.npmjs.com/package/${packageName}`,
notes: override.notes,
};
}
function readThirdPartyExtraJson() {
const path = "ThirdParty.extra.json";
if (fsExtra.existsSync(path)) {
const contents = fsExtra.readFileSync(path);
return JSON.parse(contents);
}
return [];
}
async function generateThirdParty() {
const packageJson = JSON.parse(fsExtra.readFileSync("package.json"));
const thirdPartyExtraJson = readThirdPartyExtraJson();
const thirdPartyJson = [];
const dependencies = packageJson.dependencies;
for (const packageName in dependencies) {
if (dependencies.hasOwnProperty(packageName)) {
const override = thirdPartyExtraJson.find(
(entry) => entry.name === packageName
);
thirdPartyJson.push(getLicenseDataFromPackage(packageName, override));
}
}
thirdPartyJson.sort(function (a, b) {
const nameA = a.name.toLowerCase();
const nameB = b.name.toLowerCase();
if (nameA < nameB) {
return -1;
}
if (nameA > nameB) {
return 1;
}
return 0;
});
fsExtra.writeFileSync(
"ThirdParty.json",
JSON.stringify(thirdPartyJson, null, 2)
);
}

View File

@ -65,7 +65,8 @@
"cloc": "gulp cloc", "cloc": "gulp cloc",
"prettier": "prettier --write \"**/*\"", "prettier": "prettier --write \"**/*\"",
"prettier-check": "prettier --check \"**/*\"", "prettier-check": "prettier --check \"**/*\"",
"pretty-quick": "pretty-quick" "pretty-quick": "pretty-quick",
"generate-third-party": "gulp generate-third-party"
}, },
"bin": { "bin": {
"obj2gltf": "./bin/obj2gltf.js" "obj2gltf": "./bin/obj2gltf.js"