Skip to content

Commit

Permalink
fix(webapps): ensure third-party license headers are present
Browse files Browse the repository at this point in the history
related to CAM-14493, closes camunda#1989
  • Loading branch information
tasso94 authored Aug 19, 2022
1 parent 518460c commit 0090807
Show file tree
Hide file tree
Showing 17 changed files with 1,947 additions and 9,466 deletions.
128 changes: 108 additions & 20 deletions webapps/camunda-commons-ui/grunt/tasks/ensureLibs.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@

var fs = require('fs');
var through = require('through2');
const path = require('path');

var included = [
'angular',
'moment',
'camunda-bpm-sdk-js/lib/angularjs/index',
'camunda-bpm-sdk-js',
'q',
'@bpmn-io/dmn-migrate',
'@bpmn-io/form-js-editor',
'@bpmn-io/form-js-viewer',
'@bpmn-io/form-js',
'angular-animate',
'angular-cookies',
'angular-data-depend',
Expand All @@ -35,28 +35,46 @@ var included = [
'angular-sanitize',
'angular-touch',
'angular-translate',
'angular-ui-bootstrap',
'angular',
'bootstrap',
'bpmn-js',
'bpmn-js/lib/NavigatedViewer',
'camunda-bpm-sdk-js',
'camunda-bpm-sdk-js/lib/angularjs/index',
'clipboard',
'cmmn-js',
'dmn-js',
'jquery',
'lodash',

// Okay, this looks bad. But hear me out:
// We create our own DMN editor using DMN-JS
// DMN-JS only exports a viewer on the default entry, so we have to require the modules directly
// As we don't want to ship dmn-js multiple times, we need to bundle all the required libs here as well
// let's hope we can refactor this when we introduce DMN 1.3
// The culprit is over here:
// camunda-bpm-webapp/camunda-commons-ui/lib/widgets/dmn-viewer/lib/navigatedViewer.js
'dmn-js-shared/lib/base/Manager',
'dmn-js-drd/lib/NavigatedViewer',
'cmmn-js/lib/Viewer',
'cmmn-js/lib/NavigatedViewer',
'core-js',
'dmn-js-decision-table/lib/Viewer',
'dmn-js-drd/lib/NavigatedViewer',
'dmn-js-literal-expression/lib/Viewer',
'dmn-js-shared/lib/util/ModelUtil',
'dmn-js-shared/lib/base/Manager',
'dmn-js-shared/lib/util/DiUtil',
'dmn-js/lib/Modeler'
'dmn-js-shared/lib/util/ModelUtil',
'dmn-js',
'dmn-js/lib/Modeler',
'dmn-moddle',
'dom4',
'events',
'fast-xml-parser',
'jquery',
'jquery/external/sizzle/dist/sizzle',
'jquery-ui/ui/data',
'jquery-ui/ui/plugin',
'jquery-ui/ui/safe-active-element',
'jquery-ui/ui/safe-blur',
'jquery-ui/ui/scroll-parent',
'jquery-ui/ui/version',
'jquery-ui/ui/widget',
'jquery-ui/ui/widgets/draggable',
'jquery-ui/ui/widgets/mouse',
'lodash',
'moment',
'mousetrap',
'q',
'superagent'
];

module.exports = function(grunt, dirname, licensebookConfig) {
Expand Down Expand Up @@ -114,6 +132,76 @@ module.exports = function(grunt, dirname, licensebookConfig) {
persistifyOptions
);

const addMissingLicenseHeaders = row => {
if (
row.file &&
!row.file.endsWith('.json') &&
!/@license|@preserve|@lic|@cc_on|^\/\**!/i.test(row.source)
) {
let pkg = null;
if (row.file.includes('node_modules')) {
pkg = row.file.replace(
/^(.*)node_modules\/(@[a-z-\d.]+\/[a-z-\d.]+)?([a-z-\d.]+)?(.*)$/,
(match, p1, p2, p3) => p2 || p3
);
} else if (!row.file.includes('camunda-bpm-sdk-js')) {
pkg = row.file.replace(
/^(@[a-z-\d.]+\/[a-z-\d.]+)?([a-z-\d.]+)?(.*)$/,
(match, p1, p2) => p2 || p1
);
}

if (pkg) {
const packageJsonPath = require.resolve(`${pkg}/package.json`);
const packagePath = path.dirname(packageJsonPath);

let licenseInfo = null;
try {
licenseInfo = fs.readFileSync(`${packagePath}/LICENSE`, 'utf8');
} catch (e) {
try {
licenseInfo = fs.readFileSync(
`${packagePath}/LICENSE.md`,
'utf8'
);
} catch (e) {
try {
licenseInfo = fs.readFileSync(
`${packagePath}/LICENSE-MIT.txt`,
'utf8'
);
} catch (e) {
try {
licenseInfo = fs.readFileSync(
`${packagePath}/LICENSE.txt`,
'utf8'
);
} catch (e) {
console.log(`${pkg} has no license file. 🤷‍`);
}
}
}
}

const {version, license} = require(packageJsonPath);
if (licenseInfo) {
row.source = `/*!\n@license ${pkg}@${version}\n${licenseInfo}*/\n${row.source}`;
} else if (license) {
console.log(`${pkg} has a "license" property. 🤷‍`);
row.source = `/*! @license ${pkg}@${version} (${license}) */\n${row.source}`;
}
}
}
};

b.pipeline.get('deps').push(
through.obj(function(row, enc, next) {
addMissingLicenseHeaders(row);
this.push(row);
next();
})
);

const includedFiles = licensebookConfig.includedFiles;
if (licensebookConfig.enabled) {
b.pipeline.get('deps').push(
Expand Down
2 changes: 1 addition & 1 deletion webapps/camunda-commons-ui/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function requirejsConf(options) {
'angular-touch': 'node_modules/angular-touch/angular-touch',

// #### vendor dependencies
'angular-bootstrap': 'vendor/ui-bootstrap-tpls-2.5.0-camunda',
'angular-bootstrap': 'angular-ui-bootstrap',
prismjs: 'vendor/prism',
'bpmn-io': 'node_modules/bower-bpmn-js/dist/bpmn-navigated-viewer',
'dmn-io': 'node_modules/dmn-js/dist/dmn-modeler'
Expand Down
2 changes: 1 addition & 1 deletion webapps/camunda-commons-ui/lib/directives/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var angular = require('../../../camunda-bpm-sdk-js/vendor/angular'),
instantTypeahead = require('./instantTypeahead'),
util = require('../util/index');

require('../../vendor/ui-bootstrap-tpls-2.5.0-camunda');
require('angular-ui-bootstrap');

var directivesModule = angular.module('camunda.common.directives', [
'ui.bootstrap',
Expand Down
2 changes: 1 addition & 1 deletion webapps/camunda-commons-ui/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var angular = require('../../camunda-bpm-sdk-js/vendor/angular'),
widgets = require('./widgets/index'),
dateFilter = require('./filter/date/index');

require('../vendor/ui-bootstrap-tpls-2.5.0-camunda');
require('angular-ui-bootstrap');
require('angular-translate');
require('angular-cookies');
require('angular-animate');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var angular = require('../../../../../camunda-bpm-sdk-js/vendor/angular');
var camShareLink = require('../cam-share-link');
var clipboardDefinition = require('../../clipboard/cam-widget-clipboard');

require('../../../../vendor/ui-bootstrap-tpls-2.5.0-camunda');
require('angular-ui-bootstrap');
require('angular-translate');


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var angular = require('../../../../../camunda-bpm-sdk-js/vendor/angular'),
data = {},
chartLineDefinition = require('../cam-widget-chart-line');

require('../../../../vendor/ui-bootstrap-tpls-2.5.0-camunda');
require('angular-ui-bootstrap');

function shiftTimestamps(json) {
var diff = moment().valueOf() - moment(json[0].timestamp).valueOf();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
var angular = require('../../../../../camunda-bpm-sdk-js/vendor/angular');
var clipboardDefinition = require('../cam-widget-clipboard');

require('../../../../vendor/ui-bootstrap-tpls-2.5.0-camunda');
require('angular-ui-bootstrap');

var clipboardModule = angular.module('clipboardModule', [
'ui.bootstrap'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
var angular = require('../../../../../camunda-bpm-sdk-js/vendor/angular'),
headerDefinition = require('../cam-widget-header');

require('../../../../vendor/ui-bootstrap-tpls-2.5.0-camunda');
require('angular-ui-bootstrap');
require('angular-translate');

// naive auth object for test purposes
Expand Down
2 changes: 1 addition & 1 deletion webapps/camunda-commons-ui/lib/widgets/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ var angular = require('../../../camunda-bpm-sdk-js/vendor/angular'),
password = require('./password/cam-widget-password'),
selectionType = require('./selection-type/cam-widget-selection-type');

require('../../vendor/ui-bootstrap-tpls-2.5.0-camunda');
require('angular-ui-bootstrap');

var widgetModule = angular.module('camunda.common.widgets', [
filtersModule.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
var angular = require('../../../../../camunda-bpm-sdk-js/vendor/angular'),
loaderDefinition = require('../cam-widget-loader');

require('../../../../vendor/ui-bootstrap-tpls-2.5.0-camunda');
require('angular-ui-bootstrap');

var loaderModule = angular.module('loaderModule', ['ui.bootstrap']);
loaderModule.directive('camWidgetLoader', loaderDefinition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var angular = require('../../../../../camunda-bpm-sdk-js/vendor/angular'),
variableDefinition = require('../cam-widget-variable'),
variableValidator = require('../cam-variable-validator');

require('../../../../vendor/ui-bootstrap-tpls-2.5.0-camunda');
require('angular-ui-bootstrap');
require('angular-translate');

var variableModule = angular.module('variableModule', [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var angular = require('../../../../../camunda-bpm-sdk-js/vendor/angular'),
varUtils = require('../../variable/cam-variable-utils'),
camCommonsUi = require('../../index');

require('../../../../vendor/ui-bootstrap-tpls-2.5.0-camunda');
require('angular-ui-bootstrap');
require('angular-translate');

var variableModule = angular.module('variableModule', [
Expand Down
Loading

0 comments on commit 0090807

Please sign in to comment.