mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-579] - move license check in webpack (#1859)
* move license check in webpack * fix exclusion check header * different headers
This commit is contained in:
committed by
Eugenio Romano
parent
774017ac62
commit
80d67212b7
@@ -1,14 +1,16 @@
|
||||
@license
|
||||
Copyright 2016 Alfresco Software, Ltd.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2016 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
14
ng2-components/config/assets/license_header_add.txt
Normal file
14
ng2-components/config/assets/license_header_add.txt
Normal file
@@ -0,0 +1,14 @@
|
||||
@license
|
||||
Copyright 2016 Alfresco Software, Ltd.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
67
ng2-components/config/custom-loaders/license-check.js
Normal file
67
ng2-components/config/custom-loaders/license-check.js
Normal file
@@ -0,0 +1,67 @@
|
||||
var path = require('path');
|
||||
var loaderUtils = require('loader-utils');
|
||||
var fs = require('fs');
|
||||
|
||||
var licenseFileUtf8Store = undefined;
|
||||
|
||||
function readLicenseHeaderFile(licenseFilePath) {
|
||||
if (licenseFileUtf8Store) {
|
||||
return licenseFileUtf8Store;
|
||||
}
|
||||
|
||||
if (fs.existsSync(licenseFilePath)) {
|
||||
licenseFileUtf8Store = fs.readFileSync(licenseFilePath, 'utf8').split(/\r?\n/);
|
||||
return licenseFileUtf8Store;
|
||||
}
|
||||
|
||||
throw new Error('The license header file path is wrong ' + licenseFilePath);
|
||||
}
|
||||
|
||||
function isFileEmpty(fileContents) {
|
||||
return fileContents.toString('utf8').trim() === '';
|
||||
}
|
||||
|
||||
function readCurrentFile(fileContent) {
|
||||
return fileContent.toString('utf8').split(/\r?\n/);
|
||||
}
|
||||
|
||||
function isLicenseHeaderPresent(currentFileContent, licenseFilePath) {
|
||||
if (!isFileEmpty(currentFileContent)) {
|
||||
var currentFileUtf8 = readCurrentFile(currentFileContent),
|
||||
licenseFileUtf8 = readLicenseHeaderFile(licenseFilePath);
|
||||
skipStrict = 0;
|
||||
|
||||
if(currentFileUtf8[0] === '"use strict";' ) {
|
||||
skipStrict = 1;
|
||||
}
|
||||
|
||||
for (var i = skipStrict; i < licenseFileUtf8.length; i++) {
|
||||
if (currentFileUtf8[i + skipStrict] !== licenseFileUtf8[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function report(hasHeader, emitter, filename) {
|
||||
if (hasHeader) return;
|
||||
emitter('Missing license header file : ' + filename);
|
||||
}
|
||||
|
||||
function licenseCheck(webpackInstance, input, options) {
|
||||
var isLicensePresent = isLicenseHeaderPresent(input, options.licenseFile);
|
||||
|
||||
var emitter = options.emitErrors ? webpackInstance.emitError : webpackInstance.emitWarning;
|
||||
|
||||
report(isLicensePresent, emitter, webpackInstance.resourcePath);
|
||||
}
|
||||
|
||||
module.exports = function(input, map) {
|
||||
this.cacheable && this.cacheable();
|
||||
var callback = this.async();
|
||||
|
||||
var options = loaderUtils.getOptions(this);
|
||||
licenseCheck(this, input, options);
|
||||
callback(null, input, map);
|
||||
};
|
@@ -7,7 +7,8 @@ module.exports = {
|
||||
|
||||
resolveLoader: {
|
||||
alias: {
|
||||
"file-multi-loader": path.resolve(__dirname, "./custom-loaders/file-loader-multi")
|
||||
"file-multi-loader": path.resolve(__dirname, "./custom-loaders/file-loader-multi"),
|
||||
"license-check": path.resolve(__dirname, "./custom-loaders/license-check")
|
||||
}
|
||||
},
|
||||
|
||||
@@ -65,6 +66,15 @@ module.exports = {
|
||||
test: /\.css$/,
|
||||
loader: ['to-string-loader', 'css-loader'],
|
||||
exclude: [/node_modules/, /bundles/, /dist/, /demo/]
|
||||
},{
|
||||
enforce: 'pre',
|
||||
test: /\.ts$/,
|
||||
loader: 'license-check',
|
||||
options: {
|
||||
emitErrors: true,
|
||||
licenseFile: path.resolve(__dirname, './assets/license_header.txt')
|
||||
},
|
||||
exclude: [/node_modules/, /bundles/, /dist/, /demo/, /rendering-queue.services.ts/ ],
|
||||
},
|
||||
{
|
||||
test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)$/,
|
||||
@@ -95,7 +105,7 @@ module.exports = {
|
||||
plugins: [
|
||||
new webpack.NoEmitOnErrorsPlugin(),
|
||||
|
||||
new webpack.BannerPlugin(fs.readFileSync(path.resolve(__dirname, './assets/license_header.txt'), 'utf8')),
|
||||
new webpack.BannerPlugin(fs.readFileSync(path.resolve(__dirname, './assets/license_header_add.txt'), 'utf8')),
|
||||
|
||||
// Workaround for angular/angular#11580
|
||||
new webpack.ContextReplacementPlugin(
|
||||
|
Reference in New Issue
Block a user