Skip to content

Commit

Permalink
export bin as .mjs
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisCarriere committed Mar 3, 2024
1 parent 1b19782 commit 430e28a
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 24 deletions.
8 changes: 6 additions & 2 deletions bin/cli.ts → bin/cli.mts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@
import { Option } from "commander";
import { commander } from "substreams-sink";
import { action } from "../index.js";
import pkg from "../package.json" assert { type: "json" };
import { version } from "../version.js";

export interface CSVRunOptions extends commander.RunOptions {
schema: string;
filename?: string;
}

const name = "substreams-sink-csv";
const description = "Substreams Sink CSV";
const pkg = {name, version, description};

// Run Webhook Sink
const program = commander.program(pkg);
const command = commander.addRunOptions(program, pkg, {metrics: false, http: false});
const command = commander.addRunOptions(program, {metrics: false, http: false});
command.addOption(new Option("--filename <string>", "CSV filename (default: '<endpoint>-<module_hash>-<module_name>.csv')").env("FILENAME"));
command.addOption(new Option("--schema <string>", "SQL Table Schema for CSV").default("schema.sql").env("SCHEMA"));
command.action(action);
Expand Down
6 changes: 3 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import fs from "fs";
import path from "path";
import pkg from "./package.json" assert { type: "json" };
import { version } from './version.js'
import { setup, fileCursor } from "substreams-sink";
import { CSVRunOptions } from "./bin/cli.js"
import { CSVRunOptions } from "./bin/cli.mjs"
import { EntityChanges, getValuesInEntityChange } from "@substreams/sink-entity-changes/zod"
import logUpdate from "log-update";
import { getModuleHash, isRemotePath } from "./src/getModuleHash.js";
Expand All @@ -11,7 +11,7 @@ import { parseClock } from "./src/parseClock.js";
import { parseSchema } from "./src/parseSchema.js";

export async function action(options: CSVRunOptions ) {
console.log(`[substreams-sink-csv] v${pkg.version}`);
console.log(`[substreams-sink-csv] v${version}`);

// handle file system manifest
// can be removed when issue resolved
Expand Down
16 changes: 4 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,22 @@
"name": "substreams-sink-csv",
"description": "Substreams Sink CSV",
"type": "module",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"bin": {
"substreams-sink-csv": "dist/bin/cli.js"
"substreams-sink-csv": "dist/bin/cli.mjs"
},
"author": {
"name": "Denis",
"email": "[email protected]"
},
"files": [
"index.ts",
"version.ts",
"dist",
"bin",
"src"
],
"sideEffects": false,
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js",
"default": "./dist/index.js"
}
},
"scripts": {
"start": "tsc && node ./dist/bin/cli.js",
"start": "tsc && node ./dist/bin/cli.mjs",
"test": "bun test",
"posttest": "tsc --noEmit",
"prepublishOnly": "tsc"
Expand Down
2 changes: 1 addition & 1 deletion src/getModuleHash.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { readPackage } from "@substreams/manifest";
import { CSVRunOptions } from "../bin/cli.js";
import { CSVRunOptions } from "../bin/cli.mjs";
import { createModuleHashHex } from "@substreams/core";

export function isRemotePath(path: string): boolean {
Expand Down
2 changes: 1 addition & 1 deletion src/parseFilename.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from "path";
import fs from "fs";
import { CSVRunOptions } from "../bin/cli.js";
import { CSVRunOptions } from "../bin/cli.mjs";

export function parseFilename(moduleHash: string, options: CSVRunOptions) {
// user provided filename
Expand Down
9 changes: 4 additions & 5 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
{
"compilerOptions": {
"target": "ESNext",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"resolveJsonModule": true,
"declaration": true,
"declarationMap": true,
"sourceMap": true,
Expand All @@ -13,11 +12,11 @@
"strictNullChecks": true,
"alwaysStrict": true,
"skipLibCheck": true,
"types": ["bun-types"]
"types": ["@types/bun"]
},
"include": [
"index-csv.ts",
"src",
"bin/cli.ts"
"bin/cli.mts"
]
}
}
1 change: 1 addition & 0 deletions version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const version = "0.2.9";

0 comments on commit 430e28a

Please sign in to comment.