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
67
demo-shell-ng2/config/loaders/license-check.js
Normal file
67
demo-shell-ng2/config/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);
|
||||
};
|
@@ -29,6 +29,13 @@ module.exports = {
|
||||
'vendor': './app/vendor.ts',
|
||||
'app': './app/main.ts'
|
||||
},
|
||||
|
||||
resolveLoader: {
|
||||
alias: {
|
||||
"license-check": path.resolve(__dirname, "./loaders/license-check")
|
||||
}
|
||||
},
|
||||
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
@@ -84,6 +91,17 @@ module.exports = {
|
||||
{
|
||||
test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)$/,
|
||||
loader: 'file-loader?name=assets/[name].[hash].[ext]'
|
||||
},
|
||||
{
|
||||
enforce: 'pre',
|
||||
test: /\.ts$/,
|
||||
loader: 'license-check',
|
||||
include: helpers.root('app'),
|
||||
options: {
|
||||
emitErrors: true,
|
||||
licenseFile: path.resolve(__dirname, '../assets/license_header.txt')
|
||||
},
|
||||
exclude: [/node_modules/, /bundles/, /dist/, /demo/],
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@@ -4,14 +4,13 @@
|
||||
"version": "1.4.0",
|
||||
"author": "Alfresco Software, Ltd.",
|
||||
"scripts": {
|
||||
"build": "rimraf dist && npm run licensecheck && webpack --config config/webpack.prod.js --progress --profile --bail",
|
||||
"build": "rimraf dist && webpack --config config/webpack.prod.js --progress --profile --bail",
|
||||
"start": "npm run server-versions && node --max_old_space_size=4096 node_modules/webpack-dev-server/bin/webpack-dev-server.js --progress",
|
||||
"test": "rimraf coverage && karma start --single-run",
|
||||
"clean": "npm run clean-build && rimraf dist node_modules typings dist",
|
||||
"clean-build": "rimraf 'app/{,**/}**.js' 'app/{,**/}**.js.map' 'app/{,**/}**.d.ts'",
|
||||
"server-versions": "rimraf versions.json && npm list --depth=0 --json=true --prod=true > versions.json || exit 0",
|
||||
"aws": "node app.js",
|
||||
"licensecheck": "license-check"
|
||||
"aws": "node app.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -118,7 +117,6 @@
|
||||
"karma-remap-istanbul": "^0.6.0",
|
||||
"karma-sourcemap-loader": "^0.3.7",
|
||||
"karma-webpack": "^2.0.2",
|
||||
"license-check": "1.1.5",
|
||||
"null-loader": "^0.1.1",
|
||||
"to-string-loader": "^1.1.4",
|
||||
"raw-loader": "^0.5.1",
|
||||
@@ -134,15 +132,5 @@
|
||||
"webpack": "^2.2.1",
|
||||
"webpack-dev-server": "^2.3.0",
|
||||
"webpack-merge": "^2.6.1"
|
||||
},
|
||||
"license-check-config": {
|
||||
"src": [
|
||||
"./app/**/*.js",
|
||||
"!./app/js/*.js"
|
||||
],
|
||||
"path": "assets/license_header.txt",
|
||||
"blocking": true,
|
||||
"logInfo": false,
|
||||
"logError": true
|
||||
}
|
||||
}
|
||||
|
@@ -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(
|
||||
|
@@ -47,7 +47,6 @@ done
|
||||
cd "$DIR/../ng2-components/"
|
||||
npm install package-json-merge -g
|
||||
npm install rimraf -g
|
||||
npm install license-check -g
|
||||
npm run pkg-build
|
||||
npm install && npm run build || exit 1
|
||||
|
||||
@@ -55,7 +54,6 @@ for PACKAGE in ${projects[@]}
|
||||
do
|
||||
DESTDIR="$DIR/../ng2-components/${PACKAGE}"
|
||||
cd $DESTDIR
|
||||
npm run license-check || exit 1
|
||||
if $RUN_TEST == true; then
|
||||
test_project $PACKAGE
|
||||
fi
|
||||
|
Reference in New Issue
Block a user