Browse Source

CHG: new post install npm hook event
CHG: node modules are now globally installed and linked inside local node_modules folder
FIX: fixFindBoxSVG -> fixed images url inside svg

Giancarlo Voci 7 years ago
parent
commit
26d22573b6
7 changed files with 88 additions and 52 deletions
  1. 1 0
      .npmignore
  2. 32 23
      package.json
  3. 9 0
      postinstall.js
  4. 21 6
      src/OpenMind/FindBox/FindBoxCoreSystem.php
  5. 23 21
      ui/admin/package.json
  6. 1 1
      ui/admin/webpack.config.js
  7. 1 1
      webpack.config.js

+ 1 - 0
.npmignore

@@ -0,0 +1 @@
+*

+ 32 - 23
package.json

@@ -1,36 +1,45 @@
 {
 {
 	"name": "OM-Link",
 	"name": "OM-Link",
+	"projectname": "omlink",
 	"version": "1.9.7",
 	"version": "1.9.7",
 	"private": true,
 	"private": true,
 	"description": "OM-Link Engine",
 	"description": "OM-Link Engine",
 	"author": "Open Mind",
 	"author": "Open Mind",
 	"scripts": {
 	"scripts": {
-		"Clean": "shx --silent rm -rf deploy.tar.gz tmp node_modules ui/admin/node_modules src_minified assets/frontend assets/admin Site.log cfg/*.old ui/*/masterpage.tpl fbtpl",
-		"Install": "npm install",
-		"Build DEV": "webpack --mode=none --config webpack.config.js --display-error-details",
-		"Build PROD": "webpack --mode=production --config webpack.config.js --display-error-details",
-		"Watch": "webpack --mode=none --config webpack.config.js --display-error-details --watch",
-		"Deploy": "tar -zcvf deploy.tar.gz --exclude cfg/config.ini --exclude masterpage_template.tpl --exclude node_modules assets lib src ui/frontend/*.tpl index.php *.sql cfg"
-	},
-	"devDependencies": {
-		"acorn": "^6.1.1",
-		"clean-webpack-plugin": "^2.0.2",
-		"css-loader": "^2.1.1",
-		"file-loader": "^3.0.1",
-		"html-webpack-plugin": "^3.2.0",
-		"html-webpack-prefix-plugin": "^1.1.0",
-		"mini-css-extract-plugin": "^0.6.0",
-		"node-sass": "^4.12.0",
-		"optimize-css-assets-webpack-plugin": "^5.0.1",
-		"sass-loader": "^7.1.0",
-		"terser": "^3.17.0",
-		"url-loader": "^1.1.2",
-		"webpack": "^4.31.0",
-		"webpack-cli": "^3.3.2"
+		"clean": "shx --silent rm -rf deploy.tar.gz tmp node_modules ui/admin/node_modules src_minified assets/frontend assets/admin Site.log cfg/*.old ui/*/masterpage.tpl fbtpl *.tgz",
+		"postinstall": "node postinstall.js",
+		"buildDev": "webpack --mode=none --display-error-details",
+		"buildProd": "webpack --mode=production --display-error-details",
+		"watch": "webpack --mode=none --display-error-details --watch",
+		"pack": "npm pack"
 	},
 	},
+	"globalDependencies": [
+		"acorn",
+		"clean-webpack-plugin",
+		"css-loader",
+		"file-loader",
+		"html-webpack-plugin",
+		"html-webpack-prefix-plugin",
+		"mini-css-extract-plugin",
+		"node-sass",
+		"optimize-css-assets-webpack-plugin",
+		"sass-loader",
+		"terser-webpack-plugin",
+		"url-loader",
+		"webpack",
+		"webpack-cli"
+	],
 	"dependencies": {
 	"dependencies": {
 		"bootstrap": "^4.3.1",
 		"bootstrap": "^4.3.1",
 		"jquery": "^3.4.1",
 		"jquery": "^3.4.1",
 		"popper.js": "^1.15.0"
 		"popper.js": "^1.15.0"
-	}
+	},
+	"files": [
+		"index.php",
+		"src",
+		"lib",
+		"cfg/config.bin",
+		"ui/*/*.tpl",
+		"assets"
+	]
 }
 }

+ 9 - 0
postinstall.js

@@ -0,0 +1,9 @@
+const fs = require('fs');
+const {execSync} = require('child_process')
+
+let packageJson = JSON.parse(fs.readFileSync('package.json'));
+
+let globalModules = packageJson.globalDependencies.join(' ');
+
+execSync(`npm i -g ${globalModules}`);
+execSync(`npm link ${globalModules}`);

+ 21 - 6
src/OpenMind/FindBox/FindBoxCoreSystem.php

