diff --git a/.gitignore b/.gitignore index 4b148a6d..e0ecba3b 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,7 @@ npm-debug.log* coverage .nyc_output -build/* -!build/README.md +/build +dist/ deployment/*.retry 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/build/README.md b/build/.gitkeep similarity index 100% rename from build/README.md rename to build/.gitkeep 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", 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..1931bd36 100644 --- a/test/common.js +++ b/test/common.js @@ -8,7 +8,7 @@ const urls = {} const mocks = {} paths.root = path.join(__dirname, '..') -paths.build = path.join(paths.root, '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') 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) => { 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()