Skip to content

Commit 5dc6839

Browse files
committed
Visualize local codes
1 parent a02d303 commit 5dc6839

File tree

5 files changed

+79
-8
lines changed

5 files changed

+79
-8
lines changed

package-lock.json

Lines changed: 49 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "algorithm-visualizer",
3-
"version": "2.1.3",
3+
"version": "2.1.4",
44
"description": "JavaScript Tracers for Algorithm Visualizer",
55
"main": "dist/tracers.js",
66
"scripts": {
@@ -20,6 +20,11 @@
2020
"clean-webpack-plugin": "^0.1.19",
2121
"uglifyjs-webpack-plugin": "^1.2.7",
2222
"webpack": "^4.15.1",
23-
"webpack-cli": "^3.0.8"
23+
"webpack-cli": "^3.0.8",
24+
"webpack-node-externals": "^1.7.2"
25+
},
26+
"dependencies": {
27+
"axios": "^0.18.0",
28+
"opn": "^5.4.0"
2429
}
2530
}

src/Tracer.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,18 @@ class Tracer {
4343
Tracer.tracerCount = 0;
4444
Tracer.traces = [];
4545

46+
const { ALGORITHM_VISUALIZER } = process.env;
47+
if (ALGORITHM_VISUALIZER) {
48+
} else {
49+
const axios = require('axios');
50+
const opn = require('opn');
51+
process.on('beforeExit', () => {
52+
axios.post('https://algorithm-visualizer.org/api/visualizations', { content: JSON.stringify(Tracer.traces) })
53+
.then(response => {
54+
opn(response.data, { wait: false });
55+
process.exit();
56+
});
57+
});
58+
}
59+
4660
export default Tracer;

test/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const { LogTracer } = require('../dist/algorithm-visualizer');
2+
3+
const logTracer = new LogTracer();
4+
5+
for (let i = 0; i < 3; i++)
6+
logTracer.print('tt ee ss tt').delay();

webpack.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const nodeExternals = require('webpack-node-externals');
12
const CleanWebpackPlugin = require('clean-webpack-plugin');
23
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
34
const path = require('path');
@@ -6,8 +7,9 @@ const buildPath = path.resolve(__dirname, 'dist');
67
const srcPath = path.resolve(__dirname, 'src');
78

89
module.exports = [{
9-
target: 'web',
10+
target: 'node',
1011
entry: srcPath,
12+
externals: [nodeExternals()],
1113
resolve: {
1214
modules: [path.resolve(__dirname, 'node_modules')],
1315
extensions: ['.js'],

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy