Add import template into tui. Fix tests that fail on macos. Fix some updates.
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import { existsSync, readFileSync, writeFileSync } from "fs";
|
||||
import { existsSync, writeFileSync } from "fs";
|
||||
import path from "path";
|
||||
import { generateTemplateIdentifier } from "@xo-cash/engine";
|
||||
import type { XOTemplate } from "@xo-cash/types";
|
||||
|
||||
import { bold, dim, formatObject } from "../utils.js";
|
||||
import { loadTemplateFromFile, TemplateLoadError } from "../../utils/load-template-from-file.js";
|
||||
import { resolveTemplateReferences } from "../../utils/templates.js";
|
||||
import type { CommandDependencies, CommandIO } from "./types.js";
|
||||
import { CommandError } from "./types.js";
|
||||
@@ -18,7 +19,7 @@ export const printTemplateHelp = (io: CommandIO): void => {
|
||||
${bold("Usage:")} xo-cli template <sub-command>
|
||||
|
||||
${bold("Sub-commands:")}
|
||||
- import <template-file> ${dim("Import a template from a file")}
|
||||
- import <template-file> ${dim("Import a template from a JSON, JS, or TS file")}
|
||||
- list ${dim("List all templates")}
|
||||
- list <category> <identifier> ${dim("List all options of the field type in a template")}
|
||||
- inspect <category> <identifier> <field> ${dim("Inspect a field in a template")}
|
||||
@@ -464,12 +465,26 @@ export const handleTemplateCommand = async (
|
||||
);
|
||||
}
|
||||
|
||||
// Read the template file
|
||||
const template = await readFileSync(templatePath, "utf8");
|
||||
// Read and load the template file (JSON directly, TS/JS via child process).
|
||||
let templateContents: string;
|
||||
try {
|
||||
templateContents = await loadTemplateFromFile(templatePath);
|
||||
} catch (error) {
|
||||
const message =
|
||||
error instanceof TemplateLoadError
|
||||
? error.message
|
||||
: error instanceof Error
|
||||
? error.message
|
||||
: String(error);
|
||||
deps.io.err(message);
|
||||
printTemplateHelp(deps.io);
|
||||
throw new CommandError("template.import.load_failed", message);
|
||||
}
|
||||
|
||||
deps.io.verbose(`Importing template: ${templateFile}`);
|
||||
|
||||
// Import the template
|
||||
await deps.app.engine.importTemplate(template);
|
||||
await deps.app.engine.importTemplate(templateContents);
|
||||
deps.io.verbose(`Template imported: ${templateFile}`);
|
||||
|
||||
// Return the template file
|
||||
|
||||
Reference in New Issue
Block a user