proca 1.7.8 → 1.8.3
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/README.md +469 -134
- package/package.json +5 -3
- package/proca-cli +2 -2
- package/src/commands/action/add.mjs +131 -131
- package/src/commands/action/confirm.mjs +44 -44
- package/src/commands/action/count.mjs +41 -41
- package/src/commands/action/list.mjs +130 -130
- package/src/commands/action/replay.mjs +30 -30
- package/src/commands/action/requeue.mjs +110 -110
- package/src/commands/campaign/add.mjs +95 -83
- package/src/commands/campaign/copy.mjs +91 -0
- package/src/commands/campaign/delete.mjs +36 -56
- package/src/commands/campaign/get.mjs +5 -0
- package/src/commands/campaign/list.mjs +128 -123
- package/src/commands/campaign/queries.graphql +14 -14
- package/src/commands/campaign/status.mjs +39 -39
- package/src/commands/campaign/widget/archive.mjs +124 -0
- package/src/commands/campaign/widget/copy.mjs +175 -0
- package/src/commands/campaign/widget/get.mjs +19 -0
- package/src/commands/campaign/widget/index.mjs +17 -0
- package/src/commands/campaign/widget/rebuild.mjs +50 -0
- package/src/commands/config/add.mjs +78 -78
- package/src/commands/config/folder.mjs +30 -30
- package/src/commands/config/server.mjs +15 -15
- package/src/commands/config/set.mjs +84 -84
- package/src/commands/config/user.mjs +50 -48
- package/src/commands/contact/count.mjs +22 -23
- package/src/commands/contact/list.mjs +131 -131
- package/src/commands/org/add.mjs +51 -51
- package/src/commands/org/crm.mjs +61 -61
- package/src/commands/org/delete.mjs +31 -31
- package/src/commands/org/email.mjs +94 -66
- package/src/commands/org/get.mjs +10 -5
- package/src/commands/service/add.mjs +59 -59
- package/src/commands/service/list.mjs +15 -15
- package/src/commands/target/add.mjs +52 -52
- package/src/commands/template/add.mjs +67 -67
- package/src/commands/template/list.mjs +33 -33
- package/src/commands/user/get.mjs +60 -60
- package/src/commands/user/invite.mjs +37 -37
- package/src/commands/user/join.mjs +51 -51
- package/src/commands/user/leave.mjs +47 -47
- package/src/commands/user/list.mjs +2 -2
- package/src/commands/user/reset.mjs +72 -72
- package/src/commands/widget/add.mjs +61 -70
- package/src/commands/widget/delete.mjs +27 -27
- package/src/commands/widget/get.mjs +34 -33
- package/src/commands/widget/list.mjs +93 -80
- package/src/commands/widget/rebuild.mjs +64 -0
- package/src/commands/widget/update.mjs +174 -0
- package/src/config.mjs +31 -31
- package/src/generated/schema.json +10675 -10675
- package/src/hooks/help.mjs +9 -9
- package/src/hooks/init.mjs +26 -26
- package/src/procaCommand.mjs +22 -1
- package/src/urql.mjs +39 -39
- package/src/util/twitter.mjs +19 -19
- package/theme.json +27 -27
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
query SearchCampaigns($name: String!) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
campaigns(name: $name) {
|
|
3
|
+
id
|
|
4
|
+
name
|
|
5
|
+
title
|
|
6
|
+
config
|
|
7
|
+
}
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
query GetOrgCampaigns($org: String!) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
org(name: $org) {
|
|
12
|
+
campaigns {
|
|
13
|
+
id
|
|
14
|
+
name
|
|
15
|
+
title
|
|
16
|
+
config
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
19
|
}
|
|
@@ -4,31 +4,31 @@ import Command from "#src/procaCommand.mjs";
|
|
|
4
4
|
import { gql, mutation } from "#src/urql.mjs";
|
|
5
5
|
|
|
6
6
|
export default class CampaignStatus extends Command {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
7
|
+
static args = this.multiid();
|
|
8
|
+
static aliases = ["campaign:close"];
|
|
9
|
+
|
|
10
|
+
static examples = [
|
|
11
|
+
"<%= config.bin %> <%= command.id %> -name <campaign>",
|
|
12
|
+
"<%= config.bin %> <%= command.id %> -i <campaign_id>",
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
static isCloseCommand =
|
|
16
|
+
process.argv.includes("close") ||
|
|
17
|
+
this.commandPath?.includes("close") ||
|
|
18
|
+
this.id?.includes("close");
|
|
19
|
+
|
|
20
|
+
static flags = {
|
|
21
|
+
status: Flags.string({
|
|
22
|
+
...this.flagify({ multiid: true }),
|
|
23
|
+
description: "Status to set",
|
|
24
|
+
required: true,
|
|
25
|
+
default: this.isCloseCommand ? "close" : undefined,
|
|
26
|
+
options: ["draft", "live", "closed", "ignored"],
|
|
27
|
+
}),
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
updateStatus = async (props) => {
|
|
31
|
+
const Query = gql`
|
|
32
32
|
mutation (
|
|
33
33
|
$id: Int,
|
|
34
34
|
$name: String
|
|
@@ -43,21 +43,21 @@ $status: String!
|
|
|
43
43
|
}
|
|
44
44
|
`;
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
const result = await mutation(Query, {
|
|
47
|
+
// org: props.org,
|
|
48
|
+
id: props.id,
|
|
49
|
+
name: props.name,
|
|
50
|
+
status: props.status.toUpperCase(),
|
|
51
|
+
});
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
console.log("result", result);
|
|
54
|
+
return result.updateCampaign;
|
|
55
|
+
};
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
async run() {
|
|
58
|
+
const { args, flags } = await this.parse();
|
|
59
59
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
const data = await this.updateStatus(flags);
|
|
61
|
+
return this.output(data);
|
|
62
|
+
}
|
|
63
63
|
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { Flags } from "@oclif/core";
|
|
2
|
+
import prompts from "prompts";
|
|
3
|
+
import CampaignGet from "#src/commands/campaign/get.mjs";
|
|
4
|
+
import WidgetList from "#src/commands/widget/list.mjs";
|
|
5
|
+
import WidgetUpdate from "#src/commands/widget/update.mjs";
|
|
6
|
+
import Command from "#src/procaCommand.mjs";
|
|
7
|
+
|
|
8
|
+
export default class CampaignWidgetArchive extends Command {
|
|
9
|
+
static args = this.multiid(); // Add this!
|
|
10
|
+
|
|
11
|
+
static description = "Archive all widgets in the campaign by adding suffix";
|
|
12
|
+
|
|
13
|
+
static examples = [
|
|
14
|
+
"<%= config.bin %> <%= command.id %> old_campaign",
|
|
15
|
+
"<%= config.bin %> <%= command.id %> -n old_campaign --suffix _backup",
|
|
16
|
+
"<%= config.bin %> <%= command.id %> old_campaign --dry-run",
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
static flags = {
|
|
20
|
+
...this.flagify({ multiid: true }),
|
|
21
|
+
suffix: Flags.string({
|
|
22
|
+
char: "s",
|
|
23
|
+
description: "custom suffix to append (default: _archive)",
|
|
24
|
+
helpValue: "<suffix>",
|
|
25
|
+
default: "_archive",
|
|
26
|
+
}),
|
|
27
|
+
"dry-run": Flags.boolean({
|
|
28
|
+
description: "preview changes without executing",
|
|
29
|
+
default: false,
|
|
30
|
+
}),
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
fetchCampaign = async ({ id, name }) => {
|
|
34
|
+
const campaignGet = new CampaignGet([], this.config);
|
|
35
|
+
return await campaignGet.fetch({ id, name });
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
fetchWidgets = async (campaignName) => {
|
|
39
|
+
const widgetList = new WidgetList([], this.config);
|
|
40
|
+
widgetList.flags = { campaign: campaignName, config: true };
|
|
41
|
+
return await widgetList.fetchCampaign(campaignName);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
async run() {
|
|
45
|
+
const { flags } = await this.parse();
|
|
46
|
+
const { id, name, suffix, "dry-run": dryRun } = flags;
|
|
47
|
+
|
|
48
|
+
this.log(`Fetching source campaign: ${name || id}`);
|
|
49
|
+
const campaign = await this.fetchCampaign({ id, name });
|
|
50
|
+
|
|
51
|
+
if (!campaign) {
|
|
52
|
+
this.error("Campaign not found");
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
this.log(`Fetching widgets for campaign: ${campaign.name}`);
|
|
57
|
+
const widgets = await this.fetchWidgets(campaign.name);
|
|
58
|
+
|
|
59
|
+
if (!widgets || widgets.length === 0) {
|
|
60
|
+
this.warn("No widgets found for this campaign");
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
this.log(`Found ${widgets.length} widgets`);
|
|
65
|
+
|
|
66
|
+
const renameList = widgets.map((widget) => ({
|
|
67
|
+
id: widget.id,
|
|
68
|
+
oldName: widget.name,
|
|
69
|
+
newName: `${widget.name}${suffix}`,
|
|
70
|
+
locale: widget.locale,
|
|
71
|
+
}));
|
|
72
|
+
|
|
73
|
+
this.log("\nArchive plan:");
|
|
74
|
+
this.table(renameList);
|
|
75
|
+
|
|
76
|
+
if (dryRun) {
|
|
77
|
+
this.log("\n[DRY RUN] No changes made");
|
|
78
|
+
return renameList;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Confirm before proceeding
|
|
82
|
+
const response = await prompts({
|
|
83
|
+
type: "confirm",
|
|
84
|
+
name: "proceed",
|
|
85
|
+
message: `Archive ${renameList.length} widgets by adding suffix "${suffix}"?`,
|
|
86
|
+
initial: false,
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
if (!response.proceed) {
|
|
90
|
+
this.log("Cancelled");
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const widgetUpdate = new WidgetUpdate([], this.config);
|
|
95
|
+
const results = [];
|
|
96
|
+
|
|
97
|
+
for (const item of renameList) {
|
|
98
|
+
try {
|
|
99
|
+
this.log(`Archiving: ${item.oldName} → ${item.newName}`);
|
|
100
|
+
const input = {
|
|
101
|
+
name: item.newName,
|
|
102
|
+
locale: item.locale,
|
|
103
|
+
};
|
|
104
|
+
const result = await widgetUpdate.update(item.id, input);
|
|
105
|
+
results.push({
|
|
106
|
+
id: result.id,
|
|
107
|
+
name: result.name,
|
|
108
|
+
status: "success",
|
|
109
|
+
});
|
|
110
|
+
} catch (error) {
|
|
111
|
+
this.error(`Failed to archive ${item.oldName}: ${error.message}`);
|
|
112
|
+
results.push({
|
|
113
|
+
id: item.id,
|
|
114
|
+
name: item.oldName,
|
|
115
|
+
status: "failed",
|
|
116
|
+
error: error.message,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
this.log("\nArchive complete!");
|
|
122
|
+
return this.output(results);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { Flags } from "@oclif/core";
|
|
2
|
+
import prompts from "prompts";
|
|
3
|
+
import CampaignGet from "#src/commands/campaign/get.mjs";
|
|
4
|
+
import WidgetAdd from "#src/commands/widget/add.mjs";
|
|
5
|
+
import WidgetList from "#src/commands/widget/list.mjs";
|
|
6
|
+
import Command from "#src/procaCommand.mjs";
|
|
7
|
+
|
|
8
|
+
export default class CampaignWidgetCopy extends Command {
|
|
9
|
+
static args = this.multiid();
|
|
10
|
+
|
|
11
|
+
static description = "Copy widgets from one campaign to another";
|
|
12
|
+
|
|
13
|
+
static examples = [
|
|
14
|
+
"<%= config.bin %> <%= command.id %> old_campaign --to new_campaign",
|
|
15
|
+
"<%= config.bin %> <%= command.id %> -n old_campaign --to new_campaign",
|
|
16
|
+
"<%= config.bin %> <%= command.id %> old_campaign --to new_campaign --suffix _archive",
|
|
17
|
+
"<%= config.bin %> <%= command.id %> old_campaign --to new_campaign --dry-run",
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
static flags = {
|
|
21
|
+
...this.flagify({ multiid: true }),
|
|
22
|
+
to: Flags.string({
|
|
23
|
+
char: "t",
|
|
24
|
+
required: true,
|
|
25
|
+
description: "destination campaign name",
|
|
26
|
+
helpValue: "<campaign name>",
|
|
27
|
+
}),
|
|
28
|
+
suffix: Flags.string({
|
|
29
|
+
char: "s",
|
|
30
|
+
description: "suffix to remove from widget names (e.g., _archive, -v1)",
|
|
31
|
+
helpValue: "<suffix>",
|
|
32
|
+
default: "_archive",
|
|
33
|
+
}),
|
|
34
|
+
"dry-run": Flags.boolean({
|
|
35
|
+
description: "preview changes without executing",
|
|
36
|
+
default: false,
|
|
37
|
+
}),
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
fetchCampaign = async ({ id, name }) => {
|
|
41
|
+
const campaignGet = new CampaignGet([], this.config);
|
|
42
|
+
return await campaignGet.fetch({ id, name });
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
fetchWidgets = async (campaignName) => {
|
|
46
|
+
const widgetList = new WidgetList([], this.config);
|
|
47
|
+
widgetList.flags = { campaign: campaignName, config: true };
|
|
48
|
+
return await widgetList.fetchCampaign(campaignName);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
async run() {
|
|
52
|
+
const { flags } = await this.parse();
|
|
53
|
+
const { id, name, to, suffix, "dry-run": dryRun } = flags;
|
|
54
|
+
|
|
55
|
+
this.log(`Fetching source campaign: ${name || id}`);
|
|
56
|
+
const sourceCampaign = await this.fetchCampaign({ id, name });
|
|
57
|
+
|
|
58
|
+
if (!sourceCampaign) {
|
|
59
|
+
this.error(`Source campaign not found: ${name || id}`);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
this.log(`Fetching widgets from: ${sourceCampaign.name}`);
|
|
64
|
+
const sourceWidgets = await this.fetchWidgets(sourceCampaign.name);
|
|
65
|
+
|
|
66
|
+
if (!sourceWidgets || sourceWidgets.length === 0) {
|
|
67
|
+
this.warn("No widgets found in source campaign");
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
this.log(`Found ${sourceWidgets.length} widgets`);
|
|
72
|
+
|
|
73
|
+
const widgets = sourceWidgets.map((widget) => {
|
|
74
|
+
const newName = widget.name.replace(suffix, "");
|
|
75
|
+
return {
|
|
76
|
+
newName,
|
|
77
|
+
lang: widget.locale,
|
|
78
|
+
org: widget.org.name,
|
|
79
|
+
|
|
80
|
+
config: widget.config ? JSON.stringify(widget.config) : undefined,
|
|
81
|
+
|
|
82
|
+
thankYouTemplate: widget.thankYouTemplateRef ?? widget.thankYouTemplate,
|
|
83
|
+
};
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
this.log("\n=== WIDGET COPY PLAN ===");
|
|
87
|
+
this.log(`From: ${sourceCampaign.name}`);
|
|
88
|
+
this.log(`To: ${to}`);
|
|
89
|
+
this.log(`\nWidgets (${widgets.length}):`);
|
|
90
|
+
this.table(widgets);
|
|
91
|
+
|
|
92
|
+
if (dryRun) {
|
|
93
|
+
this.log("\n[DRY RUN] No changes made");
|
|
94
|
+
return widgets;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const response = await prompts({
|
|
98
|
+
type: "confirm",
|
|
99
|
+
name: "proceed",
|
|
100
|
+
message: `Copy ${widgets.length} widgets to campaign "${to}"?`,
|
|
101
|
+
initial: false,
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
if (!response.proceed) {
|
|
105
|
+
this.log("Cancelled");
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
this.log("\nCopying widgets...");
|
|
110
|
+
const widgetAdd = new WidgetAdd([], this.config);
|
|
111
|
+
const results = [];
|
|
112
|
+
|
|
113
|
+
for (const widget of widgets) {
|
|
114
|
+
try {
|
|
115
|
+
this.log(` Creating: ${widget.newName}`);
|
|
116
|
+
const created = await widgetAdd.create({
|
|
117
|
+
campaign: to,
|
|
118
|
+
org: widget.org,
|
|
119
|
+
name: widget.newName,
|
|
120
|
+
lang: widget.lang,
|
|
121
|
+
|
|
122
|
+
config: widget.config,
|
|
123
|
+
thankYouTemplate: widget.thankYouTemplate,
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
results.push({
|
|
127
|
+
name: widget.newName,
|
|
128
|
+
id: created.id,
|
|
129
|
+
status: "success",
|
|
130
|
+
});
|
|
131
|
+
} catch (error) {
|
|
132
|
+
if (error.message.includes("invalid name (already taken?)")) {
|
|
133
|
+
// Just log and continue for existing widgets
|
|
134
|
+
this.log(` ⚠ Skipped (already exists): ${widget.newName}`);
|
|
135
|
+
results.push({
|
|
136
|
+
name: widget.newName,
|
|
137
|
+
status: "skipped",
|
|
138
|
+
reason: "already exists",
|
|
139
|
+
});
|
|
140
|
+
} else if (
|
|
141
|
+
error.message.includes("User is not a member of organisation")
|
|
142
|
+
) {
|
|
143
|
+
// Skip widgets where user doesn't have permission
|
|
144
|
+
this.log(
|
|
145
|
+
` ⚠ Skipped (no permission): ${widget.newName} (org: ${widget.org})`,
|
|
146
|
+
);
|
|
147
|
+
results.push({
|
|
148
|
+
name: widget.newName,
|
|
149
|
+
status: "skipped",
|
|
150
|
+
reason: "no permission",
|
|
151
|
+
org: widget.org,
|
|
152
|
+
});
|
|
153
|
+
} else {
|
|
154
|
+
this.warn(` Failed to create ${widget.newName}: ${error.message}`);
|
|
155
|
+
results.push({
|
|
156
|
+
name: widget.newName,
|
|
157
|
+
status: "failed",
|
|
158
|
+
error: error.message,
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
this.log("\n=== COPY COMPLETE ===");
|
|
165
|
+
const successful = results.filter((r) => r.status === "success").length;
|
|
166
|
+
const skipped = results.filter((r) => r.status === "skipped").length;
|
|
167
|
+
const failed = results.filter((r) => r.status === "failed").length;
|
|
168
|
+
|
|
169
|
+
this.log(`Widgets created: ${successful}`);
|
|
170
|
+
if (skipped > 0) this.log(`Widgets skipped: ${skipped}`);
|
|
171
|
+
if (failed > 0) this.warn(`Widgets failed: ${failed}`);
|
|
172
|
+
|
|
173
|
+
return this.output(results);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import Command from "#src/procaCommand.mjs";
|
|
2
|
+
import WidgetList from "../../widget/list.mjs";
|
|
3
|
+
|
|
4
|
+
export default class CampaignWidgetList extends Command {
|
|
5
|
+
static description = "List widgets in a campaign";
|
|
6
|
+
static args = this.multiid();
|
|
7
|
+
|
|
8
|
+
static flags = {
|
|
9
|
+
// flag with no value (-f, --force)
|
|
10
|
+
...this.flagify({ multiid: true }),
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
async run() {
|
|
14
|
+
const { flags } = await this.parse();
|
|
15
|
+
|
|
16
|
+
// Delegate to widget list, but with campaign pre-filled
|
|
17
|
+
await WidgetList.run(["--campaign", flags.name], this.config);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Command } from "@oclif/core";
|
|
2
|
+
|
|
3
|
+
export default class CampaignWidget extends Command {
|
|
4
|
+
static description = "commands for multiple widgets in a campaign";
|
|
5
|
+
static aliases = ["campaign:widget"];
|
|
6
|
+
static hidden = true; // Hide from command list, only show as topic
|
|
7
|
+
|
|
8
|
+
static id = "campaign:widget";
|
|
9
|
+
|
|
10
|
+
async run() {
|
|
11
|
+
const { Help } = await import("@oclif/core");
|
|
12
|
+
const help = new Help(this.config, { all: true });
|
|
13
|
+
const formatted = help.formatCommand(this);
|
|
14
|
+
this.log(formatted);
|
|
15
|
+
// this.error("Please specify a subcommand, run with --help to list them");
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import WidgetList from "#src/commands/widget/list.mjs";
|
|
2
|
+
import WidgetRebuild from "#src/commands/widget/rebuild.mjs";
|
|
3
|
+
import Command from "#src/procaCommand.mjs";
|
|
4
|
+
|
|
5
|
+
export default class CampaignWidgetRebuild extends Command {
|
|
6
|
+
static description = "(re)build all the widgets of a campaign";
|
|
7
|
+
|
|
8
|
+
static examples = ["$ proca-cli campaign widget rebuild climate-action"];
|
|
9
|
+
|
|
10
|
+
static args = this.multiid();
|
|
11
|
+
|
|
12
|
+
static flags = {
|
|
13
|
+
// flag with no value (-f, --force)
|
|
14
|
+
...this.flagify({ multiid: true }),
|
|
15
|
+
// dryRun: Flags.boolean({
|
|
16
|
+
// description: 'Show what would be rebuilt without actually doing it',
|
|
17
|
+
// }),
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
simplify = (d) => {
|
|
21
|
+
d.location = undefined;
|
|
22
|
+
d.config = undefined;
|
|
23
|
+
d.org = d.org.name;
|
|
24
|
+
return d;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
table = (r) => {
|
|
28
|
+
super.table(r, null, null);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
rebuild = async (props) => {
|
|
32
|
+
const wapi = new WidgetList();
|
|
33
|
+
const rebuildapi = new WidgetRebuild();
|
|
34
|
+
wapi.flags.config = true; //we need to fetch each widget config
|
|
35
|
+
const widgets = await wapi.fetchCampaign(props.name); //list all widgets
|
|
36
|
+
const result = [];
|
|
37
|
+
for (const widget of widgets) {
|
|
38
|
+
// do not process all widgets in parallel but in sequence
|
|
39
|
+
const r = await rebuildapi.rebuild({ widget });
|
|
40
|
+
result.push(r);
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
async run() {
|
|
46
|
+
const { flags } = await this.parse();
|
|
47
|
+
const r = await this.rebuild(flags);
|
|
48
|
+
return this.output(r);
|
|
49
|
+
}
|
|
50
|
+
}
|