This commit is contained in:
Eugene Pankov 2021-05-22 15:52:23 +02:00
commit ff29392dad
No known key found for this signature in database
GPG Key ID: 5896FCBBDD1CF4F4
13 changed files with 4715 additions and 0 deletions

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
node_modules
index.d.ts
*.ignore.js
*.ignore.js.map
dist

2
.pug-lintrc.js Normal file
View File

@ -0,0 +1,2 @@
module.export = {
}

1
index.html Normal file
View File

@ -0,0 +1 @@
<!DOCTYPE html><html><head><base href="dist/"><meta name="viewport" content="initial-scale=1, minimal-ui, shrink-to-fit=no"><link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400" rel="stylesheet"><script src="index.js"></script><title>Terminus</title></head><body><div class="terminal"><iframe src="terminal.html"></iframe></div></body></html>

11
index.pug Normal file
View File

@ -0,0 +1,11 @@
doctype html
html
head
base(href='dist/')
meta(name='viewport', content='initial-scale=1, minimal-ui, shrink-to-fit=no')
link(href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400", rel="stylesheet")
script(src='index.js')
title Terminus
body
.terminal
iframe(src='terminal.html')

1
index.ts Normal file
View File

@ -0,0 +1 @@
import './styles.scss'

46
package.json Normal file
View File

@ -0,0 +1,46 @@
{
"name": "terminus-web",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"build": "webpack --progress",
"watch": "TERMINUS_DEV=1 webpack --progress --watch"
},
"private": true,
"devDependencies": {
"@fortawesome/fontawesome-free": "^5.7.2",
"@types/node": "^11.9.5",
"assert": "1.5.0",
"awesome-typescript-loader": "^5.2.1",
"bootstrap": "^4.3.1",
"browserify-zlib": "^0.2.0",
"buffer": "^6.0.3",
"core-js": "^3.8.3",
"crypto-browserify": "^3.12.0",
"css-loader": "^2.1.0",
"file-loader": "^1.1.11",
"js-yaml": "^4.1.0",
"node-sass": "^6.0.0",
"pug": "^2.0.3",
"pug-cli": "^1.0.0-alpha6",
"pug-html-loader": "^1.1.5",
"raw-loader": "^1.0.0",
"sass-loader": "^11.1.1",
"script-loader": "^0.7.2",
"setimmediate": "^1.0.5",
"source-code-pro": "^2.30.1",
"source-sans-pro": "^2.45.0",
"stream-browserify": "^3.0.0",
"style-loader": "^0.23.1",
"typescript": "3.3.3333",
"val-loader": "^1.1.1",
"webpack": "^5.37.0",
"webpack-cli": "^4.7.0"
},
"resolutions": {
"**/util": "^0.12.0"
},
"dependencies": {
"events": "^3.3.0"
}
}

27
styles.scss Normal file
View File

@ -0,0 +1,27 @@
$font-family-sans-serif: "Source Sans Pro";
$border-radius-lg: 0;
$btn-border-width: 3px;
// @import "node_modules/bootstrap/scss/bootstrap";
.terminal {
position: absolute;
top: 100px;
left: 100px;
width: calc(100vw - 200px);
height: calc(100vh - 200px);
border-radius: 9px;
overflow: hidden;
box-shadow: 0 0 100px black;
}
iframe {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
border: none;
}

18
terminal.d.ts vendored Normal file
View File

@ -0,0 +1,18 @@
/// <reference types="node" />
import 'core-js/proposals/reflect-metadata';
import '@fortawesome/fontawesome-free/css/solid.css';
import '@fortawesome/fontawesome-free/css/brands.css';
import '@fortawesome/fontawesome-free/css/fontawesome.css';
import 'source-code-pro/source-code-pro.css';
import 'source-sans-pro/source-sans-pro.css';
import { Duplex } from 'stream-browserify';
export declare class Socket extends Duplex {
webSocket: WebSocket;
constructor();
connect(): void;
setNoDelay(): void;
setTimeout(): void;
_read(size: number): void;
_write(chunk: Buffer, _encoding: string, callback: (error?: Error | null) => void): void;
_destroy(error: Error | null, callback: (error: Error | null) => void): void;
}

