clean up files

main
Olivier Gagnon 2 years ago
parent 52f9dc5671
commit 8423852a8b

@ -1,26 +0,0 @@
module.exports = {
env: {
browser: true,
commonjs: true,
es6: false,
},
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"],
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaVersion: 8,
sourceType: "module",
ecmaFeatures: {
experimentalObjectRestSpread: true,
},
project: ['./tsconfig.json'],
tsconfigRootDir: __dirname,
},
plugins: ["@typescript-eslint"],
ignorePatterns: ['*.d.ts', '*.js'],
rules: {
'no-constant-condition': ['off'],
"@typescript-eslint/no-floating-promises": "error",
}
}

@ -1,4 +1,5 @@
## Extension Recommendations
[vscode-bitburner-connector](https://github.com/bitburner-official/bitburner-vscode) ([vscode extension marketplace](https://marketplace.visualstudio.com/items?itemName=bitburner.bitburner-vscode-integration)) to upload your files into the game
[vscode-eslint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) to use live linting in editor
@ -8,61 +9,50 @@
There is a workspace file in `.vscode` which contains the recommended settings for all of these
## Dependencies
[Node.js](https://nodejs.org/en/download/) required for compiling typescript and installing dependencies
## Installation
```
git clone https://github.com/bitburner-official/vscode-template
npm install
npm run defs
git clone https://github.com/bitburner-official/typescript-template
npm i
```
## How to use this template
Write all your typescript source code in the `/src` directory
To autocompile as you save, run `npm run watch` in a terminal
To update your Netscript Definitions, run `npm run defs` in a terminal
Press F1 and Select `Bitburner: Enable File Watcher` to enable auto uploading to the game
If you run `watcher.js` in game, the game will automatically detect file changes and restart the associated scripts
## Imports
To ensure both the game and typescript have no issues with import paths, your import statements should follow a few formatting rules:
* Paths must be absolute from the root of `src/`, which will be equivalent to the root directory of your home drive
* Paths must contain no leading slash
* Paths must end with no file extension
- Paths must be absolute from the root of `src/`, which will be equivalent to the root directory of your home drive
- Paths must contain no leading slash
- Paths must end with no file extension
### Examples:
### Examples:
To import `helperFunction` from the file `helpers.ts` located in the directory `src/lib/`:
To import `helperFunction` from the file `helpers.ts` located in the directory `src/lib/`:
```js
import { helperFunction } from 'lib/helpers'
import { helperFunction } from "lib/helpers";
```
To import all functions from the file `helpers.ts` located in the `src/lib/` directory as the namespace `helpers`:
```js
import * as helpers from 'lib/helpers'
import * as helpers from "lib/helpers";
```
To import `someFunction` from the file `main.ts` located in the `src/` directory:
```js
import { someFunction } from 'main'
import { someFunction } from "main";
```
## Deugging
For debugging bitburner on Steam you will need to enable a remote debugging port. This can be done by rightclicking bitburner in your Steam library and selecting properties. There you need to add `--remote-debugging-port=9222` [Thanks @DarkMio]
When debugging you see errors like the following:
```
Could not read source map for file:///path/to/Steam/steamapps/common/Bitburner/resources/app/dist/ext/monaco-editor/min/vs/editor/editor.main.js: ENOENT: no such file or directory, open '/path/to/Steam/steamapps/common/Bitburner/resources/app/dist/ext/monaco-editor/min/vs/editor/editor.main.js.map'
```
These errors are to be expected, they are referring to the game's files and the game does not come packaged with sourcemaps.

19
global.d.ts vendored

@ -1,19 +0,0 @@
import _ from 'lodash'
import * as bitburner from "./NetscriptDefinitions";
export { };
declare global {
const _: typeof _
interface NS extends bitburner.NS {}
type AutocompleteConfig = [string, string | number | boolean | string[]][];
interface AutocompleteData {
servers: string[],
txts: string[],
scripts: string[],
flags: (config: AutocompleteConfig) => any
}
}

3140
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -1,29 +1,11 @@
{
"name": "bitburner-typescript-template",
"version": "1.0.0",
"description": "",
"main": "index.js",
"version": "0.0.0",
"scripts": {
"watch": "npx tsc -w",
"lint": "eslint . --ext .ts",
"defs": "node ./updateDefs.js"
"watch": "npx tsc -w"
},
"repository": {
"type": "git",
"url": "git+https://github.com/bitburner-official/vscode-template.git"
},
"author": "SlyCedix",
"bugs": {
"url": "https://github.com/bitburner-official/vscode-template/issues"
},
"homepage": "https://github.com/bitburner-official/vscode-template#readme",
"author": "hydroflame, based on work by SlyCedix",
"devDependencies": {
"@types/lodash": "^4.14.178",
"@types/node": "^16.4.3",
"@typescript-eslint/eslint-plugin": "^4.28.4",
"@typescript-eslint/parser": "^4.28.4",
"eslint": "^7.31.0",
"ts-node": "^9.1.1",
"typescript": "^4.3.5"
"typescript": "^4.7.4"
}
}
}

@ -0,0 +1,5 @@
import { NS } from "@ns";
export async function main(ns: NS): Promise<void> {
ns.tprint("Hello Remote API!");
}

@ -1,53 +0,0 @@
import { NS, ProcessInfo } from '@ns'
export async function main(ns: NS): Promise<void> {
const hashes: Record<string,number> = {}
const files = ns.ls('home', '.js')
for (const file of files) {
const contents = ns.read(file)
hashes[file] = getHash(contents)
}
while (true) {
const files = ns.ls('home', '.js')
for (const file of files) {
const contents = ns.read(file)
const hash = getHash(contents)
if (hash != hashes[file]) {
ns.tprintf(`INFO: Detected change in ${file}`)
const processes = ns.ps().filter((p: ProcessInfo) => {
return p.filename == file
})
for (const process of processes) {
ns.tprintf(`INFO: Restarting ${process.filename} ${process.args} -t ${process.threads}`)
if (process.filename != ns.getScriptName()) {
ns.kill(process.pid)
ns.run(process.filename, process.threads, ...process.args)
} else {
ns.spawn(process.filename, process.threads, ...process.args)
}
}
hashes[file] = hash
}
}
await ns.sleep(1000)
}
}
const getHash = (input: string): number => {
let hash = 0, i, chr
if (input.length === 0) return hash
for (i = 0; i < input.length; i++) {
chr = input.charCodeAt(i)
hash = ((hash << 5) - hash) + chr
hash |= 0 // Convert to 32bit integer
}
return hash
}

@ -1,9 +1,5 @@
{
"include": [
"NetscriptDefinitions.d.ts",
"global.d.ts",
"src/**/*",
],
"include": ["NetscriptDefinitions.d.ts", "src/**/*"],
"compilerOptions": {
"module": "esnext",
"target": "esnext",
@ -12,18 +8,13 @@
"noImplicitThis": true,
"esModuleInterop": true,
"inlineSourceMap": true,
"sourceRoot": "http://localhost:8000/sources/",
"strict": true,
"rootDir": "src/",
"outDir": "dist/",
"baseUrl": "src/",
"paths": {
"/*": [
"*"
],
"@ns": [
"../NetscriptDefinitions.d.ts"
]
"/*": ["*"],
"@ns": ["../NetscriptDefinitions.d.ts"]
}
}
}

@ -1,19 +0,0 @@
const https = require("https")
const fs = require("fs")
const url = 'https://raw.githubusercontent.com/danielyxie/bitburner/dev/src/ScriptEditor/NetscriptDefinitions.d.ts'
const path = './NetscriptDefinitions.d.ts'
https.get(url, (res) => {
const file = fs.createWriteStream(path)
res.pipe(file)
file.on('finish', () => {
file.close
console.log('Netscript Type Definitions Updated')
})
}).on("error", (err) => {
console.log("Error: ", err.message)
})
Loading…
Cancel
Save