diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index b8c8eed..0000000 --- a/.eslintignore +++ /dev/null @@ -1,6 +0,0 @@ -node_modules/ -.esm-cache -lib -public/ -*hterm* -build diff --git a/build.sh b/build.sh deleted file mode 100644 index f449df8..0000000 --- a/build.sh +++ /dev/null @@ -1,85 +0,0 @@ -#! /usr/bin/env bash -### -### build.sh - Build WeTTy assets for packaging and dev -### -### Usage: -### build.sh [--flag] -### -### Options: -### --clean Clean repo and delete all built files -### --watch Run dev env and rebuild on change -### -h,--help Show this help dialogue - -set -eo pipefail -export NODE_ENV=development - -show_usage() { - : 'Print out help info' - # awk -F '### ' '/^### ?/ { print $2 }' "$0" - sed -n 's/^### \?//p' "$0" -} - -clean() { - : 'Clean repo and delete all built files' - rm -rf build yarn-error.log -} - -build-css() { - : 'build sass assets in to css files' - sass src/assets/scss:build/assets/css \ - --load-path=node_modules \ - -s compressed \ - --no-source-map "$@" -} - -build-js() { - : 'Compile all typescript to javescript' - tsc -p tsconfig.json "$@" -} - -build-assets() { - : 'Move assets not handled by sass and typescript to build dir' - mkdir -p build/assets - cp src/assets/*.ico build/assets -} - -watch() { - : 'Run dev env and rebuild on change' - build-assets - build-js - concurrently \ - --kill-others \ - --success first \ - "build-js --watch" \ - "build-css --watch" \ - "nodemon ." -} - -build() { - : 'Build all assets' - build-assets - build-css - build-js -} - -if [[ $# -eq 0 ]]; then - build - exit -fi -while test $# -gt 0; do - case $1 in - --watch) - watch - exit - ;; - --clean) - clean - exit - ;; - --help | -h) - show_usage - exit 1 - ;; - esac - shift -done diff --git a/package.json b/package.json index 24520d0..74b5276 100644 --- a/package.json +++ b/package.json @@ -12,13 +12,13 @@ ], "scripts": { "build": "snowpack build", - "dev": "snowpack dev", + "dev": "NODE_ENV=development concurrently --kill-others --success first \"snowpack dev\" \"nodemon .\"", "prepublishOnly": "snowpack build", + "lint": "eslint src/**/*.ts", "start": "NODE_ENV=production node .", - "lint": "eslint --ext .ts,.js .", "contributor": "all-contributors", "test": "mocha -r babel-register-ts src/**/*.spec.ts", - "clean": "bash build.sh --clean" + "clean": "rm -rf build yarn-error.log" }, "repository": { "type": "git", @@ -56,24 +56,37 @@ ] }, "snowpack": { - "install": [ - "@fortawesome/fontawesome-svg-core", - "@fortawesome/free-solid-svg-icons", - "file-type", - "lodash", - "socket.io-client", - "toastify-js", - "xterm", - "xterm-addon-fit" - ], + "installOptions": { + "sourceMap": true, + "installTypes": true + }, + "mount": { + "src/client": "/client", + "src/assets": "/assets" + }, "exclude": [ - "**" + "src/server/**/*.ts", + "src/*.ts" ], "plugins": [ [ "@snowpack/plugin-run-script", { - "cmd": "bash build.sh", + "cmd": "tsc -p tsconfig.browser.json --noEmit", + "watch": "$1 --watch" + } + ], + [ + "@snowpack/plugin-run-script", + { + "cmd": "sass src/assets/scss:build/assets/css --load-path=node_modules -s compressed --no-source-map", + "watch": "$1 --watch" + } + ], + [ + "@snowpack/plugin-run-script", + { + "cmd": "tsc -p tsconfig.node.json", "watch": "$1 --watch" } ] @@ -88,6 +101,7 @@ "file-type": "^12.3.0", "fs-extra": "^8.1.0", "helmet": "^3.20.1", + "json5": "^2.1.3", "lodash": "^4.17.19", "node-pty": "^0.9.0", "node-sass-middleware": "^0.11.0", diff --git a/src/client/wetty.ts b/src/client/wetty.ts index 2b47f76..868d882 100644 --- a/src/client/wetty.ts +++ b/src/client/wetty.ts @@ -1,9 +1,6 @@ -import _ from '/../web_modules/lodash.js'; -import { - dom, - library, -} from '/../web_modules/@fortawesome/fontawesome-svg-core.js'; -import { faCogs } from '/../web_modules/@fortawesome/free-solid-svg-icons.js'; +import _ from 'lodash'; +import { dom, library } from '@fortawesome/fontawesome-svg-core'; +import { faCogs } from '@fortawesome/free-solid-svg-icons'; import { FileDownloader } from './wetty/download.js'; import { disconnect } from './wetty/disconnect.js'; diff --git a/src/client/wetty/disconnect.ts b/src/client/wetty/disconnect.ts index 3535fb0..72a6cef 100644 --- a/src/client/wetty/disconnect.ts +++ b/src/client/wetty/disconnect.ts @@ -1,6 +1,6 @@ -import _ from '/../web_modules/lodash.js'; -import { verifyPrompt } from '../shared/verify'; -import { overlay } from '../shared/elements'; +import _ from 'lodash'; +import { verifyPrompt } from '../shared/verify.js'; +import { overlay } from '../shared/elements.js'; export function disconnect(reason: string): void { if (_.isNull(overlay)) return; diff --git a/src/client/wetty/download.ts b/src/client/wetty/download.ts index 286c8c0..0eaf508 100644 --- a/src/client/wetty/download.ts +++ b/src/client/wetty/download.ts @@ -1,6 +1,6 @@ // @ts-ignore -import Toastify from '/../web_modules/toastify-js.js'; -import fileType from '/../web_modules/file-type.js'; +import Toastify from 'toastify-js'; +import fileType from 'file-type'; const DEFAULT_FILE_BEGIN = '\u001b[5i'; const DEFAULT_FILE_END = '\u001b[4i'; diff --git a/src/client/wetty/mobile.ts b/src/client/wetty/mobile.ts index 6fda8a3..014c791 100644 --- a/src/client/wetty/mobile.ts +++ b/src/client/wetty/mobile.ts @@ -1,4 +1,4 @@ -import _ from '/../web_modules/lodash.js'; +import _ from 'lodash'; export function mobileKeyboard(): void { const [screen] = document.getElementsByClassName('xterm-screen'); diff --git a/src/client/wetty/shared/type.ts b/src/client/wetty/shared/type.ts index 3619019..44d68e6 100644 --- a/src/client/wetty/shared/type.ts +++ b/src/client/wetty/shared/type.ts @@ -1,4 +1,4 @@ -import { Terminal } from '/../../web_modules/xterm.js'; +import { Terminal } from 'xterm'; export class Term extends Terminal { resizeTerm(): void {} diff --git a/src/client/wetty/socket.ts b/src/client/wetty/socket.ts index 781531c..4195c8d 100644 --- a/src/client/wetty/socket.ts +++ b/src/client/wetty/socket.ts @@ -1,4 +1,4 @@ -import io from '/../../web_modules/socket.io-client.js'; +import io from 'socket.io-client'; const userRegex = new RegExp('ssh/[^/]+$'); export const trim = (str: string): string => str.replace(/\/*$/, ''); diff --git a/src/client/wetty/term.ts b/src/client/wetty/term.ts index 2b5fb41..08cc418 100644 --- a/src/client/wetty/term.ts +++ b/src/client/wetty/term.ts @@ -1,7 +1,7 @@ -import _ from '/../web_modules/lodash.js'; import type { Socket } from 'socket.io-client'; -import { FitAddon } from '/../web_modules/xterm-addon-fit.js'; -import { Terminal } from '/../web_modules/xterm.js'; +import _ from 'lodash'; +import { FitAddon } from 'xterm-addon-fit'; +import { Terminal } from 'xterm'; import type { Term } from './shared/type'; import { configureTerm } from './term/confiruragtion.js'; diff --git a/src/client/wetty/term/confiruragtion.ts b/src/client/wetty/term/confiruragtion.ts index e1d9aa9..72fb85a 100644 --- a/src/client/wetty/term/confiruragtion.ts +++ b/src/client/wetty/term/confiruragtion.ts @@ -1,4 +1,5 @@ -import _ from '/../../web_modules/lodash.js'; +import _ from 'lodash'; +import JSON5 from 'json5'; import type { Term } from '../shared/type'; import { copySelected, copyShortcut } from './confiruragtion/clipboard'; @@ -15,7 +16,7 @@ export function configureTerm(term: Term): void { editor.value = config; editor.addEventListener('keyup', () => { try { - const updated = JSON.parse(editor.value); + const updated = JSON5.parse(editor.value); const updatedConf = JSON.stringify(updated, null, 2); editor.value = updatedConf; editor.classList.remove('error'); diff --git a/src/client/wetty/term/confiruragtion/load.ts b/src/client/wetty/term/confiruragtion/load.ts index f5dfe36..ecfcae6 100644 --- a/src/client/wetty/term/confiruragtion/load.ts +++ b/src/client/wetty/term/confiruragtion/load.ts @@ -1,4 +1,4 @@ -import _ from '/../../../web_modules/lodash.js'; +import _ from 'lodash'; export function loadOptions(): object { const defaultOptions = { fontSize: 14 }; diff --git a/src/main.ts b/src/main.ts index 1f8d497..16ebbc5 100644 --- a/src/main.ts +++ b/src/main.ts @@ -93,7 +93,6 @@ if (!opts.help) { (async () => { const config = await loadConfigFile(opts.conf); const conf = mergeCliConf(opts, config); - console.log(conf); startServer( conf.ssh, conf.server, diff --git a/tsconfig.browser.json b/tsconfig.browser.json new file mode 100644 index 0000000..034dcb6 --- /dev/null +++ b/tsconfig.browser.json @@ -0,0 +1,6 @@ +{ + "extends": "./tsconfig.json", + "include": [ + "src/client" + ] +} diff --git a/tsconfig.json b/tsconfig.json index 12cadb1..faf727c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,55 +4,17 @@ "target": "es2019", "moduleResolution": "node", "declaration": true, - "declarationMap": true, "downlevelIteration": true, "esModuleInterop": true, "forceConsistentCasingInFileNames": true, - "incremental": true, "noFallthroughCasesInSwitch": true, "noImplicitAny": true, "noImplicitReturns": true, "noImplicitThis": true, "noUnusedLocals": true, "noUnusedParameters": true, - "outDir": "./build", "removeComments": true, "skipLibCheck": true, - "sourceMap": true, - "strict": true, - "baseUrl": ".", - "paths": { - "/*/web_modules/lodash.js": [ - "node_modules/@types/lodash/index.d.ts" - ], - "/*/web_modules/xterm.js": [ - "node_modules/xterm/typings/xterm.d.ts", - "node_modules/xterm" - ], - "/*/web_modules/xterm-addon-fit.js": [ - "node_modules/xterm-addon-fit" - ], - "/*/web_modules/toastify-js.js": [ - "node_modules/toastify-js" - ], - "/*/web_modules/file-type.js": [ - "node_modules/file-type" - ], - "/*/web_modules/socket.io-client.js": [ - "node_modules/@types/socket.io-client/index.d.ts" - ], - "/*/web_modules/@fortawesome/fontawesome-svg-core.js": [ - "node_modules/@fortawesome/fontawesome-svg-core" - ], - "/*/web_modules/@fortawesome/free-solid-svg-icons.js": [ - "node_modules/@fortawesome/free-solid-svg-icons" - ] - } - }, - "include": [ - "src" - ], - "exclude": [ - "node_modules/*" - ] + "strict": true + } } diff --git a/tsconfig.node.json b/tsconfig.node.json new file mode 100644 index 0000000..e0b6049 --- /dev/null +++ b/tsconfig.node.json @@ -0,0 +1,14 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "incremental": true, + "outDir": "./build", + "sourceMap": true + }, + "include": [ + "src" + ], + "exclude": [ + "src/client" + ] +} diff --git a/yarn.lock b/yarn.lock index 5a73642..8383b0d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3263,6 +3263,13 @@ json5@^1.0.1: dependencies: minimist "^1.2.0" +json5@^2.1.3: + version "2.1.3" + resolved "https://registry.yarnpkg.com/json5/-/json5-2.1.3.tgz#c9b0f7fa9233bfe5807fe66fcf3a5617ed597d43" + integrity sha512-KXPvOm8K9IJKFM0bmdn8QXh7udDh1g/giieX0NLCaMnb4hEiVFqnop2ImTXCc5e0/oHz3LTqmHGtExn5hfMkOA== + dependencies: + minimist "^1.2.5" + jsonfile@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-4.0.0.tgz#8771aae0799b64076b76640fca058f9c10e33ecb"