Skip to content

Commit

Permalink
Fix parcel build.
Browse files Browse the repository at this point in the history
  • Loading branch information
realazthat committed Sep 2, 2024
1 parent d1e2004 commit c3257c2
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 52 deletions.
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"test": "echo \"Error: no test specified\" && exit 1",
"start": "parcel serve src/index.html --public-url '/chatgpt2graph/' --no-cache --dist-dir dist/chatgpt2graph",
"serve": "serve dist/",
"build:parcel": "parcel build src/index.html --public-url '/chatgpt2graph/' --no-cache --dist-dir dist/chatgpt2graph",
"build:parcel": "rm -R dist/chatgpt2graph && parcel build src/index.html --public-url '/chatgpt2graph/' --no-cache --dist-dir dist/chatgpt2graph",
"build": "npm run build:parcel",
"format:js": "semistandard --fix --ignore 'dist/*' --ignore .cache --ignore .git --ignore node_modules",
"format:md": "prettier --parser markdown --write .github/README.md.jinja2 LICENSE.md",
Expand Down Expand Up @@ -58,6 +58,13 @@
"util": "^0.12.5",
"vm-browserify": "^1.1.2"
},
"targets": {
"modern": {
"engines": {
"browsers": ">= 50%"
}
}
},
"engines": {
"node": ">=18.0.0 <19.0.0 || >=20.0.0 <21.0.0 || >=21.0.0 <22.0.0 || >=22.0.0 <23.0.0"
},
Expand Down
59 changes: 51 additions & 8 deletions src/cli.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,63 @@
#!/usr/bin/env node
// @flow strict
import fs from 'fs';
import path from 'path';

import caporal from '@caporal/core';
import StreamArray from 'stream-json/streamers/StreamArray.js';
import StreamJSON from 'stream-json';

import { GraphStyle } from './graph.js';
import {
MakeGraph,
FileConversationIterator,
IntermediaryOutputInterface,
ConversationIteratorInterface,
// eslint-disable-next-line no-unused-vars
GraphOutputInterface
GraphOutputInterface,
IntermediaryOutputInterface,
MakeGraph
} from './parser.js';
import { GraphStyle } from './graph.js';
import { version } from '../lib/version.js';
import caporal from '@caporal/core';
import fs from 'fs';
import path from 'path';

const { Parser } = StreamJSON;
const { streamArray } = StreamArray;
const { program } = caporal;

class FileConversationIterator extends ConversationIteratorInterface {
/*::
ConversationJSONPath: string;
processedSize: number;
totalSize: number;
pipeline: StreamArray;
*/
constructor ({ ConversationJSONPath } /*: {ConversationJSONPath: string} */) {
super();
this.ConversationJSONPath = ConversationJSONPath;
this.processedSize = 0;
this.totalSize = 0;
const self = this;
this.pipeline = fs.createReadStream(this.ConversationJSONPath)
.on('data', async chunk => {
self.processedSize += chunk.length;
if (self.totalSize === 0) {
self.totalSize = (await fs.promises.stat(self.ConversationJSONPath)).size;
}
})
.pipe(new Parser())
.pipe(streamArray());
}

async * Next () /*: AsyncGenerator<any, void, void> */ {
for await (const { value: conv } of this.pipeline) {
yield conv;
}
// TODO: This kills the program for some reason.
// await once(this.pipeline, 'end');
}

Progress () /*: number */ {
return (this.processedSize / this.totalSize);
}
}

class FileIntermediaryOutput extends IntermediaryOutputInterface {
/*::
intermediaryDir: string|void;
Expand Down
43 changes: 0 additions & 43 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,13 @@ type YearWeekStr = string;
type GraphData = Map<YearWeek, number>;
*/
import StreamJSON from 'stream-json';
import fs from 'fs';
import StreamArray from 'stream-json/streamers/StreamArray.js';
import * as dateFns from 'date-fns';
// $FlowFixMe - Flow doesn't recognize `once` export correctly
// import { once } from 'events';
import jsdom from 'jsdom';

// eslint-disable-next-line no-unused-vars
import { GraphInfo, GraphStyle, DrawGraphToSVG } from './graph.js';
const { Parser } = StreamJSON;
const { streamArray } = StreamArray;
const { JSDOM } = jsdom;

function _Get (map /*: Map<YearWeekStr, number> */, key /*: YearWeekStr */) /*: number */ {
Expand Down Expand Up @@ -139,43 +134,6 @@ class ConversationIteratorInterface {
}
}

class FileConversationIterator extends ConversationIteratorInterface {
/*::
ConversationJSONPath: string;
processedSize: number;
totalSize: number;
pipeline: StreamArray;
*/
constructor ({ ConversationJSONPath } /*: {ConversationJSONPath: string} */) {
super();
this.ConversationJSONPath = ConversationJSONPath;
this.processedSize = 0;
this.totalSize = 0;
const self = this;
this.pipeline = fs.createReadStream(this.ConversationJSONPath)
.on('data', async chunk => {
self.processedSize += chunk.length;
if (self.totalSize === 0) {
self.totalSize = (await fs.promises.stat(self.ConversationJSONPath)).size;
}
})
.pipe(new Parser())
.pipe(streamArray());
}

async * Next () /*: AsyncGenerator<any, void, void> */ {
for await (const { value: conv } of this.pipeline) {
yield conv;
}
// TODO: This kills the program for some reason.
// await once(this.pipeline, 'end');
}

Progress () /*: number */ {
return (this.processedSize / this.totalSize);
}
}

class GraphOutputInterface {
async SVG ({ style } /*: {style: GraphStyle} */)/*: Promise<string> */ {
throw new Error('Unimplemented');
Expand Down Expand Up @@ -311,7 +269,6 @@ async function MakeGraph ({ words, conversations, intermediary }/*: {words: Arra

export {
MakeGraph,
FileConversationIterator,
GraphOutputInterface,
IntermediaryOutputInterface,
ConversationIteratorInterface
Expand Down

0 comments on commit c3257c2

Please sign in to comment.