mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-05-05 23:27:55 +02:00
NETSCRIPT: Add .script deprecation notice & migration guide (#1007)
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import React from "react";
|
||||
import { Terminal } from "../../../Terminal";
|
||||
import { Settings } from "../../../Settings/Settings";
|
||||
import { Link, Typography } from "@mui/material";
|
||||
import { Router } from "../../../ui/GameRoot";
|
||||
import { Page } from "../../../ui/Router";
|
||||
|
||||
export function sendDeprecationNotice() {
|
||||
return Terminal.printRaw(
|
||||
<Typography sx={{ color: Settings.theme.warning }}>
|
||||
NOTICE: Accessing the Netscript API via .script files is deprecated and will be removed in a future update.{" "}
|
||||
<Link
|
||||
style={{ cursor: "pointer" }}
|
||||
color="inherit"
|
||||
onClick={() => Router.toPage(Page.Documentation, { docPage: "migrations/ns2.md" })}
|
||||
>
|
||||
Here are instructions
|
||||
</Link>{" "}
|
||||
to migrate your scripts to .js files instead.
|
||||
</Typography>,
|
||||
);
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import { CursorPositions } from "../../../ScriptEditor/CursorPositions";
|
||||
import { ScriptFilePath, hasScriptExtension } from "../../../Paths/ScriptFilePath";
|
||||
import { TextFilePath, hasTextExtension } from "../../../Paths/TextFilePath";
|
||||
import { getGlobbedFileMap } from "../../../Paths/GlobbedFiles";
|
||||
import { sendDeprecationNotice } from "./deprecation";
|
||||
|
||||
// 2.3: Globbing implementation was removed from this file. Globbing will be reintroduced as broader functionality and integrated here.
|
||||
|
||||
@@ -30,12 +31,14 @@ export function commonEditor(
|
||||
): void {
|
||||
if (args.length < 1) return Terminal.error(`Incorrect usage of ${command} command. Usage: ${command} [scriptname]`);
|
||||
const files = new Map<ScriptFilePath | TextFilePath, string>();
|
||||
let hasNs1 = false;
|
||||
for (const arg of args) {
|
||||
const pattern = String(arg);
|
||||
|
||||
// Glob of existing files
|
||||
if (pattern.includes("*") || pattern.includes("?")) {
|
||||
for (const [path, file] of getGlobbedFileMap(pattern, server, Terminal.currDir)) {
|
||||
if (path.endsWith(".script")) hasNs1 = true;
|
||||
files.set(path, file.content);
|
||||
}
|
||||
continue;
|
||||
@@ -47,10 +50,14 @@ export function commonEditor(
|
||||
if (!hasScriptExtension(path) && !hasTextExtension(path)) {
|
||||
return Terminal.error(`${command}: Only scripts or text files can be edited. Invalid file type: ${arg}`);
|
||||
}
|
||||
if (path.endsWith(".script")) hasNs1 = true;
|
||||
const file = server.getContentFile(path);
|
||||
const content = file ? file.content : isNs2(path) ? newNs2Template : "";
|
||||
files.set(path, content);
|
||||
if (content === newNs2Template) CursorPositions.saveCursor(path, { row: 3, column: 5 });
|
||||
}
|
||||
if (hasNs1) {
|
||||
sendDeprecationNotice();
|
||||
}
|
||||
Router.toPage(Page.ScriptEditor, { files, options });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user