@@ -319,13 +319,28 @@ class FindBoxCoreSystem
 
 
 	private function fixFindBoxSVG($svgPath)
 	private function fixFindBoxSVG($svgPath)
 	{
 	{
-		$svg_data = file_get_contents($svgPath);
+		global $f3;
 
 
-		$svgTemplate = simplexml_load_string($svg_data);
-		$svgTemplate->attributes()->width = 300;
-		$svgTemplate->attributes()->height = 180;
-		$svgTemplate->attributes()->transform = '';
+		$svgTemplate = new \DOMDocument();
+		$svgTemplate->load($svgPath);
+		$xlink = $svgTemplate->getElementsByTagName('image');
+		if ($xlink->length > 0) {
+			$href = $xlink[0]->getAttribute('xlink:href');
 
 
-		$svgTemplate->saveXML($svgPath);
+			$url = parse_url($href);
+			$url['host'] = $f3->get('CORE.fb.host');
+			$imgUrl = "{$url['scheme']}://{$url['host']}{$url['path']}";
+
+			$xlink[0]->setAttribute('xlink:href', $imgUrl);
+		}
+
+		$svgNode = $svgTemplate->getElementsByTagName('svg');
+		if ($svgNode->length > 0) {
+			$svgNode[0]->setAttribute('width', 300);
+			$svgNode[0]->setAttribute('height', 180);
+			$svgNode[0]->removeAttribute('transform');
+		}
+
+		$svgTemplate->save($svgPath);
 	}
 	}
 }
 }

+ 23 - 21
ui/admin/package.json

@@ -1,15 +1,32 @@
 {
 {
 	"name": "admin",
 	"name": "admin",
-	"version": "1.3.0",
+	"projectname": "omlink",
+	"version": "1.3.5",
 	"private": true,
 	"private": true,
 	"description": "OM-Link Admin Module",
 	"description": "OM-Link Admin Module",
-	"author": "",
+	"author": "Open Mind",
 	"scripts": {
 	"scripts": {
-		"Install": "npm install",
-		"Build DEV": "webpack --mode=none --config webpack.config.js --display-error-details",
-		"Build PROD": "webpack --mode=production --config webpack.config.js --display-error-details",
-		"Watch": "webpack --mode=none --config webpack.config.js --display-error-details --watch"
+		"postinstall": "node ../../postinstall.js",
+		"buildDev": "webpack --mode=none --display-error-details",
+		"buildProd": "webpack --mode=production --display-error-details",
+		"watch": "webpack --mode=none --display-error-details --watch"
 	},
 	},
+	"globalDependencies": [
+		"acorn",
+		"clean-webpack-plugin",
+		"css-loader",
+		"file-loader",
+		"html-webpack-plugin",
+		"html-webpack-prefix-plugin",
+		"mini-css-extract-plugin",
+		"node-sass",
+		"optimize-css-assets-webpack-plugin",
+		"sass-loader",
+		"terser-webpack-plugin",
+		"url-loader",
+		"webpack",
+		"webpack-cli"
+	],
 	"dependencies": {
 	"dependencies": {
 		"bootstrap": "4.2.1",
 		"bootstrap": "4.2.1",
 		"datatables.net": "^1.10.19",
 		"datatables.net": "^1.10.19",
@@ -25,20 +42,5 @@
 		"pdfmake": "^0.1.56",
 		"pdfmake": "^0.1.56",
 		"popper.js": "^1.15.0",
 		"popper.js": "^1.15.0",
 		"toastr": "^2.1.4"
 		"toastr": "^2.1.4"
-	},
-	"devDependencies": {
-		"clean-webpack-plugin": "^2.0.1",
-		"css-loader": "^2.1.1",
-		"file-loader": "^3.0.1",
-		"html-webpack-plugin": "^3.2.0",
-		"html-webpack-prefix-plugin": "^1.1.0",
-		"mini-css-extract-plugin": "^0.6.0",
-		"node-sass": "^4.12.0",
-		"optimize-css-assets-webpack-plugin": "^5.0.1",
-		"sass-loader": "^7.1.0",
-		"terser": "^3.17.0",
-		"url-loader": "^1.1.2",
-		"webpack": "^4.31.0",
-		"webpack-cli": "^3.3.2"
 	}
 	}
 }
 }

+ 1 - 1
ui/admin/webpack.config.js

@@ -54,7 +54,7 @@ module.exports = {
 	entry: "./assets/js/index.js",
 	entry: "./assets/js/index.js",
 	output:
 	output:
 		{
 		{
-			publicPath: '/omlink/assets/admin/',
+			publicPath: '/' + process.env.npm_package_projectname + '/assets/admin/',
 			path: path.resolve(__dirname, "../../assets/admin/"),
 			path: path.resolve(__dirname, "../../assets/admin/"),
 			filename: "bundle.[contenthash].js"
 			filename: "bundle.[contenthash].js"
 		}
 		}

+ 1 - 1
webpack.config.js

@@ -58,7 +58,7 @@ module.exports = {
 	},
 	},
 	entry: "./ui/frontend/js/index.js",
 	entry: "./ui/frontend/js/index.js",
 	output: {
 	output: {
-		publicPath: '/omlink/assets/frontend/',
+		publicPath: '/' + process.env.npm_package_projectname + '/assets/frontend/',
 		path: path.resolve(__dirname, "assets/frontend/"),
 		path: path.resolve(__dirname, "assets/frontend/"),
 		filename: "bundle.[contenthash].js"
 		filename: "bundle.[contenthash].js"
 	},
 	},