Skip to content
Open
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
07a5baa
script exporter
CTH999 Apr 24, 2026
434cf84
script exporter
CTH999 Apr 24, 2026
5f21b41
pack script
CTH999 Apr 24, 2026
e88b20f
merge into one
CTH999 Apr 24, 2026
96c6a06
correct format
CTH999 Apr 24, 2026
64e35b1
wipe file
CTH999 Apr 24, 2026
9764f08
control
CTH999 Apr 24, 2026
9015052
export+comment
CTH999 Apr 24, 2026
0f70b78
io code
CTH999 Apr 24, 2026
784f514
Merge branch 'script-exporter-code' into import+export
CTH999 May 17, 2026
a00b125
Revert "Merge branch 'script-exporter-code' into import+export"
CTH999 May 17, 2026
43c846a
script import/export
CTH999 May 17, 2026
fd97e2f
Update README.md
CTH999 May 17, 2026
852a898
Merge branch 'script-exporter' into update
CTH999 May 17, 2026
5381feb
Merge branch 'import+export' into update
CTH999 May 17, 2026
694cbff
Hardcoded Export
CTH999 May 17, 2026
c4b9cb5
Delete SCRIPT EXPORT.md
CTH999 May 17, 2026
6d9c8e1
Merge branch 'main' into update
CTH999 May 17, 2026
c0b0544
Merge branch 'main' into prepare
CTH999 May 17, 2026
aca7357
Revert "Hardcoded Export"
CTH999 May 17, 2026
2a92d26
Merge branch 'main' into Script-ImportExport
CTH999 May 17, 2026
025be61
Merge branch 'update' into prepare
CTH999 May 17, 2026
11c2c06
Merge branch 'update' into Script-ImportExport
CTH999 May 17, 2026
b97a673
Revert "Merge branch 'main' into Script-ImportExport"
CTH999 May 17, 2026
3f3a052
Merge branch 'prepare' into Script-ImportExport
CTH999 May 17, 2026
29aef75
Merge branch 'main' into Script-ImportExport
CTH999 May 21, 2026
f8dd7c6
Merge branch 'main' into Script-ImportExport
CTH999 May 25, 2026
4a7589a
Merge branch 'main' into Script-ImportExport
CTH999 May 25, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 145 additions & 0 deletions Script Exporter/scriptExporter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/** @param {NS} ns **/

export async function main(ns) {
const mode = ns.args[0]; //extract mode

const SELF = ns.getScriptName(); //get name
const JSON_OUT = "scripts_dump.json"; //name of output .json
const TXT_OUT = "scripts_dump.txt"; //name of output text

if (mode === "ex") { //trigger export
await exportScripts(ns, SELF, JSON_OUT, TXT_OUT);
}
else if (mode === "im") { //trigger import
await importScripts(ns, SELF, TXT_OUT);
}
else { //explain format
ns.tprint("Usage: run script.js [ex | im]");
}
}

async function exportScripts(ns, SELF, JSON_OUT, TXT_OUT) {

const files = ns.ls("home", ".js");

let result = {};

for (const file of files) {

// skip self (prevents recursion)
if (file === SELF) continue;

const content = ns.read(file); //get contents
if (!content) continue;

try {
result[file] = btoa(content);
} catch {
ns.tprint(`Failed to encode ${file}`);
}
}

const jsonString = JSON.stringify(result, null, 2);

await ns.write(JSON_OUT, jsonString, "w");

const packed = btoa(jsonString);

await ns.write(TXT_OUT, packed, "w");

ns.tprint(`Exported ${Object.keys(result).length} scripts`);
}

async function importScripts(ns, SELF, TXT_OUT) {

const content = ns.read(TXT_OUT);

if (!content) {
ns.tprint("ERROR: Missing dump file");
return;
}

let jsonString;
try {
jsonString = atob(content);
} catch {
ns.tprint("ERROR: Decode failed");
return;
}

let data;
try {
data = JSON.parse(jsonString);
} catch {
ns.tprint("ERROR: Invalid JSON");
return;
}

let count = 0;

for (const file in data) {

// safety: never overwrite importer/exporter script
if (file === SELF) continue;

let decoded;
try {
decoded = atob(data[file]);
} catch {
ns.tprint(`Failed: ${file}`);
continue;
}

await ns.write(file, decoded, "w");
count++;
}

ns.tprint(`Imported ${count} scripts`);
}

async function importScripts(ns, SELF, TXT_OUT) {

const content = ns.read(TXT_OUT);

if (!content) {
ns.tprint("ERROR: Missing dump file");
return;
}

let jsonString;
try {
jsonString = atob(content);
} catch {
ns.tprint("ERROR: Decode failed");
return;
}

let data;
try {
data = JSON.parse(jsonString);
} catch {
ns.tprint("ERROR: Invalid JSON");
return;
}

let count = 0;

for (const file in data) {

// safety: never overwrite importer/exporter script
if (file === SELF) continue;

let decoded;
try {
decoded = atob(data[file]);
} catch {
ns.tprint(`Failed: ${file}`);
continue;
}

await ns.write(file, decoded, "w");
count++;
}

ns.tprint(`Imported ${count} scripts`);
}