61 lines
1.7 KiB
JavaScript
61 lines
1.7 KiB
JavaScript
#!/usr/bin/env node
|
|||
|
|
"use strict";
|
||
|
|
|
||
|
|
const path = require("node:path");
|
||
|
|
const { extractZipToTemp, importWolaiExport } = require("./lib/wolai-export-importer");
|
||
|
|
|
||
|
|
function parseArgs(argv) {
|
||
|
|
const args = {};
|
||
|
|
for (let i = 0; i < argv.length; i += 1) {
|
||
|
|
const arg = argv[i];
|
||
|
|
if (!arg.startsWith("--")) continue;
|
||
|
|
const key = arg.slice(2);
|
||
|
|
if (["clear-target", "allow-unsafe-clear"].includes(key)) {
|
||
|
|
args[key] = true;
|
||
|
|
} else {
|
||
|
|
args[key] = argv[i + 1];
|
||
|
|
i += 1;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return args;
|
||
|
|
}
|
||
|
|
|
||
|
|
function usage() {
|
||
|
|
console.error([
|
||
|
|
"用法:",
|
||
|
|
" node scripts/import-wolai-export.js --source-dir <解包后的Gidnxc目录> --target-root <用户空间目录> --owner-id <用户ID> [--workspace-id <workspaceId>] [--clear-target] [--copy-mode link|copy]",
|
||
|
|
" node scripts/import-wolai-export.js --zip <wolai.zip> --target-root <用户空间目录> --owner-id <用户ID> [--root-md <Gidnxc/个人空间.md>] [--clear-target]",
|
||
|
|
].join("\n"));
|
||
|
|
}
|
||
|
|
|
||
|
|
function main() {
|
||
|
|
const args = parseArgs(process.argv.slice(2));
|
||
|
|
const targetRoot = args["target-root"];
|
||
|
|
const ownerId = args["owner-id"];
|
||
|
|
if (!targetRoot || !ownerId || (!args["source-dir"] && !args.zip)) {
|
||
|
|
usage();
|
||
|
|
process.exit(2);
|
||
|
|
}
|
||
|
|
|
||
|
|
let sourceRoot = args["source-dir"];
|
||
|
|
if (args.zip) {
|
||
|
|
const tempRoot = extractZipToTemp(path.resolve(args.zip));
|
||
|
|
sourceRoot = tempRoot;
|
||
|
|
}
|
||
|
|
|
||
|
|
const result = importWolaiExport({
|
||
|
|
sourceRoot,
|
||
|
|
targetRoot,
|
||
|
|
ownerId,
|
||
|
|
workspaceId: args["workspace-id"],
|
||
|
|
rootMd: args["root-md"],
|
||
|
|
clearTarget: Boolean(args["clear-target"]),
|
||
|
|
allowUnsafeClear: Boolean(args["allow-unsafe-clear"]),
|
||
|
|
copyMode: args["copy-mode"] === "copy" ? "copy" : "link",
|
||
|
|
});
|
||
|
|
|
||
|
|
console.log(JSON.stringify(result, null, 2));
|
||
|
|
}
|
||
|
|
|
||
|
|
main();
|