17
terminal.pug Normal file
View File

@ -0,0 +1,17 @@
doctype html
html
head
meta(charset='UTF-8')
script(src='./terminal.js')
style#custom-css
style.
body { transition: 0.5s background; }
body
app-root(style='display: none')
.preload-logo
div
.terminus-logo
h1.terminus-title Terminus
sup α
.progress
.bar(style='width: 0%')

379
terminal.ts Normal file
View File

@ -0,0 +1,379 @@
import 'core-js/proposals/reflect-metadata'
import '@fortawesome/fontawesome-free/css/solid.css'
import '@fortawesome/fontawesome-free/css/brands.css'
import '@fortawesome/fontawesome-free/css/fontawesome.css'
import 'source-code-pro/source-code-pro.css'
import 'source-sans-pro/source-sans-pro.css'
import * as yaml from 'js-yaml'
import { Duplex } from 'stream-browserify'
import { Buffer } from 'buffer'
export class Socket extends Duplex {
webSocket: WebSocket
constructor () {
console.warn('socket constr', arguments)
super({
allowHalfOpen: false,
})
}
connect () {
this.webSocket = new WebSocket('ws://localhost:9001/')
this.webSocket.onopen = event => {
this.emit('connect')
}
this.webSocket.onmessage = async event => {
this.emit('data', Buffer.from(await event.data.arrayBuffer()))
}
}
setNoDelay () {
}
setTimeout () {
}
_read (size: number): void {
console.warn('socket read', size)
}
_write (chunk: Buffer, _encoding: string, callback: (error?: Error | null) => void): void {
console.warn('socket write', chunk)
this.webSocket.send(chunk)
callback()
}
_destroy (error: Error|null, callback: (error: Error|null) => void): void {
console.warn('socket destroy', error)
callback(error)
}
}
async function start () {
class Logger {
constructor () {
for (let x of ['info', 'warn', 'error', 'log', 'debug']) {
this[x] = () => null
}
}
}
let windowReadyCallback
const configContent = `
enableAnalytics: false
enableWelcomeTab: false
terminal:
font: "Source Code Pro"
autoOpen: true
appearance:
vibrancy: false
pluginBlacklist: []
`
const config = yaml.load(configContent)
const mocks = {
fs: {
realpathSync: path => {
console.warn('mock realPathSync', path)
return path
},
existsSync: path => {
if (path === 'app-path/config.yaml') {
return true
}
console.warn('mock existsSync', path)
return false
},
mkdir: path => {
console.warn('mock mkdir', path)
},
mkdirSync: path => {
console.warn('mock mkdirSync', path)
},
stat: (path, cb) => {
if ([
'resources/builtin-plugins',
'resources/builtin-plugins/terminus-core/package.json',
'resources/builtin-plugins/terminus-ssh/package.json',
'resources/builtin-plugins/terminus-settings/package.json',
'resources/builtin-plugins/terminus-terminal/package.json',
].includes(path)) {
cb(null, {})
} else {
console.warn('mock stat', path)
cb('ENOEXIST')
}
},
writeFileSync: () => null,
readFileSync: (path) => {
if (path === 'app-path/config.yaml') {
return configContent
}
return ''
},
readFile: (path, enc, cb) => {
if ([
'resources/builtin-plugins/terminus-core/package.json',
'resources/builtin-plugins/terminus-ssh/package.json',
'resources/builtin-plugins/terminus-terminal/package.json',
'resources/builtin-plugins/terminus-settings/package.json',
].includes(path)) {
cb(null, '{ "keywords": ["terminus-builtin-plugin"], "author": "" }')
} else {
console.warn('mock readFile', path)
cb('UNKNOWN', null)
}
},
readdir: (path, cb) => {
if (path === 'resources/builtin-plugins') {
cb(null, [
'terminus-core',
'terminus-ssh',
'terminus-settings',
'terminus-terminal',
])
} else {
console.warn('mock readdir', path)
cb(null, [])
}
},
constants: {},
},
'@electron/remote': {
app: {
getVersion: () => '1.0-web',
getPath: () => 'app-path',
getWindow: () => ({
reload: () => null,
}),
},
screen: {
on: () => null,
getAllDisplays: () => [],
getPrimaryDisplay: () => ({}),
getCursorScreenPoint: () => ({}),
getDisplayNearestPoint: () => null,
},
globalShortcut: {
unregisterAll: () => null,
register: () => null,
},
autoUpdater: {
on: () => null,
once: () => null,
setFeedURL: () => null,
checkForUpdates: () => null,
},
BrowserWindow: {
fromId: () => ({
setOpacity: () => null,
setProgressBar: () => null,
}),
},
getGlobal: () => window['process'],
},
electron: {
ipcRenderer: {
on: () => null,
once: (e, c) => {
if (e === 'start') {
windowReadyCallback = c
}
},
send: msg => {
if (msg === 'ready') {
windowReadyCallback(null, {
config,
executable: '---',
})
}
console.log('[ipc]', msg)
}
},
},
path: {
join: (...x) => x.join('/'),
basename: x => x,
dirname: x => x,
relative: (a, b) => b,
resolve: (a, b) => {
console.warn('mock path.resolve', a, b)
return b
}
},
buffer: {
Buffer,
},
crypto: {
...require('crypto-browserify'),
getHashes () {
return ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160']
}
},
stream: require('stream-browserify'),
events: require('events'),
readline: {
cursorTo: () => null,
clearLine: stream => stream.write('\r'),
},
zlib: require('browserify-zlib'),
util: {
...require('util'),
promisify: () => null,
},
'any-promise': Promise,
net: {
Socket,
},
module: {
globalPaths: [],
},
assert: require('assert'),
url: {
parse: () => null,
},
http: {
Agent: { prototype: {} },
request: {},
},
https: {
Agent: { prototype: {} },
request: {},
},
querystring: {},
tty: { isatty: () => false },
child_process: {},
winston: {
Logger,
transports: {
File: Object,
Console: Object,
}
},
'readable-stream': {},
os: {
platform: () => 'linux',
homedir: () => '/home',
},
'mz/child_process': {
exec: (...x) => Promise.reject(),
},
'mz/fs': {
readFile: path => mocks.fs.readFileSync(path),
exists: path => mocks.fs.existsSync(path),
existsSync: path => mocks.fs.existsSync(path),
},
constants: {},
'hterm-umdjs': {
hterm: {
PreferenceManager: class { set () {} },
VT: {
ESC: {},
CSI: {},
OSC: {},
},
Terminal: class {},
Keyboard: class {},
},
lib: {
wc: {},
Storage: {
Memory: class {},
},
},
},
dns: {},
keytar: {
getPassword: () => null,
},
}
;(mocks.assert as any).assertNotStrictEqual = () => true
;(mocks.assert as any).notStrictEqual = () => true
let builtins = {
'@angular/core': require('@angular/core'),
'@angular/compiler': require('@angular/compiler'),
'@angular/common': require('@angular/common'),
'@angular/forms': require('@angular/forms'),
'@angular/platform-browser': require('@angular/platform-browser'),
'@angular/platform-browser/animations': require('@angular/platform-browser/animations'),
'@angular/platform-browser-dynamic': require('@angular/platform-browser-dynamic'),
'@angular/animations': require('@angular/animations'),
'@ng-bootstrap/ng-bootstrap': require('@ng-bootstrap/ng-bootstrap'),
'ngx-toastr': require('ngx-toastr'),
'deepmerge': require('deepmerge'),
'rxjs': require('rxjs'),
'rxjs/operators': require('rxjs/operators'),
'js-yaml': require('js-yaml'),
'zone.js/dist/zone.js': require('zone.js/dist/zone.js'),
}
Object.assign(window, {
require: (path) => {
if (mocks[path]) {
return mocks[path]
}
if (builtins[path]) {
return builtins[path]
}
console.warn('requiring', path)
},
process: {
env: { XWEB: 1, LOGNAME: 'root' },
argv: ['terminus'],
platform: 'linux',
on: () => null,
stdout: {},
stderr: {},
resourcesPath: 'resources',
version: '14.0.0',
nextTick: (f, ...args) => setTimeout(() => f(...args)),
// cwd: () => '/',
},
global: window,
})
window['require'].main = {
paths: []
}
window['module'] = {
paths: []
}
window['require'].resolve = path => null
window['Buffer'] = mocks.buffer.Buffer
window['__dirname'] = '__dirname'
window['setImmediate'] = setTimeout
mocks.module['prototype'] = { require: window['require'] }
let pluginCode = {
core: await import(/* webpackChunkName: "app" */ '../terminus/terminus-core/dist/index.js'),
ssh: await import(/* webpackChunkName: "app" */ '../terminus/terminus-ssh/dist/index.js'),
settings: await import(/* webpackChunkName: "app" */ '../terminus/terminus-settings/dist/index.js'),
terminal: await import(/* webpackChunkName: "app" */ '../terminus/terminus-terminal/dist/index.js'),
}
function loadPlugin (name) {
let code = `(function (exports, require, module) { \n${pluginCode[name].default}\n })`
let m = eval(code)
let module = { exports: {} }
m(module.exports, window['require'], module)
return module.exports
}
for (const plugin of ['core', 'settings', 'terminal', 'ssh']) {
builtins[`resources/builtin-plugins/terminus-${plugin}`] = builtins[`terminus-${plugin}`] = loadPlugin(plugin)
}
await import(/* webpackChunkName: "app" */ '../terminus/app/dist/preload.js')
document.querySelector('app-root')['style'].display = 'flex'
await import(/* webpackChunkName: "app" */ '../terminus/app/dist/bundle.js')
}
start()

