diff --git a/ng2-components/config/karma.conf-all.js b/ng2-components/config/karma.conf-all.js index fd07cca849..2bf0225b26 100644 --- a/ng2-components/config/karma.conf-all.js +++ b/ng2-components/config/karma.conf-all.js @@ -7,14 +7,14 @@ module.exports = function (config) { frameworks: ['jasmine-ajax', 'jasmine'], files: [ - {pattern: './node_modules/hammerjs/hammer.js', included: true, watched: false}, + {pattern: './node_modules/hammerjs/hammer.min.js', included: true, watched: false}, //diagrams {pattern: './node_modules/chart.js/dist/Chart.js', included: true, watched: false}, - {pattern: './node_modules/alfresco-js-api/dist/alfresco-js-api.js', included: true, watched: false}, - {pattern: './node_modules/raphael/raphael.js', included: true, watched: false}, + {pattern: './node_modules/alfresco-js-api/dist/alfresco-js-api.min.js', included: true, watched: false}, + {pattern: './node_modules/raphael/raphael.min.js', included: true, watched: false}, {pattern: './node_modules/moment/min/moment.min.js', included: true, watched: false}, - {pattern: './node_modules/md-date-time-picker/dist/js/mdDateTimePicker.js', included: true, watched: false}, + {pattern: './node_modules/md-date-time-picker/dist/js/mdDateTimePicker.min.js', included: true, watched: false}, {pattern: './node_modules/ng2-translate/ng2-translate.js', included: false, watched: false}, {pattern: './node_modules/ng2-charts/bundles/ng2-charts.umd.js', included: false, served: true, watched: false}, diff --git a/ng2-components/config/webpack.build.js b/ng2-components/config/webpack.build.js index d53e802508..610e43e269 100644 --- a/ng2-components/config/webpack.build.js +++ b/ng2-components/config/webpack.build.js @@ -1,4 +1,4 @@ -const webpack = require("webpack"); +const webpack = require('webpack'); const webpackMerge = require('webpack-merge'); const commonConfig = require('./webpack.common.js'); diff --git a/ng2-components/karma-test-shim.js b/ng2-components/karma-test-shim.js new file mode 100644 index 0000000000..0a93db5eff --- /dev/null +++ b/ng2-components/karma-test-shim.js @@ -0,0 +1,22 @@ +Error.stackTraceLimit = Infinity; + +require('core-js/es6'); +require('core-js/es7/reflect'); + +require('zone.js/dist/zone'); +require('zone.js/dist/long-stack-trace-zone'); +require('zone.js/dist/proxy'); +require('zone.js/dist/sync-test'); +require('zone.js/dist/jasmine-patch'); +require('zone.js/dist/async-test'); +require('zone.js/dist/fake-async-test'); + +jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000; + +var appContext = require.context('./', true, /^(?=.*(ng2-))(?!.*node_modules).*(.([^\/]*\/[^\/]*)src)((\\\\|\/)[a-zA-Z0-9_. \-]+)+\.spec.ts/); +appContext.keys().forEach(appContext); + +var testing = require('@angular/core/testing'); +var browser = require('@angular/platform-browser-dynamic/testing'); + +testing.TestBed.initTestEnvironment(browser.BrowserDynamicTestingModule, browser.platformBrowserDynamicTesting()); diff --git a/ng2-components/ng2-activiti-analytics/config/assets/license_header.txt b/ng2-components/ng2-activiti-analytics/config/assets/license_header.txt new file mode 100644 index 0000000000..58ad8b656b --- /dev/null +++ b/ng2-components/ng2-activiti-analytics/config/assets/license_header.txt @@ -0,0 +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. + */ diff --git a/ng2-components/ng2-activiti-analytics/config/assets/license_header_add.txt b/ng2-components/ng2-activiti-analytics/config/assets/license_header_add.txt new file mode 100644 index 0000000000..b38baa9716 --- /dev/null +++ b/ng2-components/ng2-activiti-analytics/config/assets/license_header_add.txt @@ -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. diff --git a/ng2-components/ng2-activiti-analytics/config/assets/tslint.json b/ng2-components/ng2-activiti-analytics/config/assets/tslint.json new file mode 100644 index 0000000000..611a015c7e --- /dev/null +++ b/ng2-components/ng2-activiti-analytics/config/assets/tslint.json @@ -0,0 +1,118 @@ +{ + "rules": { + "align": [ + true, + "parameters", + "statements" + ], + "ban": false, + "class-name": true, + "comment-format": [ + true, + "check-space" + ], + "curly": true, + "eofline": true, + "forin": true, + "indent": [ + true, + "spaces" + ], + "interface-name": false, + "jsdoc-format": true, + "label-position": true, + "max-line-length": [ + true, + 180 + ], + "member-ordering": [ + true, + "static-before-instance", + "variables-before-functions" + ], + "no-any": false, + "no-arg": true, + "no-bitwise": false, + "no-conditional-assignment": true, + "no-consecutive-blank-lines": true, + "no-console": [ + true, + "debug", + "info", + "time", + "timeEnd", + "trace" + ], + "no-construct": true, + "no-constructor-vars": false, + "no-debugger": true, + "no-duplicate-variable": true, + "no-empty": false, + "no-eval": true, + "no-inferrable-types": false, + "no-internal-module": true, + "no-require-imports": false, + "no-shadowed-variable": true, + "no-switch-case-fall-through": true, + "no-trailing-whitespace": true, + "no-unused-expression": true, + "no-unused-variable": true, + "no-use-before-declare": true, + "no-var-keyword": true, + "no-var-requires": true, + "object-literal-sort-keys": false, + "one-line": [ + true, + "check-open-brace", + "check-catch", + "check-else", + "check-whitespace" + ], + "quotemark": [ + true, + "single", + "avoid-escape" + ], + "radix": true, + "semicolon": true, + "switch-default": true, + "trailing-comma": [ + true, + { + "multiline": "never", + "singleline": "never" + } + ], + "triple-equals": [ + true, + "allow-null-check" + ], + "typedef": false, + "typedef-whitespace": [ + true, + { + "call-signature": "nospace", + "index-signature": "nospace", + "parameter": "nospace", + "property-declaration": "nospace", + "variable-declaration": "nospace" + } + ], + "use-strict": false, + "variable-name": [ + true, + "check-format", + "allow-leading-underscore", + "ban-keywords" + ], + "whitespace": [ + true, + "check-branch", + "check-operator", + "check-separator", + "check-type", + "check-module", + "check-decl" + ] + } +} diff --git a/ng2-components/ng2-activiti-analytics/config/custom-loaders/file-loader-multi.js b/ng2-components/ng2-activiti-analytics/config/custom-loaders/file-loader-multi.js new file mode 100644 index 0000000000..dfbf93e76e --- /dev/null +++ b/ng2-components/ng2-activiti-analytics/config/custom-loaders/file-loader-multi.js @@ -0,0 +1,70 @@ +var path = require('path'); +var loaderUtils = require('loader-utils'); + +module.exports = function(content) { + this.cacheable && this.cacheable(); + if(!this.emitFile) throw new Error('emitFile is required from module system'); + + var query = loaderUtils.getOptions(this) || {}; + var configKey = query.config || 'multiFileLoader'; + var options = this.options[configKey] || {}; + var config = { + publicPath: false, + useRelativePath: false, + name: '[hash].[ext]' + }; + + // options takes precedence over config + Object.keys(options).forEach(function(attr) { + config[attr] = options[attr]; + }); + + // query takes precedence over config and options + Object.keys(query).forEach(function(attr) { + config[attr] = query[attr]; + }); + + var context = config.context || this.options.context; + var url = loaderUtils.interpolateName(this, config.name, { + context: context, + content: content, + regExp: config.regExp + }); + var path = loaderUtils.interpolateName(this, '[path]', { + context: context, + content: content, + regExp: config.regExp + }); + + var outputPath = ''; + + if (config.outputPath) { + outputPath = ( + typeof config.outputPath === 'function' + ? config.outputPath(url, path) + : config.outputPath + url + ); + } else { + outputPath = url; + } + + var publicPath = JSON.stringify(url); + + if (config.publicPath) { + publicPath = JSON.stringify( + typeof config.publicPath === 'function' + ? config.publicPath(url, path) + : config.publicPath + url + ); + } + + publicPath = '__webpack_public_path__ + ' + publicPath; + + if (query.emitFile === undefined || query.emitFile) { + this.emitFile(outputPath, content); + } + + return 'module.exports = ' + publicPath + ';'; +}; + +module.exports.raw = true; diff --git a/ng2-components/ng2-activiti-analytics/config/custom-loaders/license-check.js b/ng2-components/ng2-activiti-analytics/config/custom-loaders/license-check.js new file mode 100644 index 0000000000..6a15ac03e2 --- /dev/null +++ b/ng2-components/ng2-activiti-analytics/config/custom-loaders/license-check.js @@ -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); +}; diff --git a/ng2-components/ng2-activiti-analytics/config/helpers.js b/ng2-components/ng2-activiti-analytics/config/helpers.js new file mode 100644 index 0000000000..a11fa771d6 --- /dev/null +++ b/ng2-components/ng2-activiti-analytics/config/helpers.js @@ -0,0 +1,10 @@ +var path = require('path'); + +var _root = path.resolve(__dirname, '..'); + +function root(args) { + args = Array.prototype.slice.call(arguments, 0); + return path.join.apply(path, [_root].concat(args)); +} + +exports.root = root; diff --git a/ng2-components/ng2-activiti-analytics/config/webpack.common.js b/ng2-components/ng2-activiti-analytics/config/webpack.common.js new file mode 100644 index 0000000000..95cd33177e --- /dev/null +++ b/ng2-components/ng2-activiti-analytics/config/webpack.common.js @@ -0,0 +1,124 @@ +const webpack = require('webpack'); +const helpers = require('./helpers'); +const fs = require('fs'); +const path = require('path'); + +module.exports = { + + resolveLoader: { + alias: { + "file-multi-loader": path.resolve(__dirname, "./custom-loaders/file-loader-multi"), + "license-check": path.resolve(__dirname, "./custom-loaders/license-check") + } + }, + + // require those dependencies but don't bundle them + externals: [ + /^\@angular\//, + /^rxjs\//, + 'moment', + 'raphael', + 'ng2-charts', + 'alfresco-js-api', + 'ng2-alfresco-core', + 'ng2-alfresco-datatable', + 'ng2-activiti-analytics', + 'ng2-activiti-diagrams', + 'ng2-activiti-form', + "ng2-activiti-tasklist", + 'ng2-alfresco-documentlist' + ], + + module: { + rules: [ + { + enforce: 'pre', + test: /\.js$/, + loader: 'source-map-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + enforce: 'pre', + test: /\.ts$/, + use: 'source-map-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + enforce: 'pre', + test: /\.ts$/, + loader: 'tslint-loader', + options: { + emitErrors: true, + configFile: path.resolve(__dirname, './assets/tslint.json') + }, + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.ts$/, + use: ['ts-loader', 'angular2-template-loader'], + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.html$/, + loader: 'html-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + 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)$/, + loader: 'file-multi-loader', + query: { + name: '[name].[hash].[ext]', + outputPath: (url, resourcePath)=> { + return resourcePath.replace('src', 'bundles') + url; + }, + publicPath: (url, resourcePath)=> { + var component = resourcePath.substring(0, resourcePath.indexOf('src')); + var path = resourcePath.replace(component, '').replace('src', 'bundles'); + return './' + path + url; + } + } + } + ] + }, + + resolve: { + extensions: ['.ts', '.js'], + symlinks: false, + modules: [ + '../ng2-components', 'node_modules' + ] + }, + + plugins: [ + new webpack.NoEmitOnErrorsPlugin(), + + new webpack.BannerPlugin(fs.readFileSync(path.resolve(__dirname, './assets/license_header_add.txt'), 'utf8')), + + new webpack.ContextReplacementPlugin( + /angular(\\|\/)core(\\|\/)@angular/, + helpers.root('./src'), + {} + ) + ], + + devtool: 'cheap-module-source-map', + + node: { + fs: 'empty', + module: false + } +}; diff --git a/ng2-components/ng2-activiti-analytics/config/webpack.test.js b/ng2-components/ng2-activiti-analytics/config/webpack.test.js new file mode 100644 index 0000000000..486fed8c15 --- /dev/null +++ b/ng2-components/ng2-activiti-analytics/config/webpack.test.js @@ -0,0 +1,85 @@ +const webpack = require('webpack'); +const helpers = require('./helpers'); + +const ENV = process.env.NODE_ENV = process.env.ENV = 'production'; + +module.exports = { + + devtool: 'inline-source-map', + + resolve: { + extensions: ['.ts', '.js'], + symlinks: false, + modules: [helpers.root('../ng2-components'), helpers.root('node_modules')] + }, + + module: { + rules: [ + { + enforce: 'pre', + test: /\.js$/, + loader: 'source-map-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.ts$/, + loaders: ['ts-loader?' + JSON.stringify({ transpileOnly: true}), 'angular2-template-loader'], + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.html$/, + loader: 'html-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.css$/, + loader: ['to-string-loader', 'css-loader'], + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico|pdf)$/, + loader: 'file-loader', + query: { + name: '[path][name].[ext]', + outputPath: (url)=> { + return url.replace('src', 'dist'); + } + } + }, + { + enforce: 'post', + test: /\.ts$/, + loader: 'istanbul-instrumenter-loader', + exclude: [ + /node_modules/, + /test/ + ] + } + ] + }, + + plugins: [ + new webpack.NoEmitOnErrorsPlugin(), + + new webpack.ContextReplacementPlugin( + /angular(\\|\/)core(\\|\/)@angular/, + helpers.root('./src'), + {} + ), + new webpack.DefinePlugin({ + 'process.env': { + 'ENV': JSON.stringify(ENV) + } + }), + new webpack.LoaderOptionsPlugin({ + htmlLoader: { + minimize: false // workaround for ng2 + } + }) + ], + + node: { + fs: 'empty', + module: false + } +}; diff --git a/ng2-components/ng2-activiti-analytics/karma.conf.js b/ng2-components/ng2-activiti-analytics/karma.conf.js index f7f5ca66a2..9001db1c10 100644 --- a/ng2-components/ng2-activiti-analytics/karma.conf.js +++ b/ng2-components/ng2-activiti-analytics/karma.conf.js @@ -21,11 +21,6 @@ module.exports = function (config) { {pattern: './node_modules/md-date-time-picker/**/*.js', included: false, served: true, watched: false}, {pattern: './node_modules/moment/**/*.js', included: false, served: true, watched: false}, - // pdf-js - './node_modules/pdfjs-dist/build/pdf.js', - './node_modules/pdfjs-dist/build/pdf.worker.js', - './node_modules/pdfjs-dist/web/pdf_viewer.js', - {pattern: 'karma-test-shim.js', watched: false}, {pattern: './src/assets/**/*.*', included: false, served: true, watched: false}, {pattern: './src/i18n/**/*.*', included: false, served: true, watched: false}, diff --git a/ng2-components/ng2-activiti-analytics/package.json b/ng2-components/ng2-activiti-analytics/package.json index f562749f92..691135b2f6 100644 --- a/ng2-components/ng2-activiti-analytics/package.json +++ b/ng2-components/ng2-activiti-analytics/package.json @@ -113,14 +113,5 @@ "tag", "alfresco-component" ], - "license-check-config": { - "src": [ - "./src/**/*.ts" - ], - "path": "assets/license_header.txt", - "blocking": true, - "logInfo": false, - "logError": true - }, "license": "Apache-2.0" } diff --git a/ng2-components/ng2-activiti-analytics/webpack.build.js b/ng2-components/ng2-activiti-analytics/webpack.build.js index bf06f8e80f..4a1ea06eb3 100644 --- a/ng2-components/ng2-activiti-analytics/webpack.build.js +++ b/ng2-components/ng2-activiti-analytics/webpack.build.js @@ -1,6 +1,6 @@ -const webpack = require("webpack"); +const webpack = require('webpack'); const webpackMerge = require('webpack-merge'); -const commonConfig = require('../config/webpack.common.js'); +const commonConfig = require('./config/webpack.common.js'); module.exports = webpackMerge(commonConfig, { diff --git a/ng2-components/ng2-activiti-analytics/webpack.test.js b/ng2-components/ng2-activiti-analytics/webpack.test.js index 4a61a62939..b6f4929fa4 100644 --- a/ng2-components/ng2-activiti-analytics/webpack.test.js +++ b/ng2-components/ng2-activiti-analytics/webpack.test.js @@ -1,6 +1,6 @@ const webpack = require('webpack'); const webpackMerge = require('webpack-merge'); -const testConfig = require('../config/webpack.test.js'); +const testConfig = require('./config/webpack.test.js'); module.exports = webpackMerge(testConfig, { diff --git a/ng2-components/ng2-activiti-diagrams/config/assets/license_header.txt b/ng2-components/ng2-activiti-diagrams/config/assets/license_header.txt new file mode 100644 index 0000000000..58ad8b656b --- /dev/null +++ b/ng2-components/ng2-activiti-diagrams/config/assets/license_header.txt @@ -0,0 +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. + */ diff --git a/ng2-components/ng2-activiti-diagrams/config/assets/license_header_add.txt b/ng2-components/ng2-activiti-diagrams/config/assets/license_header_add.txt new file mode 100644 index 0000000000..b38baa9716 --- /dev/null +++ b/ng2-components/ng2-activiti-diagrams/config/assets/license_header_add.txt @@ -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. diff --git a/ng2-components/ng2-activiti-diagrams/config/assets/tslint.json b/ng2-components/ng2-activiti-diagrams/config/assets/tslint.json new file mode 100644 index 0000000000..611a015c7e --- /dev/null +++ b/ng2-components/ng2-activiti-diagrams/config/assets/tslint.json @@ -0,0 +1,118 @@ +{ + "rules": { + "align": [ + true, + "parameters", + "statements" + ], + "ban": false, + "class-name": true, + "comment-format": [ + true, + "check-space" + ], + "curly": true, + "eofline": true, + "forin": true, + "indent": [ + true, + "spaces" + ], + "interface-name": false, + "jsdoc-format": true, + "label-position": true, + "max-line-length": [ + true, + 180 + ], + "member-ordering": [ + true, + "static-before-instance", + "variables-before-functions" + ], + "no-any": false, + "no-arg": true, + "no-bitwise": false, + "no-conditional-assignment": true, + "no-consecutive-blank-lines": true, + "no-console": [ + true, + "debug", + "info", + "time", + "timeEnd", + "trace" + ], + "no-construct": true, + "no-constructor-vars": false, + "no-debugger": true, + "no-duplicate-variable": true, + "no-empty": false, + "no-eval": true, + "no-inferrable-types": false, + "no-internal-module": true, + "no-require-imports": false, + "no-shadowed-variable": true, + "no-switch-case-fall-through": true, + "no-trailing-whitespace": true, + "no-unused-expression": true, + "no-unused-variable": true, + "no-use-before-declare": true, + "no-var-keyword": true, + "no-var-requires": true, + "object-literal-sort-keys": false, + "one-line": [ + true, + "check-open-brace", + "check-catch", + "check-else", + "check-whitespace" + ], + "quotemark": [ + true, + "single", + "avoid-escape" + ], + "radix": true, + "semicolon": true, + "switch-default": true, + "trailing-comma": [ + true, + { + "multiline": "never", + "singleline": "never" + } + ], + "triple-equals": [ + true, + "allow-null-check" + ], + "typedef": false, + "typedef-whitespace": [ + true, + { + "call-signature": "nospace", + "index-signature": "nospace", + "parameter": "nospace", + "property-declaration": "nospace", + "variable-declaration": "nospace" + } + ], + "use-strict": false, + "variable-name": [ + true, + "check-format", + "allow-leading-underscore", + "ban-keywords" + ], + "whitespace": [ + true, + "check-branch", + "check-operator", + "check-separator", + "check-type", + "check-module", + "check-decl" + ] + } +} diff --git a/ng2-components/ng2-activiti-diagrams/config/custom-loaders/file-loader-multi.js b/ng2-components/ng2-activiti-diagrams/config/custom-loaders/file-loader-multi.js new file mode 100644 index 0000000000..dfbf93e76e --- /dev/null +++ b/ng2-components/ng2-activiti-diagrams/config/custom-loaders/file-loader-multi.js @@ -0,0 +1,70 @@ +var path = require('path'); +var loaderUtils = require('loader-utils'); + +module.exports = function(content) { + this.cacheable && this.cacheable(); + if(!this.emitFile) throw new Error('emitFile is required from module system'); + + var query = loaderUtils.getOptions(this) || {}; + var configKey = query.config || 'multiFileLoader'; + var options = this.options[configKey] || {}; + var config = { + publicPath: false, + useRelativePath: false, + name: '[hash].[ext]' + }; + + // options takes precedence over config + Object.keys(options).forEach(function(attr) { + config[attr] = options[attr]; + }); + + // query takes precedence over config and options + Object.keys(query).forEach(function(attr) { + config[attr] = query[attr]; + }); + + var context = config.context || this.options.context; + var url = loaderUtils.interpolateName(this, config.name, { + context: context, + content: content, + regExp: config.regExp + }); + var path = loaderUtils.interpolateName(this, '[path]', { + context: context, + content: content, + regExp: config.regExp + }); + + var outputPath = ''; + + if (config.outputPath) { + outputPath = ( + typeof config.outputPath === 'function' + ? config.outputPath(url, path) + : config.outputPath + url + ); + } else { + outputPath = url; + } + + var publicPath = JSON.stringify(url); + + if (config.publicPath) { + publicPath = JSON.stringify( + typeof config.publicPath === 'function' + ? config.publicPath(url, path) + : config.publicPath + url + ); + } + + publicPath = '__webpack_public_path__ + ' + publicPath; + + if (query.emitFile === undefined || query.emitFile) { + this.emitFile(outputPath, content); + } + + return 'module.exports = ' + publicPath + ';'; +}; + +module.exports.raw = true; diff --git a/ng2-components/ng2-activiti-diagrams/config/custom-loaders/license-check.js b/ng2-components/ng2-activiti-diagrams/config/custom-loaders/license-check.js new file mode 100644 index 0000000000..6a15ac03e2 --- /dev/null +++ b/ng2-components/ng2-activiti-diagrams/config/custom-loaders/license-check.js @@ -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); +}; diff --git a/ng2-components/ng2-activiti-diagrams/config/helpers.js b/ng2-components/ng2-activiti-diagrams/config/helpers.js new file mode 100644 index 0000000000..a11fa771d6 --- /dev/null +++ b/ng2-components/ng2-activiti-diagrams/config/helpers.js @@ -0,0 +1,10 @@ +var path = require('path'); + +var _root = path.resolve(__dirname, '..'); + +function root(args) { + args = Array.prototype.slice.call(arguments, 0); + return path.join.apply(path, [_root].concat(args)); +} + +exports.root = root; diff --git a/ng2-components/ng2-activiti-diagrams/config/webpack.common.js b/ng2-components/ng2-activiti-diagrams/config/webpack.common.js new file mode 100644 index 0000000000..95cd33177e --- /dev/null +++ b/ng2-components/ng2-activiti-diagrams/config/webpack.common.js @@ -0,0 +1,124 @@ +const webpack = require('webpack'); +const helpers = require('./helpers'); +const fs = require('fs'); +const path = require('path'); + +module.exports = { + + resolveLoader: { + alias: { + "file-multi-loader": path.resolve(__dirname, "./custom-loaders/file-loader-multi"), + "license-check": path.resolve(__dirname, "./custom-loaders/license-check") + } + }, + + // require those dependencies but don't bundle them + externals: [ + /^\@angular\//, + /^rxjs\//, + 'moment', + 'raphael', + 'ng2-charts', + 'alfresco-js-api', + 'ng2-alfresco-core', + 'ng2-alfresco-datatable', + 'ng2-activiti-analytics', + 'ng2-activiti-diagrams', + 'ng2-activiti-form', + "ng2-activiti-tasklist", + 'ng2-alfresco-documentlist' + ], + + module: { + rules: [ + { + enforce: 'pre', + test: /\.js$/, + loader: 'source-map-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + enforce: 'pre', + test: /\.ts$/, + use: 'source-map-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + enforce: 'pre', + test: /\.ts$/, + loader: 'tslint-loader', + options: { + emitErrors: true, + configFile: path.resolve(__dirname, './assets/tslint.json') + }, + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.ts$/, + use: ['ts-loader', 'angular2-template-loader'], + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.html$/, + loader: 'html-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + 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)$/, + loader: 'file-multi-loader', + query: { + name: '[name].[hash].[ext]', + outputPath: (url, resourcePath)=> { + return resourcePath.replace('src', 'bundles') + url; + }, + publicPath: (url, resourcePath)=> { + var component = resourcePath.substring(0, resourcePath.indexOf('src')); + var path = resourcePath.replace(component, '').replace('src', 'bundles'); + return './' + path + url; + } + } + } + ] + }, + + resolve: { + extensions: ['.ts', '.js'], + symlinks: false, + modules: [ + '../ng2-components', 'node_modules' + ] + }, + + plugins: [ + new webpack.NoEmitOnErrorsPlugin(), + + new webpack.BannerPlugin(fs.readFileSync(path.resolve(__dirname, './assets/license_header_add.txt'), 'utf8')), + + new webpack.ContextReplacementPlugin( + /angular(\\|\/)core(\\|\/)@angular/, + helpers.root('./src'), + {} + ) + ], + + devtool: 'cheap-module-source-map', + + node: { + fs: 'empty', + module: false + } +}; diff --git a/ng2-components/ng2-activiti-diagrams/config/webpack.test.js b/ng2-components/ng2-activiti-diagrams/config/webpack.test.js new file mode 100644 index 0000000000..486fed8c15 --- /dev/null +++ b/ng2-components/ng2-activiti-diagrams/config/webpack.test.js @@ -0,0 +1,85 @@ +const webpack = require('webpack'); +const helpers = require('./helpers'); + +const ENV = process.env.NODE_ENV = process.env.ENV = 'production'; + +module.exports = { + + devtool: 'inline-source-map', + + resolve: { + extensions: ['.ts', '.js'], + symlinks: false, + modules: [helpers.root('../ng2-components'), helpers.root('node_modules')] + }, + + module: { + rules: [ + { + enforce: 'pre', + test: /\.js$/, + loader: 'source-map-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.ts$/, + loaders: ['ts-loader?' + JSON.stringify({ transpileOnly: true}), 'angular2-template-loader'], + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.html$/, + loader: 'html-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.css$/, + loader: ['to-string-loader', 'css-loader'], + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico|pdf)$/, + loader: 'file-loader', + query: { + name: '[path][name].[ext]', + outputPath: (url)=> { + return url.replace('src', 'dist'); + } + } + }, + { + enforce: 'post', + test: /\.ts$/, + loader: 'istanbul-instrumenter-loader', + exclude: [ + /node_modules/, + /test/ + ] + } + ] + }, + + plugins: [ + new webpack.NoEmitOnErrorsPlugin(), + + new webpack.ContextReplacementPlugin( + /angular(\\|\/)core(\\|\/)@angular/, + helpers.root('./src'), + {} + ), + new webpack.DefinePlugin({ + 'process.env': { + 'ENV': JSON.stringify(ENV) + } + }), + new webpack.LoaderOptionsPlugin({ + htmlLoader: { + minimize: false // workaround for ng2 + } + }) + ], + + node: { + fs: 'empty', + module: false + } +}; diff --git a/ng2-components/ng2-activiti-diagrams/karma.conf.js b/ng2-components/ng2-activiti-diagrams/karma.conf.js index f7f5ca66a2..9001db1c10 100644 --- a/ng2-components/ng2-activiti-diagrams/karma.conf.js +++ b/ng2-components/ng2-activiti-diagrams/karma.conf.js @@ -21,11 +21,6 @@ module.exports = function (config) { {pattern: './node_modules/md-date-time-picker/**/*.js', included: false, served: true, watched: false}, {pattern: './node_modules/moment/**/*.js', included: false, served: true, watched: false}, - // pdf-js - './node_modules/pdfjs-dist/build/pdf.js', - './node_modules/pdfjs-dist/build/pdf.worker.js', - './node_modules/pdfjs-dist/web/pdf_viewer.js', - {pattern: 'karma-test-shim.js', watched: false}, {pattern: './src/assets/**/*.*', included: false, served: true, watched: false}, {pattern: './src/i18n/**/*.*', included: false, served: true, watched: false}, diff --git a/ng2-components/ng2-activiti-diagrams/package.json b/ng2-components/ng2-activiti-diagrams/package.json index f950286ec6..1b8864ed2e 100644 --- a/ng2-components/ng2-activiti-diagrams/package.json +++ b/ng2-components/ng2-activiti-diagrams/package.json @@ -105,14 +105,5 @@ "alfresco-analytics", "alfresco-diagrams" ], - "license-check-config": { - "src": [ - "./src/**/*.ts" - ], - "path": "assets/license_header.txt", - "blocking": true, - "logInfo": false, - "logError": true - }, "license": "Apache-2.0" } diff --git a/ng2-components/ng2-activiti-diagrams/webpack.build.js b/ng2-components/ng2-activiti-diagrams/webpack.build.js index 9c7a2eb9c2..b4d7b1f542 100644 --- a/ng2-components/ng2-activiti-diagrams/webpack.build.js +++ b/ng2-components/ng2-activiti-diagrams/webpack.build.js @@ -1,6 +1,6 @@ -const webpack = require("webpack"); +const webpack = require('webpack'); const webpackMerge = require('webpack-merge'); -const commonConfig = require('../config/webpack.common.js'); +const commonConfig = require('./config/webpack.common.js'); module.exports = webpackMerge(commonConfig, { diff --git a/ng2-components/ng2-activiti-diagrams/webpack.test.js b/ng2-components/ng2-activiti-diagrams/webpack.test.js index 4a61a62939..b6f4929fa4 100644 --- a/ng2-components/ng2-activiti-diagrams/webpack.test.js +++ b/ng2-components/ng2-activiti-diagrams/webpack.test.js @@ -1,6 +1,6 @@ const webpack = require('webpack'); const webpackMerge = require('webpack-merge'); -const testConfig = require('../config/webpack.test.js'); +const testConfig = require('./config/webpack.test.js'); module.exports = webpackMerge(testConfig, { diff --git a/ng2-components/ng2-activiti-form/config/assets/license_header.txt b/ng2-components/ng2-activiti-form/config/assets/license_header.txt new file mode 100644 index 0000000000..58ad8b656b --- /dev/null +++ b/ng2-components/ng2-activiti-form/config/assets/license_header.txt @@ -0,0 +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. + */ diff --git a/ng2-components/ng2-activiti-form/config/assets/license_header_add.txt b/ng2-components/ng2-activiti-form/config/assets/license_header_add.txt new file mode 100644 index 0000000000..b38baa9716 --- /dev/null +++ b/ng2-components/ng2-activiti-form/config/assets/license_header_add.txt @@ -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. diff --git a/ng2-components/ng2-activiti-form/config/assets/tslint.json b/ng2-components/ng2-activiti-form/config/assets/tslint.json new file mode 100644 index 0000000000..611a015c7e --- /dev/null +++ b/ng2-components/ng2-activiti-form/config/assets/tslint.json @@ -0,0 +1,118 @@ +{ + "rules": { + "align": [ + true, + "parameters", + "statements" + ], + "ban": false, + "class-name": true, + "comment-format": [ + true, + "check-space" + ], + "curly": true, + "eofline": true, + "forin": true, + "indent": [ + true, + "spaces" + ], + "interface-name": false, + "jsdoc-format": true, + "label-position": true, + "max-line-length": [ + true, + 180 + ], + "member-ordering": [ + true, + "static-before-instance", + "variables-before-functions" + ], + "no-any": false, + "no-arg": true, + "no-bitwise": false, + "no-conditional-assignment": true, + "no-consecutive-blank-lines": true, + "no-console": [ + true, + "debug", + "info", + "time", + "timeEnd", + "trace" + ], + "no-construct": true, + "no-constructor-vars": false, + "no-debugger": true, + "no-duplicate-variable": true, + "no-empty": false, + "no-eval": true, + "no-inferrable-types": false, + "no-internal-module": true, + "no-require-imports": false, + "no-shadowed-variable": true, + "no-switch-case-fall-through": true, + "no-trailing-whitespace": true, + "no-unused-expression": true, + "no-unused-variable": true, + "no-use-before-declare": true, + "no-var-keyword": true, + "no-var-requires": true, + "object-literal-sort-keys": false, + "one-line": [ + true, + "check-open-brace", + "check-catch", + "check-else", + "check-whitespace" + ], + "quotemark": [ + true, + "single", + "avoid-escape" + ], + "radix": true, + "semicolon": true, + "switch-default": true, + "trailing-comma": [ + true, + { + "multiline": "never", + "singleline": "never" + } + ], + "triple-equals": [ + true, + "allow-null-check" + ], + "typedef": false, + "typedef-whitespace": [ + true, + { + "call-signature": "nospace", + "index-signature": "nospace", + "parameter": "nospace", + "property-declaration": "nospace", + "variable-declaration": "nospace" + } + ], + "use-strict": false, + "variable-name": [ + true, + "check-format", + "allow-leading-underscore", + "ban-keywords" + ], + "whitespace": [ + true, + "check-branch", + "check-operator", + "check-separator", + "check-type", + "check-module", + "check-decl" + ] + } +} diff --git a/ng2-components/ng2-activiti-form/config/custom-loaders/file-loader-multi.js b/ng2-components/ng2-activiti-form/config/custom-loaders/file-loader-multi.js new file mode 100644 index 0000000000..dfbf93e76e --- /dev/null +++ b/ng2-components/ng2-activiti-form/config/custom-loaders/file-loader-multi.js @@ -0,0 +1,70 @@ +var path = require('path'); +var loaderUtils = require('loader-utils'); + +module.exports = function(content) { + this.cacheable && this.cacheable(); + if(!this.emitFile) throw new Error('emitFile is required from module system'); + + var query = loaderUtils.getOptions(this) || {}; + var configKey = query.config || 'multiFileLoader'; + var options = this.options[configKey] || {}; + var config = { + publicPath: false, + useRelativePath: false, + name: '[hash].[ext]' + }; + + // options takes precedence over config + Object.keys(options).forEach(function(attr) { + config[attr] = options[attr]; + }); + + // query takes precedence over config and options + Object.keys(query).forEach(function(attr) { + config[attr] = query[attr]; + }); + + var context = config.context || this.options.context; + var url = loaderUtils.interpolateName(this, config.name, { + context: context, + content: content, + regExp: config.regExp + }); + var path = loaderUtils.interpolateName(this, '[path]', { + context: context, + content: content, + regExp: config.regExp + }); + + var outputPath = ''; + + if (config.outputPath) { + outputPath = ( + typeof config.outputPath === 'function' + ? config.outputPath(url, path) + : config.outputPath + url + ); + } else { + outputPath = url; + } + + var publicPath = JSON.stringify(url); + + if (config.publicPath) { + publicPath = JSON.stringify( + typeof config.publicPath === 'function' + ? config.publicPath(url, path) + : config.publicPath + url + ); + } + + publicPath = '__webpack_public_path__ + ' + publicPath; + + if (query.emitFile === undefined || query.emitFile) { + this.emitFile(outputPath, content); + } + + return 'module.exports = ' + publicPath + ';'; +}; + +module.exports.raw = true; diff --git a/ng2-components/ng2-activiti-form/config/custom-loaders/license-check.js b/ng2-components/ng2-activiti-form/config/custom-loaders/license-check.js new file mode 100644 index 0000000000..6a15ac03e2 --- /dev/null +++ b/ng2-components/ng2-activiti-form/config/custom-loaders/license-check.js @@ -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); +}; diff --git a/ng2-components/ng2-activiti-form/config/helpers.js b/ng2-components/ng2-activiti-form/config/helpers.js new file mode 100644 index 0000000000..a11fa771d6 --- /dev/null +++ b/ng2-components/ng2-activiti-form/config/helpers.js @@ -0,0 +1,10 @@ +var path = require('path'); + +var _root = path.resolve(__dirname, '..'); + +function root(args) { + args = Array.prototype.slice.call(arguments, 0); + return path.join.apply(path, [_root].concat(args)); +} + +exports.root = root; diff --git a/ng2-components/ng2-activiti-form/config/webpack.common.js b/ng2-components/ng2-activiti-form/config/webpack.common.js new file mode 100644 index 0000000000..95cd33177e --- /dev/null +++ b/ng2-components/ng2-activiti-form/config/webpack.common.js @@ -0,0 +1,124 @@ +const webpack = require('webpack'); +const helpers = require('./helpers'); +const fs = require('fs'); +const path = require('path'); + +module.exports = { + + resolveLoader: { + alias: { + "file-multi-loader": path.resolve(__dirname, "./custom-loaders/file-loader-multi"), + "license-check": path.resolve(__dirname, "./custom-loaders/license-check") + } + }, + + // require those dependencies but don't bundle them + externals: [ + /^\@angular\//, + /^rxjs\//, + 'moment', + 'raphael', + 'ng2-charts', + 'alfresco-js-api', + 'ng2-alfresco-core', + 'ng2-alfresco-datatable', + 'ng2-activiti-analytics', + 'ng2-activiti-diagrams', + 'ng2-activiti-form', + "ng2-activiti-tasklist", + 'ng2-alfresco-documentlist' + ], + + module: { + rules: [ + { + enforce: 'pre', + test: /\.js$/, + loader: 'source-map-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + enforce: 'pre', + test: /\.ts$/, + use: 'source-map-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + enforce: 'pre', + test: /\.ts$/, + loader: 'tslint-loader', + options: { + emitErrors: true, + configFile: path.resolve(__dirname, './assets/tslint.json') + }, + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.ts$/, + use: ['ts-loader', 'angular2-template-loader'], + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.html$/, + loader: 'html-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + 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)$/, + loader: 'file-multi-loader', + query: { + name: '[name].[hash].[ext]', + outputPath: (url, resourcePath)=> { + return resourcePath.replace('src', 'bundles') + url; + }, + publicPath: (url, resourcePath)=> { + var component = resourcePath.substring(0, resourcePath.indexOf('src')); + var path = resourcePath.replace(component, '').replace('src', 'bundles'); + return './' + path + url; + } + } + } + ] + }, + + resolve: { + extensions: ['.ts', '.js'], + symlinks: false, + modules: [ + '../ng2-components', 'node_modules' + ] + }, + + plugins: [ + new webpack.NoEmitOnErrorsPlugin(), + + new webpack.BannerPlugin(fs.readFileSync(path.resolve(__dirname, './assets/license_header_add.txt'), 'utf8')), + + new webpack.ContextReplacementPlugin( + /angular(\\|\/)core(\\|\/)@angular/, + helpers.root('./src'), + {} + ) + ], + + devtool: 'cheap-module-source-map', + + node: { + fs: 'empty', + module: false + } +}; diff --git a/ng2-components/ng2-activiti-form/config/webpack.test.js b/ng2-components/ng2-activiti-form/config/webpack.test.js new file mode 100644 index 0000000000..486fed8c15 --- /dev/null +++ b/ng2-components/ng2-activiti-form/config/webpack.test.js @@ -0,0 +1,85 @@ +const webpack = require('webpack'); +const helpers = require('./helpers'); + +const ENV = process.env.NODE_ENV = process.env.ENV = 'production'; + +module.exports = { + + devtool: 'inline-source-map', + + resolve: { + extensions: ['.ts', '.js'], + symlinks: false, + modules: [helpers.root('../ng2-components'), helpers.root('node_modules')] + }, + + module: { + rules: [ + { + enforce: 'pre', + test: /\.js$/, + loader: 'source-map-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.ts$/, + loaders: ['ts-loader?' + JSON.stringify({ transpileOnly: true}), 'angular2-template-loader'], + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.html$/, + loader: 'html-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.css$/, + loader: ['to-string-loader', 'css-loader'], + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico|pdf)$/, + loader: 'file-loader', + query: { + name: '[path][name].[ext]', + outputPath: (url)=> { + return url.replace('src', 'dist'); + } + } + }, + { + enforce: 'post', + test: /\.ts$/, + loader: 'istanbul-instrumenter-loader', + exclude: [ + /node_modules/, + /test/ + ] + } + ] + }, + + plugins: [ + new webpack.NoEmitOnErrorsPlugin(), + + new webpack.ContextReplacementPlugin( + /angular(\\|\/)core(\\|\/)@angular/, + helpers.root('./src'), + {} + ), + new webpack.DefinePlugin({ + 'process.env': { + 'ENV': JSON.stringify(ENV) + } + }), + new webpack.LoaderOptionsPlugin({ + htmlLoader: { + minimize: false // workaround for ng2 + } + }) + ], + + node: { + fs: 'empty', + module: false + } +}; diff --git a/ng2-components/ng2-activiti-form/karma.conf.js b/ng2-components/ng2-activiti-form/karma.conf.js index f7f5ca66a2..9001db1c10 100644 --- a/ng2-components/ng2-activiti-form/karma.conf.js +++ b/ng2-components/ng2-activiti-form/karma.conf.js @@ -21,11 +21,6 @@ module.exports = function (config) { {pattern: './node_modules/md-date-time-picker/**/*.js', included: false, served: true, watched: false}, {pattern: './node_modules/moment/**/*.js', included: false, served: true, watched: false}, - // pdf-js - './node_modules/pdfjs-dist/build/pdf.js', - './node_modules/pdfjs-dist/build/pdf.worker.js', - './node_modules/pdfjs-dist/web/pdf_viewer.js', - {pattern: 'karma-test-shim.js', watched: false}, {pattern: './src/assets/**/*.*', included: false, served: true, watched: false}, {pattern: './src/i18n/**/*.*', included: false, served: true, watched: false}, diff --git a/ng2-components/ng2-activiti-form/package.json b/ng2-components/ng2-activiti-form/package.json index 01f4d3dfe2..2886e31b79 100644 --- a/ng2-components/ng2-activiti-form/package.json +++ b/ng2-components/ng2-activiti-form/package.json @@ -108,14 +108,5 @@ "webpack-merge": "2.6.1", "wsrv": "^0.1.7" }, - "license-check-config": { - "src": [ - "./src/**/*.ts" - ], - "path": "assets/license_header.txt", - "blocking": true, - "logInfo": false, - "logError": true - }, "license": "Apache-2.0" } diff --git a/ng2-components/ng2-activiti-form/webpack.build.js b/ng2-components/ng2-activiti-form/webpack.build.js index ca03eac369..44d7d15072 100644 --- a/ng2-components/ng2-activiti-form/webpack.build.js +++ b/ng2-components/ng2-activiti-form/webpack.build.js @@ -1,6 +1,6 @@ -const webpack = require("webpack"); +const webpack = require('webpack'); const webpackMerge = require('webpack-merge'); -const commonConfig = require('../config/webpack.common.js'); +const commonConfig = require('./config/webpack.common.js'); module.exports = webpackMerge(commonConfig, { diff --git a/ng2-components/ng2-activiti-form/webpack.test.js b/ng2-components/ng2-activiti-form/webpack.test.js index 4a61a62939..b6f4929fa4 100644 --- a/ng2-components/ng2-activiti-form/webpack.test.js +++ b/ng2-components/ng2-activiti-form/webpack.test.js @@ -1,6 +1,6 @@ const webpack = require('webpack'); const webpackMerge = require('webpack-merge'); -const testConfig = require('../config/webpack.test.js'); +const testConfig = require('./config/webpack.test.js'); module.exports = webpackMerge(testConfig, { diff --git a/ng2-components/ng2-activiti-processlist/config/assets/license_header.txt b/ng2-components/ng2-activiti-processlist/config/assets/license_header.txt new file mode 100644 index 0000000000..58ad8b656b --- /dev/null +++ b/ng2-components/ng2-activiti-processlist/config/assets/license_header.txt @@ -0,0 +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. + */ diff --git a/ng2-components/ng2-activiti-processlist/config/assets/license_header_add.txt b/ng2-components/ng2-activiti-processlist/config/assets/license_header_add.txt new file mode 100644 index 0000000000..b38baa9716 --- /dev/null +++ b/ng2-components/ng2-activiti-processlist/config/assets/license_header_add.txt @@ -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. diff --git a/ng2-components/ng2-activiti-processlist/config/assets/tslint.json b/ng2-components/ng2-activiti-processlist/config/assets/tslint.json new file mode 100644 index 0000000000..611a015c7e --- /dev/null +++ b/ng2-components/ng2-activiti-processlist/config/assets/tslint.json @@ -0,0 +1,118 @@ +{ + "rules": { + "align": [ + true, + "parameters", + "statements" + ], + "ban": false, + "class-name": true, + "comment-format": [ + true, + "check-space" + ], + "curly": true, + "eofline": true, + "forin": true, + "indent": [ + true, + "spaces" + ], + "interface-name": false, + "jsdoc-format": true, + "label-position": true, + "max-line-length": [ + true, + 180 + ], + "member-ordering": [ + true, + "static-before-instance", + "variables-before-functions" + ], + "no-any": false, + "no-arg": true, + "no-bitwise": false, + "no-conditional-assignment": true, + "no-consecutive-blank-lines": true, + "no-console": [ + true, + "debug", + "info", + "time", + "timeEnd", + "trace" + ], + "no-construct": true, + "no-constructor-vars": false, + "no-debugger": true, + "no-duplicate-variable": true, + "no-empty": false, + "no-eval": true, + "no-inferrable-types": false, + "no-internal-module": true, + "no-require-imports": false, + "no-shadowed-variable": true, + "no-switch-case-fall-through": true, + "no-trailing-whitespace": true, + "no-unused-expression": true, + "no-unused-variable": true, + "no-use-before-declare": true, + "no-var-keyword": true, + "no-var-requires": true, + "object-literal-sort-keys": false, + "one-line": [ + true, + "check-open-brace", + "check-catch", + "check-else", + "check-whitespace" + ], + "quotemark": [ + true, + "single", + "avoid-escape" + ], + "radix": true, + "semicolon": true, + "switch-default": true, + "trailing-comma": [ + true, + { + "multiline": "never", + "singleline": "never" + } + ], + "triple-equals": [ + true, + "allow-null-check" + ], + "typedef": false, + "typedef-whitespace": [ + true, + { + "call-signature": "nospace", + "index-signature": "nospace", + "parameter": "nospace", + "property-declaration": "nospace", + "variable-declaration": "nospace" + } + ], + "use-strict": false, + "variable-name": [ + true, + "check-format", + "allow-leading-underscore", + "ban-keywords" + ], + "whitespace": [ + true, + "check-branch", + "check-operator", + "check-separator", + "check-type", + "check-module", + "check-decl" + ] + } +} diff --git a/ng2-components/ng2-activiti-processlist/config/custom-loaders/file-loader-multi.js b/ng2-components/ng2-activiti-processlist/config/custom-loaders/file-loader-multi.js new file mode 100644 index 0000000000..dfbf93e76e --- /dev/null +++ b/ng2-components/ng2-activiti-processlist/config/custom-loaders/file-loader-multi.js @@ -0,0 +1,70 @@ +var path = require('path'); +var loaderUtils = require('loader-utils'); + +module.exports = function(content) { + this.cacheable && this.cacheable(); + if(!this.emitFile) throw new Error('emitFile is required from module system'); + + var query = loaderUtils.getOptions(this) || {}; + var configKey = query.config || 'multiFileLoader'; + var options = this.options[configKey] || {}; + var config = { + publicPath: false, + useRelativePath: false, + name: '[hash].[ext]' + }; + + // options takes precedence over config + Object.keys(options).forEach(function(attr) { + config[attr] = options[attr]; + }); + + // query takes precedence over config and options + Object.keys(query).forEach(function(attr) { + config[attr] = query[attr]; + }); + + var context = config.context || this.options.context; + var url = loaderUtils.interpolateName(this, config.name, { + context: context, + content: content, + regExp: config.regExp + }); + var path = loaderUtils.interpolateName(this, '[path]', { + context: context, + content: content, + regExp: config.regExp + }); + + var outputPath = ''; + + if (config.outputPath) { + outputPath = ( + typeof config.outputPath === 'function' + ? config.outputPath(url, path) + : config.outputPath + url + ); + } else { + outputPath = url; + } + + var publicPath = JSON.stringify(url); + + if (config.publicPath) { + publicPath = JSON.stringify( + typeof config.publicPath === 'function' + ? config.publicPath(url, path) + : config.publicPath + url + ); + } + + publicPath = '__webpack_public_path__ + ' + publicPath; + + if (query.emitFile === undefined || query.emitFile) { + this.emitFile(outputPath, content); + } + + return 'module.exports = ' + publicPath + ';'; +}; + +module.exports.raw = true; diff --git a/ng2-components/ng2-activiti-processlist/config/custom-loaders/license-check.js b/ng2-components/ng2-activiti-processlist/config/custom-loaders/license-check.js new file mode 100644 index 0000000000..6a15ac03e2 --- /dev/null +++ b/ng2-components/ng2-activiti-processlist/config/custom-loaders/license-check.js @@ -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); +}; diff --git a/ng2-components/ng2-activiti-processlist/config/helpers.js b/ng2-components/ng2-activiti-processlist/config/helpers.js new file mode 100644 index 0000000000..a11fa771d6 --- /dev/null +++ b/ng2-components/ng2-activiti-processlist/config/helpers.js @@ -0,0 +1,10 @@ +var path = require('path'); + +var _root = path.resolve(__dirname, '..'); + +function root(args) { + args = Array.prototype.slice.call(arguments, 0); + return path.join.apply(path, [_root].concat(args)); +} + +exports.root = root; diff --git a/ng2-components/ng2-activiti-processlist/config/webpack.common.js b/ng2-components/ng2-activiti-processlist/config/webpack.common.js new file mode 100644 index 0000000000..95cd33177e --- /dev/null +++ b/ng2-components/ng2-activiti-processlist/config/webpack.common.js @@ -0,0 +1,124 @@ +const webpack = require('webpack'); +const helpers = require('./helpers'); +const fs = require('fs'); +const path = require('path'); + +module.exports = { + + resolveLoader: { + alias: { + "file-multi-loader": path.resolve(__dirname, "./custom-loaders/file-loader-multi"), + "license-check": path.resolve(__dirname, "./custom-loaders/license-check") + } + }, + + // require those dependencies but don't bundle them + externals: [ + /^\@angular\//, + /^rxjs\//, + 'moment', + 'raphael', + 'ng2-charts', + 'alfresco-js-api', + 'ng2-alfresco-core', + 'ng2-alfresco-datatable', + 'ng2-activiti-analytics', + 'ng2-activiti-diagrams', + 'ng2-activiti-form', + "ng2-activiti-tasklist", + 'ng2-alfresco-documentlist' + ], + + module: { + rules: [ + { + enforce: 'pre', + test: /\.js$/, + loader: 'source-map-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + enforce: 'pre', + test: /\.ts$/, + use: 'source-map-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + enforce: 'pre', + test: /\.ts$/, + loader: 'tslint-loader', + options: { + emitErrors: true, + configFile: path.resolve(__dirname, './assets/tslint.json') + }, + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.ts$/, + use: ['ts-loader', 'angular2-template-loader'], + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.html$/, + loader: 'html-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + 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)$/, + loader: 'file-multi-loader', + query: { + name: '[name].[hash].[ext]', + outputPath: (url, resourcePath)=> { + return resourcePath.replace('src', 'bundles') + url; + }, + publicPath: (url, resourcePath)=> { + var component = resourcePath.substring(0, resourcePath.indexOf('src')); + var path = resourcePath.replace(component, '').replace('src', 'bundles'); + return './' + path + url; + } + } + } + ] + }, + + resolve: { + extensions: ['.ts', '.js'], + symlinks: false, + modules: [ + '../ng2-components', 'node_modules' + ] + }, + + plugins: [ + new webpack.NoEmitOnErrorsPlugin(), + + new webpack.BannerPlugin(fs.readFileSync(path.resolve(__dirname, './assets/license_header_add.txt'), 'utf8')), + + new webpack.ContextReplacementPlugin( + /angular(\\|\/)core(\\|\/)@angular/, + helpers.root('./src'), + {} + ) + ], + + devtool: 'cheap-module-source-map', + + node: { + fs: 'empty', + module: false + } +}; diff --git a/ng2-components/ng2-activiti-processlist/config/webpack.test.js b/ng2-components/ng2-activiti-processlist/config/webpack.test.js new file mode 100644 index 0000000000..486fed8c15 --- /dev/null +++ b/ng2-components/ng2-activiti-processlist/config/webpack.test.js @@ -0,0 +1,85 @@ +const webpack = require('webpack'); +const helpers = require('./helpers'); + +const ENV = process.env.NODE_ENV = process.env.ENV = 'production'; + +module.exports = { + + devtool: 'inline-source-map', + + resolve: { + extensions: ['.ts', '.js'], + symlinks: false, + modules: [helpers.root('../ng2-components'), helpers.root('node_modules')] + }, + + module: { + rules: [ + { + enforce: 'pre', + test: /\.js$/, + loader: 'source-map-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.ts$/, + loaders: ['ts-loader?' + JSON.stringify({ transpileOnly: true}), 'angular2-template-loader'], + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.html$/, + loader: 'html-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.css$/, + loader: ['to-string-loader', 'css-loader'], + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico|pdf)$/, + loader: 'file-loader', + query: { + name: '[path][name].[ext]', + outputPath: (url)=> { + return url.replace('src', 'dist'); + } + } + }, + { + enforce: 'post', + test: /\.ts$/, + loader: 'istanbul-instrumenter-loader', + exclude: [ + /node_modules/, + /test/ + ] + } + ] + }, + + plugins: [ + new webpack.NoEmitOnErrorsPlugin(), + + new webpack.ContextReplacementPlugin( + /angular(\\|\/)core(\\|\/)@angular/, + helpers.root('./src'), + {} + ), + new webpack.DefinePlugin({ + 'process.env': { + 'ENV': JSON.stringify(ENV) + } + }), + new webpack.LoaderOptionsPlugin({ + htmlLoader: { + minimize: false // workaround for ng2 + } + }) + ], + + node: { + fs: 'empty', + module: false + } +}; diff --git a/ng2-components/ng2-activiti-processlist/karma.conf.js b/ng2-components/ng2-activiti-processlist/karma.conf.js index f7f5ca66a2..9001db1c10 100644 --- a/ng2-components/ng2-activiti-processlist/karma.conf.js +++ b/ng2-components/ng2-activiti-processlist/karma.conf.js @@ -21,11 +21,6 @@ module.exports = function (config) { {pattern: './node_modules/md-date-time-picker/**/*.js', included: false, served: true, watched: false}, {pattern: './node_modules/moment/**/*.js', included: false, served: true, watched: false}, - // pdf-js - './node_modules/pdfjs-dist/build/pdf.js', - './node_modules/pdfjs-dist/build/pdf.worker.js', - './node_modules/pdfjs-dist/web/pdf_viewer.js', - {pattern: 'karma-test-shim.js', watched: false}, {pattern: './src/assets/**/*.*', included: false, served: true, watched: false}, {pattern: './src/i18n/**/*.*', included: false, served: true, watched: false}, diff --git a/ng2-components/ng2-activiti-processlist/package.json b/ng2-components/ng2-activiti-processlist/package.json index bc415c3316..582c9a34b9 100644 --- a/ng2-components/ng2-activiti-processlist/package.json +++ b/ng2-components/ng2-activiti-processlist/package.json @@ -110,14 +110,5 @@ "webpack-merge": "2.6.1", "wsrv": "^0.1.7" }, - "license-check-config": { - "src": [ - "./src/**/*.ts" - ], - "path": "assets/license_header.txt", - "blocking": false, - "logInfo": false, - "logError": true - }, "license": "Apache-2.0" } diff --git a/ng2-components/ng2-activiti-processlist/webpack.build.js b/ng2-components/ng2-activiti-processlist/webpack.build.js index 00308bce8f..e4e4a4e69f 100644 --- a/ng2-components/ng2-activiti-processlist/webpack.build.js +++ b/ng2-components/ng2-activiti-processlist/webpack.build.js @@ -1,6 +1,6 @@ -const webpack = require("webpack"); +const webpack = require('webpack'); const webpackMerge = require('webpack-merge'); -const commonConfig = require('../config/webpack.common.js'); +const commonConfig = require('./config/webpack.common.js'); module.exports = webpackMerge(commonConfig, { diff --git a/ng2-components/ng2-activiti-processlist/webpack.test.js b/ng2-components/ng2-activiti-processlist/webpack.test.js index 4a61a62939..b6f4929fa4 100644 --- a/ng2-components/ng2-activiti-processlist/webpack.test.js +++ b/ng2-components/ng2-activiti-processlist/webpack.test.js @@ -1,6 +1,6 @@ const webpack = require('webpack'); const webpackMerge = require('webpack-merge'); -const testConfig = require('../config/webpack.test.js'); +const testConfig = require('./config/webpack.test.js'); module.exports = webpackMerge(testConfig, { diff --git a/ng2-components/ng2-activiti-tasklist/config/assets/license_header.txt b/ng2-components/ng2-activiti-tasklist/config/assets/license_header.txt new file mode 100644 index 0000000000..58ad8b656b --- /dev/null +++ b/ng2-components/ng2-activiti-tasklist/config/assets/license_header.txt @@ -0,0 +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. + */ diff --git a/ng2-components/ng2-activiti-tasklist/config/assets/license_header_add.txt b/ng2-components/ng2-activiti-tasklist/config/assets/license_header_add.txt new file mode 100644 index 0000000000..b38baa9716 --- /dev/null +++ b/ng2-components/ng2-activiti-tasklist/config/assets/license_header_add.txt @@ -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. diff --git a/ng2-components/ng2-activiti-tasklist/config/assets/tslint.json b/ng2-components/ng2-activiti-tasklist/config/assets/tslint.json new file mode 100644 index 0000000000..611a015c7e --- /dev/null +++ b/ng2-components/ng2-activiti-tasklist/config/assets/tslint.json @@ -0,0 +1,118 @@ +{ + "rules": { + "align": [ + true, + "parameters", + "statements" + ], + "ban": false, + "class-name": true, + "comment-format": [ + true, + "check-space" + ], + "curly": true, + "eofline": true, + "forin": true, + "indent": [ + true, + "spaces" + ], + "interface-name": false, + "jsdoc-format": true, + "label-position": true, + "max-line-length": [ + true, + 180 + ], + "member-ordering": [ + true, + "static-before-instance", + "variables-before-functions" + ], + "no-any": false, + "no-arg": true, + "no-bitwise": false, + "no-conditional-assignment": true, + "no-consecutive-blank-lines": true, + "no-console": [ + true, + "debug", + "info", + "time", + "timeEnd", + "trace" + ], + "no-construct": true, + "no-constructor-vars": false, + "no-debugger": true, + "no-duplicate-variable": true, + "no-empty": false, + "no-eval": true, + "no-inferrable-types": false, + "no-internal-module": true, + "no-require-imports": false, + "no-shadowed-variable": true, + "no-switch-case-fall-through": true, + "no-trailing-whitespace": true, + "no-unused-expression": true, + "no-unused-variable": true, + "no-use-before-declare": true, + "no-var-keyword": true, + "no-var-requires": true, + "object-literal-sort-keys": false, + "one-line": [ + true, + "check-open-brace", + "check-catch", + "check-else", + "check-whitespace" + ], + "quotemark": [ + true, + "single", + "avoid-escape" + ], + "radix": true, + "semicolon": true, + "switch-default": true, + "trailing-comma": [ + true, + { + "multiline": "never", + "singleline": "never" + } + ], + "triple-equals": [ + true, + "allow-null-check" + ], + "typedef": false, + "typedef-whitespace": [ + true, + { + "call-signature": "nospace", + "index-signature": "nospace", + "parameter": "nospace", + "property-declaration": "nospace", + "variable-declaration": "nospace" + } + ], + "use-strict": false, + "variable-name": [ + true, + "check-format", + "allow-leading-underscore", + "ban-keywords" + ], + "whitespace": [ + true, + "check-branch", + "check-operator", + "check-separator", + "check-type", + "check-module", + "check-decl" + ] + } +} diff --git a/ng2-components/ng2-activiti-tasklist/config/custom-loaders/file-loader-multi.js b/ng2-components/ng2-activiti-tasklist/config/custom-loaders/file-loader-multi.js new file mode 100644 index 0000000000..dfbf93e76e --- /dev/null +++ b/ng2-components/ng2-activiti-tasklist/config/custom-loaders/file-loader-multi.js @@ -0,0 +1,70 @@ +var path = require('path'); +var loaderUtils = require('loader-utils'); + +module.exports = function(content) { + this.cacheable && this.cacheable(); + if(!this.emitFile) throw new Error('emitFile is required from module system'); + + var query = loaderUtils.getOptions(this) || {}; + var configKey = query.config || 'multiFileLoader'; + var options = this.options[configKey] || {}; + var config = { + publicPath: false, + useRelativePath: false, + name: '[hash].[ext]' + }; + + // options takes precedence over config + Object.keys(options).forEach(function(attr) { + config[attr] = options[attr]; + }); + + // query takes precedence over config and options + Object.keys(query).forEach(function(attr) { + config[attr] = query[attr]; + }); + + var context = config.context || this.options.context; + var url = loaderUtils.interpolateName(this, config.name, { + context: context, + content: content, + regExp: config.regExp + }); + var path = loaderUtils.interpolateName(this, '[path]', { + context: context, + content: content, + regExp: config.regExp + }); + + var outputPath = ''; + + if (config.outputPath) { + outputPath = ( + typeof config.outputPath === 'function' + ? config.outputPath(url, path) + : config.outputPath + url + ); + } else { + outputPath = url; + } + + var publicPath = JSON.stringify(url); + + if (config.publicPath) { + publicPath = JSON.stringify( + typeof config.publicPath === 'function' + ? config.publicPath(url, path) + : config.publicPath + url + ); + } + + publicPath = '__webpack_public_path__ + ' + publicPath; + + if (query.emitFile === undefined || query.emitFile) { + this.emitFile(outputPath, content); + } + + return 'module.exports = ' + publicPath + ';'; +}; + +module.exports.raw = true; diff --git a/ng2-components/ng2-activiti-tasklist/config/custom-loaders/license-check.js b/ng2-components/ng2-activiti-tasklist/config/custom-loaders/license-check.js new file mode 100644 index 0000000000..6a15ac03e2 --- /dev/null +++ b/ng2-components/ng2-activiti-tasklist/config/custom-loaders/license-check.js @@ -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); +}; diff --git a/ng2-components/ng2-activiti-tasklist/config/helpers.js b/ng2-components/ng2-activiti-tasklist/config/helpers.js new file mode 100644 index 0000000000..a11fa771d6 --- /dev/null +++ b/ng2-components/ng2-activiti-tasklist/config/helpers.js @@ -0,0 +1,10 @@ +var path = require('path'); + +var _root = path.resolve(__dirname, '..'); + +function root(args) { + args = Array.prototype.slice.call(arguments, 0); + return path.join.apply(path, [_root].concat(args)); +} + +exports.root = root; diff --git a/ng2-components/ng2-activiti-tasklist/config/webpack.common.js b/ng2-components/ng2-activiti-tasklist/config/webpack.common.js new file mode 100644 index 0000000000..95cd33177e --- /dev/null +++ b/ng2-components/ng2-activiti-tasklist/config/webpack.common.js @@ -0,0 +1,124 @@ +const webpack = require('webpack'); +const helpers = require('./helpers'); +const fs = require('fs'); +const path = require('path'); + +module.exports = { + + resolveLoader: { + alias: { + "file-multi-loader": path.resolve(__dirname, "./custom-loaders/file-loader-multi"), + "license-check": path.resolve(__dirname, "./custom-loaders/license-check") + } + }, + + // require those dependencies but don't bundle them + externals: [ + /^\@angular\//, + /^rxjs\//, + 'moment', + 'raphael', + 'ng2-charts', + 'alfresco-js-api', + 'ng2-alfresco-core', + 'ng2-alfresco-datatable', + 'ng2-activiti-analytics', + 'ng2-activiti-diagrams', + 'ng2-activiti-form', + "ng2-activiti-tasklist", + 'ng2-alfresco-documentlist' + ], + + module: { + rules: [ + { + enforce: 'pre', + test: /\.js$/, + loader: 'source-map-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + enforce: 'pre', + test: /\.ts$/, + use: 'source-map-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + enforce: 'pre', + test: /\.ts$/, + loader: 'tslint-loader', + options: { + emitErrors: true, + configFile: path.resolve(__dirname, './assets/tslint.json') + }, + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.ts$/, + use: ['ts-loader', 'angular2-template-loader'], + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.html$/, + loader: 'html-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + 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)$/, + loader: 'file-multi-loader', + query: { + name: '[name].[hash].[ext]', + outputPath: (url, resourcePath)=> { + return resourcePath.replace('src', 'bundles') + url; + }, + publicPath: (url, resourcePath)=> { + var component = resourcePath.substring(0, resourcePath.indexOf('src')); + var path = resourcePath.replace(component, '').replace('src', 'bundles'); + return './' + path + url; + } + } + } + ] + }, + + resolve: { + extensions: ['.ts', '.js'], + symlinks: false, + modules: [ + '../ng2-components', 'node_modules' + ] + }, + + plugins: [ + new webpack.NoEmitOnErrorsPlugin(), + + new webpack.BannerPlugin(fs.readFileSync(path.resolve(__dirname, './assets/license_header_add.txt'), 'utf8')), + + new webpack.ContextReplacementPlugin( + /angular(\\|\/)core(\\|\/)@angular/, + helpers.root('./src'), + {} + ) + ], + + devtool: 'cheap-module-source-map', + + node: { + fs: 'empty', + module: false + } +}; diff --git a/ng2-components/ng2-activiti-tasklist/config/webpack.test.js b/ng2-components/ng2-activiti-tasklist/config/webpack.test.js new file mode 100644 index 0000000000..486fed8c15 --- /dev/null +++ b/ng2-components/ng2-activiti-tasklist/config/webpack.test.js @@ -0,0 +1,85 @@ +const webpack = require('webpack'); +const helpers = require('./helpers'); + +const ENV = process.env.NODE_ENV = process.env.ENV = 'production'; + +module.exports = { + + devtool: 'inline-source-map', + + resolve: { + extensions: ['.ts', '.js'], + symlinks: false, + modules: [helpers.root('../ng2-components'), helpers.root('node_modules')] + }, + + module: { + rules: [ + { + enforce: 'pre', + test: /\.js$/, + loader: 'source-map-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.ts$/, + loaders: ['ts-loader?' + JSON.stringify({ transpileOnly: true}), 'angular2-template-loader'], + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.html$/, + loader: 'html-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.css$/, + loader: ['to-string-loader', 'css-loader'], + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico|pdf)$/, + loader: 'file-loader', + query: { + name: '[path][name].[ext]', + outputPath: (url)=> { + return url.replace('src', 'dist'); + } + } + }, + { + enforce: 'post', + test: /\.ts$/, + loader: 'istanbul-instrumenter-loader', + exclude: [ + /node_modules/, + /test/ + ] + } + ] + }, + + plugins: [ + new webpack.NoEmitOnErrorsPlugin(), + + new webpack.ContextReplacementPlugin( + /angular(\\|\/)core(\\|\/)@angular/, + helpers.root('./src'), + {} + ), + new webpack.DefinePlugin({ + 'process.env': { + 'ENV': JSON.stringify(ENV) + } + }), + new webpack.LoaderOptionsPlugin({ + htmlLoader: { + minimize: false // workaround for ng2 + } + }) + ], + + node: { + fs: 'empty', + module: false + } +}; diff --git a/ng2-components/ng2-activiti-tasklist/karma.conf.js b/ng2-components/ng2-activiti-tasklist/karma.conf.js index f7f5ca66a2..9001db1c10 100644 --- a/ng2-components/ng2-activiti-tasklist/karma.conf.js +++ b/ng2-components/ng2-activiti-tasklist/karma.conf.js @@ -21,11 +21,6 @@ module.exports = function (config) { {pattern: './node_modules/md-date-time-picker/**/*.js', included: false, served: true, watched: false}, {pattern: './node_modules/moment/**/*.js', included: false, served: true, watched: false}, - // pdf-js - './node_modules/pdfjs-dist/build/pdf.js', - './node_modules/pdfjs-dist/build/pdf.worker.js', - './node_modules/pdfjs-dist/web/pdf_viewer.js', - {pattern: 'karma-test-shim.js', watched: false}, {pattern: './src/assets/**/*.*', included: false, served: true, watched: false}, {pattern: './src/i18n/**/*.*', included: false, served: true, watched: false}, diff --git a/ng2-components/ng2-activiti-tasklist/package.json b/ng2-components/ng2-activiti-tasklist/package.json index 6257b3e41b..ec63f4b06a 100644 --- a/ng2-components/ng2-activiti-tasklist/package.json +++ b/ng2-components/ng2-activiti-tasklist/package.json @@ -20,7 +20,6 @@ "bugs": { "url": "https://github.com/Alfresco/alfresco-ng2-components/issues" }, - "license": "Apache-2.0", "contributors": [ { "name": "Maurizio Vitale", @@ -114,13 +113,5 @@ "webpack-merge": "2.6.1", "wsrv": "^0.1.7" }, - "license-check-config": { - "src": [ - "./src/**/*.ts" - ], - "path": "assets/license_header.txt", - "blocking": true, - "logInfo": false, - "logError": true - } + "license": "Apache-2.0" } diff --git a/ng2-components/ng2-activiti-tasklist/webpack.build.js b/ng2-components/ng2-activiti-tasklist/webpack.build.js index 9ba6ea0a4f..03c29be996 100644 --- a/ng2-components/ng2-activiti-tasklist/webpack.build.js +++ b/ng2-components/ng2-activiti-tasklist/webpack.build.js @@ -1,6 +1,6 @@ -const webpack = require("webpack"); +const webpack = require('webpack'); const webpackMerge = require('webpack-merge'); -const commonConfig = require('../config/webpack.common.js'); +const commonConfig = require('./config/webpack.common.js'); module.exports = webpackMerge(commonConfig, { diff --git a/ng2-components/ng2-activiti-tasklist/webpack.test.js b/ng2-components/ng2-activiti-tasklist/webpack.test.js index 4a61a62939..b6f4929fa4 100644 --- a/ng2-components/ng2-activiti-tasklist/webpack.test.js +++ b/ng2-components/ng2-activiti-tasklist/webpack.test.js @@ -1,6 +1,6 @@ const webpack = require('webpack'); const webpackMerge = require('webpack-merge'); -const testConfig = require('../config/webpack.test.js'); +const testConfig = require('./config/webpack.test.js'); module.exports = webpackMerge(testConfig, { diff --git a/ng2-components/ng2-alfresco-core/config/assets/license_header.txt b/ng2-components/ng2-alfresco-core/config/assets/license_header.txt new file mode 100644 index 0000000000..58ad8b656b --- /dev/null +++ b/ng2-components/ng2-alfresco-core/config/assets/license_header.txt @@ -0,0 +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. + */ diff --git a/ng2-components/ng2-alfresco-core/config/assets/license_header_add.txt b/ng2-components/ng2-alfresco-core/config/assets/license_header_add.txt new file mode 100644 index 0000000000..b38baa9716 --- /dev/null +++ b/ng2-components/ng2-alfresco-core/config/assets/license_header_add.txt @@ -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. diff --git a/ng2-components/ng2-alfresco-core/config/assets/tslint.json b/ng2-components/ng2-alfresco-core/config/assets/tslint.json new file mode 100644 index 0000000000..611a015c7e --- /dev/null +++ b/ng2-components/ng2-alfresco-core/config/assets/tslint.json @@ -0,0 +1,118 @@ +{ + "rules": { + "align": [ + true, + "parameters", + "statements" + ], + "ban": false, + "class-name": true, + "comment-format": [ + true, + "check-space" + ], + "curly": true, + "eofline": true, + "forin": true, + "indent": [ + true, + "spaces" + ], + "interface-name": false, + "jsdoc-format": true, + "label-position": true, + "max-line-length": [ + true, + 180 + ], + "member-ordering": [ + true, + "static-before-instance", + "variables-before-functions" + ], + "no-any": false, + "no-arg": true, + "no-bitwise": false, + "no-conditional-assignment": true, + "no-consecutive-blank-lines": true, + "no-console": [ + true, + "debug", + "info", + "time", + "timeEnd", + "trace" + ], + "no-construct": true, + "no-constructor-vars": false, + "no-debugger": true, + "no-duplicate-variable": true, + "no-empty": false, + "no-eval": true, + "no-inferrable-types": false, + "no-internal-module": true, + "no-require-imports": false, + "no-shadowed-variable": true, + "no-switch-case-fall-through": true, + "no-trailing-whitespace": true, + "no-unused-expression": true, + "no-unused-variable": true, + "no-use-before-declare": true, + "no-var-keyword": true, + "no-var-requires": true, + "object-literal-sort-keys": false, + "one-line": [ + true, + "check-open-brace", + "check-catch", + "check-else", + "check-whitespace" + ], + "quotemark": [ + true, + "single", + "avoid-escape" + ], + "radix": true, + "semicolon": true, + "switch-default": true, + "trailing-comma": [ + true, + { + "multiline": "never", + "singleline": "never" + } + ], + "triple-equals": [ + true, + "allow-null-check" + ], + "typedef": false, + "typedef-whitespace": [ + true, + { + "call-signature": "nospace", + "index-signature": "nospace", + "parameter": "nospace", + "property-declaration": "nospace", + "variable-declaration": "nospace" + } + ], + "use-strict": false, + "variable-name": [ + true, + "check-format", + "allow-leading-underscore", + "ban-keywords" + ], + "whitespace": [ + true, + "check-branch", + "check-operator", + "check-separator", + "check-type", + "check-module", + "check-decl" + ] + } +} diff --git a/ng2-components/ng2-alfresco-core/config/custom-loaders/file-loader-multi.js b/ng2-components/ng2-alfresco-core/config/custom-loaders/file-loader-multi.js new file mode 100644 index 0000000000..dfbf93e76e --- /dev/null +++ b/ng2-components/ng2-alfresco-core/config/custom-loaders/file-loader-multi.js @@ -0,0 +1,70 @@ +var path = require('path'); +var loaderUtils = require('loader-utils'); + +module.exports = function(content) { + this.cacheable && this.cacheable(); + if(!this.emitFile) throw new Error('emitFile is required from module system'); + + var query = loaderUtils.getOptions(this) || {}; + var configKey = query.config || 'multiFileLoader'; + var options = this.options[configKey] || {}; + var config = { + publicPath: false, + useRelativePath: false, + name: '[hash].[ext]' + }; + + // options takes precedence over config + Object.keys(options).forEach(function(attr) { + config[attr] = options[attr]; + }); + + // query takes precedence over config and options + Object.keys(query).forEach(function(attr) { + config[attr] = query[attr]; + }); + + var context = config.context || this.options.context; + var url = loaderUtils.interpolateName(this, config.name, { + context: context, + content: content, + regExp: config.regExp + }); + var path = loaderUtils.interpolateName(this, '[path]', { + context: context, + content: content, + regExp: config.regExp + }); + + var outputPath = ''; + + if (config.outputPath) { + outputPath = ( + typeof config.outputPath === 'function' + ? config.outputPath(url, path) + : config.outputPath + url + ); + } else { + outputPath = url; + } + + var publicPath = JSON.stringify(url); + + if (config.publicPath) { + publicPath = JSON.stringify( + typeof config.publicPath === 'function' + ? config.publicPath(url, path) + : config.publicPath + url + ); + } + + publicPath = '__webpack_public_path__ + ' + publicPath; + + if (query.emitFile === undefined || query.emitFile) { + this.emitFile(outputPath, content); + } + + return 'module.exports = ' + publicPath + ';'; +}; + +module.exports.raw = true; diff --git a/ng2-components/ng2-alfresco-core/config/custom-loaders/license-check.js b/ng2-components/ng2-alfresco-core/config/custom-loaders/license-check.js new file mode 100644 index 0000000000..6a15ac03e2 --- /dev/null +++ b/ng2-components/ng2-alfresco-core/config/custom-loaders/license-check.js @@ -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); +}; diff --git a/ng2-components/ng2-alfresco-core/config/helpers.js b/ng2-components/ng2-alfresco-core/config/helpers.js new file mode 100644 index 0000000000..a11fa771d6 --- /dev/null +++ b/ng2-components/ng2-alfresco-core/config/helpers.js @@ -0,0 +1,10 @@ +var path = require('path'); + +var _root = path.resolve(__dirname, '..'); + +function root(args) { + args = Array.prototype.slice.call(arguments, 0); + return path.join.apply(path, [_root].concat(args)); +} + +exports.root = root; diff --git a/ng2-components/ng2-alfresco-core/config/webpack.common.js b/ng2-components/ng2-alfresco-core/config/webpack.common.js new file mode 100644 index 0000000000..95cd33177e --- /dev/null +++ b/ng2-components/ng2-alfresco-core/config/webpack.common.js @@ -0,0 +1,124 @@ +const webpack = require('webpack'); +const helpers = require('./helpers'); +const fs = require('fs'); +const path = require('path'); + +module.exports = { + + resolveLoader: { + alias: { + "file-multi-loader": path.resolve(__dirname, "./custom-loaders/file-loader-multi"), + "license-check": path.resolve(__dirname, "./custom-loaders/license-check") + } + }, + + // require those dependencies but don't bundle them + externals: [ + /^\@angular\//, + /^rxjs\//, + 'moment', + 'raphael', + 'ng2-charts', + 'alfresco-js-api', + 'ng2-alfresco-core', + 'ng2-alfresco-datatable', + 'ng2-activiti-analytics', + 'ng2-activiti-diagrams', + 'ng2-activiti-form', + "ng2-activiti-tasklist", + 'ng2-alfresco-documentlist' + ], + + module: { + rules: [ + { + enforce: 'pre', + test: /\.js$/, + loader: 'source-map-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + enforce: 'pre', + test: /\.ts$/, + use: 'source-map-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + enforce: 'pre', + test: /\.ts$/, + loader: 'tslint-loader', + options: { + emitErrors: true, + configFile: path.resolve(__dirname, './assets/tslint.json') + }, + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.ts$/, + use: ['ts-loader', 'angular2-template-loader'], + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.html$/, + loader: 'html-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + 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)$/, + loader: 'file-multi-loader', + query: { + name: '[name].[hash].[ext]', + outputPath: (url, resourcePath)=> { + return resourcePath.replace('src', 'bundles') + url; + }, + publicPath: (url, resourcePath)=> { + var component = resourcePath.substring(0, resourcePath.indexOf('src')); + var path = resourcePath.replace(component, '').replace('src', 'bundles'); + return './' + path + url; + } + } + } + ] + }, + + resolve: { + extensions: ['.ts', '.js'], + symlinks: false, + modules: [ + '../ng2-components', 'node_modules' + ] + }, + + plugins: [ + new webpack.NoEmitOnErrorsPlugin(), + + new webpack.BannerPlugin(fs.readFileSync(path.resolve(__dirname, './assets/license_header_add.txt'), 'utf8')), + + new webpack.ContextReplacementPlugin( + /angular(\\|\/)core(\\|\/)@angular/, + helpers.root('./src'), + {} + ) + ], + + devtool: 'cheap-module-source-map', + + node: { + fs: 'empty', + module: false + } +}; diff --git a/ng2-components/ng2-alfresco-core/config/webpack.test.js b/ng2-components/ng2-alfresco-core/config/webpack.test.js new file mode 100644 index 0000000000..486fed8c15 --- /dev/null +++ b/ng2-components/ng2-alfresco-core/config/webpack.test.js @@ -0,0 +1,85 @@ +const webpack = require('webpack'); +const helpers = require('./helpers'); + +const ENV = process.env.NODE_ENV = process.env.ENV = 'production'; + +module.exports = { + + devtool: 'inline-source-map', + + resolve: { + extensions: ['.ts', '.js'], + symlinks: false, + modules: [helpers.root('../ng2-components'), helpers.root('node_modules')] + }, + + module: { + rules: [ + { + enforce: 'pre', + test: /\.js$/, + loader: 'source-map-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.ts$/, + loaders: ['ts-loader?' + JSON.stringify({ transpileOnly: true}), 'angular2-template-loader'], + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.html$/, + loader: 'html-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.css$/, + loader: ['to-string-loader', 'css-loader'], + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico|pdf)$/, + loader: 'file-loader', + query: { + name: '[path][name].[ext]', + outputPath: (url)=> { + return url.replace('src', 'dist'); + } + } + }, + { + enforce: 'post', + test: /\.ts$/, + loader: 'istanbul-instrumenter-loader', + exclude: [ + /node_modules/, + /test/ + ] + } + ] + }, + + plugins: [ + new webpack.NoEmitOnErrorsPlugin(), + + new webpack.ContextReplacementPlugin( + /angular(\\|\/)core(\\|\/)@angular/, + helpers.root('./src'), + {} + ), + new webpack.DefinePlugin({ + 'process.env': { + 'ENV': JSON.stringify(ENV) + } + }), + new webpack.LoaderOptionsPlugin({ + htmlLoader: { + minimize: false // workaround for ng2 + } + }) + ], + + node: { + fs: 'empty', + module: false + } +}; diff --git a/ng2-components/ng2-alfresco-core/karma.conf.js b/ng2-components/ng2-alfresco-core/karma.conf.js index f7f5ca66a2..9001db1c10 100644 --- a/ng2-components/ng2-alfresco-core/karma.conf.js +++ b/ng2-components/ng2-alfresco-core/karma.conf.js @@ -21,11 +21,6 @@ module.exports = function (config) { {pattern: './node_modules/md-date-time-picker/**/*.js', included: false, served: true, watched: false}, {pattern: './node_modules/moment/**/*.js', included: false, served: true, watched: false}, - // pdf-js - './node_modules/pdfjs-dist/build/pdf.js', - './node_modules/pdfjs-dist/build/pdf.worker.js', - './node_modules/pdfjs-dist/web/pdf_viewer.js', - {pattern: 'karma-test-shim.js', watched: false}, {pattern: './src/assets/**/*.*', included: false, served: true, watched: false}, {pattern: './src/i18n/**/*.*', included: false, served: true, watched: false}, diff --git a/ng2-components/ng2-alfresco-core/package.json b/ng2-components/ng2-alfresco-core/package.json index b5ea9e0f6e..10649392d9 100644 --- a/ng2-components/ng2-alfresco-core/package.json +++ b/ng2-components/ng2-alfresco-core/package.json @@ -5,7 +5,6 @@ "author": "Alfresco Software, Ltd.", "scripts": { "clean": "rimraf dist node_modules typings bundles coverage .npmrc", - "rimraf": "rimraf", "build": "webpack --config webpack.build.js --progress --profile --bail", "test": "karma start karma.conf.js --reporters mocha,coverage --single-run --component", "test-browser": "karma start karma.conf.js --reporters kjhtml --component", @@ -20,7 +19,6 @@ "bugs": { "url": "https://github.com/Alfresco/alfresco-ng2-components/issues" }, - "license": "Apache-2.0", "contributors": [ { "name": "Denys Vuika", @@ -120,13 +118,5 @@ "webpack-merge": "2.6.1", "wsrv": "^0.1.7" }, - "license-check-config": { - "src": [ - "./src/**/*.ts" - ], - "path": "assets/license_header.txt", - "blocking": true, - "logInfo": false, - "logError": true - } + "license": "Apache-2.0" } diff --git a/ng2-components/ng2-alfresco-core/src/services/notification.service.spec.ts b/ng2-components/ng2-alfresco-core/src/services/notification.service.spec.ts index 98eb8178e6..767103a3d2 100644 --- a/ng2-components/ng2-alfresco-core/src/services/notification.service.spec.ts +++ b/ng2-components/ng2-alfresco-core/src/services/notification.service.spec.ts @@ -47,14 +47,13 @@ describe('NotificationService', () => { it('should open a message notification bar', (done) => { let promise = fixture.componentInstance.sendMessage(); + promise.afterDismissed().subscribe(() => { + done(); + }); fixture.detectChanges(); expect(document.querySelector('snack-bar-container')).not.toBeNull(); - - promise.afterDismissed().subscribe(() => { - done(); - }); }); }); @@ -62,15 +61,14 @@ describe('NotificationService', () => { it('should open a message notification bar with action', (done) => { let promise = fixture.componentInstance.sendMessageAction(); + promise.afterDismissed().subscribe(() => { + done(); + }); fixture.detectChanges(); expect(document.querySelector('snack-bar-container')).not.toBeNull(); expect(document.querySelector('.md-simple-snackbar-action')).not.toBeNull(); - - promise.afterDismissed().subscribe(() => { - done(); - }); }); }); @@ -86,12 +84,12 @@ class ComponentThatProvidesNotificationService { } sendMessage() { - let promise = this.notificationService.openSnackMessage('Test notification', 2000); + let promise = this.notificationService.openSnackMessage('Test notification', 5000); return promise; } sendMessageAction() { - let promise = this.notificationService.openSnackMessageAction('Test notification', 'TestWarn', 2000); + let promise = this.notificationService.openSnackMessageAction('Test notification', 'TestWarn', 5000); return promise; } diff --git a/ng2-components/ng2-alfresco-core/webpack.build.js b/ng2-components/ng2-alfresco-core/webpack.build.js index 176daf7abc..0a56f02ee3 100644 --- a/ng2-components/ng2-alfresco-core/webpack.build.js +++ b/ng2-components/ng2-alfresco-core/webpack.build.js @@ -1,6 +1,6 @@ -const webpack = require("webpack"); +const webpack = require('webpack'); const webpackMerge = require('webpack-merge'); -const commonConfig = require('../config/webpack.common.js'); +const commonConfig = require('./config/webpack.common.js'); module.exports = webpackMerge(commonConfig, { diff --git a/ng2-components/ng2-alfresco-core/webpack.test.js b/ng2-components/ng2-alfresco-core/webpack.test.js index 4a61a62939..b6f4929fa4 100644 --- a/ng2-components/ng2-alfresco-core/webpack.test.js +++ b/ng2-components/ng2-alfresco-core/webpack.test.js @@ -1,6 +1,6 @@ const webpack = require('webpack'); const webpackMerge = require('webpack-merge'); -const testConfig = require('../config/webpack.test.js'); +const testConfig = require('./config/webpack.test.js'); module.exports = webpackMerge(testConfig, { diff --git a/ng2-components/ng2-alfresco-datatable/config/assets/license_header.txt b/ng2-components/ng2-alfresco-datatable/config/assets/license_header.txt new file mode 100644 index 0000000000..58ad8b656b --- /dev/null +++ b/ng2-components/ng2-alfresco-datatable/config/assets/license_header.txt @@ -0,0 +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. + */ diff --git a/ng2-components/ng2-alfresco-datatable/config/assets/license_header_add.txt b/ng2-components/ng2-alfresco-datatable/config/assets/license_header_add.txt new file mode 100644 index 0000000000..b38baa9716 --- /dev/null +++ b/ng2-components/ng2-alfresco-datatable/config/assets/license_header_add.txt @@ -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. diff --git a/ng2-components/ng2-alfresco-datatable/config/assets/tslint.json b/ng2-components/ng2-alfresco-datatable/config/assets/tslint.json new file mode 100644 index 0000000000..611a015c7e --- /dev/null +++ b/ng2-components/ng2-alfresco-datatable/config/assets/tslint.json @@ -0,0 +1,118 @@ +{ + "rules": { + "align": [ + true, + "parameters", + "statements" + ], + "ban": false, + "class-name": true, + "comment-format": [ + true, + "check-space" + ], + "curly": true, + "eofline": true, + "forin": true, + "indent": [ + true, + "spaces" + ], + "interface-name": false, + "jsdoc-format": true, + "label-position": true, + "max-line-length": [ + true, + 180 + ], + "member-ordering": [ + true, + "static-before-instance", + "variables-before-functions" + ], + "no-any": false, + "no-arg": true, + "no-bitwise": false, + "no-conditional-assignment": true, + "no-consecutive-blank-lines": true, + "no-console": [ + true, + "debug", + "info", + "time", + "timeEnd", + "trace" + ], + "no-construct": true, + "no-constructor-vars": false, + "no-debugger": true, + "no-duplicate-variable": true, + "no-empty": false, + "no-eval": true, + "no-inferrable-types": false, + "no-internal-module": true, + "no-require-imports": false, + "no-shadowed-variable": true, + "no-switch-case-fall-through": true, + "no-trailing-whitespace": true, + "no-unused-expression": true, + "no-unused-variable": true, + "no-use-before-declare": true, + "no-var-keyword": true, + "no-var-requires": true, + "object-literal-sort-keys": false, + "one-line": [ + true, + "check-open-brace", + "check-catch", + "check-else", + "check-whitespace" + ], + "quotemark": [ + true, + "single", + "avoid-escape" + ], + "radix": true, + "semicolon": true, + "switch-default": true, + "trailing-comma": [ + true, + { + "multiline": "never", + "singleline": "never" + } + ], + "triple-equals": [ + true, + "allow-null-check" + ], + "typedef": false, + "typedef-whitespace": [ + true, + { + "call-signature": "nospace", + "index-signature": "nospace", + "parameter": "nospace", + "property-declaration": "nospace", + "variable-declaration": "nospace" + } + ], + "use-strict": false, + "variable-name": [ + true, + "check-format", + "allow-leading-underscore", + "ban-keywords" + ], + "whitespace": [ + true, + "check-branch", + "check-operator", + "check-separator", + "check-type", + "check-module", + "check-decl" + ] + } +} diff --git a/ng2-components/ng2-alfresco-datatable/config/custom-loaders/file-loader-multi.js b/ng2-components/ng2-alfresco-datatable/config/custom-loaders/file-loader-multi.js new file mode 100644 index 0000000000..dfbf93e76e --- /dev/null +++ b/ng2-components/ng2-alfresco-datatable/config/custom-loaders/file-loader-multi.js @@ -0,0 +1,70 @@ +var path = require('path'); +var loaderUtils = require('loader-utils'); + +module.exports = function(content) { + this.cacheable && this.cacheable(); + if(!this.emitFile) throw new Error('emitFile is required from module system'); + + var query = loaderUtils.getOptions(this) || {}; + var configKey = query.config || 'multiFileLoader'; + var options = this.options[configKey] || {}; + var config = { + publicPath: false, + useRelativePath: false, + name: '[hash].[ext]' + }; + + // options takes precedence over config + Object.keys(options).forEach(function(attr) { + config[attr] = options[attr]; + }); + + // query takes precedence over config and options + Object.keys(query).forEach(function(attr) { + config[attr] = query[attr]; + }); + + var context = config.context || this.options.context; + var url = loaderUtils.interpolateName(this, config.name, { + context: context, + content: content, + regExp: config.regExp + }); + var path = loaderUtils.interpolateName(this, '[path]', { + context: context, + content: content, + regExp: config.regExp + }); + + var outputPath = ''; + + if (config.outputPath) { + outputPath = ( + typeof config.outputPath === 'function' + ? config.outputPath(url, path) + : config.outputPath + url + ); + } else { + outputPath = url; + } + + var publicPath = JSON.stringify(url); + + if (config.publicPath) { + publicPath = JSON.stringify( + typeof config.publicPath === 'function' + ? config.publicPath(url, path) + : config.publicPath + url + ); + } + + publicPath = '__webpack_public_path__ + ' + publicPath; + + if (query.emitFile === undefined || query.emitFile) { + this.emitFile(outputPath, content); + } + + return 'module.exports = ' + publicPath + ';'; +}; + +module.exports.raw = true; diff --git a/ng2-components/ng2-alfresco-datatable/config/custom-loaders/license-check.js b/ng2-components/ng2-alfresco-datatable/config/custom-loaders/license-check.js new file mode 100644 index 0000000000..6a15ac03e2 --- /dev/null +++ b/ng2-components/ng2-alfresco-datatable/config/custom-loaders/license-check.js @@ -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); +}; diff --git a/ng2-components/ng2-alfresco-datatable/config/helpers.js b/ng2-components/ng2-alfresco-datatable/config/helpers.js new file mode 100644 index 0000000000..a11fa771d6 --- /dev/null +++ b/ng2-components/ng2-alfresco-datatable/config/helpers.js @@ -0,0 +1,10 @@ +var path = require('path'); + +var _root = path.resolve(__dirname, '..'); + +function root(args) { + args = Array.prototype.slice.call(arguments, 0); + return path.join.apply(path, [_root].concat(args)); +} + +exports.root = root; diff --git a/ng2-components/ng2-alfresco-datatable/config/webpack.common.js b/ng2-components/ng2-alfresco-datatable/config/webpack.common.js new file mode 100644 index 0000000000..95cd33177e --- /dev/null +++ b/ng2-components/ng2-alfresco-datatable/config/webpack.common.js @@ -0,0 +1,124 @@ +const webpack = require('webpack'); +const helpers = require('./helpers'); +const fs = require('fs'); +const path = require('path'); + +module.exports = { + + resolveLoader: { + alias: { + "file-multi-loader": path.resolve(__dirname, "./custom-loaders/file-loader-multi"), + "license-check": path.resolve(__dirname, "./custom-loaders/license-check") + } + }, + + // require those dependencies but don't bundle them + externals: [ + /^\@angular\//, + /^rxjs\//, + 'moment', + 'raphael', + 'ng2-charts', + 'alfresco-js-api', + 'ng2-alfresco-core', + 'ng2-alfresco-datatable', + 'ng2-activiti-analytics', + 'ng2-activiti-diagrams', + 'ng2-activiti-form', + "ng2-activiti-tasklist", + 'ng2-alfresco-documentlist' + ], + + module: { + rules: [ + { + enforce: 'pre', + test: /\.js$/, + loader: 'source-map-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + enforce: 'pre', + test: /\.ts$/, + use: 'source-map-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + enforce: 'pre', + test: /\.ts$/, + loader: 'tslint-loader', + options: { + emitErrors: true, + configFile: path.resolve(__dirname, './assets/tslint.json') + }, + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.ts$/, + use: ['ts-loader', 'angular2-template-loader'], + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.html$/, + loader: 'html-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + 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)$/, + loader: 'file-multi-loader', + query: { + name: '[name].[hash].[ext]', + outputPath: (url, resourcePath)=> { + return resourcePath.replace('src', 'bundles') + url; + }, + publicPath: (url, resourcePath)=> { + var component = resourcePath.substring(0, resourcePath.indexOf('src')); + var path = resourcePath.replace(component, '').replace('src', 'bundles'); + return './' + path + url; + } + } + } + ] + }, + + resolve: { + extensions: ['.ts', '.js'], + symlinks: false, + modules: [ + '../ng2-components', 'node_modules' + ] + }, + + plugins: [ + new webpack.NoEmitOnErrorsPlugin(), + + new webpack.BannerPlugin(fs.readFileSync(path.resolve(__dirname, './assets/license_header_add.txt'), 'utf8')), + + new webpack.ContextReplacementPlugin( + /angular(\\|\/)core(\\|\/)@angular/, + helpers.root('./src'), + {} + ) + ], + + devtool: 'cheap-module-source-map', + + node: { + fs: 'empty', + module: false + } +}; diff --git a/ng2-components/ng2-alfresco-datatable/config/webpack.test.js b/ng2-components/ng2-alfresco-datatable/config/webpack.test.js new file mode 100644 index 0000000000..486fed8c15 --- /dev/null +++ b/ng2-components/ng2-alfresco-datatable/config/webpack.test.js @@ -0,0 +1,85 @@ +const webpack = require('webpack'); +const helpers = require('./helpers'); + +const ENV = process.env.NODE_ENV = process.env.ENV = 'production'; + +module.exports = { + + devtool: 'inline-source-map', + + resolve: { + extensions: ['.ts', '.js'], + symlinks: false, + modules: [helpers.root('../ng2-components'), helpers.root('node_modules')] + }, + + module: { + rules: [ + { + enforce: 'pre', + test: /\.js$/, + loader: 'source-map-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.ts$/, + loaders: ['ts-loader?' + JSON.stringify({ transpileOnly: true}), 'angular2-template-loader'], + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.html$/, + loader: 'html-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.css$/, + loader: ['to-string-loader', 'css-loader'], + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico|pdf)$/, + loader: 'file-loader', + query: { + name: '[path][name].[ext]', + outputPath: (url)=> { + return url.replace('src', 'dist'); + } + } + }, + { + enforce: 'post', + test: /\.ts$/, + loader: 'istanbul-instrumenter-loader', + exclude: [ + /node_modules/, + /test/ + ] + } + ] + }, + + plugins: [ + new webpack.NoEmitOnErrorsPlugin(), + + new webpack.ContextReplacementPlugin( + /angular(\\|\/)core(\\|\/)@angular/, + helpers.root('./src'), + {} + ), + new webpack.DefinePlugin({ + 'process.env': { + 'ENV': JSON.stringify(ENV) + } + }), + new webpack.LoaderOptionsPlugin({ + htmlLoader: { + minimize: false // workaround for ng2 + } + }) + ], + + node: { + fs: 'empty', + module: false + } +}; diff --git a/ng2-components/ng2-alfresco-datatable/karma.conf.js b/ng2-components/ng2-alfresco-datatable/karma.conf.js index f7f5ca66a2..9001db1c10 100644 --- a/ng2-components/ng2-alfresco-datatable/karma.conf.js +++ b/ng2-components/ng2-alfresco-datatable/karma.conf.js @@ -21,11 +21,6 @@ module.exports = function (config) { {pattern: './node_modules/md-date-time-picker/**/*.js', included: false, served: true, watched: false}, {pattern: './node_modules/moment/**/*.js', included: false, served: true, watched: false}, - // pdf-js - './node_modules/pdfjs-dist/build/pdf.js', - './node_modules/pdfjs-dist/build/pdf.worker.js', - './node_modules/pdfjs-dist/web/pdf_viewer.js', - {pattern: 'karma-test-shim.js', watched: false}, {pattern: './src/assets/**/*.*', included: false, served: true, watched: false}, {pattern: './src/i18n/**/*.*', included: false, served: true, watched: false}, diff --git a/ng2-components/ng2-alfresco-datatable/package.json b/ng2-components/ng2-alfresco-datatable/package.json index 41b8a54050..5b87b26137 100644 --- a/ng2-components/ng2-alfresco-datatable/package.json +++ b/ng2-components/ng2-alfresco-datatable/package.json @@ -20,7 +20,6 @@ "bugs": { "url": "https://github.com/Alfresco/alfresco-ng2-components/issues" }, - "license": "Apache-2.0", "contributors": [ { "name": "Denys Vuika", @@ -106,13 +105,5 @@ "webpack-merge": "2.6.1", "wsrv": "^0.1.7" }, - "license-check-config": { - "src": [ - "./src/**/*.ts" - ], - "path": "assets/license_header.txt", - "blocking": true, - "logInfo": false, - "logError": true - } + "license": "Apache-2.0" } diff --git a/ng2-components/ng2-alfresco-datatable/webpack.build.js b/ng2-components/ng2-alfresco-datatable/webpack.build.js index 84d761017a..29afcdceb9 100644 --- a/ng2-components/ng2-alfresco-datatable/webpack.build.js +++ b/ng2-components/ng2-alfresco-datatable/webpack.build.js @@ -1,6 +1,6 @@ -const webpack = require("webpack"); +const webpack = require('webpack'); const webpackMerge = require('webpack-merge'); -const commonConfig = require('../config/webpack.common.js'); +const commonConfig = require('./config/webpack.common.js'); module.exports = webpackMerge(commonConfig, { diff --git a/ng2-components/ng2-alfresco-datatable/webpack.test.js b/ng2-components/ng2-alfresco-datatable/webpack.test.js index 4a61a62939..b6f4929fa4 100644 --- a/ng2-components/ng2-alfresco-datatable/webpack.test.js +++ b/ng2-components/ng2-alfresco-datatable/webpack.test.js @@ -1,6 +1,6 @@ const webpack = require('webpack'); const webpackMerge = require('webpack-merge'); -const testConfig = require('../config/webpack.test.js'); +const testConfig = require('./config/webpack.test.js'); module.exports = webpackMerge(testConfig, { diff --git a/ng2-components/ng2-alfresco-documentlist/config/assets/license_header.txt b/ng2-components/ng2-alfresco-documentlist/config/assets/license_header.txt new file mode 100644 index 0000000000..58ad8b656b --- /dev/null +++ b/ng2-components/ng2-alfresco-documentlist/config/assets/license_header.txt @@ -0,0 +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. + */ diff --git a/ng2-components/ng2-alfresco-documentlist/config/assets/license_header_add.txt b/ng2-components/ng2-alfresco-documentlist/config/assets/license_header_add.txt new file mode 100644 index 0000000000..b38baa9716 --- /dev/null +++ b/ng2-components/ng2-alfresco-documentlist/config/assets/license_header_add.txt @@ -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. diff --git a/ng2-components/ng2-alfresco-documentlist/config/assets/tslint.json b/ng2-components/ng2-alfresco-documentlist/config/assets/tslint.json new file mode 100644 index 0000000000..611a015c7e --- /dev/null +++ b/ng2-components/ng2-alfresco-documentlist/config/assets/tslint.json @@ -0,0 +1,118 @@ +{ + "rules": { + "align": [ + true, + "parameters", + "statements" + ], + "ban": false, + "class-name": true, + "comment-format": [ + true, + "check-space" + ], + "curly": true, + "eofline": true, + "forin": true, + "indent": [ + true, + "spaces" + ], + "interface-name": false, + "jsdoc-format": true, + "label-position": true, + "max-line-length": [ + true, + 180 + ], + "member-ordering": [ + true, + "static-before-instance", + "variables-before-functions" + ], + "no-any": false, + "no-arg": true, + "no-bitwise": false, + "no-conditional-assignment": true, + "no-consecutive-blank-lines": true, + "no-console": [ + true, + "debug", + "info", + "time", + "timeEnd", + "trace" + ], + "no-construct": true, + "no-constructor-vars": false, + "no-debugger": true, + "no-duplicate-variable": true, + "no-empty": false, + "no-eval": true, + "no-inferrable-types": false, + "no-internal-module": true, + "no-require-imports": false, + "no-shadowed-variable": true, + "no-switch-case-fall-through": true, + "no-trailing-whitespace": true, + "no-unused-expression": true, + "no-unused-variable": true, + "no-use-before-declare": true, + "no-var-keyword": true, + "no-var-requires": true, + "object-literal-sort-keys": false, + "one-line": [ + true, + "check-open-brace", + "check-catch", + "check-else", + "check-whitespace" + ], + "quotemark": [ + true, + "single", + "avoid-escape" + ], + "radix": true, + "semicolon": true, + "switch-default": true, + "trailing-comma": [ + true, + { + "multiline": "never", + "singleline": "never" + } + ], + "triple-equals": [ + true, + "allow-null-check" + ], + "typedef": false, + "typedef-whitespace": [ + true, + { + "call-signature": "nospace", + "index-signature": "nospace", + "parameter": "nospace", + "property-declaration": "nospace", + "variable-declaration": "nospace" + } + ], + "use-strict": false, + "variable-name": [ + true, + "check-format", + "allow-leading-underscore", + "ban-keywords" + ], + "whitespace": [ + true, + "check-branch", + "check-operator", + "check-separator", + "check-type", + "check-module", + "check-decl" + ] + } +} diff --git a/ng2-components/ng2-alfresco-documentlist/config/custom-loaders/file-loader-multi.js b/ng2-components/ng2-alfresco-documentlist/config/custom-loaders/file-loader-multi.js new file mode 100644 index 0000000000..dfbf93e76e --- /dev/null +++ b/ng2-components/ng2-alfresco-documentlist/config/custom-loaders/file-loader-multi.js @@ -0,0 +1,70 @@ +var path = require('path'); +var loaderUtils = require('loader-utils'); + +module.exports = function(content) { + this.cacheable && this.cacheable(); + if(!this.emitFile) throw new Error('emitFile is required from module system'); + + var query = loaderUtils.getOptions(this) || {}; + var configKey = query.config || 'multiFileLoader'; + var options = this.options[configKey] || {}; + var config = { + publicPath: false, + useRelativePath: false, + name: '[hash].[ext]' + }; + + // options takes precedence over config + Object.keys(options).forEach(function(attr) { + config[attr] = options[attr]; + }); + + // query takes precedence over config and options + Object.keys(query).forEach(function(attr) { + config[attr] = query[attr]; + }); + + var context = config.context || this.options.context; + var url = loaderUtils.interpolateName(this, config.name, { + context: context, + content: content, + regExp: config.regExp + }); + var path = loaderUtils.interpolateName(this, '[path]', { + context: context, + content: content, + regExp: config.regExp + }); + + var outputPath = ''; + + if (config.outputPath) { + outputPath = ( + typeof config.outputPath === 'function' + ? config.outputPath(url, path) + : config.outputPath + url + ); + } else { + outputPath = url; + } + + var publicPath = JSON.stringify(url); + + if (config.publicPath) { + publicPath = JSON.stringify( + typeof config.publicPath === 'function' + ? config.publicPath(url, path) + : config.publicPath + url + ); + } + + publicPath = '__webpack_public_path__ + ' + publicPath; + + if (query.emitFile === undefined || query.emitFile) { + this.emitFile(outputPath, content); + } + + return 'module.exports = ' + publicPath + ';'; +}; + +module.exports.raw = true; diff --git a/ng2-components/ng2-alfresco-documentlist/config/custom-loaders/license-check.js b/ng2-components/ng2-alfresco-documentlist/config/custom-loaders/license-check.js new file mode 100644 index 0000000000..6a15ac03e2 --- /dev/null +++ b/ng2-components/ng2-alfresco-documentlist/config/custom-loaders/license-check.js @@ -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); +}; diff --git a/ng2-components/ng2-alfresco-documentlist/config/helpers.js b/ng2-components/ng2-alfresco-documentlist/config/helpers.js new file mode 100644 index 0000000000..a11fa771d6 --- /dev/null +++ b/ng2-components/ng2-alfresco-documentlist/config/helpers.js @@ -0,0 +1,10 @@ +var path = require('path'); + +var _root = path.resolve(__dirname, '..'); + +function root(args) { + args = Array.prototype.slice.call(arguments, 0); + return path.join.apply(path, [_root].concat(args)); +} + +exports.root = root; diff --git a/ng2-components/ng2-alfresco-documentlist/config/webpack.common.js b/ng2-components/ng2-alfresco-documentlist/config/webpack.common.js new file mode 100644 index 0000000000..95cd33177e --- /dev/null +++ b/ng2-components/ng2-alfresco-documentlist/config/webpack.common.js @@ -0,0 +1,124 @@ +const webpack = require('webpack'); +const helpers = require('./helpers'); +const fs = require('fs'); +const path = require('path'); + +module.exports = { + + resolveLoader: { + alias: { + "file-multi-loader": path.resolve(__dirname, "./custom-loaders/file-loader-multi"), + "license-check": path.resolve(__dirname, "./custom-loaders/license-check") + } + }, + + // require those dependencies but don't bundle them + externals: [ + /^\@angular\//, + /^rxjs\//, + 'moment', + 'raphael', + 'ng2-charts', + 'alfresco-js-api', + 'ng2-alfresco-core', + 'ng2-alfresco-datatable', + 'ng2-activiti-analytics', + 'ng2-activiti-diagrams', + 'ng2-activiti-form', + "ng2-activiti-tasklist", + 'ng2-alfresco-documentlist' + ], + + module: { + rules: [ + { + enforce: 'pre', + test: /\.js$/, + loader: 'source-map-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + enforce: 'pre', + test: /\.ts$/, + use: 'source-map-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + enforce: 'pre', + test: /\.ts$/, + loader: 'tslint-loader', + options: { + emitErrors: true, + configFile: path.resolve(__dirname, './assets/tslint.json') + }, + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.ts$/, + use: ['ts-loader', 'angular2-template-loader'], + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.html$/, + loader: 'html-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + 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)$/, + loader: 'file-multi-loader', + query: { + name: '[name].[hash].[ext]', + outputPath: (url, resourcePath)=> { + return resourcePath.replace('src', 'bundles') + url; + }, + publicPath: (url, resourcePath)=> { + var component = resourcePath.substring(0, resourcePath.indexOf('src')); + var path = resourcePath.replace(component, '').replace('src', 'bundles'); + return './' + path + url; + } + } + } + ] + }, + + resolve: { + extensions: ['.ts', '.js'], + symlinks: false, + modules: [ + '../ng2-components', 'node_modules' + ] + }, + + plugins: [ + new webpack.NoEmitOnErrorsPlugin(), + + new webpack.BannerPlugin(fs.readFileSync(path.resolve(__dirname, './assets/license_header_add.txt'), 'utf8')), + + new webpack.ContextReplacementPlugin( + /angular(\\|\/)core(\\|\/)@angular/, + helpers.root('./src'), + {} + ) + ], + + devtool: 'cheap-module-source-map', + + node: { + fs: 'empty', + module: false + } +}; diff --git a/ng2-components/ng2-alfresco-documentlist/config/webpack.test.js b/ng2-components/ng2-alfresco-documentlist/config/webpack.test.js new file mode 100644 index 0000000000..486fed8c15 --- /dev/null +++ b/ng2-components/ng2-alfresco-documentlist/config/webpack.test.js @@ -0,0 +1,85 @@ +const webpack = require('webpack'); +const helpers = require('./helpers'); + +const ENV = process.env.NODE_ENV = process.env.ENV = 'production'; + +module.exports = { + + devtool: 'inline-source-map', + + resolve: { + extensions: ['.ts', '.js'], + symlinks: false, + modules: [helpers.root('../ng2-components'), helpers.root('node_modules')] + }, + + module: { + rules: [ + { + enforce: 'pre', + test: /\.js$/, + loader: 'source-map-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.ts$/, + loaders: ['ts-loader?' + JSON.stringify({ transpileOnly: true}), 'angular2-template-loader'], + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.html$/, + loader: 'html-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.css$/, + loader: ['to-string-loader', 'css-loader'], + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico|pdf)$/, + loader: 'file-loader', + query: { + name: '[path][name].[ext]', + outputPath: (url)=> { + return url.replace('src', 'dist'); + } + } + }, + { + enforce: 'post', + test: /\.ts$/, + loader: 'istanbul-instrumenter-loader', + exclude: [ + /node_modules/, + /test/ + ] + } + ] + }, + + plugins: [ + new webpack.NoEmitOnErrorsPlugin(), + + new webpack.ContextReplacementPlugin( + /angular(\\|\/)core(\\|\/)@angular/, + helpers.root('./src'), + {} + ), + new webpack.DefinePlugin({ + 'process.env': { + 'ENV': JSON.stringify(ENV) + } + }), + new webpack.LoaderOptionsPlugin({ + htmlLoader: { + minimize: false // workaround for ng2 + } + }) + ], + + node: { + fs: 'empty', + module: false + } +}; diff --git a/ng2-components/ng2-alfresco-documentlist/karma.conf.js b/ng2-components/ng2-alfresco-documentlist/karma.conf.js index f7f5ca66a2..9001db1c10 100644 --- a/ng2-components/ng2-alfresco-documentlist/karma.conf.js +++ b/ng2-components/ng2-alfresco-documentlist/karma.conf.js @@ -21,11 +21,6 @@ module.exports = function (config) { {pattern: './node_modules/md-date-time-picker/**/*.js', included: false, served: true, watched: false}, {pattern: './node_modules/moment/**/*.js', included: false, served: true, watched: false}, - // pdf-js - './node_modules/pdfjs-dist/build/pdf.js', - './node_modules/pdfjs-dist/build/pdf.worker.js', - './node_modules/pdfjs-dist/web/pdf_viewer.js', - {pattern: 'karma-test-shim.js', watched: false}, {pattern: './src/assets/**/*.*', included: false, served: true, watched: false}, {pattern: './src/i18n/**/*.*', included: false, served: true, watched: false}, diff --git a/ng2-components/ng2-alfresco-documentlist/package.json b/ng2-components/ng2-alfresco-documentlist/package.json index 9980b8ade3..d505dc3b20 100644 --- a/ng2-components/ng2-alfresco-documentlist/package.json +++ b/ng2-components/ng2-alfresco-documentlist/package.json @@ -20,7 +20,6 @@ "bugs": { "url": "https://github.com/Alfresco/alfresco-ng2-components/issues" }, - "license": "Apache-2.0", "contributors": [ { "name": "Denys Vuika", @@ -115,13 +114,5 @@ "webpack-merge": "2.6.1", "wsrv": "^0.1.7" }, - "license-check-config": { - "src": [ - "./src/**/*.ts" - ], - "path": "assets/license_header.txt", - "blocking": true, - "logInfo": false, - "logError": true - } + "license": "Apache-2.0" } diff --git a/ng2-components/ng2-alfresco-documentlist/webpack.build.js b/ng2-components/ng2-alfresco-documentlist/webpack.build.js index fca998d50f..8246ca3c84 100644 --- a/ng2-components/ng2-alfresco-documentlist/webpack.build.js +++ b/ng2-components/ng2-alfresco-documentlist/webpack.build.js @@ -1,6 +1,6 @@ -const webpack = require("webpack"); +const webpack = require('webpack'); const webpackMerge = require('webpack-merge'); -const commonConfig = require('../config/webpack.common.js'); +const commonConfig = require('./config/webpack.common.js'); module.exports = webpackMerge(commonConfig, { diff --git a/ng2-components/ng2-alfresco-documentlist/webpack.test.js b/ng2-components/ng2-alfresco-documentlist/webpack.test.js index 4a61a62939..b6f4929fa4 100644 --- a/ng2-components/ng2-alfresco-documentlist/webpack.test.js +++ b/ng2-components/ng2-alfresco-documentlist/webpack.test.js @@ -1,6 +1,6 @@ const webpack = require('webpack'); const webpackMerge = require('webpack-merge'); -const testConfig = require('../config/webpack.test.js'); +const testConfig = require('./config/webpack.test.js'); module.exports = webpackMerge(testConfig, { diff --git a/ng2-components/ng2-alfresco-login/config/assets/license_header.txt b/ng2-components/ng2-alfresco-login/config/assets/license_header.txt new file mode 100644 index 0000000000..58ad8b656b --- /dev/null +++ b/ng2-components/ng2-alfresco-login/config/assets/license_header.txt @@ -0,0 +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. + */ diff --git a/ng2-components/ng2-alfresco-login/config/assets/license_header_add.txt b/ng2-components/ng2-alfresco-login/config/assets/license_header_add.txt new file mode 100644 index 0000000000..b38baa9716 --- /dev/null +++ b/ng2-components/ng2-alfresco-login/config/assets/license_header_add.txt @@ -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. diff --git a/ng2-components/ng2-alfresco-login/config/assets/tslint.json b/ng2-components/ng2-alfresco-login/config/assets/tslint.json new file mode 100644 index 0000000000..611a015c7e --- /dev/null +++ b/ng2-components/ng2-alfresco-login/config/assets/tslint.json @@ -0,0 +1,118 @@ +{ + "rules": { + "align": [ + true, + "parameters", + "statements" + ], + "ban": false, + "class-name": true, + "comment-format": [ + true, + "check-space" + ], + "curly": true, + "eofline": true, + "forin": true, + "indent": [ + true, + "spaces" + ], + "interface-name": false, + "jsdoc-format": true, + "label-position": true, + "max-line-length": [ + true, + 180 + ], + "member-ordering": [ + true, + "static-before-instance", + "variables-before-functions" + ], + "no-any": false, + "no-arg": true, + "no-bitwise": false, + "no-conditional-assignment": true, + "no-consecutive-blank-lines": true, + "no-console": [ + true, + "debug", + "info", + "time", + "timeEnd", + "trace" + ], + "no-construct": true, + "no-constructor-vars": false, + "no-debugger": true, + "no-duplicate-variable": true, + "no-empty": false, + "no-eval": true, + "no-inferrable-types": false, + "no-internal-module": true, + "no-require-imports": false, + "no-shadowed-variable": true, + "no-switch-case-fall-through": true, + "no-trailing-whitespace": true, + "no-unused-expression": true, + "no-unused-variable": true, + "no-use-before-declare": true, + "no-var-keyword": true, + "no-var-requires": true, + "object-literal-sort-keys": false, + "one-line": [ + true, + "check-open-brace", + "check-catch", + "check-else", + "check-whitespace" + ], + "quotemark": [ + true, + "single", + "avoid-escape" + ], + "radix": true, + "semicolon": true, + "switch-default": true, + "trailing-comma": [ + true, + { + "multiline": "never", + "singleline": "never" + } + ], + "triple-equals": [ + true, + "allow-null-check" + ], + "typedef": false, + "typedef-whitespace": [ + true, + { + "call-signature": "nospace", + "index-signature": "nospace", + "parameter": "nospace", + "property-declaration": "nospace", + "variable-declaration": "nospace" + } + ], + "use-strict": false, + "variable-name": [ + true, + "check-format", + "allow-leading-underscore", + "ban-keywords" + ], + "whitespace": [ + true, + "check-branch", + "check-operator", + "check-separator", + "check-type", + "check-module", + "check-decl" + ] + } +} diff --git a/ng2-components/ng2-alfresco-login/config/custom-loaders/file-loader-multi.js b/ng2-components/ng2-alfresco-login/config/custom-loaders/file-loader-multi.js new file mode 100644 index 0000000000..dfbf93e76e --- /dev/null +++ b/ng2-components/ng2-alfresco-login/config/custom-loaders/file-loader-multi.js @@ -0,0 +1,70 @@ +var path = require('path'); +var loaderUtils = require('loader-utils'); + +module.exports = function(content) { + this.cacheable && this.cacheable(); + if(!this.emitFile) throw new Error('emitFile is required from module system'); + + var query = loaderUtils.getOptions(this) || {}; + var configKey = query.config || 'multiFileLoader'; + var options = this.options[configKey] || {}; + var config = { + publicPath: false, + useRelativePath: false, + name: '[hash].[ext]' + }; + + // options takes precedence over config + Object.keys(options).forEach(function(attr) { + config[attr] = options[attr]; + }); + + // query takes precedence over config and options + Object.keys(query).forEach(function(attr) { + config[attr] = query[attr]; + }); + + var context = config.context || this.options.context; + var url = loaderUtils.interpolateName(this, config.name, { + context: context, + content: content, + regExp: config.regExp + }); + var path = loaderUtils.interpolateName(this, '[path]', { + context: context, + content: content, + regExp: config.regExp + }); + + var outputPath = ''; + + if (config.outputPath) { + outputPath = ( + typeof config.outputPath === 'function' + ? config.outputPath(url, path) + : config.outputPath + url + ); + } else { + outputPath = url; + } + + var publicPath = JSON.stringify(url); + + if (config.publicPath) { + publicPath = JSON.stringify( + typeof config.publicPath === 'function' + ? config.publicPath(url, path) + : config.publicPath + url + ); + } + + publicPath = '__webpack_public_path__ + ' + publicPath; + + if (query.emitFile === undefined || query.emitFile) { + this.emitFile(outputPath, content); + } + + return 'module.exports = ' + publicPath + ';'; +}; + +module.exports.raw = true; diff --git a/ng2-components/ng2-alfresco-login/config/custom-loaders/license-check.js b/ng2-components/ng2-alfresco-login/config/custom-loaders/license-check.js new file mode 100644 index 0000000000..6a15ac03e2 --- /dev/null +++ b/ng2-components/ng2-alfresco-login/config/custom-loaders/license-check.js @@ -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); +}; diff --git a/ng2-components/ng2-alfresco-login/config/helpers.js b/ng2-components/ng2-alfresco-login/config/helpers.js new file mode 100644 index 0000000000..a11fa771d6 --- /dev/null +++ b/ng2-components/ng2-alfresco-login/config/helpers.js @@ -0,0 +1,10 @@ +var path = require('path'); + +var _root = path.resolve(__dirname, '..'); + +function root(args) { + args = Array.prototype.slice.call(arguments, 0); + return path.join.apply(path, [_root].concat(args)); +} + +exports.root = root; diff --git a/ng2-components/ng2-alfresco-login/config/webpack.common.js b/ng2-components/ng2-alfresco-login/config/webpack.common.js new file mode 100644 index 0000000000..95cd33177e --- /dev/null +++ b/ng2-components/ng2-alfresco-login/config/webpack.common.js @@ -0,0 +1,124 @@ +const webpack = require('webpack'); +const helpers = require('./helpers'); +const fs = require('fs'); +const path = require('path'); + +module.exports = { + + resolveLoader: { + alias: { + "file-multi-loader": path.resolve(__dirname, "./custom-loaders/file-loader-multi"), + "license-check": path.resolve(__dirname, "./custom-loaders/license-check") + } + }, + + // require those dependencies but don't bundle them + externals: [ + /^\@angular\//, + /^rxjs\//, + 'moment', + 'raphael', + 'ng2-charts', + 'alfresco-js-api', + 'ng2-alfresco-core', + 'ng2-alfresco-datatable', + 'ng2-activiti-analytics', + 'ng2-activiti-diagrams', + 'ng2-activiti-form', + "ng2-activiti-tasklist", + 'ng2-alfresco-documentlist' + ], + + module: { + rules: [ + { + enforce: 'pre', + test: /\.js$/, + loader: 'source-map-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + enforce: 'pre', + test: /\.ts$/, + use: 'source-map-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + enforce: 'pre', + test: /\.ts$/, + loader: 'tslint-loader', + options: { + emitErrors: true, + configFile: path.resolve(__dirname, './assets/tslint.json') + }, + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.ts$/, + use: ['ts-loader', 'angular2-template-loader'], + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.html$/, + loader: 'html-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + 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)$/, + loader: 'file-multi-loader', + query: { + name: '[name].[hash].[ext]', + outputPath: (url, resourcePath)=> { + return resourcePath.replace('src', 'bundles') + url; + }, + publicPath: (url, resourcePath)=> { + var component = resourcePath.substring(0, resourcePath.indexOf('src')); + var path = resourcePath.replace(component, '').replace('src', 'bundles'); + return './' + path + url; + } + } + } + ] + }, + + resolve: { + extensions: ['.ts', '.js'], + symlinks: false, + modules: [ + '../ng2-components', 'node_modules' + ] + }, + + plugins: [ + new webpack.NoEmitOnErrorsPlugin(), + + new webpack.BannerPlugin(fs.readFileSync(path.resolve(__dirname, './assets/license_header_add.txt'), 'utf8')), + + new webpack.ContextReplacementPlugin( + /angular(\\|\/)core(\\|\/)@angular/, + helpers.root('./src'), + {} + ) + ], + + devtool: 'cheap-module-source-map', + + node: { + fs: 'empty', + module: false + } +}; diff --git a/ng2-components/ng2-alfresco-login/config/webpack.test.js b/ng2-components/ng2-alfresco-login/config/webpack.test.js new file mode 100644 index 0000000000..486fed8c15 --- /dev/null +++ b/ng2-components/ng2-alfresco-login/config/webpack.test.js @@ -0,0 +1,85 @@ +const webpack = require('webpack'); +const helpers = require('./helpers'); + +const ENV = process.env.NODE_ENV = process.env.ENV = 'production'; + +module.exports = { + + devtool: 'inline-source-map', + + resolve: { + extensions: ['.ts', '.js'], + symlinks: false, + modules: [helpers.root('../ng2-components'), helpers.root('node_modules')] + }, + + module: { + rules: [ + { + enforce: 'pre', + test: /\.js$/, + loader: 'source-map-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.ts$/, + loaders: ['ts-loader?' + JSON.stringify({ transpileOnly: true}), 'angular2-template-loader'], + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.html$/, + loader: 'html-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.css$/, + loader: ['to-string-loader', 'css-loader'], + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico|pdf)$/, + loader: 'file-loader', + query: { + name: '[path][name].[ext]', + outputPath: (url)=> { + return url.replace('src', 'dist'); + } + } + }, + { + enforce: 'post', + test: /\.ts$/, + loader: 'istanbul-instrumenter-loader', + exclude: [ + /node_modules/, + /test/ + ] + } + ] + }, + + plugins: [ + new webpack.NoEmitOnErrorsPlugin(), + + new webpack.ContextReplacementPlugin( + /angular(\\|\/)core(\\|\/)@angular/, + helpers.root('./src'), + {} + ), + new webpack.DefinePlugin({ + 'process.env': { + 'ENV': JSON.stringify(ENV) + } + }), + new webpack.LoaderOptionsPlugin({ + htmlLoader: { + minimize: false // workaround for ng2 + } + }) + ], + + node: { + fs: 'empty', + module: false + } +}; diff --git a/ng2-components/ng2-alfresco-login/karma.conf.js b/ng2-components/ng2-alfresco-login/karma.conf.js index f7f5ca66a2..9001db1c10 100644 --- a/ng2-components/ng2-alfresco-login/karma.conf.js +++ b/ng2-components/ng2-alfresco-login/karma.conf.js @@ -21,11 +21,6 @@ module.exports = function (config) { {pattern: './node_modules/md-date-time-picker/**/*.js', included: false, served: true, watched: false}, {pattern: './node_modules/moment/**/*.js', included: false, served: true, watched: false}, - // pdf-js - './node_modules/pdfjs-dist/build/pdf.js', - './node_modules/pdfjs-dist/build/pdf.worker.js', - './node_modules/pdfjs-dist/web/pdf_viewer.js', - {pattern: 'karma-test-shim.js', watched: false}, {pattern: './src/assets/**/*.*', included: false, served: true, watched: false}, {pattern: './src/i18n/**/*.*', included: false, served: true, watched: false}, diff --git a/ng2-components/ng2-alfresco-login/package.json b/ng2-components/ng2-alfresco-login/package.json index a10f722ecb..3b6b4ac985 100644 --- a/ng2-components/ng2-alfresco-login/package.json +++ b/ng2-components/ng2-alfresco-login/package.json @@ -20,7 +20,6 @@ "bugs": { "url": "https://github.com/Alfresco/alfresco-ng2-components/issues" }, - "license": "Apache-2.0", "contributors": [ { "name": "Denys Vuika", @@ -117,13 +116,5 @@ "webpack-merge": "2.6.1", "wsrv": "^0.1.7" }, - "license-check-config": { - "src": [ - "./src/**/*.ts" - ], - "path": "assets/license_header.txt", - "blocking": true, - "logInfo": false, - "logError": true - } + "license": "Apache-2.0" } diff --git a/ng2-components/ng2-alfresco-login/webpack.build.js b/ng2-components/ng2-alfresco-login/webpack.build.js index 81b2ab9019..d171c95fc7 100644 --- a/ng2-components/ng2-alfresco-login/webpack.build.js +++ b/ng2-components/ng2-alfresco-login/webpack.build.js @@ -1,6 +1,6 @@ -const webpack = require("webpack"); +const webpack = require('webpack'); const webpackMerge = require('webpack-merge'); -const commonConfig = require('../config/webpack.common.js'); +const commonConfig = require('./config/webpack.common.js'); module.exports = webpackMerge(commonConfig, { diff --git a/ng2-components/ng2-alfresco-login/webpack.test.js b/ng2-components/ng2-alfresco-login/webpack.test.js index 4a61a62939..b6f4929fa4 100644 --- a/ng2-components/ng2-alfresco-login/webpack.test.js +++ b/ng2-components/ng2-alfresco-login/webpack.test.js @@ -1,6 +1,6 @@ const webpack = require('webpack'); const webpackMerge = require('webpack-merge'); -const testConfig = require('../config/webpack.test.js'); +const testConfig = require('./config/webpack.test.js'); module.exports = webpackMerge(testConfig, { diff --git a/ng2-components/ng2-alfresco-search/config/assets/license_header.txt b/ng2-components/ng2-alfresco-search/config/assets/license_header.txt new file mode 100644 index 0000000000..58ad8b656b --- /dev/null +++ b/ng2-components/ng2-alfresco-search/config/assets/license_header.txt @@ -0,0 +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. + */ diff --git a/ng2-components/ng2-alfresco-search/config/assets/license_header_add.txt b/ng2-components/ng2-alfresco-search/config/assets/license_header_add.txt new file mode 100644 index 0000000000..b38baa9716 --- /dev/null +++ b/ng2-components/ng2-alfresco-search/config/assets/license_header_add.txt @@ -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. diff --git a/ng2-components/ng2-alfresco-search/config/assets/tslint.json b/ng2-components/ng2-alfresco-search/config/assets/tslint.json new file mode 100644 index 0000000000..611a015c7e --- /dev/null +++ b/ng2-components/ng2-alfresco-search/config/assets/tslint.json @@ -0,0 +1,118 @@ +{ + "rules": { + "align": [ + true, + "parameters", + "statements" + ], + "ban": false, + "class-name": true, + "comment-format": [ + true, + "check-space" + ], + "curly": true, + "eofline": true, + "forin": true, + "indent": [ + true, + "spaces" + ], + "interface-name": false, + "jsdoc-format": true, + "label-position": true, + "max-line-length": [ + true, + 180 + ], + "member-ordering": [ + true, + "static-before-instance", + "variables-before-functions" + ], + "no-any": false, + "no-arg": true, + "no-bitwise": false, + "no-conditional-assignment": true, + "no-consecutive-blank-lines": true, + "no-console": [ + true, + "debug", + "info", + "time", + "timeEnd", + "trace" + ], + "no-construct": true, + "no-constructor-vars": false, + "no-debugger": true, + "no-duplicate-variable": true, + "no-empty": false, + "no-eval": true, + "no-inferrable-types": false, + "no-internal-module": true, + "no-require-imports": false, + "no-shadowed-variable": true, + "no-switch-case-fall-through": true, + "no-trailing-whitespace": true, + "no-unused-expression": true, + "no-unused-variable": true, + "no-use-before-declare": true, + "no-var-keyword": true, + "no-var-requires": true, + "object-literal-sort-keys": false, + "one-line": [ + true, + "check-open-brace", + "check-catch", + "check-else", + "check-whitespace" + ], + "quotemark": [ + true, + "single", + "avoid-escape" + ], + "radix": true, + "semicolon": true, + "switch-default": true, + "trailing-comma": [ + true, + { + "multiline": "never", + "singleline": "never" + } + ], + "triple-equals": [ + true, + "allow-null-check" + ], + "typedef": false, + "typedef-whitespace": [ + true, + { + "call-signature": "nospace", + "index-signature": "nospace", + "parameter": "nospace", + "property-declaration": "nospace", + "variable-declaration": "nospace" + } + ], + "use-strict": false, + "variable-name": [ + true, + "check-format", + "allow-leading-underscore", + "ban-keywords" + ], + "whitespace": [ + true, + "check-branch", + "check-operator", + "check-separator", + "check-type", + "check-module", + "check-decl" + ] + } +} diff --git a/ng2-components/ng2-alfresco-search/config/custom-loaders/file-loader-multi.js b/ng2-components/ng2-alfresco-search/config/custom-loaders/file-loader-multi.js new file mode 100644 index 0000000000..dfbf93e76e --- /dev/null +++ b/ng2-components/ng2-alfresco-search/config/custom-loaders/file-loader-multi.js @@ -0,0 +1,70 @@ +var path = require('path'); +var loaderUtils = require('loader-utils'); + +module.exports = function(content) { + this.cacheable && this.cacheable(); + if(!this.emitFile) throw new Error('emitFile is required from module system'); + + var query = loaderUtils.getOptions(this) || {}; + var configKey = query.config || 'multiFileLoader'; + var options = this.options[configKey] || {}; + var config = { + publicPath: false, + useRelativePath: false, + name: '[hash].[ext]' + }; + + // options takes precedence over config + Object.keys(options).forEach(function(attr) { + config[attr] = options[attr]; + }); + + // query takes precedence over config and options + Object.keys(query).forEach(function(attr) { + config[attr] = query[attr]; + }); + + var context = config.context || this.options.context; + var url = loaderUtils.interpolateName(this, config.name, { + context: context, + content: content, + regExp: config.regExp + }); + var path = loaderUtils.interpolateName(this, '[path]', { + context: context, + content: content, + regExp: config.regExp + }); + + var outputPath = ''; + + if (config.outputPath) { + outputPath = ( + typeof config.outputPath === 'function' + ? config.outputPath(url, path) + : config.outputPath + url + ); + } else { + outputPath = url; + } + + var publicPath = JSON.stringify(url); + + if (config.publicPath) { + publicPath = JSON.stringify( + typeof config.publicPath === 'function' + ? config.publicPath(url, path) + : config.publicPath + url + ); + } + + publicPath = '__webpack_public_path__ + ' + publicPath; + + if (query.emitFile === undefined || query.emitFile) { + this.emitFile(outputPath, content); + } + + return 'module.exports = ' + publicPath + ';'; +}; + +module.exports.raw = true; diff --git a/ng2-components/ng2-alfresco-search/config/custom-loaders/license-check.js b/ng2-components/ng2-alfresco-search/config/custom-loaders/license-check.js new file mode 100644 index 0000000000..6a15ac03e2 --- /dev/null +++ b/ng2-components/ng2-alfresco-search/config/custom-loaders/license-check.js @@ -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); +}; diff --git a/ng2-components/ng2-alfresco-search/config/helpers.js b/ng2-components/ng2-alfresco-search/config/helpers.js new file mode 100644 index 0000000000..a11fa771d6 --- /dev/null +++ b/ng2-components/ng2-alfresco-search/config/helpers.js @@ -0,0 +1,10 @@ +var path = require('path'); + +var _root = path.resolve(__dirname, '..'); + +function root(args) { + args = Array.prototype.slice.call(arguments, 0); + return path.join.apply(path, [_root].concat(args)); +} + +exports.root = root; diff --git a/ng2-components/ng2-alfresco-search/config/webpack.common.js b/ng2-components/ng2-alfresco-search/config/webpack.common.js new file mode 100644 index 0000000000..95cd33177e --- /dev/null +++ b/ng2-components/ng2-alfresco-search/config/webpack.common.js @@ -0,0 +1,124 @@ +const webpack = require('webpack'); +const helpers = require('./helpers'); +const fs = require('fs'); +const path = require('path'); + +module.exports = { + + resolveLoader: { + alias: { + "file-multi-loader": path.resolve(__dirname, "./custom-loaders/file-loader-multi"), + "license-check": path.resolve(__dirname, "./custom-loaders/license-check") + } + }, + + // require those dependencies but don't bundle them + externals: [ + /^\@angular\//, + /^rxjs\//, + 'moment', + 'raphael', + 'ng2-charts', + 'alfresco-js-api', + 'ng2-alfresco-core', + 'ng2-alfresco-datatable', + 'ng2-activiti-analytics', + 'ng2-activiti-diagrams', + 'ng2-activiti-form', + "ng2-activiti-tasklist", + 'ng2-alfresco-documentlist' + ], + + module: { + rules: [ + { + enforce: 'pre', + test: /\.js$/, + loader: 'source-map-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + enforce: 'pre', + test: /\.ts$/, + use: 'source-map-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + enforce: 'pre', + test: /\.ts$/, + loader: 'tslint-loader', + options: { + emitErrors: true, + configFile: path.resolve(__dirname, './assets/tslint.json') + }, + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.ts$/, + use: ['ts-loader', 'angular2-template-loader'], + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.html$/, + loader: 'html-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + 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)$/, + loader: 'file-multi-loader', + query: { + name: '[name].[hash].[ext]', + outputPath: (url, resourcePath)=> { + return resourcePath.replace('src', 'bundles') + url; + }, + publicPath: (url, resourcePath)=> { + var component = resourcePath.substring(0, resourcePath.indexOf('src')); + var path = resourcePath.replace(component, '').replace('src', 'bundles'); + return './' + path + url; + } + } + } + ] + }, + + resolve: { + extensions: ['.ts', '.js'], + symlinks: false, + modules: [ + '../ng2-components', 'node_modules' + ] + }, + + plugins: [ + new webpack.NoEmitOnErrorsPlugin(), + + new webpack.BannerPlugin(fs.readFileSync(path.resolve(__dirname, './assets/license_header_add.txt'), 'utf8')), + + new webpack.ContextReplacementPlugin( + /angular(\\|\/)core(\\|\/)@angular/, + helpers.root('./src'), + {} + ) + ], + + devtool: 'cheap-module-source-map', + + node: { + fs: 'empty', + module: false + } +}; diff --git a/ng2-components/ng2-alfresco-search/config/webpack.test.js b/ng2-components/ng2-alfresco-search/config/webpack.test.js new file mode 100644 index 0000000000..486fed8c15 --- /dev/null +++ b/ng2-components/ng2-alfresco-search/config/webpack.test.js @@ -0,0 +1,85 @@ +const webpack = require('webpack'); +const helpers = require('./helpers'); + +const ENV = process.env.NODE_ENV = process.env.ENV = 'production'; + +module.exports = { + + devtool: 'inline-source-map', + + resolve: { + extensions: ['.ts', '.js'], + symlinks: false, + modules: [helpers.root('../ng2-components'), helpers.root('node_modules')] + }, + + module: { + rules: [ + { + enforce: 'pre', + test: /\.js$/, + loader: 'source-map-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.ts$/, + loaders: ['ts-loader?' + JSON.stringify({ transpileOnly: true}), 'angular2-template-loader'], + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.html$/, + loader: 'html-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.css$/, + loader: ['to-string-loader', 'css-loader'], + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico|pdf)$/, + loader: 'file-loader', + query: { + name: '[path][name].[ext]', + outputPath: (url)=> { + return url.replace('src', 'dist'); + } + } + }, + { + enforce: 'post', + test: /\.ts$/, + loader: 'istanbul-instrumenter-loader', + exclude: [ + /node_modules/, + /test/ + ] + } + ] + }, + + plugins: [ + new webpack.NoEmitOnErrorsPlugin(), + + new webpack.ContextReplacementPlugin( + /angular(\\|\/)core(\\|\/)@angular/, + helpers.root('./src'), + {} + ), + new webpack.DefinePlugin({ + 'process.env': { + 'ENV': JSON.stringify(ENV) + } + }), + new webpack.LoaderOptionsPlugin({ + htmlLoader: { + minimize: false // workaround for ng2 + } + }) + ], + + node: { + fs: 'empty', + module: false + } +}; diff --git a/ng2-components/ng2-alfresco-search/karma.conf.js b/ng2-components/ng2-alfresco-search/karma.conf.js index f7f5ca66a2..9001db1c10 100644 --- a/ng2-components/ng2-alfresco-search/karma.conf.js +++ b/ng2-components/ng2-alfresco-search/karma.conf.js @@ -21,11 +21,6 @@ module.exports = function (config) { {pattern: './node_modules/md-date-time-picker/**/*.js', included: false, served: true, watched: false}, {pattern: './node_modules/moment/**/*.js', included: false, served: true, watched: false}, - // pdf-js - './node_modules/pdfjs-dist/build/pdf.js', - './node_modules/pdfjs-dist/build/pdf.worker.js', - './node_modules/pdfjs-dist/web/pdf_viewer.js', - {pattern: 'karma-test-shim.js', watched: false}, {pattern: './src/assets/**/*.*', included: false, served: true, watched: false}, {pattern: './src/i18n/**/*.*', included: false, served: true, watched: false}, diff --git a/ng2-components/ng2-alfresco-search/package.json b/ng2-components/ng2-alfresco-search/package.json index e606650b36..73f0ee291f 100644 --- a/ng2-components/ng2-alfresco-search/package.json +++ b/ng2-components/ng2-alfresco-search/package.json @@ -20,7 +20,6 @@ "bugs": { "url": "https://github.com/Alfresco/alfresco-ng2-components/issues" }, - "license": "Apache-2.0", "contributors": [ { "name": "Will Abson", @@ -116,13 +115,5 @@ "webpack-merge": "2.6.1", "wsrv": "^0.1.7" }, - "license-check-config": { - "src": [ - "./src/**/*.ts" - ], - "path": "assets/license_header.txt", - "blocking": true, - "logInfo": false, - "logError": true - } + "license": "Apache-2.0" } diff --git a/ng2-components/ng2-alfresco-search/webpack.build.js b/ng2-components/ng2-alfresco-search/webpack.build.js index 25c421022d..fb9fd48596 100644 --- a/ng2-components/ng2-alfresco-search/webpack.build.js +++ b/ng2-components/ng2-alfresco-search/webpack.build.js @@ -1,6 +1,6 @@ -const webpack = require("webpack"); +const webpack = require('webpack'); const webpackMerge = require('webpack-merge'); -const commonConfig = require('../config/webpack.common.js'); +const commonConfig = require('./config/webpack.common.js'); module.exports = webpackMerge(commonConfig, { diff --git a/ng2-components/ng2-alfresco-search/webpack.test.js b/ng2-components/ng2-alfresco-search/webpack.test.js index 4a61a62939..b6f4929fa4 100644 --- a/ng2-components/ng2-alfresco-search/webpack.test.js +++ b/ng2-components/ng2-alfresco-search/webpack.test.js @@ -1,6 +1,6 @@ const webpack = require('webpack'); const webpackMerge = require('webpack-merge'); -const testConfig = require('../config/webpack.test.js'); +const testConfig = require('./config/webpack.test.js'); module.exports = webpackMerge(testConfig, { diff --git a/ng2-components/ng2-alfresco-social/config/assets/license_header.txt b/ng2-components/ng2-alfresco-social/config/assets/license_header.txt new file mode 100644 index 0000000000..58ad8b656b --- /dev/null +++ b/ng2-components/ng2-alfresco-social/config/assets/license_header.txt @@ -0,0 +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. + */ diff --git a/ng2-components/ng2-alfresco-social/config/assets/license_header_add.txt b/ng2-components/ng2-alfresco-social/config/assets/license_header_add.txt new file mode 100644 index 0000000000..b38baa9716 --- /dev/null +++ b/ng2-components/ng2-alfresco-social/config/assets/license_header_add.txt @@ -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. diff --git a/ng2-components/ng2-alfresco-social/config/assets/tslint.json b/ng2-components/ng2-alfresco-social/config/assets/tslint.json new file mode 100644 index 0000000000..611a015c7e --- /dev/null +++ b/ng2-components/ng2-alfresco-social/config/assets/tslint.json @@ -0,0 +1,118 @@ +{ + "rules": { + "align": [ + true, + "parameters", + "statements" + ], + "ban": false, + "class-name": true, + "comment-format": [ + true, + "check-space" + ], + "curly": true, + "eofline": true, + "forin": true, + "indent": [ + true, + "spaces" + ], + "interface-name": false, + "jsdoc-format": true, + "label-position": true, + "max-line-length": [ + true, + 180 + ], + "member-ordering": [ + true, + "static-before-instance", + "variables-before-functions" + ], + "no-any": false, + "no-arg": true, + "no-bitwise": false, + "no-conditional-assignment": true, + "no-consecutive-blank-lines": true, + "no-console": [ + true, + "debug", + "info", + "time", + "timeEnd", + "trace" + ], + "no-construct": true, + "no-constructor-vars": false, + "no-debugger": true, + "no-duplicate-variable": true, + "no-empty": false, + "no-eval": true, + "no-inferrable-types": false, + "no-internal-module": true, + "no-require-imports": false, + "no-shadowed-variable": true, + "no-switch-case-fall-through": true, + "no-trailing-whitespace": true, + "no-unused-expression": true, + "no-unused-variable": true, + "no-use-before-declare": true, + "no-var-keyword": true, + "no-var-requires": true, + "object-literal-sort-keys": false, + "one-line": [ + true, + "check-open-brace", + "check-catch", + "check-else", + "check-whitespace" + ], + "quotemark": [ + true, + "single", + "avoid-escape" + ], + "radix": true, + "semicolon": true, + "switch-default": true, + "trailing-comma": [ + true, + { + "multiline": "never", + "singleline": "never" + } + ], + "triple-equals": [ + true, + "allow-null-check" + ], + "typedef": false, + "typedef-whitespace": [ + true, + { + "call-signature": "nospace", + "index-signature": "nospace", + "parameter": "nospace", + "property-declaration": "nospace", + "variable-declaration": "nospace" + } + ], + "use-strict": false, + "variable-name": [ + true, + "check-format", + "allow-leading-underscore", + "ban-keywords" + ], + "whitespace": [ + true, + "check-branch", + "check-operator", + "check-separator", + "check-type", + "check-module", + "check-decl" + ] + } +} diff --git a/ng2-components/ng2-alfresco-social/config/custom-loaders/file-loader-multi.js b/ng2-components/ng2-alfresco-social/config/custom-loaders/file-loader-multi.js new file mode 100644 index 0000000000..dfbf93e76e --- /dev/null +++ b/ng2-components/ng2-alfresco-social/config/custom-loaders/file-loader-multi.js @@ -0,0 +1,70 @@ +var path = require('path'); +var loaderUtils = require('loader-utils'); + +module.exports = function(content) { + this.cacheable && this.cacheable(); + if(!this.emitFile) throw new Error('emitFile is required from module system'); + + var query = loaderUtils.getOptions(this) || {}; + var configKey = query.config || 'multiFileLoader'; + var options = this.options[configKey] || {}; + var config = { + publicPath: false, + useRelativePath: false, + name: '[hash].[ext]' + }; + + // options takes precedence over config + Object.keys(options).forEach(function(attr) { + config[attr] = options[attr]; + }); + + // query takes precedence over config and options + Object.keys(query).forEach(function(attr) { + config[attr] = query[attr]; + }); + + var context = config.context || this.options.context; + var url = loaderUtils.interpolateName(this, config.name, { + context: context, + content: content, + regExp: config.regExp + }); + var path = loaderUtils.interpolateName(this, '[path]', { + context: context, + content: content, + regExp: config.regExp + }); + + var outputPath = ''; + + if (config.outputPath) { + outputPath = ( + typeof config.outputPath === 'function' + ? config.outputPath(url, path) + : config.outputPath + url + ); + } else { + outputPath = url; + } + + var publicPath = JSON.stringify(url); + + if (config.publicPath) { + publicPath = JSON.stringify( + typeof config.publicPath === 'function' + ? config.publicPath(url, path) + : config.publicPath + url + ); + } + + publicPath = '__webpack_public_path__ + ' + publicPath; + + if (query.emitFile === undefined || query.emitFile) { + this.emitFile(outputPath, content); + } + + return 'module.exports = ' + publicPath + ';'; +}; + +module.exports.raw = true; diff --git a/ng2-components/ng2-alfresco-social/config/custom-loaders/license-check.js b/ng2-components/ng2-alfresco-social/config/custom-loaders/license-check.js new file mode 100644 index 0000000000..6a15ac03e2 --- /dev/null +++ b/ng2-components/ng2-alfresco-social/config/custom-loaders/license-check.js @@ -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); +}; diff --git a/ng2-components/ng2-alfresco-social/config/helpers.js b/ng2-components/ng2-alfresco-social/config/helpers.js new file mode 100644 index 0000000000..a11fa771d6 --- /dev/null +++ b/ng2-components/ng2-alfresco-social/config/helpers.js @@ -0,0 +1,10 @@ +var path = require('path'); + +var _root = path.resolve(__dirname, '..'); + +function root(args) { + args = Array.prototype.slice.call(arguments, 0); + return path.join.apply(path, [_root].concat(args)); +} + +exports.root = root; diff --git a/ng2-components/ng2-alfresco-social/config/webpack.common.js b/ng2-components/ng2-alfresco-social/config/webpack.common.js new file mode 100644 index 0000000000..95cd33177e --- /dev/null +++ b/ng2-components/ng2-alfresco-social/config/webpack.common.js @@ -0,0 +1,124 @@ +const webpack = require('webpack'); +const helpers = require('./helpers'); +const fs = require('fs'); +const path = require('path'); + +module.exports = { + + resolveLoader: { + alias: { + "file-multi-loader": path.resolve(__dirname, "./custom-loaders/file-loader-multi"), + "license-check": path.resolve(__dirname, "./custom-loaders/license-check") + } + }, + + // require those dependencies but don't bundle them + externals: [ + /^\@angular\//, + /^rxjs\//, + 'moment', + 'raphael', + 'ng2-charts', + 'alfresco-js-api', + 'ng2-alfresco-core', + 'ng2-alfresco-datatable', + 'ng2-activiti-analytics', + 'ng2-activiti-diagrams', + 'ng2-activiti-form', + "ng2-activiti-tasklist", + 'ng2-alfresco-documentlist' + ], + + module: { + rules: [ + { + enforce: 'pre', + test: /\.js$/, + loader: 'source-map-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + enforce: 'pre', + test: /\.ts$/, + use: 'source-map-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + enforce: 'pre', + test: /\.ts$/, + loader: 'tslint-loader', + options: { + emitErrors: true, + configFile: path.resolve(__dirname, './assets/tslint.json') + }, + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.ts$/, + use: ['ts-loader', 'angular2-template-loader'], + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.html$/, + loader: 'html-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + 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)$/, + loader: 'file-multi-loader', + query: { + name: '[name].[hash].[ext]', + outputPath: (url, resourcePath)=> { + return resourcePath.replace('src', 'bundles') + url; + }, + publicPath: (url, resourcePath)=> { + var component = resourcePath.substring(0, resourcePath.indexOf('src')); + var path = resourcePath.replace(component, '').replace('src', 'bundles'); + return './' + path + url; + } + } + } + ] + }, + + resolve: { + extensions: ['.ts', '.js'], + symlinks: false, + modules: [ + '../ng2-components', 'node_modules' + ] + }, + + plugins: [ + new webpack.NoEmitOnErrorsPlugin(), + + new webpack.BannerPlugin(fs.readFileSync(path.resolve(__dirname, './assets/license_header_add.txt'), 'utf8')), + + new webpack.ContextReplacementPlugin( + /angular(\\|\/)core(\\|\/)@angular/, + helpers.root('./src'), + {} + ) + ], + + devtool: 'cheap-module-source-map', + + node: { + fs: 'empty', + module: false + } +}; diff --git a/ng2-components/ng2-alfresco-social/config/webpack.test.js b/ng2-components/ng2-alfresco-social/config/webpack.test.js new file mode 100644 index 0000000000..486fed8c15 --- /dev/null +++ b/ng2-components/ng2-alfresco-social/config/webpack.test.js @@ -0,0 +1,85 @@ +const webpack = require('webpack'); +const helpers = require('./helpers'); + +const ENV = process.env.NODE_ENV = process.env.ENV = 'production'; + +module.exports = { + + devtool: 'inline-source-map', + + resolve: { + extensions: ['.ts', '.js'], + symlinks: false, + modules: [helpers.root('../ng2-components'), helpers.root('node_modules')] + }, + + module: { + rules: [ + { + enforce: 'pre', + test: /\.js$/, + loader: 'source-map-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.ts$/, + loaders: ['ts-loader?' + JSON.stringify({ transpileOnly: true}), 'angular2-template-loader'], + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.html$/, + loader: 'html-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.css$/, + loader: ['to-string-loader', 'css-loader'], + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico|pdf)$/, + loader: 'file-loader', + query: { + name: '[path][name].[ext]', + outputPath: (url)=> { + return url.replace('src', 'dist'); + } + } + }, + { + enforce: 'post', + test: /\.ts$/, + loader: 'istanbul-instrumenter-loader', + exclude: [ + /node_modules/, + /test/ + ] + } + ] + }, + + plugins: [ + new webpack.NoEmitOnErrorsPlugin(), + + new webpack.ContextReplacementPlugin( + /angular(\\|\/)core(\\|\/)@angular/, + helpers.root('./src'), + {} + ), + new webpack.DefinePlugin({ + 'process.env': { + 'ENV': JSON.stringify(ENV) + } + }), + new webpack.LoaderOptionsPlugin({ + htmlLoader: { + minimize: false // workaround for ng2 + } + }) + ], + + node: { + fs: 'empty', + module: false + } +}; diff --git a/ng2-components/ng2-alfresco-social/karma.conf.js b/ng2-components/ng2-alfresco-social/karma.conf.js index f7f5ca66a2..9001db1c10 100644 --- a/ng2-components/ng2-alfresco-social/karma.conf.js +++ b/ng2-components/ng2-alfresco-social/karma.conf.js @@ -21,11 +21,6 @@ module.exports = function (config) { {pattern: './node_modules/md-date-time-picker/**/*.js', included: false, served: true, watched: false}, {pattern: './node_modules/moment/**/*.js', included: false, served: true, watched: false}, - // pdf-js - './node_modules/pdfjs-dist/build/pdf.js', - './node_modules/pdfjs-dist/build/pdf.worker.js', - './node_modules/pdfjs-dist/web/pdf_viewer.js', - {pattern: 'karma-test-shim.js', watched: false}, {pattern: './src/assets/**/*.*', included: false, served: true, watched: false}, {pattern: './src/i18n/**/*.*', included: false, served: true, watched: false}, diff --git a/ng2-components/ng2-alfresco-social/package.json b/ng2-components/ng2-alfresco-social/package.json index 9f82940c9e..304fc0b769 100644 --- a/ng2-components/ng2-alfresco-social/package.json +++ b/ng2-components/ng2-alfresco-social/package.json @@ -97,14 +97,5 @@ "rating", "alfresco-component" ], - "license-check-config": { - "src": [ - "./src/**/*.ts" - ], - "path": "assets/license_header.txt", - "blocking": true, - "logInfo": false, - "logError": true - }, "license": "Apache-2.0" } diff --git a/ng2-components/ng2-alfresco-social/webpack.build.js b/ng2-components/ng2-alfresco-social/webpack.build.js index 00156458bd..3eb2dc3493 100644 --- a/ng2-components/ng2-alfresco-social/webpack.build.js +++ b/ng2-components/ng2-alfresco-social/webpack.build.js @@ -1,6 +1,6 @@ -const webpack = require("webpack"); +const webpack = require('webpack'); const webpackMerge = require('webpack-merge'); -const commonConfig = require('../config/webpack.common.js'); +const commonConfig = require('./config/webpack.common.js'); module.exports = webpackMerge(commonConfig, { diff --git a/ng2-components/ng2-alfresco-social/webpack.test.js b/ng2-components/ng2-alfresco-social/webpack.test.js index 4a61a62939..b6f4929fa4 100644 --- a/ng2-components/ng2-alfresco-social/webpack.test.js +++ b/ng2-components/ng2-alfresco-social/webpack.test.js @@ -1,6 +1,6 @@ const webpack = require('webpack'); const webpackMerge = require('webpack-merge'); -const testConfig = require('../config/webpack.test.js'); +const testConfig = require('./config/webpack.test.js'); module.exports = webpackMerge(testConfig, { diff --git a/ng2-components/ng2-alfresco-tag/config/assets/license_header.txt b/ng2-components/ng2-alfresco-tag/config/assets/license_header.txt new file mode 100644 index 0000000000..58ad8b656b --- /dev/null +++ b/ng2-components/ng2-alfresco-tag/config/assets/license_header.txt @@ -0,0 +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. + */ diff --git a/ng2-components/ng2-alfresco-tag/config/assets/license_header_add.txt b/ng2-components/ng2-alfresco-tag/config/assets/license_header_add.txt new file mode 100644 index 0000000000..b38baa9716 --- /dev/null +++ b/ng2-components/ng2-alfresco-tag/config/assets/license_header_add.txt @@ -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. diff --git a/ng2-components/ng2-alfresco-tag/config/assets/tslint.json b/ng2-components/ng2-alfresco-tag/config/assets/tslint.json new file mode 100644 index 0000000000..611a015c7e --- /dev/null +++ b/ng2-components/ng2-alfresco-tag/config/assets/tslint.json @@ -0,0 +1,118 @@ +{ + "rules": { + "align": [ + true, + "parameters", + "statements" + ], + "ban": false, + "class-name": true, + "comment-format": [ + true, + "check-space" + ], + "curly": true, + "eofline": true, + "forin": true, + "indent": [ + true, + "spaces" + ], + "interface-name": false, + "jsdoc-format": true, + "label-position": true, + "max-line-length": [ + true, + 180 + ], + "member-ordering": [ + true, + "static-before-instance", + "variables-before-functions" + ], + "no-any": false, + "no-arg": true, + "no-bitwise": false, + "no-conditional-assignment": true, + "no-consecutive-blank-lines": true, + "no-console": [ + true, + "debug", + "info", + "time", + "timeEnd", + "trace" + ], + "no-construct": true, + "no-constructor-vars": false, + "no-debugger": true, + "no-duplicate-variable": true, + "no-empty": false, + "no-eval": true, + "no-inferrable-types": false, + "no-internal-module": true, + "no-require-imports": false, + "no-shadowed-variable": true, + "no-switch-case-fall-through": true, + "no-trailing-whitespace": true, + "no-unused-expression": true, + "no-unused-variable": true, + "no-use-before-declare": true, + "no-var-keyword": true, + "no-var-requires": true, + "object-literal-sort-keys": false, + "one-line": [ + true, + "check-open-brace", + "check-catch", + "check-else", + "check-whitespace" + ], + "quotemark": [ + true, + "single", + "avoid-escape" + ], + "radix": true, + "semicolon": true, + "switch-default": true, + "trailing-comma": [ + true, + { + "multiline": "never", + "singleline": "never" + } + ], + "triple-equals": [ + true, + "allow-null-check" + ], + "typedef": false, + "typedef-whitespace": [ + true, + { + "call-signature": "nospace", + "index-signature": "nospace", + "parameter": "nospace", + "property-declaration": "nospace", + "variable-declaration": "nospace" + } + ], + "use-strict": false, + "variable-name": [ + true, + "check-format", + "allow-leading-underscore", + "ban-keywords" + ], + "whitespace": [ + true, + "check-branch", + "check-operator", + "check-separator", + "check-type", + "check-module", + "check-decl" + ] + } +} diff --git a/ng2-components/ng2-alfresco-tag/config/custom-loaders/file-loader-multi.js b/ng2-components/ng2-alfresco-tag/config/custom-loaders/file-loader-multi.js new file mode 100644 index 0000000000..dfbf93e76e --- /dev/null +++ b/ng2-components/ng2-alfresco-tag/config/custom-loaders/file-loader-multi.js @@ -0,0 +1,70 @@ +var path = require('path'); +var loaderUtils = require('loader-utils'); + +module.exports = function(content) { + this.cacheable && this.cacheable(); + if(!this.emitFile) throw new Error('emitFile is required from module system'); + + var query = loaderUtils.getOptions(this) || {}; + var configKey = query.config || 'multiFileLoader'; + var options = this.options[configKey] || {}; + var config = { + publicPath: false, + useRelativePath: false, + name: '[hash].[ext]' + }; + + // options takes precedence over config + Object.keys(options).forEach(function(attr) { + config[attr] = options[attr]; + }); + + // query takes precedence over config and options + Object.keys(query).forEach(function(attr) { + config[attr] = query[attr]; + }); + + var context = config.context || this.options.context; + var url = loaderUtils.interpolateName(this, config.name, { + context: context, + content: content, + regExp: config.regExp + }); + var path = loaderUtils.interpolateName(this, '[path]', { + context: context, + content: content, + regExp: config.regExp + }); + + var outputPath = ''; + + if (config.outputPath) { + outputPath = ( + typeof config.outputPath === 'function' + ? config.outputPath(url, path) + : config.outputPath + url + ); + } else { + outputPath = url; + } + + var publicPath = JSON.stringify(url); + + if (config.publicPath) { + publicPath = JSON.stringify( + typeof config.publicPath === 'function' + ? config.publicPath(url, path) + : config.publicPath + url + ); + } + + publicPath = '__webpack_public_path__ + ' + publicPath; + + if (query.emitFile === undefined || query.emitFile) { + this.emitFile(outputPath, content); + } + + return 'module.exports = ' + publicPath + ';'; +}; + +module.exports.raw = true; diff --git a/ng2-components/ng2-alfresco-tag/config/custom-loaders/license-check.js b/ng2-components/ng2-alfresco-tag/config/custom-loaders/license-check.js new file mode 100644 index 0000000000..6a15ac03e2 --- /dev/null +++ b/ng2-components/ng2-alfresco-tag/config/custom-loaders/license-check.js @@ -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); +}; diff --git a/ng2-components/ng2-alfresco-tag/config/helpers.js b/ng2-components/ng2-alfresco-tag/config/helpers.js new file mode 100644 index 0000000000..a11fa771d6 --- /dev/null +++ b/ng2-components/ng2-alfresco-tag/config/helpers.js @@ -0,0 +1,10 @@ +var path = require('path'); + +var _root = path.resolve(__dirname, '..'); + +function root(args) { + args = Array.prototype.slice.call(arguments, 0); + return path.join.apply(path, [_root].concat(args)); +} + +exports.root = root; diff --git a/ng2-components/ng2-alfresco-tag/config/webpack.common.js b/ng2-components/ng2-alfresco-tag/config/webpack.common.js new file mode 100644 index 0000000000..95cd33177e --- /dev/null +++ b/ng2-components/ng2-alfresco-tag/config/webpack.common.js @@ -0,0 +1,124 @@ +const webpack = require('webpack'); +const helpers = require('./helpers'); +const fs = require('fs'); +const path = require('path'); + +module.exports = { + + resolveLoader: { + alias: { + "file-multi-loader": path.resolve(__dirname, "./custom-loaders/file-loader-multi"), + "license-check": path.resolve(__dirname, "./custom-loaders/license-check") + } + }, + + // require those dependencies but don't bundle them + externals: [ + /^\@angular\//, + /^rxjs\//, + 'moment', + 'raphael', + 'ng2-charts', + 'alfresco-js-api', + 'ng2-alfresco-core', + 'ng2-alfresco-datatable', + 'ng2-activiti-analytics', + 'ng2-activiti-diagrams', + 'ng2-activiti-form', + "ng2-activiti-tasklist", + 'ng2-alfresco-documentlist' + ], + + module: { + rules: [ + { + enforce: 'pre', + test: /\.js$/, + loader: 'source-map-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + enforce: 'pre', + test: /\.ts$/, + use: 'source-map-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + enforce: 'pre', + test: /\.ts$/, + loader: 'tslint-loader', + options: { + emitErrors: true, + configFile: path.resolve(__dirname, './assets/tslint.json') + }, + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.ts$/, + use: ['ts-loader', 'angular2-template-loader'], + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.html$/, + loader: 'html-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + 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)$/, + loader: 'file-multi-loader', + query: { + name: '[name].[hash].[ext]', + outputPath: (url, resourcePath)=> { + return resourcePath.replace('src', 'bundles') + url; + }, + publicPath: (url, resourcePath)=> { + var component = resourcePath.substring(0, resourcePath.indexOf('src')); + var path = resourcePath.replace(component, '').replace('src', 'bundles'); + return './' + path + url; + } + } + } + ] + }, + + resolve: { + extensions: ['.ts', '.js'], + symlinks: false, + modules: [ + '../ng2-components', 'node_modules' + ] + }, + + plugins: [ + new webpack.NoEmitOnErrorsPlugin(), + + new webpack.BannerPlugin(fs.readFileSync(path.resolve(__dirname, './assets/license_header_add.txt'), 'utf8')), + + new webpack.ContextReplacementPlugin( + /angular(\\|\/)core(\\|\/)@angular/, + helpers.root('./src'), + {} + ) + ], + + devtool: 'cheap-module-source-map', + + node: { + fs: 'empty', + module: false + } +}; diff --git a/ng2-components/ng2-alfresco-tag/config/webpack.test.js b/ng2-components/ng2-alfresco-tag/config/webpack.test.js new file mode 100644 index 0000000000..486fed8c15 --- /dev/null +++ b/ng2-components/ng2-alfresco-tag/config/webpack.test.js @@ -0,0 +1,85 @@ +const webpack = require('webpack'); +const helpers = require('./helpers'); + +const ENV = process.env.NODE_ENV = process.env.ENV = 'production'; + +module.exports = { + + devtool: 'inline-source-map', + + resolve: { + extensions: ['.ts', '.js'], + symlinks: false, + modules: [helpers.root('../ng2-components'), helpers.root('node_modules')] + }, + + module: { + rules: [ + { + enforce: 'pre', + test: /\.js$/, + loader: 'source-map-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.ts$/, + loaders: ['ts-loader?' + JSON.stringify({ transpileOnly: true}), 'angular2-template-loader'], + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.html$/, + loader: 'html-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.css$/, + loader: ['to-string-loader', 'css-loader'], + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico|pdf)$/, + loader: 'file-loader', + query: { + name: '[path][name].[ext]', + outputPath: (url)=> { + return url.replace('src', 'dist'); + } + } + }, + { + enforce: 'post', + test: /\.ts$/, + loader: 'istanbul-instrumenter-loader', + exclude: [ + /node_modules/, + /test/ + ] + } + ] + }, + + plugins: [ + new webpack.NoEmitOnErrorsPlugin(), + + new webpack.ContextReplacementPlugin( + /angular(\\|\/)core(\\|\/)@angular/, + helpers.root('./src'), + {} + ), + new webpack.DefinePlugin({ + 'process.env': { + 'ENV': JSON.stringify(ENV) + } + }), + new webpack.LoaderOptionsPlugin({ + htmlLoader: { + minimize: false // workaround for ng2 + } + }) + ], + + node: { + fs: 'empty', + module: false + } +}; diff --git a/ng2-components/ng2-alfresco-tag/karma.conf.js b/ng2-components/ng2-alfresco-tag/karma.conf.js index f7f5ca66a2..9001db1c10 100644 --- a/ng2-components/ng2-alfresco-tag/karma.conf.js +++ b/ng2-components/ng2-alfresco-tag/karma.conf.js @@ -21,11 +21,6 @@ module.exports = function (config) { {pattern: './node_modules/md-date-time-picker/**/*.js', included: false, served: true, watched: false}, {pattern: './node_modules/moment/**/*.js', included: false, served: true, watched: false}, - // pdf-js - './node_modules/pdfjs-dist/build/pdf.js', - './node_modules/pdfjs-dist/build/pdf.worker.js', - './node_modules/pdfjs-dist/web/pdf_viewer.js', - {pattern: 'karma-test-shim.js', watched: false}, {pattern: './src/assets/**/*.*', included: false, served: true, watched: false}, {pattern: './src/i18n/**/*.*', included: false, served: true, watched: false}, diff --git a/ng2-components/ng2-alfresco-tag/package.json b/ng2-components/ng2-alfresco-tag/package.json index 6fc86fe6d0..8170c978eb 100644 --- a/ng2-components/ng2-alfresco-tag/package.json +++ b/ng2-components/ng2-alfresco-tag/package.json @@ -97,14 +97,5 @@ "tag", "alfresco-component" ], - "license-check-config": { - "src": [ - "./src/**/*.ts" - ], - "path": "assets/license_header.txt", - "blocking": true, - "logInfo": false, - "logError": true - }, "license": "Apache-2.0" } diff --git a/ng2-components/ng2-alfresco-tag/webpack.build.js b/ng2-components/ng2-alfresco-tag/webpack.build.js index ddfc811cff..7ad7de3b43 100644 --- a/ng2-components/ng2-alfresco-tag/webpack.build.js +++ b/ng2-components/ng2-alfresco-tag/webpack.build.js @@ -1,6 +1,6 @@ -const webpack = require("webpack"); +const webpack = require('webpack'); const webpackMerge = require('webpack-merge'); -const commonConfig = require('../config/webpack.common.js'); +const commonConfig = require('./config/webpack.common.js'); module.exports = webpackMerge(commonConfig, { diff --git a/ng2-components/ng2-alfresco-tag/webpack.test.js b/ng2-components/ng2-alfresco-tag/webpack.test.js index 4a61a62939..b6f4929fa4 100644 --- a/ng2-components/ng2-alfresco-tag/webpack.test.js +++ b/ng2-components/ng2-alfresco-tag/webpack.test.js @@ -1,6 +1,6 @@ const webpack = require('webpack'); const webpackMerge = require('webpack-merge'); -const testConfig = require('../config/webpack.test.js'); +const testConfig = require('./config/webpack.test.js'); module.exports = webpackMerge(testConfig, { diff --git a/ng2-components/ng2-alfresco-upload/config/assets/license_header.txt b/ng2-components/ng2-alfresco-upload/config/assets/license_header.txt new file mode 100644 index 0000000000..58ad8b656b --- /dev/null +++ b/ng2-components/ng2-alfresco-upload/config/assets/license_header.txt @@ -0,0 +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. + */ diff --git a/ng2-components/ng2-alfresco-upload/config/assets/license_header_add.txt b/ng2-components/ng2-alfresco-upload/config/assets/license_header_add.txt new file mode 100644 index 0000000000..b38baa9716 --- /dev/null +++ b/ng2-components/ng2-alfresco-upload/config/assets/license_header_add.txt @@ -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. diff --git a/ng2-components/ng2-alfresco-upload/config/assets/tslint.json b/ng2-components/ng2-alfresco-upload/config/assets/tslint.json new file mode 100644 index 0000000000..611a015c7e --- /dev/null +++ b/ng2-components/ng2-alfresco-upload/config/assets/tslint.json @@ -0,0 +1,118 @@ +{ + "rules": { + "align": [ + true, + "parameters", + "statements" + ], + "ban": false, + "class-name": true, + "comment-format": [ + true, + "check-space" + ], + "curly": true, + "eofline": true, + "forin": true, + "indent": [ + true, + "spaces" + ], + "interface-name": false, + "jsdoc-format": true, + "label-position": true, + "max-line-length": [ + true, + 180 + ], + "member-ordering": [ + true, + "static-before-instance", + "variables-before-functions" + ], + "no-any": false, + "no-arg": true, + "no-bitwise": false, + "no-conditional-assignment": true, + "no-consecutive-blank-lines": true, + "no-console": [ + true, + "debug", + "info", + "time", + "timeEnd", + "trace" + ], + "no-construct": true, + "no-constructor-vars": false, + "no-debugger": true, + "no-duplicate-variable": true, + "no-empty": false, + "no-eval": true, + "no-inferrable-types": false, + "no-internal-module": true, + "no-require-imports": false, + "no-shadowed-variable": true, + "no-switch-case-fall-through": true, + "no-trailing-whitespace": true, + "no-unused-expression": true, + "no-unused-variable": true, + "no-use-before-declare": true, + "no-var-keyword": true, + "no-var-requires": true, + "object-literal-sort-keys": false, + "one-line": [ + true, + "check-open-brace", + "check-catch", + "check-else", + "check-whitespace" + ], + "quotemark": [ + true, + "single", + "avoid-escape" + ], + "radix": true, + "semicolon": true, + "switch-default": true, + "trailing-comma": [ + true, + { + "multiline": "never", + "singleline": "never" + } + ], + "triple-equals": [ + true, + "allow-null-check" + ], + "typedef": false, + "typedef-whitespace": [ + true, + { + "call-signature": "nospace", + "index-signature": "nospace", + "parameter": "nospace", + "property-declaration": "nospace", + "variable-declaration": "nospace" + } + ], + "use-strict": false, + "variable-name": [ + true, + "check-format", + "allow-leading-underscore", + "ban-keywords" + ], + "whitespace": [ + true, + "check-branch", + "check-operator", + "check-separator", + "check-type", + "check-module", + "check-decl" + ] + } +} diff --git a/ng2-components/ng2-alfresco-upload/config/custom-loaders/file-loader-multi.js b/ng2-components/ng2-alfresco-upload/config/custom-loaders/file-loader-multi.js new file mode 100644 index 0000000000..dfbf93e76e --- /dev/null +++ b/ng2-components/ng2-alfresco-upload/config/custom-loaders/file-loader-multi.js @@ -0,0 +1,70 @@ +var path = require('path'); +var loaderUtils = require('loader-utils'); + +module.exports = function(content) { + this.cacheable && this.cacheable(); + if(!this.emitFile) throw new Error('emitFile is required from module system'); + + var query = loaderUtils.getOptions(this) || {}; + var configKey = query.config || 'multiFileLoader'; + var options = this.options[configKey] || {}; + var config = { + publicPath: false, + useRelativePath: false, + name: '[hash].[ext]' + }; + + // options takes precedence over config + Object.keys(options).forEach(function(attr) { + config[attr] = options[attr]; + }); + + // query takes precedence over config and options + Object.keys(query).forEach(function(attr) { + config[attr] = query[attr]; + }); + + var context = config.context || this.options.context; + var url = loaderUtils.interpolateName(this, config.name, { + context: context, + content: content, + regExp: config.regExp + }); + var path = loaderUtils.interpolateName(this, '[path]', { + context: context, + content: content, + regExp: config.regExp + }); + + var outputPath = ''; + + if (config.outputPath) { + outputPath = ( + typeof config.outputPath === 'function' + ? config.outputPath(url, path) + : config.outputPath + url + ); + } else { + outputPath = url; + } + + var publicPath = JSON.stringify(url); + + if (config.publicPath) { + publicPath = JSON.stringify( + typeof config.publicPath === 'function' + ? config.publicPath(url, path) + : config.publicPath + url + ); + } + + publicPath = '__webpack_public_path__ + ' + publicPath; + + if (query.emitFile === undefined || query.emitFile) { + this.emitFile(outputPath, content); + } + + return 'module.exports = ' + publicPath + ';'; +}; + +module.exports.raw = true; diff --git a/ng2-components/ng2-alfresco-upload/config/custom-loaders/license-check.js b/ng2-components/ng2-alfresco-upload/config/custom-loaders/license-check.js new file mode 100644 index 0000000000..6a15ac03e2 --- /dev/null +++ b/ng2-components/ng2-alfresco-upload/config/custom-loaders/license-check.js @@ -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); +}; diff --git a/ng2-components/ng2-alfresco-upload/config/helpers.js b/ng2-components/ng2-alfresco-upload/config/helpers.js new file mode 100644 index 0000000000..a11fa771d6 --- /dev/null +++ b/ng2-components/ng2-alfresco-upload/config/helpers.js @@ -0,0 +1,10 @@ +var path = require('path'); + +var _root = path.resolve(__dirname, '..'); + +function root(args) { + args = Array.prototype.slice.call(arguments, 0); + return path.join.apply(path, [_root].concat(args)); +} + +exports.root = root; diff --git a/ng2-components/ng2-alfresco-upload/config/webpack.common.js b/ng2-components/ng2-alfresco-upload/config/webpack.common.js new file mode 100644 index 0000000000..95cd33177e --- /dev/null +++ b/ng2-components/ng2-alfresco-upload/config/webpack.common.js @@ -0,0 +1,124 @@ +const webpack = require('webpack'); +const helpers = require('./helpers'); +const fs = require('fs'); +const path = require('path'); + +module.exports = { + + resolveLoader: { + alias: { + "file-multi-loader": path.resolve(__dirname, "./custom-loaders/file-loader-multi"), + "license-check": path.resolve(__dirname, "./custom-loaders/license-check") + } + }, + + // require those dependencies but don't bundle them + externals: [ + /^\@angular\//, + /^rxjs\//, + 'moment', + 'raphael', + 'ng2-charts', + 'alfresco-js-api', + 'ng2-alfresco-core', + 'ng2-alfresco-datatable', + 'ng2-activiti-analytics', + 'ng2-activiti-diagrams', + 'ng2-activiti-form', + "ng2-activiti-tasklist", + 'ng2-alfresco-documentlist' + ], + + module: { + rules: [ + { + enforce: 'pre', + test: /\.js$/, + loader: 'source-map-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + enforce: 'pre', + test: /\.ts$/, + use: 'source-map-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + enforce: 'pre', + test: /\.ts$/, + loader: 'tslint-loader', + options: { + emitErrors: true, + configFile: path.resolve(__dirname, './assets/tslint.json') + }, + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.ts$/, + use: ['ts-loader', 'angular2-template-loader'], + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.html$/, + loader: 'html-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + 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)$/, + loader: 'file-multi-loader', + query: { + name: '[name].[hash].[ext]', + outputPath: (url, resourcePath)=> { + return resourcePath.replace('src', 'bundles') + url; + }, + publicPath: (url, resourcePath)=> { + var component = resourcePath.substring(0, resourcePath.indexOf('src')); + var path = resourcePath.replace(component, '').replace('src', 'bundles'); + return './' + path + url; + } + } + } + ] + }, + + resolve: { + extensions: ['.ts', '.js'], + symlinks: false, + modules: [ + '../ng2-components', 'node_modules' + ] + }, + + plugins: [ + new webpack.NoEmitOnErrorsPlugin(), + + new webpack.BannerPlugin(fs.readFileSync(path.resolve(__dirname, './assets/license_header_add.txt'), 'utf8')), + + new webpack.ContextReplacementPlugin( + /angular(\\|\/)core(\\|\/)@angular/, + helpers.root('./src'), + {} + ) + ], + + devtool: 'cheap-module-source-map', + + node: { + fs: 'empty', + module: false + } +}; diff --git a/ng2-components/ng2-alfresco-upload/config/webpack.test.js b/ng2-components/ng2-alfresco-upload/config/webpack.test.js new file mode 100644 index 0000000000..486fed8c15 --- /dev/null +++ b/ng2-components/ng2-alfresco-upload/config/webpack.test.js @@ -0,0 +1,85 @@ +const webpack = require('webpack'); +const helpers = require('./helpers'); + +const ENV = process.env.NODE_ENV = process.env.ENV = 'production'; + +module.exports = { + + devtool: 'inline-source-map', + + resolve: { + extensions: ['.ts', '.js'], + symlinks: false, + modules: [helpers.root('../ng2-components'), helpers.root('node_modules')] + }, + + module: { + rules: [ + { + enforce: 'pre', + test: /\.js$/, + loader: 'source-map-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.ts$/, + loaders: ['ts-loader?' + JSON.stringify({ transpileOnly: true}), 'angular2-template-loader'], + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.html$/, + loader: 'html-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.css$/, + loader: ['to-string-loader', 'css-loader'], + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico|pdf)$/, + loader: 'file-loader', + query: { + name: '[path][name].[ext]', + outputPath: (url)=> { + return url.replace('src', 'dist'); + } + } + }, + { + enforce: 'post', + test: /\.ts$/, + loader: 'istanbul-instrumenter-loader', + exclude: [ + /node_modules/, + /test/ + ] + } + ] + }, + + plugins: [ + new webpack.NoEmitOnErrorsPlugin(), + + new webpack.ContextReplacementPlugin( + /angular(\\|\/)core(\\|\/)@angular/, + helpers.root('./src'), + {} + ), + new webpack.DefinePlugin({ + 'process.env': { + 'ENV': JSON.stringify(ENV) + } + }), + new webpack.LoaderOptionsPlugin({ + htmlLoader: { + minimize: false // workaround for ng2 + } + }) + ], + + node: { + fs: 'empty', + module: false + } +}; diff --git a/ng2-components/ng2-alfresco-upload/karma.conf.js b/ng2-components/ng2-alfresco-upload/karma.conf.js index f7f5ca66a2..9001db1c10 100644 --- a/ng2-components/ng2-alfresco-upload/karma.conf.js +++ b/ng2-components/ng2-alfresco-upload/karma.conf.js @@ -21,11 +21,6 @@ module.exports = function (config) { {pattern: './node_modules/md-date-time-picker/**/*.js', included: false, served: true, watched: false}, {pattern: './node_modules/moment/**/*.js', included: false, served: true, watched: false}, - // pdf-js - './node_modules/pdfjs-dist/build/pdf.js', - './node_modules/pdfjs-dist/build/pdf.worker.js', - './node_modules/pdfjs-dist/web/pdf_viewer.js', - {pattern: 'karma-test-shim.js', watched: false}, {pattern: './src/assets/**/*.*', included: false, served: true, watched: false}, {pattern: './src/i18n/**/*.*', included: false, served: true, watched: false}, diff --git a/ng2-components/ng2-alfresco-upload/package.json b/ng2-components/ng2-alfresco-upload/package.json index 6f0742b867..0d65c5f890 100644 --- a/ng2-components/ng2-alfresco-upload/package.json +++ b/ng2-components/ng2-alfresco-upload/package.json @@ -20,7 +20,6 @@ "bugs": { "url": "https://github.com/Alfresco/alfresco-ng2-components/issues" }, - "license": "Apache-2.0", "contributors": [ { "name": "Mario Romano", @@ -115,13 +114,5 @@ "webpack-merge": "2.6.1", "wsrv": "^0.1.7" }, - "license-check-config": { - "src": [ - "./src/**/*.ts" - ], - "path": "assets/license_header.txt", - "blocking": true, - "logInfo": false, - "logError": true - } + "license": "Apache-2.0" } diff --git a/ng2-components/ng2-alfresco-upload/webpack.build.js b/ng2-components/ng2-alfresco-upload/webpack.build.js index 61d28b4335..a15fb613b4 100644 --- a/ng2-components/ng2-alfresco-upload/webpack.build.js +++ b/ng2-components/ng2-alfresco-upload/webpack.build.js @@ -1,6 +1,6 @@ -const webpack = require("webpack"); +const webpack = require('webpack'); const webpackMerge = require('webpack-merge'); -const commonConfig = require('../config/webpack.common.js'); +const commonConfig = require('./config/webpack.common.js'); module.exports = webpackMerge(commonConfig, { diff --git a/ng2-components/ng2-alfresco-upload/webpack.test.js b/ng2-components/ng2-alfresco-upload/webpack.test.js index 4a61a62939..b6f4929fa4 100644 --- a/ng2-components/ng2-alfresco-upload/webpack.test.js +++ b/ng2-components/ng2-alfresco-upload/webpack.test.js @@ -1,6 +1,6 @@ const webpack = require('webpack'); const webpackMerge = require('webpack-merge'); -const testConfig = require('../config/webpack.test.js'); +const testConfig = require('./config/webpack.test.js'); module.exports = webpackMerge(testConfig, { diff --git a/ng2-components/ng2-alfresco-userinfo/config/assets/license_header.txt b/ng2-components/ng2-alfresco-userinfo/config/assets/license_header.txt new file mode 100644 index 0000000000..58ad8b656b --- /dev/null +++ b/ng2-components/ng2-alfresco-userinfo/config/assets/license_header.txt @@ -0,0 +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. + */ diff --git a/ng2-components/ng2-alfresco-userinfo/config/assets/license_header_add.txt b/ng2-components/ng2-alfresco-userinfo/config/assets/license_header_add.txt new file mode 100644 index 0000000000..b38baa9716 --- /dev/null +++ b/ng2-components/ng2-alfresco-userinfo/config/assets/license_header_add.txt @@ -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. diff --git a/ng2-components/ng2-alfresco-userinfo/config/assets/tslint.json b/ng2-components/ng2-alfresco-userinfo/config/assets/tslint.json new file mode 100644 index 0000000000..611a015c7e --- /dev/null +++ b/ng2-components/ng2-alfresco-userinfo/config/assets/tslint.json @@ -0,0 +1,118 @@ +{ + "rules": { + "align": [ + true, + "parameters", + "statements" + ], + "ban": false, + "class-name": true, + "comment-format": [ + true, + "check-space" + ], + "curly": true, + "eofline": true, + "forin": true, + "indent": [ + true, + "spaces" + ], + "interface-name": false, + "jsdoc-format": true, + "label-position": true, + "max-line-length": [ + true, + 180 + ], + "member-ordering": [ + true, + "static-before-instance", + "variables-before-functions" + ], + "no-any": false, + "no-arg": true, + "no-bitwise": false, + "no-conditional-assignment": true, + "no-consecutive-blank-lines": true, + "no-console": [ + true, + "debug", + "info", + "time", + "timeEnd", + "trace" + ], + "no-construct": true, + "no-constructor-vars": false, + "no-debugger": true, + "no-duplicate-variable": true, + "no-empty": false, + "no-eval": true, + "no-inferrable-types": false, + "no-internal-module": true, + "no-require-imports": false, + "no-shadowed-variable": true, + "no-switch-case-fall-through": true, + "no-trailing-whitespace": true, + "no-unused-expression": true, + "no-unused-variable": true, + "no-use-before-declare": true, + "no-var-keyword": true, + "no-var-requires": true, + "object-literal-sort-keys": false, + "one-line": [ + true, + "check-open-brace", + "check-catch", + "check-else", + "check-whitespace" + ], + "quotemark": [ + true, + "single", + "avoid-escape" + ], + "radix": true, + "semicolon": true, + "switch-default": true, + "trailing-comma": [ + true, + { + "multiline": "never", + "singleline": "never" + } + ], + "triple-equals": [ + true, + "allow-null-check" + ], + "typedef": false, + "typedef-whitespace": [ + true, + { + "call-signature": "nospace", + "index-signature": "nospace", + "parameter": "nospace", + "property-declaration": "nospace", + "variable-declaration": "nospace" + } + ], + "use-strict": false, + "variable-name": [ + true, + "check-format", + "allow-leading-underscore", + "ban-keywords" + ], + "whitespace": [ + true, + "check-branch", + "check-operator", + "check-separator", + "check-type", + "check-module", + "check-decl" + ] + } +} diff --git a/ng2-components/ng2-alfresco-userinfo/config/custom-loaders/file-loader-multi.js b/ng2-components/ng2-alfresco-userinfo/config/custom-loaders/file-loader-multi.js new file mode 100644 index 0000000000..dfbf93e76e --- /dev/null +++ b/ng2-components/ng2-alfresco-userinfo/config/custom-loaders/file-loader-multi.js @@ -0,0 +1,70 @@ +var path = require('path'); +var loaderUtils = require('loader-utils'); + +module.exports = function(content) { + this.cacheable && this.cacheable(); + if(!this.emitFile) throw new Error('emitFile is required from module system'); + + var query = loaderUtils.getOptions(this) || {}; + var configKey = query.config || 'multiFileLoader'; + var options = this.options[configKey] || {}; + var config = { + publicPath: false, + useRelativePath: false, + name: '[hash].[ext]' + }; + + // options takes precedence over config + Object.keys(options).forEach(function(attr) { + config[attr] = options[attr]; + }); + + // query takes precedence over config and options + Object.keys(query).forEach(function(attr) { + config[attr] = query[attr]; + }); + + var context = config.context || this.options.context; + var url = loaderUtils.interpolateName(this, config.name, { + context: context, + content: content, + regExp: config.regExp + }); + var path = loaderUtils.interpolateName(this, '[path]', { + context: context, + content: content, + regExp: config.regExp + }); + + var outputPath = ''; + + if (config.outputPath) { + outputPath = ( + typeof config.outputPath === 'function' + ? config.outputPath(url, path) + : config.outputPath + url + ); + } else { + outputPath = url; + } + + var publicPath = JSON.stringify(url); + + if (config.publicPath) { + publicPath = JSON.stringify( + typeof config.publicPath === 'function' + ? config.publicPath(url, path) + : config.publicPath + url + ); + } + + publicPath = '__webpack_public_path__ + ' + publicPath; + + if (query.emitFile === undefined || query.emitFile) { + this.emitFile(outputPath, content); + } + + return 'module.exports = ' + publicPath + ';'; +}; + +module.exports.raw = true; diff --git a/ng2-components/ng2-alfresco-userinfo/config/custom-loaders/license-check.js b/ng2-components/ng2-alfresco-userinfo/config/custom-loaders/license-check.js new file mode 100644 index 0000000000..6a15ac03e2 --- /dev/null +++ b/ng2-components/ng2-alfresco-userinfo/config/custom-loaders/license-check.js @@ -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); +}; diff --git a/ng2-components/ng2-alfresco-userinfo/config/helpers.js b/ng2-components/ng2-alfresco-userinfo/config/helpers.js new file mode 100644 index 0000000000..a11fa771d6 --- /dev/null +++ b/ng2-components/ng2-alfresco-userinfo/config/helpers.js @@ -0,0 +1,10 @@ +var path = require('path'); + +var _root = path.resolve(__dirname, '..'); + +function root(args) { + args = Array.prototype.slice.call(arguments, 0); + return path.join.apply(path, [_root].concat(args)); +} + +exports.root = root; diff --git a/ng2-components/ng2-alfresco-userinfo/config/webpack.common.js b/ng2-components/ng2-alfresco-userinfo/config/webpack.common.js new file mode 100644 index 0000000000..95cd33177e --- /dev/null +++ b/ng2-components/ng2-alfresco-userinfo/config/webpack.common.js @@ -0,0 +1,124 @@ +const webpack = require('webpack'); +const helpers = require('./helpers'); +const fs = require('fs'); +const path = require('path'); + +module.exports = { + + resolveLoader: { + alias: { + "file-multi-loader": path.resolve(__dirname, "./custom-loaders/file-loader-multi"), + "license-check": path.resolve(__dirname, "./custom-loaders/license-check") + } + }, + + // require those dependencies but don't bundle them + externals: [ + /^\@angular\//, + /^rxjs\//, + 'moment', + 'raphael', + 'ng2-charts', + 'alfresco-js-api', + 'ng2-alfresco-core', + 'ng2-alfresco-datatable', + 'ng2-activiti-analytics', + 'ng2-activiti-diagrams', + 'ng2-activiti-form', + "ng2-activiti-tasklist", + 'ng2-alfresco-documentlist' + ], + + module: { + rules: [ + { + enforce: 'pre', + test: /\.js$/, + loader: 'source-map-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + enforce: 'pre', + test: /\.ts$/, + use: 'source-map-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + enforce: 'pre', + test: /\.ts$/, + loader: 'tslint-loader', + options: { + emitErrors: true, + configFile: path.resolve(__dirname, './assets/tslint.json') + }, + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.ts$/, + use: ['ts-loader', 'angular2-template-loader'], + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.html$/, + loader: 'html-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + 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)$/, + loader: 'file-multi-loader', + query: { + name: '[name].[hash].[ext]', + outputPath: (url, resourcePath)=> { + return resourcePath.replace('src', 'bundles') + url; + }, + publicPath: (url, resourcePath)=> { + var component = resourcePath.substring(0, resourcePath.indexOf('src')); + var path = resourcePath.replace(component, '').replace('src', 'bundles'); + return './' + path + url; + } + } + } + ] + }, + + resolve: { + extensions: ['.ts', '.js'], + symlinks: false, + modules: [ + '../ng2-components', 'node_modules' + ] + }, + + plugins: [ + new webpack.NoEmitOnErrorsPlugin(), + + new webpack.BannerPlugin(fs.readFileSync(path.resolve(__dirname, './assets/license_header_add.txt'), 'utf8')), + + new webpack.ContextReplacementPlugin( + /angular(\\|\/)core(\\|\/)@angular/, + helpers.root('./src'), + {} + ) + ], + + devtool: 'cheap-module-source-map', + + node: { + fs: 'empty', + module: false + } +}; diff --git a/ng2-components/ng2-alfresco-userinfo/config/webpack.test.js b/ng2-components/ng2-alfresco-userinfo/config/webpack.test.js new file mode 100644 index 0000000000..486fed8c15 --- /dev/null +++ b/ng2-components/ng2-alfresco-userinfo/config/webpack.test.js @@ -0,0 +1,85 @@ +const webpack = require('webpack'); +const helpers = require('./helpers'); + +const ENV = process.env.NODE_ENV = process.env.ENV = 'production'; + +module.exports = { + + devtool: 'inline-source-map', + + resolve: { + extensions: ['.ts', '.js'], + symlinks: false, + modules: [helpers.root('../ng2-components'), helpers.root('node_modules')] + }, + + module: { + rules: [ + { + enforce: 'pre', + test: /\.js$/, + loader: 'source-map-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.ts$/, + loaders: ['ts-loader?' + JSON.stringify({ transpileOnly: true}), 'angular2-template-loader'], + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.html$/, + loader: 'html-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.css$/, + loader: ['to-string-loader', 'css-loader'], + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico|pdf)$/, + loader: 'file-loader', + query: { + name: '[path][name].[ext]', + outputPath: (url)=> { + return url.replace('src', 'dist'); + } + } + }, + { + enforce: 'post', + test: /\.ts$/, + loader: 'istanbul-instrumenter-loader', + exclude: [ + /node_modules/, + /test/ + ] + } + ] + }, + + plugins: [ + new webpack.NoEmitOnErrorsPlugin(), + + new webpack.ContextReplacementPlugin( + /angular(\\|\/)core(\\|\/)@angular/, + helpers.root('./src'), + {} + ), + new webpack.DefinePlugin({ + 'process.env': { + 'ENV': JSON.stringify(ENV) + } + }), + new webpack.LoaderOptionsPlugin({ + htmlLoader: { + minimize: false // workaround for ng2 + } + }) + ], + + node: { + fs: 'empty', + module: false + } +}; diff --git a/ng2-components/ng2-alfresco-userinfo/karma.conf.js b/ng2-components/ng2-alfresco-userinfo/karma.conf.js index f7f5ca66a2..9001db1c10 100644 --- a/ng2-components/ng2-alfresco-userinfo/karma.conf.js +++ b/ng2-components/ng2-alfresco-userinfo/karma.conf.js @@ -21,11 +21,6 @@ module.exports = function (config) { {pattern: './node_modules/md-date-time-picker/**/*.js', included: false, served: true, watched: false}, {pattern: './node_modules/moment/**/*.js', included: false, served: true, watched: false}, - // pdf-js - './node_modules/pdfjs-dist/build/pdf.js', - './node_modules/pdfjs-dist/build/pdf.worker.js', - './node_modules/pdfjs-dist/web/pdf_viewer.js', - {pattern: 'karma-test-shim.js', watched: false}, {pattern: './src/assets/**/*.*', included: false, served: true, watched: false}, {pattern: './src/i18n/**/*.*', included: false, served: true, watched: false}, diff --git a/ng2-components/ng2-alfresco-userinfo/package.json b/ng2-components/ng2-alfresco-userinfo/package.json index 9842b41455..1cad39a289 100644 --- a/ng2-components/ng2-alfresco-userinfo/package.json +++ b/ng2-components/ng2-alfresco-userinfo/package.json @@ -97,14 +97,5 @@ "userinfo", "alfresco-component" ], - "license-check-config": { - "src": [ - "./src/**/*.ts" - ], - "path": "assets/license_header.txt", - "blocking": true, - "logInfo": false, - "logError": true - }, "license": "Apache-2.0" } diff --git a/ng2-components/ng2-alfresco-userinfo/webpack.build.js b/ng2-components/ng2-alfresco-userinfo/webpack.build.js index c22fd50cd9..5fef48387d 100644 --- a/ng2-components/ng2-alfresco-userinfo/webpack.build.js +++ b/ng2-components/ng2-alfresco-userinfo/webpack.build.js @@ -1,6 +1,6 @@ -const webpack = require("webpack"); +const webpack = require('webpack'); const webpackMerge = require('webpack-merge'); -const commonConfig = require('../config/webpack.common.js'); +const commonConfig = require('./config/webpack.common.js'); module.exports = webpackMerge(commonConfig, { diff --git a/ng2-components/ng2-alfresco-userinfo/webpack.test.js b/ng2-components/ng2-alfresco-userinfo/webpack.test.js index 4a61a62939..b6f4929fa4 100644 --- a/ng2-components/ng2-alfresco-userinfo/webpack.test.js +++ b/ng2-components/ng2-alfresco-userinfo/webpack.test.js @@ -1,6 +1,6 @@ const webpack = require('webpack'); const webpackMerge = require('webpack-merge'); -const testConfig = require('../config/webpack.test.js'); +const testConfig = require('./config/webpack.test.js'); module.exports = webpackMerge(testConfig, { diff --git a/ng2-components/ng2-alfresco-viewer/config/assets/license_header.txt b/ng2-components/ng2-alfresco-viewer/config/assets/license_header.txt new file mode 100644 index 0000000000..58ad8b656b --- /dev/null +++ b/ng2-components/ng2-alfresco-viewer/config/assets/license_header.txt @@ -0,0 +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. + */ diff --git a/ng2-components/ng2-alfresco-viewer/config/assets/license_header_add.txt b/ng2-components/ng2-alfresco-viewer/config/assets/license_header_add.txt new file mode 100644 index 0000000000..b38baa9716 --- /dev/null +++ b/ng2-components/ng2-alfresco-viewer/config/assets/license_header_add.txt @@ -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. diff --git a/ng2-components/ng2-alfresco-viewer/config/assets/tslint.json b/ng2-components/ng2-alfresco-viewer/config/assets/tslint.json new file mode 100644 index 0000000000..611a015c7e --- /dev/null +++ b/ng2-components/ng2-alfresco-viewer/config/assets/tslint.json @@ -0,0 +1,118 @@ +{ + "rules": { + "align": [ + true, + "parameters", + "statements" + ], + "ban": false, + "class-name": true, + "comment-format": [ + true, + "check-space" + ], + "curly": true, + "eofline": true, + "forin": true, + "indent": [ + true, + "spaces" + ], + "interface-name": false, + "jsdoc-format": true, + "label-position": true, + "max-line-length": [ + true, + 180 + ], + "member-ordering": [ + true, + "static-before-instance", + "variables-before-functions" + ], + "no-any": false, + "no-arg": true, + "no-bitwise": false, + "no-conditional-assignment": true, + "no-consecutive-blank-lines": true, + "no-console": [ + true, + "debug", + "info", + "time", + "timeEnd", + "trace" + ], + "no-construct": true, + "no-constructor-vars": false, + "no-debugger": true, + "no-duplicate-variable": true, + "no-empty": false, + "no-eval": true, + "no-inferrable-types": false, + "no-internal-module": true, + "no-require-imports": false, + "no-shadowed-variable": true, + "no-switch-case-fall-through": true, + "no-trailing-whitespace": true, + "no-unused-expression": true, + "no-unused-variable": true, + "no-use-before-declare": true, + "no-var-keyword": true, + "no-var-requires": true, + "object-literal-sort-keys": false, + "one-line": [ + true, + "check-open-brace", + "check-catch", + "check-else", + "check-whitespace" + ], + "quotemark": [ + true, + "single", + "avoid-escape" + ], + "radix": true, + "semicolon": true, + "switch-default": true, + "trailing-comma": [ + true, + { + "multiline": "never", + "singleline": "never" + } + ], + "triple-equals": [ + true, + "allow-null-check" + ], + "typedef": false, + "typedef-whitespace": [ + true, + { + "call-signature": "nospace", + "index-signature": "nospace", + "parameter": "nospace", + "property-declaration": "nospace", + "variable-declaration": "nospace" + } + ], + "use-strict": false, + "variable-name": [ + true, + "check-format", + "allow-leading-underscore", + "ban-keywords" + ], + "whitespace": [ + true, + "check-branch", + "check-operator", + "check-separator", + "check-type", + "check-module", + "check-decl" + ] + } +} diff --git a/ng2-components/ng2-alfresco-viewer/config/custom-loaders/file-loader-multi.js b/ng2-components/ng2-alfresco-viewer/config/custom-loaders/file-loader-multi.js new file mode 100644 index 0000000000..dfbf93e76e --- /dev/null +++ b/ng2-components/ng2-alfresco-viewer/config/custom-loaders/file-loader-multi.js @@ -0,0 +1,70 @@ +var path = require('path'); +var loaderUtils = require('loader-utils'); + +module.exports = function(content) { + this.cacheable && this.cacheable(); + if(!this.emitFile) throw new Error('emitFile is required from module system'); + + var query = loaderUtils.getOptions(this) || {}; + var configKey = query.config || 'multiFileLoader'; + var options = this.options[configKey] || {}; + var config = { + publicPath: false, + useRelativePath: false, + name: '[hash].[ext]' + }; + + // options takes precedence over config + Object.keys(options).forEach(function(attr) { + config[attr] = options[attr]; + }); + + // query takes precedence over config and options + Object.keys(query).forEach(function(attr) { + config[attr] = query[attr]; + }); + + var context = config.context || this.options.context; + var url = loaderUtils.interpolateName(this, config.name, { + context: context, + content: content, + regExp: config.regExp + }); + var path = loaderUtils.interpolateName(this, '[path]', { + context: context, + content: content, + regExp: config.regExp + }); + + var outputPath = ''; + + if (config.outputPath) { + outputPath = ( + typeof config.outputPath === 'function' + ? config.outputPath(url, path) + : config.outputPath + url + ); + } else { + outputPath = url; + } + + var publicPath = JSON.stringify(url); + + if (config.publicPath) { + publicPath = JSON.stringify( + typeof config.publicPath === 'function' + ? config.publicPath(url, path) + : config.publicPath + url + ); + } + + publicPath = '__webpack_public_path__ + ' + publicPath; + + if (query.emitFile === undefined || query.emitFile) { + this.emitFile(outputPath, content); + } + + return 'module.exports = ' + publicPath + ';'; +}; + +module.exports.raw = true; diff --git a/ng2-components/ng2-alfresco-viewer/config/custom-loaders/license-check.js b/ng2-components/ng2-alfresco-viewer/config/custom-loaders/license-check.js new file mode 100644 index 0000000000..6a15ac03e2 --- /dev/null +++ b/ng2-components/ng2-alfresco-viewer/config/custom-loaders/license-check.js @@ -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); +}; diff --git a/ng2-components/ng2-alfresco-viewer/config/helpers.js b/ng2-components/ng2-alfresco-viewer/config/helpers.js new file mode 100644 index 0000000000..a11fa771d6 --- /dev/null +++ b/ng2-components/ng2-alfresco-viewer/config/helpers.js @@ -0,0 +1,10 @@ +var path = require('path'); + +var _root = path.resolve(__dirname, '..'); + +function root(args) { + args = Array.prototype.slice.call(arguments, 0); + return path.join.apply(path, [_root].concat(args)); +} + +exports.root = root; diff --git a/ng2-components/ng2-alfresco-viewer/config/webpack.common.js b/ng2-components/ng2-alfresco-viewer/config/webpack.common.js new file mode 100644 index 0000000000..95cd33177e --- /dev/null +++ b/ng2-components/ng2-alfresco-viewer/config/webpack.common.js @@ -0,0 +1,124 @@ +const webpack = require('webpack'); +const helpers = require('./helpers'); +const fs = require('fs'); +const path = require('path'); + +module.exports = { + + resolveLoader: { + alias: { + "file-multi-loader": path.resolve(__dirname, "./custom-loaders/file-loader-multi"), + "license-check": path.resolve(__dirname, "./custom-loaders/license-check") + } + }, + + // require those dependencies but don't bundle them + externals: [ + /^\@angular\//, + /^rxjs\//, + 'moment', + 'raphael', + 'ng2-charts', + 'alfresco-js-api', + 'ng2-alfresco-core', + 'ng2-alfresco-datatable', + 'ng2-activiti-analytics', + 'ng2-activiti-diagrams', + 'ng2-activiti-form', + "ng2-activiti-tasklist", + 'ng2-alfresco-documentlist' + ], + + module: { + rules: [ + { + enforce: 'pre', + test: /\.js$/, + loader: 'source-map-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + enforce: 'pre', + test: /\.ts$/, + use: 'source-map-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + enforce: 'pre', + test: /\.ts$/, + loader: 'tslint-loader', + options: { + emitErrors: true, + configFile: path.resolve(__dirname, './assets/tslint.json') + }, + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.ts$/, + use: ['ts-loader', 'angular2-template-loader'], + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.html$/, + loader: 'html-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + 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)$/, + loader: 'file-multi-loader', + query: { + name: '[name].[hash].[ext]', + outputPath: (url, resourcePath)=> { + return resourcePath.replace('src', 'bundles') + url; + }, + publicPath: (url, resourcePath)=> { + var component = resourcePath.substring(0, resourcePath.indexOf('src')); + var path = resourcePath.replace(component, '').replace('src', 'bundles'); + return './' + path + url; + } + } + } + ] + }, + + resolve: { + extensions: ['.ts', '.js'], + symlinks: false, + modules: [ + '../ng2-components', 'node_modules' + ] + }, + + plugins: [ + new webpack.NoEmitOnErrorsPlugin(), + + new webpack.BannerPlugin(fs.readFileSync(path.resolve(__dirname, './assets/license_header_add.txt'), 'utf8')), + + new webpack.ContextReplacementPlugin( + /angular(\\|\/)core(\\|\/)@angular/, + helpers.root('./src'), + {} + ) + ], + + devtool: 'cheap-module-source-map', + + node: { + fs: 'empty', + module: false + } +}; diff --git a/ng2-components/ng2-alfresco-viewer/config/webpack.test.js b/ng2-components/ng2-alfresco-viewer/config/webpack.test.js new file mode 100644 index 0000000000..486fed8c15 --- /dev/null +++ b/ng2-components/ng2-alfresco-viewer/config/webpack.test.js @@ -0,0 +1,85 @@ +const webpack = require('webpack'); +const helpers = require('./helpers'); + +const ENV = process.env.NODE_ENV = process.env.ENV = 'production'; + +module.exports = { + + devtool: 'inline-source-map', + + resolve: { + extensions: ['.ts', '.js'], + symlinks: false, + modules: [helpers.root('../ng2-components'), helpers.root('node_modules')] + }, + + module: { + rules: [ + { + enforce: 'pre', + test: /\.js$/, + loader: 'source-map-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.ts$/, + loaders: ['ts-loader?' + JSON.stringify({ transpileOnly: true}), 'angular2-template-loader'], + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.html$/, + loader: 'html-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.css$/, + loader: ['to-string-loader', 'css-loader'], + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico|pdf)$/, + loader: 'file-loader', + query: { + name: '[path][name].[ext]', + outputPath: (url)=> { + return url.replace('src', 'dist'); + } + } + }, + { + enforce: 'post', + test: /\.ts$/, + loader: 'istanbul-instrumenter-loader', + exclude: [ + /node_modules/, + /test/ + ] + } + ] + }, + + plugins: [ + new webpack.NoEmitOnErrorsPlugin(), + + new webpack.ContextReplacementPlugin( + /angular(\\|\/)core(\\|\/)@angular/, + helpers.root('./src'), + {} + ), + new webpack.DefinePlugin({ + 'process.env': { + 'ENV': JSON.stringify(ENV) + } + }), + new webpack.LoaderOptionsPlugin({ + htmlLoader: { + minimize: false // workaround for ng2 + } + }) + ], + + node: { + fs: 'empty', + module: false + } +}; diff --git a/ng2-components/ng2-alfresco-viewer/karma.conf.js b/ng2-components/ng2-alfresco-viewer/karma.conf.js index 0266cc71f5..f2a4bff546 100644 --- a/ng2-components/ng2-alfresco-viewer/karma.conf.js +++ b/ng2-components/ng2-alfresco-viewer/karma.conf.js @@ -21,11 +21,6 @@ module.exports = function (config) { {pattern: './node_modules/md-date-time-picker/**/*.js', included: false, served: true, watched: false}, {pattern: './node_modules/moment/**/*.js', included: false, served: true, watched: false}, - // pdf-js - './node_modules/pdfjs-dist/build/pdf.js', - './node_modules/pdfjs-dist/build/pdf.worker.js', - './node_modules/pdfjs-dist/web/pdf_viewer.js', - {pattern: 'karma-test-shim.js', watched: false}, {pattern: './dist/**/*.*', included: false, served: true, watched: false}, {pattern: './src/**/*.*', included: false, served: true, watched: false} diff --git a/ng2-components/ng2-alfresco-viewer/webpack.build.js b/ng2-components/ng2-alfresco-viewer/webpack.build.js index 3adbf6284f..816404e8e3 100644 --- a/ng2-components/ng2-alfresco-viewer/webpack.build.js +++ b/ng2-components/ng2-alfresco-viewer/webpack.build.js @@ -1,6 +1,6 @@ const webpack = require('webpack'); const webpackMerge = require('webpack-merge'); -const commonConfig = require('../config/webpack.common.js'); +const commonConfig = require('./config/webpack.common.js'); module.exports = webpackMerge(commonConfig, { diff --git a/ng2-components/ng2-alfresco-viewer/webpack.test.js b/ng2-components/ng2-alfresco-viewer/webpack.test.js index 4a61a62939..b6f4929fa4 100644 --- a/ng2-components/ng2-alfresco-viewer/webpack.test.js +++ b/ng2-components/ng2-alfresco-viewer/webpack.test.js @@ -1,6 +1,6 @@ const webpack = require('webpack'); const webpackMerge = require('webpack-merge'); -const testConfig = require('../config/webpack.test.js'); +const testConfig = require('./config/webpack.test.js'); module.exports = webpackMerge(testConfig, { diff --git a/ng2-components/ng2-alfresco-webscript/config/assets/license_header.txt b/ng2-components/ng2-alfresco-webscript/config/assets/license_header.txt new file mode 100644 index 0000000000..58ad8b656b --- /dev/null +++ b/ng2-components/ng2-alfresco-webscript/config/assets/license_header.txt @@ -0,0 +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. + */ diff --git a/ng2-components/ng2-alfresco-webscript/config/assets/license_header_add.txt b/ng2-components/ng2-alfresco-webscript/config/assets/license_header_add.txt new file mode 100644 index 0000000000..b38baa9716 --- /dev/null +++ b/ng2-components/ng2-alfresco-webscript/config/assets/license_header_add.txt @@ -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. diff --git a/ng2-components/ng2-alfresco-webscript/config/assets/tslint.json b/ng2-components/ng2-alfresco-webscript/config/assets/tslint.json new file mode 100644 index 0000000000..611a015c7e --- /dev/null +++ b/ng2-components/ng2-alfresco-webscript/config/assets/tslint.json @@ -0,0 +1,118 @@ +{ + "rules": { + "align": [ + true, + "parameters", + "statements" + ], + "ban": false, + "class-name": true, + "comment-format": [ + true, + "check-space" + ], + "curly": true, + "eofline": true, + "forin": true, + "indent": [ + true, + "spaces" + ], + "interface-name": false, + "jsdoc-format": true, + "label-position": true, + "max-line-length": [ + true, + 180 + ], + "member-ordering": [ + true, + "static-before-instance", + "variables-before-functions" + ], + "no-any": false, + "no-arg": true, + "no-bitwise": false, + "no-conditional-assignment": true, + "no-consecutive-blank-lines": true, + "no-console": [ + true, + "debug", + "info", + "time", + "timeEnd", + "trace" + ], + "no-construct": true, + "no-constructor-vars": false, + "no-debugger": true, + "no-duplicate-variable": true, + "no-empty": false, + "no-eval": true, + "no-inferrable-types": false, + "no-internal-module": true, + "no-require-imports": false, + "no-shadowed-variable": true, + "no-switch-case-fall-through": true, + "no-trailing-whitespace": true, + "no-unused-expression": true, + "no-unused-variable": true, + "no-use-before-declare": true, + "no-var-keyword": true, + "no-var-requires": true, + "object-literal-sort-keys": false, + "one-line": [ + true, + "check-open-brace", + "check-catch", + "check-else", + "check-whitespace" + ], + "quotemark": [ + true, + "single", + "avoid-escape" + ], + "radix": true, + "semicolon": true, + "switch-default": true, + "trailing-comma": [ + true, + { + "multiline": "never", + "singleline": "never" + } + ], + "triple-equals": [ + true, + "allow-null-check" + ], + "typedef": false, + "typedef-whitespace": [ + true, + { + "call-signature": "nospace", + "index-signature": "nospace", + "parameter": "nospace", + "property-declaration": "nospace", + "variable-declaration": "nospace" + } + ], + "use-strict": false, + "variable-name": [ + true, + "check-format", + "allow-leading-underscore", + "ban-keywords" + ], + "whitespace": [ + true, + "check-branch", + "check-operator", + "check-separator", + "check-type", + "check-module", + "check-decl" + ] + } +} diff --git a/ng2-components/ng2-alfresco-webscript/config/custom-loaders/file-loader-multi.js b/ng2-components/ng2-alfresco-webscript/config/custom-loaders/file-loader-multi.js new file mode 100644 index 0000000000..dfbf93e76e --- /dev/null +++ b/ng2-components/ng2-alfresco-webscript/config/custom-loaders/file-loader-multi.js @@ -0,0 +1,70 @@ +var path = require('path'); +var loaderUtils = require('loader-utils'); + +module.exports = function(content) { + this.cacheable && this.cacheable(); + if(!this.emitFile) throw new Error('emitFile is required from module system'); + + var query = loaderUtils.getOptions(this) || {}; + var configKey = query.config || 'multiFileLoader'; + var options = this.options[configKey] || {}; + var config = { + publicPath: false, + useRelativePath: false, + name: '[hash].[ext]' + }; + + // options takes precedence over config + Object.keys(options).forEach(function(attr) { + config[attr] = options[attr]; + }); + + // query takes precedence over config and options + Object.keys(query).forEach(function(attr) { + config[attr] = query[attr]; + }); + + var context = config.context || this.options.context; + var url = loaderUtils.interpolateName(this, config.name, { + context: context, + content: content, + regExp: config.regExp + }); + var path = loaderUtils.interpolateName(this, '[path]', { + context: context, + content: content, + regExp: config.regExp + }); + + var outputPath = ''; + + if (config.outputPath) { + outputPath = ( + typeof config.outputPath === 'function' + ? config.outputPath(url, path) + : config.outputPath + url + ); + } else { + outputPath = url; + } + + var publicPath = JSON.stringify(url); + + if (config.publicPath) { + publicPath = JSON.stringify( + typeof config.publicPath === 'function' + ? config.publicPath(url, path) + : config.publicPath + url + ); + } + + publicPath = '__webpack_public_path__ + ' + publicPath; + + if (query.emitFile === undefined || query.emitFile) { + this.emitFile(outputPath, content); + } + + return 'module.exports = ' + publicPath + ';'; +}; + +module.exports.raw = true; diff --git a/ng2-components/ng2-alfresco-webscript/config/custom-loaders/license-check.js b/ng2-components/ng2-alfresco-webscript/config/custom-loaders/license-check.js new file mode 100644 index 0000000000..6a15ac03e2 --- /dev/null +++ b/ng2-components/ng2-alfresco-webscript/config/custom-loaders/license-check.js @@ -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); +}; diff --git a/ng2-components/ng2-alfresco-webscript/config/helpers.js b/ng2-components/ng2-alfresco-webscript/config/helpers.js new file mode 100644 index 0000000000..a11fa771d6 --- /dev/null +++ b/ng2-components/ng2-alfresco-webscript/config/helpers.js @@ -0,0 +1,10 @@ +var path = require('path'); + +var _root = path.resolve(__dirname, '..'); + +function root(args) { + args = Array.prototype.slice.call(arguments, 0); + return path.join.apply(path, [_root].concat(args)); +} + +exports.root = root; diff --git a/ng2-components/ng2-alfresco-webscript/config/webpack.common.js b/ng2-components/ng2-alfresco-webscript/config/webpack.common.js new file mode 100644 index 0000000000..95cd33177e --- /dev/null +++ b/ng2-components/ng2-alfresco-webscript/config/webpack.common.js @@ -0,0 +1,124 @@ +const webpack = require('webpack'); +const helpers = require('./helpers'); +const fs = require('fs'); +const path = require('path'); + +module.exports = { + + resolveLoader: { + alias: { + "file-multi-loader": path.resolve(__dirname, "./custom-loaders/file-loader-multi"), + "license-check": path.resolve(__dirname, "./custom-loaders/license-check") + } + }, + + // require those dependencies but don't bundle them + externals: [ + /^\@angular\//, + /^rxjs\//, + 'moment', + 'raphael', + 'ng2-charts', + 'alfresco-js-api', + 'ng2-alfresco-core', + 'ng2-alfresco-datatable', + 'ng2-activiti-analytics', + 'ng2-activiti-diagrams', + 'ng2-activiti-form', + "ng2-activiti-tasklist", + 'ng2-alfresco-documentlist' + ], + + module: { + rules: [ + { + enforce: 'pre', + test: /\.js$/, + loader: 'source-map-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + enforce: 'pre', + test: /\.ts$/, + use: 'source-map-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + enforce: 'pre', + test: /\.ts$/, + loader: 'tslint-loader', + options: { + emitErrors: true, + configFile: path.resolve(__dirname, './assets/tslint.json') + }, + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.ts$/, + use: ['ts-loader', 'angular2-template-loader'], + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.html$/, + loader: 'html-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + 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)$/, + loader: 'file-multi-loader', + query: { + name: '[name].[hash].[ext]', + outputPath: (url, resourcePath)=> { + return resourcePath.replace('src', 'bundles') + url; + }, + publicPath: (url, resourcePath)=> { + var component = resourcePath.substring(0, resourcePath.indexOf('src')); + var path = resourcePath.replace(component, '').replace('src', 'bundles'); + return './' + path + url; + } + } + } + ] + }, + + resolve: { + extensions: ['.ts', '.js'], + symlinks: false, + modules: [ + '../ng2-components', 'node_modules' + ] + }, + + plugins: [ + new webpack.NoEmitOnErrorsPlugin(), + + new webpack.BannerPlugin(fs.readFileSync(path.resolve(__dirname, './assets/license_header_add.txt'), 'utf8')), + + new webpack.ContextReplacementPlugin( + /angular(\\|\/)core(\\|\/)@angular/, + helpers.root('./src'), + {} + ) + ], + + devtool: 'cheap-module-source-map', + + node: { + fs: 'empty', + module: false + } +}; diff --git a/ng2-components/ng2-alfresco-webscript/config/webpack.test.js b/ng2-components/ng2-alfresco-webscript/config/webpack.test.js new file mode 100644 index 0000000000..486fed8c15 --- /dev/null +++ b/ng2-components/ng2-alfresco-webscript/config/webpack.test.js @@ -0,0 +1,85 @@ +const webpack = require('webpack'); +const helpers = require('./helpers'); + +const ENV = process.env.NODE_ENV = process.env.ENV = 'production'; + +module.exports = { + + devtool: 'inline-source-map', + + resolve: { + extensions: ['.ts', '.js'], + symlinks: false, + modules: [helpers.root('../ng2-components'), helpers.root('node_modules')] + }, + + module: { + rules: [ + { + enforce: 'pre', + test: /\.js$/, + loader: 'source-map-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.ts$/, + loaders: ['ts-loader?' + JSON.stringify({ transpileOnly: true}), 'angular2-template-loader'], + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.html$/, + loader: 'html-loader', + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.css$/, + loader: ['to-string-loader', 'css-loader'], + exclude: [/node_modules/, /bundles/, /dist/, /demo/] + }, + { + test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico|pdf)$/, + loader: 'file-loader', + query: { + name: '[path][name].[ext]', + outputPath: (url)=> { + return url.replace('src', 'dist'); + } + } + }, + { + enforce: 'post', + test: /\.ts$/, + loader: 'istanbul-instrumenter-loader', + exclude: [ + /node_modules/, + /test/ + ] + } + ] + }, + + plugins: [ + new webpack.NoEmitOnErrorsPlugin(), + + new webpack.ContextReplacementPlugin( + /angular(\\|\/)core(\\|\/)@angular/, + helpers.root('./src'), + {} + ), + new webpack.DefinePlugin({ + 'process.env': { + 'ENV': JSON.stringify(ENV) + } + }), + new webpack.LoaderOptionsPlugin({ + htmlLoader: { + minimize: false // workaround for ng2 + } + }) + ], + + node: { + fs: 'empty', + module: false + } +}; diff --git a/ng2-components/ng2-alfresco-webscript/karma.conf.js b/ng2-components/ng2-alfresco-webscript/karma.conf.js index f7f5ca66a2..9001db1c10 100644 --- a/ng2-components/ng2-alfresco-webscript/karma.conf.js +++ b/ng2-components/ng2-alfresco-webscript/karma.conf.js @@ -21,11 +21,6 @@ module.exports = function (config) { {pattern: './node_modules/md-date-time-picker/**/*.js', included: false, served: true, watched: false}, {pattern: './node_modules/moment/**/*.js', included: false, served: true, watched: false}, - // pdf-js - './node_modules/pdfjs-dist/build/pdf.js', - './node_modules/pdfjs-dist/build/pdf.worker.js', - './node_modules/pdfjs-dist/web/pdf_viewer.js', - {pattern: 'karma-test-shim.js', watched: false}, {pattern: './src/assets/**/*.*', included: false, served: true, watched: false}, {pattern: './src/i18n/**/*.*', included: false, served: true, watched: false}, diff --git a/ng2-components/ng2-alfresco-webscript/package.json b/ng2-components/ng2-alfresco-webscript/package.json index 99b51f5674..96b7901a96 100644 --- a/ng2-components/ng2-alfresco-webscript/package.json +++ b/ng2-components/ng2-alfresco-webscript/package.json @@ -98,14 +98,5 @@ "webscript", "alfresco-component" ], - "license-check-config": { - "src": [ - "./src/**/*.ts" - ], - "path": "assets/license_header.txt", - "blocking": true, - "logInfo": false, - "logError": true - }, "license": "Apache-2.0" } diff --git a/ng2-components/ng2-alfresco-webscript/webpack.build.js b/ng2-components/ng2-alfresco-webscript/webpack.build.js index d84c8d7e7e..e49ab6bdaf 100644 --- a/ng2-components/ng2-alfresco-webscript/webpack.build.js +++ b/ng2-components/ng2-alfresco-webscript/webpack.build.js @@ -1,6 +1,6 @@ -const webpack = require("webpack"); +const webpack = require('webpack'); const webpackMerge = require('webpack-merge'); -const commonConfig = require('../config/webpack.common.js'); +const commonConfig = require('./config/webpack.common.js'); module.exports = webpackMerge(commonConfig, { diff --git a/ng2-components/ng2-alfresco-webscript/webpack.test.js b/ng2-components/ng2-alfresco-webscript/webpack.test.js index 4a61a62939..b6f4929fa4 100644 --- a/ng2-components/ng2-alfresco-webscript/webpack.test.js +++ b/ng2-components/ng2-alfresco-webscript/webpack.test.js @@ -1,6 +1,6 @@ const webpack = require('webpack'); const webpackMerge = require('webpack-merge'); -const testConfig = require('../config/webpack.test.js'); +const testConfig = require('./config/webpack.test.js'); module.exports = webpackMerge(testConfig, { diff --git a/ng2-components/package.json b/ng2-components/package.json index 27dd7a69a3..86142a1e7a 100644 --- a/ng2-components/package.json +++ b/ng2-components/package.json @@ -10,6 +10,7 @@ "test-browser": "karma start karma.conf.js --reporters kjhtml", "coverage": "", "prepublish": "", + "rimraf": "rimraf", "pkg-build": "package-json-merge ng2-alfresco-core/package.json ng2-alfresco-datatable/package.json ng2-activiti-diagrams/package.json ng2-activiti-analytics/package.json ng2-activiti-form/package.json ng2-activiti-tasklist/package.json ng2-activiti-processlist/package.json ng2-alfresco-documentlist/package.json ng2-alfresco-login/package.json ng2-alfresco-search/package.json ng2-alfresco-tag/package.json ng2-alfresco-upload/package.json ng2-alfresco-viewer/package.json ng2-alfresco-webscript/package.json ng2-alfresco-webscript/package.json ng2-alfresco-userinfo/package.json ng2-alfresco-social/package.json package-base.json > package.json", "tslint": "", "tsc": "", @@ -25,7 +26,6 @@ "bugs": { "url": "https://github.com/Alfresco/alfresco-ng2-components/issues" }, - "license": "Apache-2.0", "contributors": { "0": { "name": "Eugenio Romano", @@ -144,15 +144,7 @@ "wsrv": "^0.1.7", "license-check": "1.1.5" }, - "license-check-config": { - "src": { - "0": "./src/**/*.ts" - }, - "path": "assets/license_header.txt", - "blocking": true, - "logInfo": false, - "logError": true - }, + "license": "Apache-2.0", "module": "./index.js", "typings": "./index.d.ts" } diff --git a/scripts/README.md b/scripts/README.md index a6205bd6a8..a6f4771596 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -105,6 +105,20 @@ feel for what's available. ./npm-build-all.sh -gitjsapi de92be966e2ce7eca642ca9e9d7647ba4f849356 ``` +* If you want avoid initial build and run only all the test + +```sh +./npm-buid-all.sh -s -t +``` + +* If you want test in less time (high memoery consumign less detail) + +```sh +./npm-buid-all.sh -ft //test and build + +./npm-buid-all.sh -s -ft //only test +``` + * If you want clean all your local component and the demo shell: ```sh diff --git a/scripts/npm-build-all.sh b/scripts/npm-build-all.sh index c4c5a7370c..d78262f55e 100755 --- a/scripts/npm-build-all.sh +++ b/scripts/npm-build-all.sh @@ -2,7 +2,9 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" eval RUN_TEST=false +eval EXEC_FAST_TEST=false eval EXEC_CLEAN=false +eval EXEC_BUILD=true eval EXEC_GIT_NPM_INSTALL_JSAPI=false eval GIT_ISH="" @@ -27,7 +29,9 @@ eval projects=( "ng2-alfresco-core" show_help() { echo "Usage: npm-build-all.sh" echo "" + echo "-e or -exclude exclude initial build" echo "-t or -test build all your local component and run also the test on them" + echo "-ft or -fast test build all your local component and run also the test in one single karmatestshim (high memory consuming and less details)" echo "-c or -clean the node_modules folder before to start the build" echo "-gitjsapi to build all the components against a commit-ish version of the JS-API" } @@ -41,6 +45,10 @@ test_project() { npm run test -- --component $1 || exit 1 } +enable_fast_test() { + EXEC_FAST_TEST=true +} + enable_js_api_git_link() { GIT_ISH='git://github.com/Alfresco/alfresco-js-api.git#'$1 EXEC_GIT_NPM_INSTALL_JSAPI=true @@ -50,13 +58,19 @@ clean() { EXEC_CLEAN=true } +exclude_build(){ + EXEC_BUILD=false +} + while [[ $1 == -* ]]; do case "$1" in -h|--help|-\?) show_help; exit 0;; -t|--test) enable_test; shift;; + -ft|--fasttest) enable_fast_test; shift;; -gitjsapi) enable_js_api_git_link $2; shift 2;; -v|--version) install_version_pacakge $2; shift 2;; -c|--clean) clean; shift;; + -s|--skipbuild) exclude_build; shift;; -*) echo "invalid option: $1" 1>&2; show_help; exit 1;; esac done @@ -84,8 +98,15 @@ if $EXEC_GIT_NPM_INSTALL_JSAPI == true; then cd "$DIR/../ng2-components/" fi -echo "====== Build ng2-components =====" -npm run build || exit 1 +if $EXEC_BUILD == true; then + echo "====== Build ng2-components =====" + npm run build || exit 1 +fi + +if $EXEC_FAST_TEST == true; then + echo "====== Test all ng2-components (fast option) =====" + npm run test || exit 1 +fi for PACKAGE in ${projects[@]} do diff --git a/scripts/npm-publish.sh b/scripts/npm-publish.sh index c4168f520f..9395024b80 100755 --- a/scripts/npm-publish.sh +++ b/scripts/npm-publish.sh @@ -107,7 +107,7 @@ do fi echo "====== PUBLISHING: ${DESTDIR} ===== npm publish ${OPTIONS}" - npm publish ${OPTIONS} + npm publish ${OPTIONS} || exit 1 if $EXEC_CHANGE_REGISTRY == true; then npm run rimraf .npmrc