mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +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
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user