From 3c5cb5393692272bca31187ae588bbc13b0a160d Mon Sep 17 00:00:00 2001 From: Nic O'Connor Date: Tue, 8 Aug 2017 10:13:24 -0400 Subject: [PATCH 1/2] Added Gruntfile and package.json for npm install; updated .gitignore --- .gitignore | 1 + Gruntfile.js | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 96 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 198 insertions(+) create mode 100644 Gruntfile.js create mode 100644 package.json diff --git a/.gitignore b/.gitignore index f85c5a3f8..ed7d8b552 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ node_modules javascript/dist .jshintrc javascript/examples/**/dist +.idea/ diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 000000000..294c2cb67 --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,101 @@ +var path = require("path"), + fs = require("fs"), + parentFolderName = path.basename(path.resolve('..')), + mxClientContent, + deps; + +// To get the dependencies for the project, read the filenames by matching +// mxClient.include([...]) in mxClient.js. This is not perfect, but the list is +// required in mxClient.js for compatibility. +mxClientContent = fs.readFileSync( + path.join(__dirname, "./javascript/src/js/mxClient.js"), + "utf8" +); +deps = mxClientContent.match(/mxClient\.include\([^"']+["'](.*?)["']/gi).map(function (str) { + return "." + str.match(/mxClient\.include\([^"']+["'](.*?)["']/)[1]; +}); +deps = ["./js/mxClient.js"].concat(deps.slice(0)); + +module.exports = function (grunt) { + grunt.initConfig({ + copy: { + main: { + files: [{ + expand: true, + cwd: "./javascript/src", + src: deps, + dest: "./javascript/dist" + }], + options: { + // After each module, add the object to the '__mxOutput' namespace + // E.g. __mxOutput.mxLog, etc. + process: function (content, srcpath) { + var afterContent = "", + moduleName = path.basename(srcpath, ".js"); + + afterContent += "\n__mxOutput." + path.basename(srcpath, ".js") + + " = typeof " + moduleName + " !== 'undefined' ? " + moduleName + " : undefined;\n"; + + return content + afterContent; + } + } + } + }, + concat: { + dist: { + src: deps.map(function (dep) { + return path.join("./javascript/dist", dep); + }), + dest: './javascript/dist/build.js' + }, + options: { + banner: "(function (root, factory) {\n" + + "if (typeof define === 'function' && define.amd) {\n" + + "define([], factory);\n" + + "} else if (typeof module === 'object' && module.exports) {\n" + + "module.exports = factory();\n" + + "} else {\n" + + "root.mxgraph = factory();\n" + + "}\n" + + "}(this, function () {\n" + + "return function (opts) {\n" + + // Opts will be passed into this function, expand them out as if + // they were globals so they can get picked up by the logic in + // mxClient.js. + "for (var name in opts) { this[name] = opts[name]; }\n" + + "var __mxOutput = {};\n", + footer: "return __mxOutput;\n" + + "};\n" + + "}));" + } + }, + webpack: { + examples: { + entry: "./javascript/examples/webpack/src/anchors.js", + output: { + path: path.resolve(__dirname, "./javascript/examples/webpack/dist"), + filename: "anchors.js" + } + } + }, + watch: { + javascripts: { + files: "javascript/src/**/*.js", + tasks: ["umdify"], + options: { + interrupt: true + } + } + }, + }); + + require(parentFolderName === "node_modules" ? "load-grunt-parent-tasks" : "load-grunt-tasks")(grunt); + grunt.registerTask("default", [ + "copy", + "concat", + "webpack" + ]); + grunt.registerTask("build", [ + "default" + ]); +}; diff --git a/package.json b/package.json new file mode 100644 index 000000000..ae8bfa595 --- /dev/null +++ b/package.json @@ -0,0 +1,96 @@ +{ + "_args": [ + [ + { + "raw": "mxgraph@^3.7.4", + "scope": null, + "escapedName": "mxgraph", + "name": "mxgraph", + "rawSpec": "^3.7.4", + "spec": ">=3.7.4 <4.0.0", + "type": "range" + }, + "/Users/nic/source/cartographer-web" + ] + ], + "_from": "mxgraph@>=3.7.4 <4.0.0", + "_id": "mxgraph@3.7.4", + "_inCache": true, + "_location": "/mxgraph", + "_nodeVersion": "4.7.2", + "_npmOperationalInternal": { + "host": "s3://npm-registry-packages", + "tmp": "tmp/mxgraph-3.7.4.tgz_1498590682767_0.9278142049442977" + }, + "_npmUser": { + "name": "drawio", + "email": "npm@jgraph.com" + }, + "_npmVersion": "3.5.2", + "_phantomChildren": {}, + "_requested": { + "raw": "mxgraph@^3.7.4", + "scope": null, + "escapedName": "mxgraph", + "name": "mxgraph", + "rawSpec": "^3.7.4", + "spec": ">=3.7.4 <4.0.0", + "type": "range" + }, + "_requiredBy": [ + "#USER", + "/" + ], + "_resolved": "https://registry.npmjs.org/mxgraph/-/mxgraph-3.7.4.tgz", + "_shasum": "1066f63fa63a8647dcdb0f1d8ccdbc191e6ed452", + "_shrinkwrap": null, + "_spec": "mxgraph@^3.7.4", + "_where": "/Users/nic/source/cartographer-web", + "author": { + "name": "JGraph Ltd", + "email": "support@jgraph.com" + }, + "bugs": { + "url": "https://github.com/jgraph/mxgraph/issues" + }, + "dependencies": { + "grunt": "^1.0.1", + "grunt-contrib-concat": "^1.0.1", + "grunt-contrib-copy": "^1.0.0", + "grunt-webpack": "^2.0.1", + "load-grunt-parent-tasks": "^0.1.1", + "load-grunt-tasks": "^3.5.2", + "webpack": "^2.2.1" + }, + "description": "mxGraph is a fully client side JavaScript diagramming library that uses SVG and HTML for rendering.", + "devDependencies": {}, + "directories": {}, + "dist": { + "shasum": "1066f63fa63a8647dcdb0f1d8ccdbc191e6ed452", + "tarball": "https://registry.npmjs.org/mxgraph/-/mxgraph-3.7.4.tgz" + }, + "homepage": "https://github.com/jgraph/mxgraph", + "license": "Apache-2.0", + "main": "./javascript/dist/build.js", + "maintainers": [ + { + "name": "drawio", + "email": "npm@jgraph.com" + }, + { + "name": "brendonboshell", + "email": "brendonboshell@gmail.com" + } + ], + "name": "mxgraph", + "optionalDependencies": {}, + "readme": "ERROR: No README data found!", + "repository": { + "type": "git", + "url": "git+https://github.com/jgraph/mxgraph.git" + }, + "scripts": { + "postinstall": "grunt build" + }, + "version": "3.7.4" +} From ae4f5d1261a661cb9db44304bedd5ac5df015007 Mon Sep 17 00:00:00 2001 From: Nic O'Connor Date: Wed, 18 Oct 2017 11:16:06 -0400 Subject: [PATCH 2/2] Moved Gruntfile.js to etc/build, modified package.json to set --gruntfile and --base, modified gruntfile to use process.cwd() for __dirname --- Gruntfile.js | 101 ----------------------------------------- etc/build/Gruntfile.js | 26 +++++------ package.json | 20 ++++---- 3 files changed, 23 insertions(+), 124 deletions(-) delete mode 100644 Gruntfile.js diff --git a/Gruntfile.js b/Gruntfile.js deleted file mode 100644 index 294c2cb67..000000000 --- a/Gruntfile.js +++ /dev/null @@ -1,101 +0,0 @@ -var path = require("path"), - fs = require("fs"), - parentFolderName = path.basename(path.resolve('..')), - mxClientContent, - deps; - -// To get the dependencies for the project, read the filenames by matching -// mxClient.include([...]) in mxClient.js. This is not perfect, but the list is -// required in mxClient.js for compatibility. -mxClientContent = fs.readFileSync( - path.join(__dirname, "./javascript/src/js/mxClient.js"), - "utf8" -); -deps = mxClientContent.match(/mxClient\.include\([^"']+["'](.*?)["']/gi).map(function (str) { - return "." + str.match(/mxClient\.include\([^"']+["'](.*?)["']/)[1]; -}); -deps = ["./js/mxClient.js"].concat(deps.slice(0)); - -module.exports = function (grunt) { - grunt.initConfig({ - copy: { - main: { - files: [{ - expand: true, - cwd: "./javascript/src", - src: deps, - dest: "./javascript/dist" - }], - options: { - // After each module, add the object to the '__mxOutput' namespace - // E.g. __mxOutput.mxLog, etc. - process: function (content, srcpath) { - var afterContent = "", - moduleName = path.basename(srcpath, ".js"); - - afterContent += "\n__mxOutput." + path.basename(srcpath, ".js") + - " = typeof " + moduleName + " !== 'undefined' ? " + moduleName + " : undefined;\n"; - - return content + afterContent; - } - } - } - }, - concat: { - dist: { - src: deps.map(function (dep) { - return path.join("./javascript/dist", dep); - }), - dest: './javascript/dist/build.js' - }, - options: { - banner: "(function (root, factory) {\n" + - "if (typeof define === 'function' && define.amd) {\n" + - "define([], factory);\n" + - "} else if (typeof module === 'object' && module.exports) {\n" + - "module.exports = factory();\n" + - "} else {\n" + - "root.mxgraph = factory();\n" + - "}\n" + - "}(this, function () {\n" + - "return function (opts) {\n" + - // Opts will be passed into this function, expand them out as if - // they were globals so they can get picked up by the logic in - // mxClient.js. - "for (var name in opts) { this[name] = opts[name]; }\n" + - "var __mxOutput = {};\n", - footer: "return __mxOutput;\n" + - "};\n" + - "}));" - } - }, - webpack: { - examples: { - entry: "./javascript/examples/webpack/src/anchors.js", - output: { - path: path.resolve(__dirname, "./javascript/examples/webpack/dist"), - filename: "anchors.js" - } - } - }, - watch: { - javascripts: { - files: "javascript/src/**/*.js", - tasks: ["umdify"], - options: { - interrupt: true - } - } - }, - }); - - require(parentFolderName === "node_modules" ? "load-grunt-parent-tasks" : "load-grunt-tasks")(grunt); - grunt.registerTask("default", [ - "copy", - "concat", - "webpack" - ]); - grunt.registerTask("build", [ - "default" - ]); -}; diff --git a/etc/build/Gruntfile.js b/etc/build/Gruntfile.js index 294c2cb67..b6ba9d349 100644 --- a/etc/build/Gruntfile.js +++ b/etc/build/Gruntfile.js @@ -4,19 +4,19 @@ var path = require("path"), mxClientContent, deps; -// To get the dependencies for the project, read the filenames by matching -// mxClient.include([...]) in mxClient.js. This is not perfect, but the list is -// required in mxClient.js for compatibility. -mxClientContent = fs.readFileSync( - path.join(__dirname, "./javascript/src/js/mxClient.js"), - "utf8" -); -deps = mxClientContent.match(/mxClient\.include\([^"']+["'](.*?)["']/gi).map(function (str) { - return "." + str.match(/mxClient\.include\([^"']+["'](.*?)["']/)[1]; -}); -deps = ["./js/mxClient.js"].concat(deps.slice(0)); - module.exports = function (grunt) { + // To get the dependencies for the project, read the filenames by matching + // mxClient.include([...]) in mxClient.js. This is not perfect, but the list is + // required in mxClient.js for compatibility. + mxClientContent = fs.readFileSync( + path.join(process.cwd(), "./javascript/src/js/mxClient.js"), + "utf8" + ); + deps = mxClientContent.match(/mxClient\.include\([^"']+["'](.*?)["']/gi).map(function (str) { + return "." + str.match(/mxClient\.include\([^"']+["'](.*?)["']/)[1]; + }); + deps = ["./js/mxClient.js"].concat(deps.slice(0)); + grunt.initConfig({ copy: { main: { @@ -73,7 +73,7 @@ module.exports = function (grunt) { examples: { entry: "./javascript/examples/webpack/src/anchors.js", output: { - path: path.resolve(__dirname, "./javascript/examples/webpack/dist"), + path: path.resolve(process.cwd(), "./javascript/examples/webpack/dist"), filename: "anchors.js" } } diff --git a/package.json b/package.json index ae8bfa595..d387cb48b 100644 --- a/package.json +++ b/package.json @@ -2,18 +2,18 @@ "_args": [ [ { - "raw": "mxgraph@^3.7.4", + "raw": "mxgraph@^3.7.5", "scope": null, "escapedName": "mxgraph", "name": "mxgraph", - "rawSpec": "^3.7.4", - "spec": ">=3.7.4 <4.0.0", + "rawSpec": "^3.7.5", + "spec": ">=3.7.5 <4.0.0", "type": "range" }, "/Users/nic/source/cartographer-web" ] ], - "_from": "mxgraph@>=3.7.4 <4.0.0", + "_from": "mxgraph@>=3.7.5 <4.0.0", "_id": "mxgraph@3.7.4", "_inCache": true, "_location": "/mxgraph", @@ -29,12 +29,12 @@ "_npmVersion": "3.5.2", "_phantomChildren": {}, "_requested": { - "raw": "mxgraph@^3.7.4", + "raw": "mxgraph@^3.7.5", "scope": null, "escapedName": "mxgraph", "name": "mxgraph", - "rawSpec": "^3.7.4", - "spec": ">=3.7.4 <4.0.0", + "rawSpec": "^3.7.5", + "spec": ">=3.7.5 <4.0.0", "type": "range" }, "_requiredBy": [ @@ -44,7 +44,7 @@ "_resolved": "https://registry.npmjs.org/mxgraph/-/mxgraph-3.7.4.tgz", "_shasum": "1066f63fa63a8647dcdb0f1d8ccdbc191e6ed452", "_shrinkwrap": null, - "_spec": "mxgraph@^3.7.4", + "_spec": "mxgraph@^3.7.5", "_where": "/Users/nic/source/cartographer-web", "author": { "name": "JGraph Ltd", @@ -90,7 +90,7 @@ "url": "git+https://github.com/jgraph/mxgraph.git" }, "scripts": { - "postinstall": "grunt build" + "postinstall": "grunt build --base \"$(npm prefix)\" --gruntfile etc/build/Gruntfile.js" }, - "version": "3.7.4" + "version": "3.7.5" }