Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependencies and use esbuild for bundling #303

Merged
merged 2 commits into from
Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions copy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const { copyFileSync } = require("fs");
import { copyFileSync } from "fs";

copyFileSync("insect.js", "web/insect.js");
copyFileSync("node_modules/keyboardevent-key-polyfill/index.js", "web/keyboardevent-key-polyfill.js");
copyFileSync("node_modules/jquery/dist/jquery.min.js", "web/jquery.min.js");
copyFileSync("node_modules/jquery.terminal/js/jquery.terminal.min.js", "web/jquery.terminal.min.js");
Expand Down
24 changes: 10 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/usr/bin/env node

var os = require("os");
var path = require("path");
var Insect = require('./output/Insect/index.js');
import * as Insect from "./output/Insect/index.js";
import * as path from "path";

var insectEnv = Insect.initialEnvironment;

Expand Down Expand Up @@ -46,7 +45,8 @@ if (process.argv.length >= 4) {
}

if (process.env.INSECT_NO_RC !== "true") {
var lineReader = require("line-reader");
var [os, lineReader] = await Promise.all([import("os"), import("line-reader")]);

var rcFile = path.join(os.homedir(), ".insectrc");
lineReader.eachLine(rcFile, function (line) {
var res = runInsect(Insect.fmtPlain, line);
Expand All @@ -67,18 +67,14 @@ if (process.env.INSECT_NO_RC !== "true") {
startInsect();
}

function startInsect() {
async function startInsect() {
var interactive = process.stdin.isTTY;

if (interactive) {
var readline = require('readline');
var xdgBasedir = require('xdg-basedir');
var path = require('path');
var clipboardy = require('clipboardy');
var fs = require('fs');
var [fs, clipboardy, readline, xdgBasedir] = await Promise.all([import("fs"), import("clipboardy"), import("readline"), import("xdg-basedir")]);

// Open the history file for reading and appending.
var historyFd = fs.openSync(path.join(xdgBasedir.data, "insect-history"), 'a+');
var historyFd = fs.openSync(path.join(xdgBasedir.xdgData, "insect-history"), 'a+');

var maxHistoryLength = 5000;

Expand Down Expand Up @@ -161,11 +157,11 @@ function startInsect() {

rl.prompt();
} else {
// Read from non-interactive stream (shell pipe)

if (typeof lineReader === "undefined") {
var lineReader = require("line-reader");
var lineReader = await import("line-reader");
}

// Read from non-interactive stream (shell pipe)
lineReader.eachLine(process.stdin, function(line) {
var res = runInsect(Insect.fmtPlain, line);
if (res) {
Expand Down
Loading