@waron97/prbot 3.0.1 → 3.0.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@waron97/prbot",
3
- "version": "3.0.1",
3
+ "version": "3.0.2",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -55,7 +55,7 @@ function escapeXml(str) {
55
55
  function generateXml(templates) {
56
56
  const records = templates
57
57
  .map((t) => {
58
- const id = toXmlId(t.name);
58
+ const id = `mail_template_${toXmlId(t.template_code)}`;
59
59
  const modelRef = Object.values(t.model_id)[0];
60
60
  return ` <record id="${id}" model="mail.template">
61
61
  <field name="name">${escapeXml(t.name)}</field>
@@ -93,28 +93,41 @@ async function exportEmailTemplates(opts) {
93
93
  const token = await getToken();
94
94
 
95
95
  const moduleChoices = await getModuleChoices();
96
- const module = await search({
97
- message: 'Select module:',
98
- source: async (input) => {
99
- if (!input) return moduleChoices;
100
- return moduleChoices.filter((c) => fuzzyMatch(c.name, input));
101
- },
102
- });
96
+ const moduleMatch = opts.module ? moduleChoices.find((c) => c.name === opts.module) : null;
97
+ const module = moduleMatch
98
+ ? moduleMatch.value
99
+ : await search({
100
+ message: 'Select module:',
101
+ source: async (input) => {
102
+ if (!input) return moduleChoices;
103
+ return moduleChoices.filter((c) => fuzzyMatch(c.name, input));
104
+ },
105
+ });
103
106
 
104
107
  console.log('Fetching workflows...');
105
108
  const workflows = await getWorkflows(token);
106
109
  const choices = workflows.map((w) => ({ name: w.name, value: w.id }));
107
110
 
108
- const workflowId = await search({
109
- message: 'Select workflow:',
110
- source: async (input) => {
111
- if (!input) return choices;
112
- return choices.filter((c) => fuzzyMatch(c.name, input));
113
- },
114
- });
111
+ const workflowMatch = opts.workflow
112
+ ? workflows.find((w) => w.name === opts.workflow || String(w.id) === opts.workflow)
113
+ : null;
114
+ const workflowId = workflowMatch
115
+ ? workflowMatch.id
116
+ : await search({
117
+ message: 'Select workflow:',
118
+ source: async (input) => {
119
+ if (!input) return choices;
120
+ return choices.filter((c) => fuzzyMatch(c.name, input));
121
+ },
122
+ });
115
123
 
116
124
  console.log(`Fetching email templates for workflow ${workflowId}...`);
117
- const templates = await getEmailTemplates(workflowId, token);
125
+ const excludes = opts.exclude ?? [];
126
+ const templates = (await getEmailTemplates(workflowId, token))
127
+ .filter((t) => t.template_code)
128
+ .filter((t) => {
129
+ return !excludes.some((ex) => ex === String(t.id) || ex === t.name || ex === t.template_code);
130
+ });
118
131
 
119
132
  if (!templates.length) {
120
133
  console.log('No email templates found for this workflow.');
package/src/index.js CHANGED
@@ -112,6 +112,9 @@ exportCmd
112
112
  exportCmd
113
113
  .command('email-templates')
114
114
  .option('--no-commit')
115
+ .option('-e, --exclude <value...>', 'exclude templates matching id, name, or template_code')
116
+ .option('-m, --module <name>', 'module directory name (skip prompt)')
117
+ .option('-w, --workflow <value>', 'workflow name or id (skip prompt)')
115
118
  .action((opts) => {
116
119
  exportEmailTemplates(opts).catch((err) => {
117
120
  throw err;