mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-10 09:43:54 +01:00
Merge pull request #303 from kopelli/typescript
Add Typescript and TSLint to the tool chain
This commit is contained in:
commit
3a291cf4dd
2052
package-lock.json
generated
2052
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -62,6 +62,9 @@
|
||||
"sinon": "^2.3.2",
|
||||
"source-map": "^0.7.3",
|
||||
"style-loader": "^0.21.0",
|
||||
"ts-loader": "^4.4.1",
|
||||
"tslint": "^5.10.0",
|
||||
"typescript": "^2.9.2",
|
||||
"url-loader": "^1.0.1",
|
||||
"watchpack": "^1.6.0",
|
||||
"webpack": "^4.12.0",
|
||||
@ -84,6 +87,7 @@
|
||||
"start:dev": "webpack-dev-server",
|
||||
"build": "webpack --mode production",
|
||||
"build:dev": "webpack --mode development",
|
||||
"lint:typescript": "tslint --project . --exclude **/*.d.ts --format stylish src/**/*.ts utils/**/*.ts",
|
||||
"watch": "webpack --watch --mode production",
|
||||
"watch:dev": "webpack --watch --mode development"
|
||||
},
|
||||
|
@ -1,40 +1,43 @@
|
||||
/* HelpText.js */
|
||||
let TerminalHelpText =
|
||||
"Type 'help name' to learn more about the command 'name'<br><br>" +
|
||||
'alias [-g] [name="value"] Create or display Terminal aliases<br>' +
|
||||
"analyze Get information about the current machine <br>" +
|
||||
"buy [-l/program] Purchase a program through the Dark Web<br>" +
|
||||
"cat [file] Display a .msg, .lit, or .txt file<br>" +
|
||||
"check [script] [args...] Print a script's logs to Terminal<br>" +
|
||||
"clear Clear all text on the terminal <br>" +
|
||||
"cls See 'clear' command <br>" +
|
||||
"connect [ip/hostname] Connects to a remote server<br>" +
|
||||
"download [script/text file] Downloads scripts or text files to your computer<br>" +
|
||||
"free Check the machine's memory (RAM) usage<br>" +
|
||||
"hack Hack the current machine<br>" +
|
||||
"help [command] Display this help text, or the help text for a command<br>" +
|
||||
"home Connect to home computer<br>" +
|
||||
"hostname Displays the hostname of the machine<br>" +
|
||||
"ifconfig Displays the IP address of the machine<br>" +
|
||||
"kill [script] [args...] Stops the specified script on the current server <br>" +
|
||||
"killall Stops all running scripts on the current machine<br>" +
|
||||
"ls [| grep pattern] Displays all files on the machine<br>" +
|
||||
"lscpu Displays the number of CPU cores on the machine<br>" +
|
||||
"mem [script] [-t] [n] Displays the amount of RAM required to run the script<br>" +
|
||||
"nano [file] Text editor - Open up and edit a script or text file<br>" +
|
||||
"ps Display all scripts that are currently running<br>" +
|
||||
"rm [file] Delete a file from the server<br>" +
|
||||
"run [name] [-t] [n] [args...] Execute a program or script<br>" +
|
||||
"scan Prints all immediately-available network connections<br>" +
|
||||
"scan-analyze [d] [-a] Prints info for all servers up to <i>d</i> nodes away<br>" +
|
||||
"scp [file] [server] Copies a file to a destination server<br>" +
|
||||
"sudov Shows whether you have root access on this computer<br>" +
|
||||
"tail [script] [args...] Displays dynamic logs for the specified script<br>" +
|
||||
"theme [preset] | bg txt hlgt Change the color scheme of the UI<br>" +
|
||||
"top Displays all running scripts and their RAM usage<br>" +
|
||||
'unalias "[alias name]" Deletes the specified alias<br>';
|
||||
/* tslint:disable:max-line-length completed-docs variable-name*/
|
||||
export const TerminalHelpText: string =
|
||||
"Type 'help name' to learn more about the command 'name'<br><br>" +
|
||||
'alias [-g] [name="value"] Create or display Terminal aliases<br>' +
|
||||
"analyze Get information about the current machine <br>" +
|
||||
"buy [-l/program] Purchase a program through the Dark Web<br>" +
|
||||
"cat [file] Display a .msg, .lit, or .txt file<br>" +
|
||||
"check [script] [args...] Print a script's logs to Terminal<br>" +
|
||||
"clear Clear all text on the terminal <br>" +
|
||||
"cls See 'clear' command <br>" +
|
||||
"connect [ip/hostname] Connects to a remote server<br>" +
|
||||
"download [script/text file] Downloads scripts or text files to your computer<br>" +
|
||||
"free Check the machine's memory (RAM) usage<br>" +
|
||||
"hack Hack the current machine<br>" +
|
||||
"help [command] Display this help text, or the help text for a command<br>" +
|
||||
"home Connect to home computer<br>" +
|
||||
"hostname Displays the hostname of the machine<br>" +
|
||||
"ifconfig Displays the IP address of the machine<br>" +
|
||||
"kill [script] [args...] Stops the specified script on the current server <br>" +
|
||||
"killall Stops all running scripts on the current machine<br>" +
|
||||
"ls [| grep pattern] Displays all files on the machine<br>" +
|
||||
"lscpu Displays the number of CPU cores on the machine<br>" +
|
||||
"mem [script] [-t] [n] Displays the amount of RAM required to run the script<br>" +
|
||||
"nano [file] Text editor - Open up and edit a script or text file<br>" +
|
||||
"ps Display all scripts that are currently running<br>" +
|
||||
"rm [file] Delete a file from the server<br>" +
|
||||
"run [name] [-t] [n] [args...] Execute a program or script<br>" +
|
||||
"scan Prints all immediately-available network connections<br>" +
|
||||
"scan-analyze [d] [-a] Prints info for all servers up to <i>d</i> nodes away<br>" +
|
||||
"scp [file] [server] Copies a file to a destination server<br>" +
|
||||
"sudov Shows whether you have root access on this computer<br>" +
|
||||
"tail [script] [args...] Displays dynamic logs for the specified script<br>" +
|
||||
"theme [preset] | bg txt hlgt Change the color scheme of the UI<br>" +
|
||||
"top Displays all running scripts and their RAM usage<br>" +
|
||||
'unalias "[alias name]" Deletes the specified alias<br>';
|
||||
|
||||
let HelpTexts = {
|
||||
interface IMap<T> {
|
||||
[key: string]: T;
|
||||
}
|
||||
export const HelpTexts: IMap<string> = {
|
||||
alias: 'alias [-g] [name="value"] <br>' +
|
||||
"Create or display aliases. An alias enables a replacement of a word with another string. " +
|
||||
"It can be used to abbreviate a commonly used command, or commonly used parts of a command. The NAME " +
|
||||
@ -212,6 +215,4 @@ let HelpTexts = {
|
||||
'unalias "r"<br><br>' +
|
||||
"It is not necessary to differentiate between global and non-global aliases when using 'unalias'",
|
||||
|
||||
}
|
||||
|
||||
export {TerminalHelpText, HelpTexts};
|
||||
};
|
@ -36,7 +36,7 @@ import {StockMarket, StockSymbols, SymbolToStockMap, initStockSymbols,
|
||||
Stock, shortStock, sellShort, OrderTypes,
|
||||
PositionTypes, placeOrder, cancelOrder} from "./StockMarket.js";
|
||||
import {post} from "./Terminal.js";
|
||||
import {TextFile, getTextFile, createTextFile} from "./TextFile.js";
|
||||
import {TextFile, getTextFile, createTextFile} from "./TextFile";
|
||||
|
||||
import {WorkerScript, workerScripts,
|
||||
killWorkerScript, NetscriptPorts} from "./NetscriptWorker.js";
|
||||
|
@ -30,7 +30,7 @@ import {Player} from "./Player.js";
|
||||
import {AllServers, processSingleServerGrowth} from "./Server.js";
|
||||
import {Settings} from "./Settings.js";
|
||||
import {post, Terminal} from "./Terminal.js";
|
||||
import {TextFile} from "./TextFile.js";
|
||||
import {TextFile} from "./TextFile";
|
||||
|
||||
import {parse, Node} from "../utils/acorn.js";
|
||||
import {dialogBoxCreate} from "../utils/DialogBox.js";
|
||||
|
@ -9,7 +9,7 @@ import {executeDarkwebTerminalCommand,
|
||||
import {Engine} from "./engine.js";
|
||||
import {FconfSettings, parseFconfSettings,
|
||||
createFconf} from "./Fconf.js";
|
||||
import {TerminalHelpText, HelpTexts} from "./HelpText.js";
|
||||
import {TerminalHelpText, HelpTexts} from "./HelpText";
|
||||
import {iTutorialNextStep, iTutorialSteps,
|
||||
iTutorialIsRunning,
|
||||
currITutorialStep} from "./InteractiveTutorial.js";
|
||||
@ -29,8 +29,7 @@ import {AllServers, GetServerByHostname,
|
||||
import {Settings} from "./Settings.js";
|
||||
import {SpecialServerIps,
|
||||
SpecialServerNames} from "./SpecialServerIps.js";
|
||||
import {TextFile, getTextFile,
|
||||
createTextFile} from "./TextFile.js";
|
||||
import {TextFile, getTextFile} from "./TextFile";
|
||||
|
||||
import {containsAllStrings, longestCommonStart,
|
||||
formatNumber, isString} from "../utils/StringHelperFunctions.js";
|
||||
|
@ -1,90 +0,0 @@
|
||||
import {Server} from "./Server.js";
|
||||
import {dialogBoxCreate} from "../utils/DialogBox.js";
|
||||
import {Reviver, Generic_toJSON,
|
||||
Generic_fromJSON} from "../utils/JSONReviver.js";
|
||||
|
||||
function TextFile(fn="", txt="") {
|
||||
this.fn = fn.endsWith(".txt") ? fn : fn + ".txt";
|
||||
this.fn = this.fn.replace(/\s+/g, '');
|
||||
this.text = String(txt);
|
||||
}
|
||||
|
||||
TextFile.prototype.append = function(txt) {
|
||||
this.text += String(txt);
|
||||
}
|
||||
|
||||
TextFile.prototype.write = function(txt) {
|
||||
this.text = String(txt);
|
||||
}
|
||||
|
||||
TextFile.prototype.read = function() {
|
||||
return this.txt;
|
||||
}
|
||||
|
||||
TextFile.prototype.show = function() {
|
||||
dialogBoxCreate(this.fn + "<br><br>" + this.text, true);
|
||||
}
|
||||
|
||||
TextFile.prototype.download = function() {
|
||||
var filename = this.fn;
|
||||
var file = new Blob([this.text], {type: 'text/plain'});
|
||||
if (window.navigator.msSaveOrOpenBlob) {// IE10+
|
||||
window.navigator.msSaveOrOpenBlob(file, filename);
|
||||
} else { // Others
|
||||
var a = document.createElement("a"),
|
||||
url = URL.createObjectURL(file);
|
||||
a.href = url;
|
||||
a.download = this.fn;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
setTimeout(function() {
|
||||
document.body.removeChild(a);
|
||||
window.URL.revokeObjectURL(url);
|
||||
}, 0);
|
||||
}
|
||||
}
|
||||
|
||||
TextFile.prototype.toJSON = function() {
|
||||
return Generic_toJSON("TextFile", this);
|
||||
}
|
||||
|
||||
TextFile.fromJSON = function(value) {
|
||||
return Generic_fromJSON(TextFile, value.data);
|
||||
}
|
||||
|
||||
Reviver.constructors.TextFile = TextFile;
|
||||
|
||||
function getTextFile(fn, server) {
|
||||
if (!fn.endsWith(".txt")) {fn += ".txt";}
|
||||
for (var i = 0; i < server.textFiles.length; ++i) {
|
||||
if (server.textFiles[i].fn === fn) {
|
||||
return server.textFiles[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
//Returns the TextFile object that was just created
|
||||
function createTextFile(fn, txt, server) {
|
||||
if (getTextFile(fn, server) !== null) {
|
||||
console.log("ERROR: createTextFile failed because the specified " +
|
||||
"server already has a text file with the same fn");
|
||||
return;
|
||||
}
|
||||
var file = new TextFile(fn, txt);
|
||||
server.textFiles.push(file);
|
||||
return file;
|
||||
}
|
||||
|
||||
function deleteTextFile(fn, server) {
|
||||
if (!fn.endsWith(".txt")) {fn += ".txt";}
|
||||
for (var i = 0; i < server.textFiles.length; ++i) {
|
||||
if (server.textFiles[i].fn === fn) {
|
||||
server.textFiles.splice(i, 1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export {TextFile, getTextFile, createTextFile};
|
147
src/TextFile.ts
Normal file
147
src/TextFile.ts
Normal file
@ -0,0 +1,147 @@
|
||||
import { dialogBoxCreate } from "../utils/DialogBox";
|
||||
import { Generic_fromJSON, Generic_toJSON, Reviver } from "../utils/JSONReviver";
|
||||
|
||||
/**
|
||||
* Represents a plain text file that is typically stored on a server.
|
||||
*/
|
||||
export class TextFile {
|
||||
/**
|
||||
* Initiatizes a TextFile from a JSON save state.
|
||||
*/
|
||||
static fromJSON(value: any): TextFile {
|
||||
return Generic_fromJSON(TextFile, value.data);
|
||||
}
|
||||
|
||||
/**
|
||||
* The full file name.
|
||||
*/
|
||||
fn: string;
|
||||
|
||||
/**
|
||||
* The content of the file.
|
||||
*/
|
||||
text: string;
|
||||
|
||||
constructor(fn: string = "", txt: string = "") {
|
||||
this.fn = (fn.endsWith(".txt") ? fn : `${fn}.txt`).replace(/\s+/g, "");
|
||||
this.text = txt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Concatenates the raw values to the end of current content.
|
||||
*/
|
||||
append(txt: string): void {
|
||||
this.text += txt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serves the file to the user as a downloadable resource through the browser.
|
||||
*/
|
||||
download(): void {
|
||||
const filename: string = this.fn;
|
||||
const file: Blob = new Blob([ this.text ], { type: "text/plain" });
|
||||
/* tslint:disable-next-line:strict-boolean-expressions */
|
||||
if (window.navigator.msSaveOrOpenBlob) {
|
||||
// IE10+
|
||||
window.navigator.msSaveOrOpenBlob(file, filename);
|
||||
} else {
|
||||
// Others
|
||||
const a: HTMLAnchorElement = document.createElement("a");
|
||||
const url: string = URL.createObjectURL(file);
|
||||
a.href = url;
|
||||
a.download = this.fn;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
setTimeout(
|
||||
() => {
|
||||
document.body.removeChild(a);
|
||||
window.URL.revokeObjectURL(url);
|
||||
},
|
||||
0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the content of the file.
|
||||
*/
|
||||
read(): string {
|
||||
return this.text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the content to the user via the game's dialog box.
|
||||
*/
|
||||
show(): void {
|
||||
dialogBoxCreate(`${this.fn}<br /><br />${this.text}`, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize the current file to a JSON save state.
|
||||
*/
|
||||
toJSON(): any {
|
||||
return Generic_toJSON("TextFile", this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces the current content with the text provided.
|
||||
*/
|
||||
write(txt: string): void {
|
||||
this.text = txt;
|
||||
}
|
||||
}
|
||||
|
||||
Reviver.constructors.TextFile = TextFile;
|
||||
|
||||
/**
|
||||
* Retrieve the file object for the filename on the specified server.
|
||||
* @param fn The file name to look for
|
||||
* @param server The server object to look in
|
||||
* @returns The file object, or null if it couldn't find it.
|
||||
*/
|
||||
export function getTextFile(fn: string, server: any): TextFile | null {
|
||||
const filename: string = !fn.endsWith(".txt") ? `${fn}.txt` : fn;
|
||||
|
||||
for (const file of (server.textFiles as TextFile[])) {
|
||||
if (file.fn === filename) {
|
||||
return file;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a TextFile on the target server.
|
||||
* @param fn The file name to create.
|
||||
* @param txt The contents of the file.
|
||||
* @param server The server that the file should be created on.
|
||||
* @returns The instance of the file.
|
||||
*/
|
||||
export function createTextFile(fn: string, txt: string, server: any): TextFile | undefined {
|
||||
if (getTextFile(fn, server) !== null) {
|
||||
// This should probably be a `throw`...
|
||||
/* tslint:disable-next-line:no-console */
|
||||
console.error(`A file named "${fn}" already exists on server ${server.hostname}.`);
|
||||
|
||||
return undefined;
|
||||
}
|
||||
const file: TextFile = new TextFile(fn, txt);
|
||||
server.textFiles.push(file);
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
/* tslint:disable-next-line:no-unused-variable */
|
||||
function deleteTextFile(fn: string, server: any): boolean {
|
||||
const filename: string = !fn.endsWith(".txt") ? `${fn}.txt` : fn;
|
||||
/* tslint:disable-next-line:typedef */
|
||||
for (let i = 0; i < server.textFiles.length; ++i) {
|
||||
if (server.textFiles[i].fn === filename) {
|
||||
server.textFiles.splice(i, 1);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
11
tsconfig.json
Normal file
11
tsconfig.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"sourceMap": true,
|
||||
"strict": true
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
]
|
||||
}
|
76
tslint.json
Normal file
76
tslint.json
Normal file
@ -0,0 +1,76 @@
|
||||
{
|
||||
"defaultSeverity": "error",
|
||||
"extends": [
|
||||
"tslint:all"
|
||||
],
|
||||
"jsRules": {},
|
||||
"linterOptions": {
|
||||
"exclude": [
|
||||
"node_modules/"
|
||||
]
|
||||
},
|
||||
"rules": {
|
||||
"completed-docs": [
|
||||
true,
|
||||
{
|
||||
"classes": true,
|
||||
"enums": true,
|
||||
"enum-members": true,
|
||||
"functions": {
|
||||
"visibilities": [
|
||||
"exported"
|
||||
]
|
||||
},
|
||||
"interfaces": true,
|
||||
"methods": {
|
||||
"privacies": [
|
||||
"public"
|
||||
]
|
||||
},
|
||||
"namespaces": true,
|
||||
"properties": true,
|
||||
"types": true,
|
||||
"variables": {
|
||||
"visibilities": [
|
||||
"exported"
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"linebreak-style": false,
|
||||
"member-access": [
|
||||
true,
|
||||
"no-public"
|
||||
],
|
||||
"no-any": false,
|
||||
"no-inferrable-types": [
|
||||
true,
|
||||
"ignore-params",
|
||||
"ignore-properties"
|
||||
],
|
||||
"no-null-keyword": false,
|
||||
"no-unsafe-any": false,
|
||||
"object-literal-key-quotes": [
|
||||
true,
|
||||
"as-needed"
|
||||
],
|
||||
"only-arrow-functions": [
|
||||
true,
|
||||
"allow-declarations",
|
||||
"allow-named-functions"
|
||||
],
|
||||
"typedef": [
|
||||
true,
|
||||
"call-signatures",
|
||||
"arrow-call-signatures",
|
||||
"parameter",
|
||||
"arrow-parameter",
|
||||
"property-declaration",
|
||||
"variable-declaration",
|
||||
"member-variable-declaration",
|
||||
"object-destructuring",
|
||||
"array-destructuring"
|
||||
]
|
||||
},
|
||||
"rulesDirectory": []
|
||||
}
|
2
utils/DialogBox.d.ts
vendored
Normal file
2
utils/DialogBox.d.ts
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
export function dialogBoxCreate(txt: string, preformatted: boolean): void;
|
||||
export var dialogBoxOpened: boolean;
|
10
utils/JSONReviver.d.ts
vendored
Normal file
10
utils/JSONReviver.d.ts
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
interface IReviverValue {
|
||||
ctor: string;
|
||||
data: object
|
||||
}
|
||||
export function Generic_fromJSON<T>(ctor: new () => T, data: any): T;
|
||||
export function Generic_toJSON(ctorName: string, obj: object, keys?: string[]): string;
|
||||
export function Reviver(key, value: IReviverValue);
|
||||
export namespace Reviver {
|
||||
export var constructors: any;
|
||||
}
|
@ -2,7 +2,6 @@ var path = require('path');
|
||||
var webpack = require('webpack');
|
||||
|
||||
module.exports = (env, argv) => ({
|
||||
//mode: "development",
|
||||
plugins: [
|
||||
new webpack.DefinePlugin({
|
||||
'process.env.NODE_ENV': argv.mode === 'development' ? "\"development\"" : "\"production\""
|
||||
@ -28,7 +27,13 @@ module.exports = (env, argv) => ({
|
||||
filename: "[name].bundle.js"
|
||||
},
|
||||
module: {
|
||||
rules: []
|
||||
rules: [
|
||||
{
|
||||
test: /\.tsx?$/,
|
||||
loader: 'ts-loader',
|
||||
exclude: /node_modules/
|
||||
}
|
||||
]
|
||||
},
|
||||
optimization: {
|
||||
removeAvailableModules: true,
|
||||
@ -47,5 +52,12 @@ module.exports = (env, argv) => ({
|
||||
},
|
||||
devServer: {
|
||||
publicPath: "/dist",
|
||||
},
|
||||
resolve: {
|
||||
extensions: [
|
||||
".tsx",
|
||||
".ts",
|
||||
".js"
|
||||
]
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user