Skip to content

Commit

Permalink
Merge pull request #219 from CesiumGS/ThirdParty.json
Browse files Browse the repository at this point in the history
  • Loading branch information
shehzan10 committed May 13, 2022
2 parents f25723c + 3192a27 commit a6f5f3c
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 5 deletions.
58 changes: 58 additions & 0 deletions samples-generator/ThirdParty.json
Original file line number Diff line number Diff line change
@@ -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": "draco3d",
"license": [
"Apache-2.0"
],
"version": "1.3.6",
"url": "https://www.npmjs.com/package/draco3d"
},
{
"name": "fs-extra",
"license": [
"MIT"
],
"version": "9.1.0",
"url": "https://www.npmjs.com/package/fs-extra"
},
{
"name": "gltf-pipeline",
"license": [
"Apache-2.0"
],
"version": "3.0.4",
"url": "https://www.npmjs.com/package/gltf-pipeline"
},
{
"name": "mime",
"license": [
"MIT"
],
"version": "2.6.0",
"url": "https://www.npmjs.com/package/mime"
},
{
"name": "simplex-noise",
"license": [
"MIT"
],
"version": "2.4.0",
"url": "https://www.npmjs.com/package/simplex-noise"
}
]
87 changes: 87 additions & 0 deletions samples-generator/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var yargs = require('yargs');
var fsExtra = require('fs-extra');
var open = require('open');

var defaultValue = Cesium.defaultValue;
var defined = Cesium.defined;
var argv = yargs.argv;

Expand Down Expand Up @@ -102,3 +103,89 @@ gulp.task('cloc', function() {
});
});
});

function getLicenseDataFromPackage(packageName, override) {
override = defaultValue(override, defaultValue.EMPTY_OBJECT);
var packagePath = path.join('node_modules', packageName, 'package.json');

if (!fsExtra.existsSync(packagePath)) {
throw new Error(`Unable to find ${packageName} license information`);
}

var contents = fsExtra.readFileSync(packagePath);
var packageJson = JSON.parse(contents);

var 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'];
}

var 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() {
var path = 'ThirdParty.extra.json';
if (fsExtra.existsSync(path)) {
var contents = fsExtra.readFileSync(path);
return JSON.parse(contents);
}
return [];
}

gulp.task('generate-third-party', async function() {
var packageJson = JSON.parse(fsExtra.readFileSync('package.json'));
var thirdPartyExtraJson = readThirdPartyExtraJson();

var thirdPartyJson = [];

var dependencies = packageJson.dependencies;
for (var packageName in dependencies) {
if (dependencies.hasOwnProperty(packageName)) {
var override = thirdPartyExtraJson.find(
(entry) => entry.name === packageName
);
thirdPartyJson.push(
getLicenseDataFromPackage(packageName, override)
);
}
}

thirdPartyJson.sort(function (a, b) {
var nameA = a.name.toLowerCase();
var 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)
);
});
11 changes: 6 additions & 5 deletions samples-generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
"node": ">=4.0.0"
},
"dependencies": {
"@types/bluebird": "^3.5.32",
"@types/jasmine": "^3.5.11",
"@types/node": "^14.0.24",
"bluebird": "^3.7.2",
"cesium": "^1.71.0",
"draco3d": "1.3.6",
Expand All @@ -35,6 +32,9 @@
"simplex-noise": "^2.4.0"
},
"devDependencies": {
"@types/bluebird": "^3.5.32",
"@types/jasmine": "^3.5.11",
"@types/node": "^14.0.24",
"@types/fs-extra": "^9.0.1",
"@types/jest": "^26.0.5",
"cloc": "^2.5.1",
Expand Down Expand Up @@ -62,9 +62,10 @@
"test": "jest",
"test-watch": "npx jest --watch",
"coverage": "npx jest --coverage",
"cloc": "gulp cloc"
"cloc": "gulp cloc",
"generate-third-party": "gulp generate-third-party"
},
"bin": {
"3d-tiles-samples-generator": "./bin/3d-tiles-samples-generator"
}
}
}

0 comments on commit a6f5f3c

Please sign in to comment.