Browse Source

use snowpack build to rewrite webmodule imports

pull/270/head
butlerx 4 years ago
parent
commit
ec669cb4c5
No known key found for this signature in database GPG Key ID: B37CA765BAA89170
  1. 6
      .eslintignore
  2. 85
      build.sh
  3. 44
      package.json
  4. 9
      src/client/wetty.ts
  5. 6
      src/client/wetty/disconnect.ts
  6. 4
      src/client/wetty/download.ts
  7. 2
      src/client/wetty/mobile.ts
  8. 2
      src/client/wetty/shared/type.ts
  9. 2
      src/client/wetty/socket.ts
  10. 6
      src/client/wetty/term.ts
  11. 5
      src/client/wetty/term/confiruragtion.ts
  12. 2
      src/client/wetty/term/confiruragtion/load.ts
  13. 1
      src/main.ts
  14. 6
      tsconfig.browser.json
  15. 42
      tsconfig.json
  16. 14
      tsconfig.node.json
  17. 7
      yarn.lock

6
.eslintignore

@ -1,6 +0,0 @@
node_modules/
.esm-cache
lib
public/
*hterm*
build

85
build.sh

@ -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

44
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",

9
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';

6
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;

4
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';

2
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');

2
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 {}

2
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(/\/*$/, '');

6
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';

5
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');

2
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 };

1
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,

6
tsconfig.browser.json

@ -0,0 +1,6 @@
{
"extends": "./tsconfig.json",
"include": [
"src/client"
]
}

42
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
}
}

14
tsconfig.node.json

@ -0,0 +1,14 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"incremental": true,
"outDir": "./build",
"sourceMap": true
},
"include": [
"src"
],
"exclude": [
"src/client"
]
}

7
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"

Loading…
Cancel
Save