emailr-cli 1.3.4 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +124 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -766,7 +766,14 @@ async function handleTemplatePreview(template) {
|
|
|
766
766
|
}
|
|
767
767
|
}
|
|
768
768
|
function createTemplatesCommand() {
|
|
769
|
-
const cmd = new Command3("templates").description(
|
|
769
|
+
const cmd = new Command3("templates").description(`Manage email templates
|
|
770
|
+
|
|
771
|
+
AGENTIC LIVE EDITING:
|
|
772
|
+
draft Create new template with live preview
|
|
773
|
+
edit <id> Edit existing template with live preview
|
|
774
|
+
|
|
775
|
+
Both commands save HTML to a local file and start a hot-reload server.
|
|
776
|
+
Edit the file and see changes instantly in the browser.`);
|
|
770
777
|
cmd.command("list").description("List all templates").option("--limit <number>", "Number of templates to return", "20").option("--page <number>", "Page number", "1").option("--format <format>", "Output format (json|table)", "table").action(async (options) => {
|
|
771
778
|
try {
|
|
772
779
|
const config = loadConfig();
|
|
@@ -1046,6 +1053,122 @@ To save changes: emailr templates update ${id} --html-file ${options.file}`);
|
|
|
1046
1053
|
process.exit(1);
|
|
1047
1054
|
}
|
|
1048
1055
|
});
|
|
1056
|
+
cmd.command("draft").description(`Start a live drafting session for a new template.
|
|
1057
|
+
|
|
1058
|
+
AGENTIC WORKFLOW:
|
|
1059
|
+
1. Run: emailr templates draft --file ./new-template.html
|
|
1060
|
+
2. Edit the file at ./new-template.html - browser auto-refreshes on save
|
|
1061
|
+
3. When done: emailr templates create --name "My Template" --subject "Subject" --html-file ./new-template.html
|
|
1062
|
+
|
|
1063
|
+
This command creates a starter HTML file and starts a live preview server with hot-reload. Perfect for building new templates from scratch with instant visual feedback.`).option("--file <path>", "Path to save the HTML file for drafting", "./new-template.html").option("--no-open", "Do not automatically open browser").option("--blank", "Start with a blank file instead of starter template").action(async (options) => {
|
|
1064
|
+
try {
|
|
1065
|
+
const filePath = path4.resolve(options.file);
|
|
1066
|
+
let htmlContent;
|
|
1067
|
+
if (options.blank) {
|
|
1068
|
+
htmlContent = "";
|
|
1069
|
+
} else {
|
|
1070
|
+
htmlContent = `<!DOCTYPE html>
|
|
1071
|
+
<html>
|
|
1072
|
+
<head>
|
|
1073
|
+
<meta charset="UTF-8">
|
|
1074
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
1075
|
+
<title>Email Template</title>
|
|
1076
|
+
<style>
|
|
1077
|
+
body {
|
|
1078
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
1079
|
+
line-height: 1.6;
|
|
1080
|
+
color: #333;
|
|
1081
|
+
max-width: 600px;
|
|
1082
|
+
margin: 0 auto;
|
|
1083
|
+
padding: 20px;
|
|
1084
|
+
}
|
|
1085
|
+
.header {
|
|
1086
|
+
text-align: center;
|
|
1087
|
+
padding: 20px 0;
|
|
1088
|
+
border-bottom: 1px solid #eee;
|
|
1089
|
+
}
|
|
1090
|
+
.content {
|
|
1091
|
+
padding: 30px 0;
|
|
1092
|
+
}
|
|
1093
|
+
.button {
|
|
1094
|
+
display: inline-block;
|
|
1095
|
+
padding: 12px 24px;
|
|
1096
|
+
background-color: #5e5de7;
|
|
1097
|
+
color: white;
|
|
1098
|
+
text-decoration: none;
|
|
1099
|
+
border-radius: 5px;
|
|
1100
|
+
font-weight: bold;
|
|
1101
|
+
}
|
|
1102
|
+
.footer {
|
|
1103
|
+
text-align: center;
|
|
1104
|
+
padding: 20px 0;
|
|
1105
|
+
border-top: 1px solid #eee;
|
|
1106
|
+
color: #888;
|
|
1107
|
+
font-size: 12px;
|
|
1108
|
+
}
|
|
1109
|
+
</style>
|
|
1110
|
+
</head>
|
|
1111
|
+
<body>
|
|
1112
|
+
<div class="header">
|
|
1113
|
+
<h1>Your Company</h1>
|
|
1114
|
+
</div>
|
|
1115
|
+
|
|
1116
|
+
<div class="content">
|
|
1117
|
+
<h2>Hello {{name}},</h2>
|
|
1118
|
+
|
|
1119
|
+
<p>This is a starter template. Edit this file and see your changes live in the browser!</p>
|
|
1120
|
+
|
|
1121
|
+
<p>You can use variables like <code>{{name}}</code> that will be replaced when sending emails.</p>
|
|
1122
|
+
|
|
1123
|
+
<p style="text-align: center; margin: 30px 0;">
|
|
1124
|
+
<a href="https://example.com" class="button">Call to Action</a>
|
|
1125
|
+
</p>
|
|
1126
|
+
|
|
1127
|
+
<p>Best regards,<br>Your Team</p>
|
|
1128
|
+
</div>
|
|
1129
|
+
|
|
1130
|
+
<div class="footer">
|
|
1131
|
+
<p>\xA9 2024 Your Company. All rights reserved.</p>
|
|
1132
|
+
<p><a href="{{unsubscribe_link}}">Unsubscribe</a></p>
|
|
1133
|
+
</div>
|
|
1134
|
+
</body>
|
|
1135
|
+
</html>`;
|
|
1136
|
+
}
|
|
1137
|
+
fs4.writeFileSync(filePath, htmlContent, "utf-8");
|
|
1138
|
+
console.log(`Template draft created: ${filePath}`);
|
|
1139
|
+
const port = await startLivePreviewServer(filePath, () => {
|
|
1140
|
+
console.log("File changed - browser refreshed");
|
|
1141
|
+
});
|
|
1142
|
+
const previewUrl = `http://127.0.0.1:${port}/`;
|
|
1143
|
+
console.log(`
|
|
1144
|
+
Live Preview: ${previewUrl}`);
|
|
1145
|
+
console.log(`
|
|
1146
|
+
Watching for changes... Edit the file and see live updates.`);
|
|
1147
|
+
console.log(`
|
|
1148
|
+
When done, create the template:`);
|
|
1149
|
+
console.log(` emailr templates create --name "Template Name" --subject "Email Subject" --html-file ${options.file}`);
|
|
1150
|
+
console.log(`
|
|
1151
|
+
Press Ctrl+C to stop.`);
|
|
1152
|
+
if (options.open !== false) {
|
|
1153
|
+
try {
|
|
1154
|
+
const open = await import("open");
|
|
1155
|
+
await open.default(previewUrl);
|
|
1156
|
+
} catch {
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
process.on("SIGINT", async () => {
|
|
1160
|
+
console.log("\n\nStopping live preview server...");
|
|
1161
|
+
await stopLivePreviewServer();
|
|
1162
|
+
console.log("Done.");
|
|
1163
|
+
console.log(`
|
|
1164
|
+
To create template: emailr templates create --name "Template Name" --subject "Email Subject" --html-file ${options.file}`);
|
|
1165
|
+
process.exit(0);
|
|
1166
|
+
});
|
|
1167
|
+
} catch (err) {
|
|
1168
|
+
error(err instanceof Error ? err.message : "Failed to start draft session");
|
|
1169
|
+
process.exit(1);
|
|
1170
|
+
}
|
|
1171
|
+
});
|
|
1049
1172
|
return cmd;
|
|
1050
1173
|
}
|
|
1051
1174
|
|