diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..37b062314 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,14 @@ +node_modules/ + +.git +.gitattributes +.gitignore +.editorconfig + +.dockerignore +Dockerfile +docker-compose.yml + +*.md +Quotes.txt +netscript_tests/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..91ad8064b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,35 @@ +FROM node:15.14.0 AS base + +WORKDIR /app + +# Scripts used in the npm preinstall hook +COPY scripts/engines-check.js scripts/semver.js scripts/ + +# Adding our dependencies and install before adding the rest of the files +# This prevents reinstallation of npm packages for every subsequent code modification +ENV npm_config_update_notifier=false +COPY package.json package-lock.json ./ +RUN npm ci --loglevel=error --no-audit --no-fund && npm rebuild node-sass + +# Adding all the remaining source files +COPY . . + +# We need more than the default 512MB otherwise webpack will throw 'heap out of memory' exceptions +# https://nodejs.org/api/cli.html#cli_max_old_space_size_size_in_megabytes +ENV NODE_OPTIONS=--max-old-space-size=1536 + +FROM base AS dev +# This is the main development build using the file watcher if you mount volumes +USER node +EXPOSE 8000 +CMD npm run start:container + +FROM base AS prod-dist +# We'll simply build the production dist files here to later reuse in a simple webserver +RUN npm run build + +FROM nginx:1.20.0-alpine AS prod +WORKDIR /usr/share/nginx/html +COPY --from=prod-dist /app/dist ./dist +COPY --from=prod-dist /app/index.html /app/favicon.ico /app/license.txt ./ +EXPOSE 80 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..bb81ce54e --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,15 @@ +version: "3.4" +services: + web: + image: bitburner:dev + build: + context: . + dockerfile: Dockerfile + target: dev + ports: + - "8000:8000" + volumes: + - ./src:/app/src + - ./css:/app/css + - ./utils:/app/utils + - ./test:/app/test diff --git a/package.json b/package.json index c12e247c6..78ee4fbc3 100644 --- a/package.json +++ b/package.json @@ -113,6 +113,7 @@ }, "scripts": { "start:dev": "webpack-dev-server --progress --env.devServer --mode development", + "start:container": "webpack-dev-server --progress --env.devServer --mode development --env.runInContainer", "build": "webpack --mode production", "build:dev": "webpack --mode development", "build:test": "webpack --config webpack.config-test.js", @@ -121,6 +122,7 @@ "lint:style": "stylelint --fix ./css/*", "preinstall": "node ./scripts/engines-check.js", "test": "mochapack --webpack-config webpack.config-test.js -r jsdom-global/register ./test/index.js", + "test:container": "mochapack --webpack-config webpack.config-test.js --slow 2000 --timeout 10000 -r jsdom-global/register ./test/index.js", "watch": "webpack --watch --mode production", "watch:dev": "webpack --watch --mode development" }, diff --git a/src/Alias.ts b/src/Alias.ts index 91c5dd96d..39931ad00 100644 --- a/src/Alias.ts +++ b/src/Alias.ts @@ -51,14 +51,14 @@ function addAlias(name: string, value: string): void { if (name in GlobalAliases) { delete GlobalAliases[name]; } - Aliases[name] = value; + Aliases[name] = value.trim(); } function addGlobalAlias(name: string, value: string): void { if (name in Aliases){ delete Aliases[name]; } - GlobalAliases[name] = value; + GlobalAliases[name] = value.trim(); } function getAlias(name: string): string | null { @@ -97,22 +97,29 @@ export function removeAlias(name: string): boolean { export function substituteAliases(origCommand: string): string { const commandArray = origCommand.split(" "); if (commandArray.length > 0){ - // For the unalias command, dont substite - if (commandArray[0] === "unalias") { return commandArray.join(" "); } + // For the alias and unalias commands, dont substite + if (commandArray[0] === "unalias" || commandArray[0] === "alias") { return commandArray.join(" "); } - const alias = getAlias(commandArray[0]); - if (alias != null) { - commandArray[0] = alias; - } else { - const alias = getGlobalAlias(commandArray[0]); + let somethingSubstituted = true; + let depth = 0; + + while(somethingSubstituted && depth < 10){ + depth++; + somethingSubstituted = false + const alias = getAlias(commandArray[0])?.split(" "); if (alias != null) { - commandArray[0] = alias; + somethingSubstituted = true + commandArray.splice(0, 1, ...alias); + //commandArray[0] = alias; } - } - for (let i = 0; i < commandArray.length; ++i) { - const alias = getGlobalAlias(commandArray[i]); - if (alias != null) { - commandArray[i] = alias; + for (let i = 0; i < commandArray.length; ++i) { + const alias = getGlobalAlias(commandArray[i])?.split(" "); + if (alias != null) { + somethingSubstituted = true + commandArray.splice(i, 1, ...alias); + i += alias.length - 1; + //commandArray[i] = alias; + } } } } diff --git a/src/Constants.ts b/src/Constants.ts index 27e1b2dfa..c110f6997 100644 --- a/src/Constants.ts +++ b/src/Constants.ts @@ -6,7 +6,7 @@ import { IMap } from "./types"; export const CONSTANTS: IMap = { - Version: "0.51.8", + Version: "0.51.9", /** Max level for any skill, assuming no multipliers. Determined by max numerical value in javascript for experience * and the skill level formula in Player.js. Note that all this means it that when experience hits MAX_INT, then @@ -228,60 +228,19 @@ export const CONSTANTS: IMap = { LatestUpdate: ` - v0.51.8 - 2021-05-07 It was there all along (hydroflame) + v0.51.9 - 2021-05-07 untitled yet ------- - Servers + Offline - * Update n00dles metadata + * Offline money gain has been reworked (it is more generous) + * If you're not working anywhere and go offline the game will work for you + at all your factions evenly. - Netscript - - * 'hashGainRate' use the correct 'usedRam' and 'maxRam' - * Fix 'setActionAutolevel' logging. - * Fix 'setActionLevel' not working at all. - * Add 'installBackdoor' singularity function. - - Hacknet - - * Fix Hacknet Servers total production always displaying 0 - - Documentation - - * Updated guide to no longer recommend BN12. - * Fix documentation for maxNumNodes (@ModdedGamers) - * Fix typo in 'sourcefiles.rst' - * Fix typo in 'recommendedbitnodeorder.rst' - * Fix 'getServer' documentation missing 'server' argument. - * Fix missing ram cost in 'getData.rst' - * Fix basic formulas examples. - * Fix typo in BN11 description. - * Fix formatting issue in Bladeburner (@Pimgd) + Export + * Exporting now gives +1 favor to all joined factions every 24h. Misc. - - * Fix negative money being displayed in full. - * Fix Hacking Missions not working. - * Fix Corporation tree not rendering. - * Fix script being needlessly recompiled. This should save real ram (not game ram) - * w0r1d_d43m0n can be backdoored - * Coding Contracts title is click-to-copy (@Rodeth) - * Covenant memory upgrade works better. - * Fix Neuroflux not being correctly calculated when entering BN with SF12. - * Delete Active Script now delete all active scripts, not just home. - * Now you can 'cd' in directories that only contain '.txt' files. - * Fix 'analyze' always saying players had root access - * Passive faction rep no longer builds for special factions. - * Donation option no longer appears for special factions. - * Rephrased some milestones. - * donation textbox now accepts money in the format '1b' and the like (@Dawe) - * Fix being able to join hated factions simultaneously. (@Dawe) - * 'ls' now displays files in multiple column. (Helps players with many files) - * Bladeburner multiplers now appear under Character>Stats and - Character>Augmentation when they are relevant. - * Fix missing functions syntax highlight in codemirror. - * Fix infiltration number formatting. - * script income transfers to parent on death. This helps keep track of - income for scripts that spawn short lived scripts. + * ls now correctly lists all files. `, } \ No newline at end of file diff --git a/src/Terminal.jsx b/src/Terminal.jsx index 4533c741d..add64e19d 100644 --- a/src/Terminal.jsx +++ b/src/Terminal.jsx @@ -625,7 +625,12 @@ let Terminal = { Terminal.commandHistoryIndex = Terminal.commandHistory.length; // Split commands and execute sequentially - commands = commands.split(";"); + commands = commands + .match(/(?:'[^']*'|"[^"]*"|[^;"])*/g) + .map(substituteAliases) + .map(c => c.match(/(?:'[^']*'|"[^"]*"|[^;"])*/g)) + .flat(); + console.log(commands); for (let i = 0; i < commands.length; i++) { if(commands[i].match(/^\s*$/)) { continue; } // Don't run commands that only have whitespace Terminal.executeCommand(commands[i].trim()); @@ -727,9 +732,6 @@ let Terminal = { return; } - // Process any aliases - command = substituteAliases(command); - // Allow usage of ./ if (command.startsWith("./")) { command = "run " + command.slice(2); @@ -873,7 +875,7 @@ let Terminal = { if (commandArray.length === 3) { if (commandArray[1] === "-g") { if (parseAliasDeclaration(commandArray[2], true)) { - post(`Set global alias ${commandArray[1]}`); + post(`Set global alias ${commandArray[2]}`); return; } } diff --git a/webpack.config.js b/webpack.config.js index da342707b..2ef501949 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -5,6 +5,7 @@ var HtmlWebpackPlugin = require('html-webpack-plugin'); module.exports = (env, argv) => { const isDevServer = (env || {}).devServer === true; + const runInContainer = (env || {}).runInContainer === true; const isDevelopment = argv.mode === 'development'; const outputDirectory = isDevServer ? "dist-dev" : "dist"; const entries = {}; @@ -22,6 +23,22 @@ module.exports = (env, argv) => { entrypoints: true, } + const devServerSettings = { + port: 8000, + publicPath: `/`, + stats: statsConfig, + }; + + // By default, the webpack-dev-server is not exposed outside of localhost. + // When running in a container we need it accessible externally. + if (runInContainer) { + devServerSettings.disableHostCheck = true; + devServerSettings.host = '0.0.0.0'; + devServerSettings.watchOptions = { + poll: true, + } + } + return { plugins: [ new webpack.DefinePlugin({ @@ -131,11 +148,7 @@ module.exports = (env, argv) => { }, }, }, - devServer: { - port: 8000, - publicPath: `/`, - stats: statsConfig, - }, + devServer: devServerSettings, resolve: { extensions: [ ".tsx",