26
tsconfig.json Normal file
View File

@ -0,0 +1,26 @@
{
"compilerOptions": {
"module": "esNext",
"target": "es6",
"moduleResolution": "node",
"noImplicitAny": false,
"removeComments": false,
"emitDeclarationOnly": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"declaration": true,
"lib": [
"dom",
"es5",
"es6",
"es7"
]
}
}

75
webpack.config.js Normal file
View File

@ -0,0 +1,75 @@
const path = require('path')
const webpack = require('webpack')
module.exports = {
target: 'web',
entry: {
'index.ignore': 'file-loader?name=../index.html!pug-html-loader!' + path.resolve(__dirname, './index.pug'),
'terminal.ignore': 'file-loader?name=terminal.html!pug-html-loader!' + path.resolve(__dirname, './terminal.pug'),
index: path.resolve(__dirname, 'index.ts'),
terminal: path.resolve(__dirname, 'terminal.ts'),
},
mode: process.env.TERMINUS_DEV ? 'development' : 'production',
context: __dirname,
devtool: 'cheap-module-source-map',
output: {
path: path.join(__dirname, 'dist'),
pathinfo: true,
filename: '[name].js',
chunkFilename: '[name].bundle.js',
},
resolve: {
modules: [
...[
'../terminus/terminus-core/node_modules/',
'../terminus/terminus-settings/node_modules/',
'../terminus/terminus-terminal/node_modules/',
'../terminus/node_modules',
'../terminus/app/node_modules',
'../terminus/app/assets/',
].map(x => path.join(__dirname, x)),
'node_modules/',
],
extensions: ['.ts', '.js'],
fallback: {
stream: require.resolve('stream-browserify'),
assert: require.resolve('assert'),
util: require.resolve('util'),
},
},
module: {
rules: [
{
test: /\.ts$/,
use: {
loader: 'awesome-typescript-loader',
options: {
configFileName: path.resolve(__dirname, 'tsconfig.json'),
},
},
},
{ test: /terminus\/app\/dist/, use: ['script-loader'] },
{ test: /dist\/index/, use: ['raw-loader'] },
{
test: /\.(ttf|eot|otf|woff|woff2)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
use: {
loader: 'file-loader',
options: {
name: 'fonts/[name].[ext]',
},
},
},
{ test: /\.scss$/, use: ['style-loader', 'css-loader', 'sass-loader'] },
{ test: /\.css$/, use: ['css-loader', 'sass-loader'] },
{
test: /\.(jpeg|png|svg)?$/,
use: {
loader: 'file-loader',
options: {
name: '[name].[ext]'
}
}
}
],
}
}

4107
yarn.lock Normal file

File diff suppressed because it is too large Load Diff