Compare commits
2
Commits
9841e88900
...
8b6dab8d52
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8b6dab8d52 | ||
|
|
29193c03bc |
No files matched your search
+29
-3
@@ -33,9 +33,35 @@ python3 target/local-beta/native-beta.py compile /path/to/main.tex /path/to/outp
|
||||
```
|
||||
|
||||
`--file` 接收相对于主文件目录的路径,可列出子文件及实际使用的图像等资源。
|
||||
编辑器在试用目录中创建工作副本。当前编辑内容保存在会话内,可以下载 PDF。
|
||||
命令行按项目实际读写作业文件。需要 BibTeX 的项目可在辅助文件生成后
|
||||
运行 BibTeX,再继续 LaTeX 编译到引用收敛。
|
||||
编辑器在试用目录中创建工作副本。命令行按项目实际读写作业文件。
|
||||
需要 BibTeX 的项目可在辅助文件生成后运行 BibTeX,再继续 LaTeX 编译到引用收敛。
|
||||
|
||||
## 使用项目的 Web 界面
|
||||
|
||||
将 texrra-web 放在引擎仓库旁边。启动或重开时指定 Web 目录。
|
||||
|
||||
~~~sh
|
||||
python3 target/local-beta/native-beta.py open --web-dir ../texrra-web
|
||||
python3 target/local-beta/native-beta.py resume /path/to/saved-project --web-dir ../texrra-web
|
||||
~~~
|
||||
|
||||
该入口显示 Web 工作台的文件栏、编辑区和预览区。编辑、局部预览、
|
||||
源码保存及下载 PDF 都使用原生 Beta 会话。每次启动打开一个由命令行
|
||||
指定的项目。现有 Web 的项目列表和 ZIP 导入仍在原 serve 入口。
|
||||
启动指令中的其他参数和保存目录格式与上文相同。
|
||||
|
||||
## 保存和重新打开
|
||||
|
||||
点击「保存源文件」将当前编辑与已声明的项目资源一起写入一个新目录。
|
||||
目录路径显示在编辑器中。里面的 sources 子目录包含可单独使用的项目文件,
|
||||
预览的 PDF 可通过「下载 PDF」另行取得。使用原 Beta 包打开保存目录。
|
||||
|
||||
~~~sh
|
||||
python3 target/local-beta/native-beta.py resume /path/to/texrra-sources-directory
|
||||
~~~
|
||||
|
||||
有编译错误的草稿也可以保存。重开目前需要通过首次编译,若草稿仍有错误,
|
||||
可先在保存目录的 sources 中修正源文件。每次保存都会得到独立的一份。
|
||||
|
||||
## 已对照的项目
|
||||
|
||||
|
||||
@@ -18,6 +18,47 @@
|
||||
| W6 会话 | 实施中 | 共享库/CLI 与当前原生文字/数学/规则来源进入公共结果;真实 A4 副本九类/27 revision 与独立干净作业页面/PDF/aux/映射一致,新增数学场景独立参考通过;详细失败/捕获重放及宿主/离线/CLI观察已通过;原子项目版本/已知生成初态及TeX流记录已接通;原样 12 页 NeurIPS 的中部编辑与恢复已验证前后缀复用、仅更新一页,且与独立全量一致。全部副作用/交叉编辑、旧来源与正式性能门禁仍待闭合 |
|
||||
| W7 总验收 | 未满足 | 原有和新增测试、原样项目、格式与会话门禁全部通过才能结项 |
|
||||
|
||||
## 2026-11-29 原生 Beta 接入 texrra-web 工作台
|
||||
|
||||
本地启动器的 --web-dir 接入现有 texrra-web 的 HTML、样式和图标。
|
||||
原生会话脚本连接同一工作台的文件栏、编辑、报错、局部页面和 PDF
|
||||
下载,支持保存源码副本及快捷键。该入口一次打开一个指定项目。
|
||||
既有项目列表与 ZIP 导入的迁移属于后续集成。
|
||||
|
||||
固定 Web 仓库 e14b7aa 及 A4 原样多文件输入。在 Edge 验证工作台
|
||||
打开、子文件切换、修改、保存、错误和恢复。修改后只更新第一页,
|
||||
来源表记录本轮子文件字节。错版继续提供上次 PDF,恢复相同文本
|
||||
沿用已显示页。下载 PDF 及辅助文件与保存副本的独立 CLI 两轮收敛
|
||||
结果逐字节一致。保留真实浏览器截图及 HTML、样式和图标身份。
|
||||
|
||||
本机试用包位于 target/native-beta-web/beta-pdftex/。证据目录
|
||||
target/native-beta-web/ 的 SHA256SUMS 指纹为
|
||||
023b5d857af62da963b7d9b2e51157534c4f14f0c256dbf81d207923bc7d4bfe。
|
||||
[Web 启动方式](NATIVE_BETA.md#使用项目的-web-界面)
|
||||
|
||||
## 2026-11-29 Beta 源码保存和恢复
|
||||
|
||||
编辑器保存时将当前浏览器缓冲与已声明的输入资源一并写入一个
|
||||
源码副本。先完成全部文件和恢复清单,再发布新目录。保存与编译
|
||||
各自处理,已有输出继续按编译版本发布。resume 读取保存目录的
|
||||
入口和实际相对路径,建立新的编译工作目录。
|
||||
|
||||
用原样 A4 主文件和子文件在 Edge 验证。在同一次操作中修改两个
|
||||
文件并保存,随后收到更新的预览。额外声明的嵌套 PDF 资源按实际
|
||||
字节保存。引入未知命令的草稿可另存,错误期间仍可下载上次 PDF。
|
||||
两次源码副本保持独立。已验证旧版本、未知文件和非 JSON 请求均被
|
||||
拒绝,未创建额外副本。
|
||||
|
||||
重新启动有效副本后,浏览器缓冲、PDF 及辅助文件与独立 CLI 两轮
|
||||
收敛作业一致。测试输入文件指纹保持。错误草稿当前重开仍受首次
|
||||
编译限制,失败和保存下来的源文件均保留。下一批从错误草稿可打开
|
||||
的资源准备路径及原样多页项目的启动耗时继续推进。
|
||||
|
||||
本机包在 target/native-beta-save/beta-pdftex/。证据目录
|
||||
target/native-beta-save/ 的 SHA256SUMS 指纹为
|
||||
46d0ba4d0fd0afe15a3dad8f19915a7ef3048c3964cae240611fc60b05053c4c。
|
||||
[Beta 使用指南](NATIVE_BETA.md#保存和重新打开)
|
||||
|
||||
## 2026-11-29 本地 Beta 启动与五份原样模板
|
||||
|
||||
本地启动脚本准备同一构建的原生 CLI、编辑器、实际格式与资源配置。
|
||||
|
||||
+101
-13
@@ -1,10 +1,17 @@
|
||||
const workspace = document.querySelector("#workspace");
|
||||
if (workspace) attachWebControls();
|
||||
|
||||
const source = document.querySelector("#source");
|
||||
const pages = document.querySelector("#pages");
|
||||
const status = document.querySelector("#status");
|
||||
const error = document.querySelector("#error");
|
||||
const status = document.querySelector("#status, #preview-status");
|
||||
const error = document.querySelector("#error, #preview-error-text");
|
||||
const errorPanel = document.querySelector("#error, #preview-error");
|
||||
const pdf = document.querySelector("#pdf");
|
||||
const save = document.querySelector("#save");
|
||||
const saved = document.querySelector("#saved, #file-panel-foot");
|
||||
const selector = document.querySelector("#project-files");
|
||||
const name = document.querySelector("#name");
|
||||
const name = document.querySelector("#name, #open-file-path");
|
||||
const fileTree = document.querySelector("#file-tree");
|
||||
const edits = new Map();
|
||||
let files;
|
||||
let activeFile;
|
||||
@@ -14,16 +21,60 @@ let draft = null;
|
||||
let frame;
|
||||
const previewDraft = new URLSearchParams(location.hash.slice(1)).get("preview") !== "published";
|
||||
|
||||
function attachWebControls() {
|
||||
const button = document.createElement("button");
|
||||
button.type = "button";
|
||||
button.id = "save";
|
||||
button.className = "btn";
|
||||
button.disabled = true;
|
||||
button.textContent = "保存源文件";
|
||||
document.querySelector(".file-tools").replaceChildren(button);
|
||||
|
||||
const download = document.createElement("a");
|
||||
download.id = "pdf";
|
||||
download.className = "btn small";
|
||||
download.download = "";
|
||||
download.hidden = true;
|
||||
download.textContent = "下载 PDF";
|
||||
document.querySelector("#export-pdf").replaceWith(download);
|
||||
|
||||
document.querySelector("#back-button").hidden = true;
|
||||
document.querySelector("#toggle-engine").hidden = true;
|
||||
document.querySelector("#header-actions").textContent = "原生 Beta";
|
||||
document.querySelector("footer").textContent = "Ctrl/Cmd+S 保存源码副本";
|
||||
document.querySelector("#source").disabled = true;
|
||||
document.querySelector("#file-panel-foot").setAttribute("role", "status");
|
||||
document.querySelector("#file-panel-foot").style.overflowWrap = "anywhere";
|
||||
workspace.hidden = false;
|
||||
}
|
||||
|
||||
function selectFile(filename) {
|
||||
activeFile = filename;
|
||||
name.textContent = filename;
|
||||
source.value = edits.get(filename) ?? files.get(filename);
|
||||
if (fileTree) {
|
||||
for (const row of fileTree.children) {
|
||||
const selected = row.dataset.path === activeFile;
|
||||
row.classList.toggle("active", selected);
|
||||
row.setAttribute("aria-pressed", selected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function showError(message) {
|
||||
status.textContent = "编译失败";
|
||||
error.textContent = message;
|
||||
error.hidden = false;
|
||||
errorPanel.hidden = false;
|
||||
}
|
||||
|
||||
function pageImage(page) {
|
||||
const img = new Image();
|
||||
img.alt = `第 ${page.index + 1} 页`;
|
||||
img.dataset.index = page.index;
|
||||
if (workspace) {
|
||||
img.className = "page";
|
||||
img.style.aspectRatio = "auto";
|
||||
}
|
||||
img.src = URL.createObjectURL(new Blob([page.svg], { type: "image/svg+xml" }));
|
||||
return img;
|
||||
}
|
||||
@@ -114,7 +165,7 @@ async function compile(edit, submitted, changes) {
|
||||
} else {
|
||||
acceptPublication(update.revision, previous);
|
||||
}
|
||||
error.hidden = true;
|
||||
errorPanel.hidden = true;
|
||||
await new Promise(requestAnimationFrame);
|
||||
await new Promise(requestAnimationFrame);
|
||||
if (edit !== sequence) return;
|
||||
@@ -171,26 +222,63 @@ function queueCompile() {
|
||||
frame = requestAnimationFrame(() => compile(edit, submitted, changes));
|
||||
}
|
||||
|
||||
async function saveSources() {
|
||||
save.disabled = true;
|
||||
saved.hidden = false;
|
||||
saved.textContent = "正在保存源文件";
|
||||
try {
|
||||
const response = await fetch("/save", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ sequence, files: Object.fromEntries(edits) }),
|
||||
});
|
||||
const result = await response.json();
|
||||
if (!response.ok) throw new Error(result.error);
|
||||
saved.textContent = "已保存源文件至 " + result.directory;
|
||||
} catch (failure) {
|
||||
saved.textContent = "保存失败:" + failure.message;
|
||||
} finally {
|
||||
save.disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function openProject() {
|
||||
try {
|
||||
const response = await fetch("/project");
|
||||
if (!response.ok) throw new Error("无法打开源文件");
|
||||
const project = await response.json();
|
||||
files = new Map(Object.entries(project.files));
|
||||
activeFile = project.name;
|
||||
name.textContent = activeFile;
|
||||
source.value = files.get(activeFile);
|
||||
if (fileTree) {
|
||||
document.querySelector("#project-title").textContent = project.name;
|
||||
for (const filename of files.keys()) {
|
||||
const row = document.createElement("button");
|
||||
row.type = "button";
|
||||
row.className = "btn tree-row file-row";
|
||||
row.style.width = "100%";
|
||||
row.dataset.path = filename;
|
||||
row.textContent = filename;
|
||||
row.title = filename;
|
||||
row.addEventListener("click", () => selectFile(filename));
|
||||
fileTree.append(row);
|
||||
}
|
||||
}
|
||||
selectFile(project.name);
|
||||
source.disabled = false;
|
||||
sequence = project.sequence;
|
||||
if (files.size > 1) {
|
||||
save.disabled = false;
|
||||
save.addEventListener("click", saveSources);
|
||||
document.addEventListener("keydown", (event) => {
|
||||
if ((event.ctrlKey || event.metaKey) && event.key.toLowerCase() === "s") {
|
||||
event.preventDefault();
|
||||
if (!save.disabled) saveSources();
|
||||
}
|
||||
});
|
||||
if (selector && files.size > 1) {
|
||||
for (const filename of files.keys()) selector.add(new Option(filename, filename));
|
||||
selector.value = activeFile;
|
||||
selector.hidden = false;
|
||||
name.hidden = true;
|
||||
selector.addEventListener("change", () => {
|
||||
activeFile = selector.value;
|
||||
source.value = edits.get(activeFile) ?? files.get(activeFile);
|
||||
});
|
||||
selector.addEventListener("change", () => selectFile(selector.value));
|
||||
}
|
||||
source.addEventListener("input", () => {
|
||||
edits.set(activeFile, source.value);
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
}
|
||||
header strong { letter-spacing: .02em; }
|
||||
header a { color: #bde5ff; }
|
||||
.actions { min-width: 0; display: flex; align-items: center; flex-wrap: wrap; gap: .6rem; }
|
||||
.actions span { overflow-wrap: anywhere; }
|
||||
main { display: grid; grid-template-columns: minmax(270px, 5fr) minmax(300px, 7fr); min-height: 0; }
|
||||
.edit { min-height: 0; display: grid; grid-template-rows: auto 1fr; background: white; }
|
||||
.file { padding: .6rem 1rem; border-bottom: 1px solid #d9e0e6; font: 14px/1.5 ui-monospace, monospace; }
|
||||
@@ -38,7 +40,11 @@
|
||||
<header>
|
||||
<strong>Texrra 原生预览</strong>
|
||||
<span id="status" role="status">正在打开文档</span>
|
||||
<a id="pdf" download hidden>下载 PDF</a>
|
||||
<div class="actions">
|
||||
<button id="save" type="button" disabled>保存源文件</button>
|
||||
<span id="saved" role="status" hidden></span>
|
||||
<a id="pdf" download hidden>下载 PDF</a>
|
||||
</div>
|
||||
</header>
|
||||
<main>
|
||||
<section class="edit" aria-label="源文件">
|
||||
|
||||
@@ -23,6 +23,8 @@ use texrra_tex_core::{
|
||||
};
|
||||
use tiny_http::{Header, Method, Request, Response, Server};
|
||||
|
||||
mod saved_project;
|
||||
|
||||
const MAX_EDIT_BODY: u64 = 2 * 1024 * 1024;
|
||||
const PAGE: &str = include_str!("index.html");
|
||||
const SCRIPT: &str = include_str!("app.js");
|
||||
@@ -38,6 +40,12 @@ struct Edit {
|
||||
preview_draft: bool,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct Save {
|
||||
sequence: u64,
|
||||
files: BTreeMap<String, String>,
|
||||
}
|
||||
|
||||
struct Work {
|
||||
request: Request,
|
||||
job: CompileJob,
|
||||
@@ -180,7 +188,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
std::process::exit(status);
|
||||
}
|
||||
let mut args = std::env::args_os().skip(1).peekable();
|
||||
let usage = "native_editor [--input-profile tex8bit|unicode|xetex] SOURCE FORMAT FORMAT_RESOURCES NEW_RUN_DIR [PORT] [FILE ...]";
|
||||
let usage = "native_editor [--input-profile tex8bit|unicode|xetex] [--web-dir DIR] SOURCE FORMAT FORMAT_RESOURCES NEW_RUN_DIR [PORT] [FILE ...]";
|
||||
let input_profile = if args.next_if(|arg| arg == "--input-profile").is_some() {
|
||||
match args.next().as_deref().and_then(std::ffi::OsStr::to_str) {
|
||||
Some("tex8bit") => InputProfile::TeX8Bit,
|
||||
@@ -191,6 +199,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
} else {
|
||||
InputProfile::TeX8Bit
|
||||
};
|
||||
let web = if args.next_if(|arg| arg == "--web-dir").is_some() {
|
||||
let path = PathBuf::from(args.next().ok_or(usage)?);
|
||||
Some(WebAssets::load(&path)?)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let mut args = args.map(PathBuf::from);
|
||||
let source = args.next().ok_or(usage)?.canonicalize()?;
|
||||
let format = args.next().ok_or(usage)?.canonicalize()?;
|
||||
@@ -208,6 +222,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
mut project,
|
||||
entry,
|
||||
editable,
|
||||
declared,
|
||||
options,
|
||||
} = prepare(&source, &format, &manifest, &run, &additional, input_profile)?;
|
||||
let compiler = NativeCompiler::default().with_automatic_entry_checkpoints();
|
||||
@@ -220,11 +235,28 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let queue = queue.clone();
|
||||
move || worker(&queue)
|
||||
});
|
||||
let mut save_number = 0;
|
||||
println!("Native editor http://{}", server.server_addr());
|
||||
for request in server.incoming_requests() {
|
||||
let path = request.url().to_owned();
|
||||
match (request.method(), path.as_str()) {
|
||||
(&Method::Get, "/") => respond(request, 200, "text/html; charset=utf-8", PAGE.into()),
|
||||
(&Method::Get, "/") => respond(
|
||||
request,
|
||||
200,
|
||||
"text/html; charset=utf-8",
|
||||
web.as_ref().map_or_else(|| PAGE.into(), |assets| assets.index.clone()),
|
||||
),
|
||||
(&Method::Get, "/styles.css") if web.is_some() => respond(
|
||||
request, 200, "text/css; charset=utf-8", web.as_ref().unwrap().styles.clone(),
|
||||
),
|
||||
(&Method::Get, "/favicon.svg") if web.is_some() => respond(
|
||||
request, 200, "image/svg+xml", web.as_ref().unwrap().favicon.clone(),
|
||||
),
|
||||
// The shared Web shell requests this stylesheet. Native preview
|
||||
// pages carry their glyph outlines in their SVG output.
|
||||
(&Method::Get, "/fonts.css") if web.is_some() => {
|
||||
respond(request, 200, "text/css; charset=utf-8", Vec::new())
|
||||
}
|
||||
(&Method::Get, "/app.js") => respond(
|
||||
request,
|
||||
200,
|
||||
@@ -252,7 +284,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
(&Method::Post, "/preview") => {
|
||||
let received = Instant::now();
|
||||
let mut request = request;
|
||||
let edit = match read_edit(&mut request) {
|
||||
let edit: Edit = match read_json(&mut request) {
|
||||
Ok(edit) => edit,
|
||||
Err(error) => {
|
||||
reply(request, 400, json!({ "error": error }));
|
||||
@@ -318,6 +350,38 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
);
|
||||
}
|
||||
}
|
||||
(&Method::Post, "/save") => {
|
||||
let mut request = request;
|
||||
if !request.headers().iter().any(|header| {
|
||||
header.field.equiv("Content-Type")
|
||||
&& header.value.as_str().split(';').next() == Some("application/json")
|
||||
}) {
|
||||
reply(request, 415, json!({"error": "Expected JSON source edits"}));
|
||||
continue;
|
||||
}
|
||||
let save: Save = match read_json(&mut request) {
|
||||
Ok(save) => save,
|
||||
Err(error) => {
|
||||
reply(request, 400, json!({ "error": error }));
|
||||
continue;
|
||||
}
|
||||
};
|
||||
if save.sequence < queue.current.load(Ordering::Acquire) {
|
||||
reply(request, 409, json!({"error": "A newer edit is already queued"}));
|
||||
continue;
|
||||
}
|
||||
let changes: Option<BTreeMap<_, _>> = save.files.iter()
|
||||
.map(|(name, data)| editable.get(name).map(|path| (path.as_path(), data.as_bytes())))
|
||||
.collect();
|
||||
let Some(changes) = changes else {
|
||||
reply(request, 422, json!({"error": "The save refers to an unknown source file"}));
|
||||
continue;
|
||||
};
|
||||
match saved_project::save(&run, &entry, &declared, &project, changes, &mut save_number) {
|
||||
Ok(path) => reply(request, 200, json!({"directory": path})),
|
||||
Err(error) => reply(request, 500, json!({"error": error.to_string()})),
|
||||
}
|
||||
}
|
||||
(&Method::Get, path) if path.starts_with("/publication?revision=") => {
|
||||
let revision = path["/publication?revision=".len()..].parse::<u64>().ok();
|
||||
let result = queue
|
||||
@@ -377,7 +441,23 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn read_edit(request: &mut Request) -> Result<Edit, String> {
|
||||
struct WebAssets {
|
||||
index: Vec<u8>,
|
||||
styles: Vec<u8>,
|
||||
favicon: Vec<u8>,
|
||||
}
|
||||
|
||||
impl WebAssets {
|
||||
fn load(path: &Path) -> std::io::Result<Self> {
|
||||
Ok(Self {
|
||||
index: fs::read(path.join("index.html"))?,
|
||||
styles: fs::read(path.join("styles.css"))?,
|
||||
favicon: fs::read(path.join("favicon.svg"))?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn read_json<T: serde::de::DeserializeOwned>(request: &mut Request) -> Result<T, String> {
|
||||
let mut body = Vec::new();
|
||||
request
|
||||
.as_reader()
|
||||
@@ -394,6 +474,7 @@ struct EditorProject {
|
||||
project: Arc<ProjectSnapshot>,
|
||||
entry: PathBuf,
|
||||
editable: BTreeMap<String, PathBuf>,
|
||||
declared: BTreeSet<PathBuf>,
|
||||
options: CompileRequest,
|
||||
}
|
||||
|
||||
@@ -545,6 +626,7 @@ fn prepare(
|
||||
project,
|
||||
entry,
|
||||
editable,
|
||||
declared,
|
||||
options: request,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
use std::{
|
||||
collections::{BTreeMap, BTreeSet},
|
||||
fs, io,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
use texrra_engine::native::ProjectSnapshot;
|
||||
|
||||
pub(super) fn save(
|
||||
run: &Path,
|
||||
entry: &Path,
|
||||
declared: &BTreeSet<PathBuf>,
|
||||
project: &ProjectSnapshot,
|
||||
edits: BTreeMap<&Path, &[u8]>,
|
||||
next_number: &mut u64,
|
||||
) -> io::Result<PathBuf> {
|
||||
let parent = run.parent().expect("the working directory has a parent");
|
||||
let (staging, destination) = loop {
|
||||
*next_number += 1;
|
||||
let name = format!("texrra-sources-{}-{next_number}", std::process::id());
|
||||
let destination = parent.join(&name);
|
||||
if destination.symlink_metadata().is_ok() {
|
||||
continue;
|
||||
}
|
||||
let staging = parent.join(format!(".{name}.pending"));
|
||||
match fs::create_dir(&staging) {
|
||||
Ok(()) => break (staging, destination),
|
||||
Err(error) if error.kind() == io::ErrorKind::AlreadyExists => continue,
|
||||
Err(error) => return Err(error),
|
||||
}
|
||||
};
|
||||
let result = (|| {
|
||||
let sources = staging.join("sources");
|
||||
fs::create_dir(&sources)?;
|
||||
let mut files = Vec::new();
|
||||
for path in declared {
|
||||
let relative = path.strip_prefix(run).expect("declared sources stay in the working copy");
|
||||
let name = relative.to_str().ok_or_else(|| {
|
||||
io::Error::new(io::ErrorKind::InvalidData, "A project file needs a UTF-8 name")
|
||||
})?;
|
||||
let saved = sources.join(relative);
|
||||
fs::create_dir_all(saved.parent().expect("a source file has a parent"))?;
|
||||
if let Some(data) = edits
|
||||
.get(path.as_path())
|
||||
.copied()
|
||||
.or_else(|| project.file(path).map(|file| file.data.as_ref()))
|
||||
{
|
||||
fs::write(&saved, data)?;
|
||||
}
|
||||
if path != entry {
|
||||
files.push(name);
|
||||
}
|
||||
}
|
||||
let entry_name = entry.file_name().expect("the entry has a name").to_str().unwrap();
|
||||
let manifest = fs::File::create(staging.join("project.json"))?;
|
||||
serde_json::to_writer_pretty(manifest, &serde_json::json!({
|
||||
"entry": entry_name, "files": files,
|
||||
}))?;
|
||||
// Publish the metadata and every source at once.
|
||||
fs::rename(&staging, &destination)
|
||||
})();
|
||||
if let Err(error) = result {
|
||||
let _ = fs::remove_dir_all(&staging);
|
||||
return Err(error);
|
||||
}
|
||||
Ok(destination)
|
||||
}
|
||||
+22
-9
@@ -125,19 +125,28 @@ def launch(args):
|
||||
env.update(manifest["environment"])
|
||||
env["TEXRRA_STATE_DIR"] = str(bundle / "state")
|
||||
profile = manifest["input_profile"]
|
||||
if args.action == "open":
|
||||
source = args.entry.resolve(strict=True) if args.entry else bundle / "a4-project/main.tex"
|
||||
assets = args.file if args.entry else ["chapter.tex", *args.file]
|
||||
if args.action in ("open", "resume"):
|
||||
if args.action == "resume":
|
||||
saved = args.snapshot.resolve(strict=True)
|
||||
project = json.loads((saved / "project.json").read_text(encoding="utf-8"))
|
||||
entry = Path(project["entry"])
|
||||
if len(entry.parts) != 1 or entry.name in ("", ".."):
|
||||
raise ValueError("The saved project entry must be a filename")
|
||||
source = (saved / "sources" / entry).resolve(strict=True)
|
||||
assets = project["files"]
|
||||
else:
|
||||
source = args.entry.resolve(strict=True) if args.entry else bundle / "a4-project/main.tex"
|
||||
assets = args.file if args.entry else ["chapter.tex", *args.file]
|
||||
runs = bundle / "runs"
|
||||
if args.run_dir:
|
||||
run = args.run_dir.resolve()
|
||||
else:
|
||||
runs.mkdir(exist_ok=True)
|
||||
run = Path(tempfile.mkdtemp(prefix="editor-", dir=runs)) / "project"
|
||||
command = [
|
||||
bundle / "bin" / binary_name("native_editor"), "--input-profile", profile,
|
||||
source, bundle / FORMAT, bundle / RESOURCES, run, str(args.port), *assets,
|
||||
]
|
||||
command = [bundle / "bin" / binary_name("native_editor"), "--input-profile", profile]
|
||||
if args.web_dir:
|
||||
command.extend(["--web-dir", args.web_dir.resolve(strict=True)])
|
||||
command.extend([source, bundle / FORMAT, bundle / RESOURCES, run, str(args.port), *assets])
|
||||
else:
|
||||
command = native_command(bundle / "bin" / binary_name("texrra"), profile, roots)
|
||||
command.extend(["--load-format", bundle / FORMAT, args.entry.resolve(strict=True),
|
||||
@@ -162,8 +171,12 @@ def main():
|
||||
editor = commands.add_parser("open", help="open a project or the bundled A4 sample")
|
||||
editor.add_argument("entry", type=Path, nargs="?")
|
||||
editor.add_argument("--file", action="append", default=[], help="path relative to the entry")
|
||||
editor.add_argument("--run-dir", type=Path)
|
||||
editor.add_argument("--port", type=int, default=0)
|
||||
resume = commands.add_parser("resume", help="reopen a saved source snapshot")
|
||||
resume.add_argument("snapshot", type=Path)
|
||||
for command in (editor, resume):
|
||||
command.add_argument("--web-dir", type=Path, help="use the texrra-web checkout")
|
||||
command.add_argument("--run-dir", type=Path)
|
||||
command.add_argument("--port", type=int, default=0)
|
||||
|
||||
compiler = commands.add_parser("compile", help="produce a PDF with the bundle's native CLI")
|
||||
compiler.add_argument("entry", type=Path)
|
||||
|
||||
Reference in new issue
Block a user