proca 0.4.1 → 0.4.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/README.md +106 -41
- package/package.json +1 -1
- package/src/commands/action/count.mjs +61 -0
- package/src/commands/supporter/count.mjs +96 -0
- package/src/commands/widget/add.mjs +1 -1
- package/src/procaCommand.mjs +5 -4
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ $ npm install -g proca
|
|
|
18
18
|
$ proca COMMAND
|
|
19
19
|
running command...
|
|
20
20
|
$ proca (--version)
|
|
21
|
-
proca/0.4.
|
|
21
|
+
proca/0.4.2 linux-x64 node-v20.12.2
|
|
22
22
|
$ proca --help [COMMAND]
|
|
23
23
|
USAGE
|
|
24
24
|
$ proca COMMAND
|
|
@@ -50,6 +50,7 @@ USAGE
|
|
|
50
50
|
|
|
51
51
|
# Commands
|
|
52
52
|
<!-- commands -->
|
|
53
|
+
* [`proca action count`](#proca-action-count)
|
|
53
54
|
* [`proca action list [TITLE]`](#proca-action-list-title)
|
|
54
55
|
* [`proca action replay`](#proca-action-replay)
|
|
55
56
|
* [`proca campaign add [TITLE]`](#proca-campaign-add-title)
|
|
@@ -75,6 +76,7 @@ USAGE
|
|
|
75
76
|
* [`proca plugins uninstall [PLUGIN]`](#proca-plugins-uninstall-plugin)
|
|
76
77
|
* [`proca plugins unlink [PLUGIN]`](#proca-plugins-unlink-plugin)
|
|
77
78
|
* [`proca plugins update`](#proca-plugins-update)
|
|
79
|
+
* [`proca supporter count`](#proca-supporter-count)
|
|
78
80
|
* [`proca user get`](#proca-user-get)
|
|
79
81
|
* [`proca user leave`](#proca-user-leave)
|
|
80
82
|
* [`proca user list`](#proca-user-list)
|
|
@@ -82,12 +84,42 @@ USAGE
|
|
|
82
84
|
* [`proca widget get`](#proca-widget-get)
|
|
83
85
|
* [`proca widget list`](#proca-widget-list)
|
|
84
86
|
|
|
87
|
+
## `proca action count`
|
|
88
|
+
|
|
89
|
+
counter of actions
|
|
90
|
+
|
|
91
|
+
```
|
|
92
|
+
USAGE
|
|
93
|
+
$ proca action count [ID_NAME_DXID] [--simplify [--json | --human | --csv]] [-i <value>
|
|
94
|
+
| -n <the_short_name> | -x <value>]
|
|
95
|
+
|
|
96
|
+
FLAGS
|
|
97
|
+
-i, --id=<value>
|
|
98
|
+
-n, --name=<the_short_name> name
|
|
99
|
+
-x, --dxid=<value> dxid
|
|
100
|
+
|
|
101
|
+
OUTPUT FLAGS
|
|
102
|
+
--csv Format output as csv
|
|
103
|
+
--human Format output to be read on screen by a human [default]
|
|
104
|
+
--json Format output as json
|
|
105
|
+
--simplify flatten and filter to output only the most important attributes, mostly relevant for json
|
|
106
|
+
|
|
107
|
+
DESCRIPTION
|
|
108
|
+
counter of actions
|
|
109
|
+
|
|
110
|
+
EXAMPLES
|
|
111
|
+
$ proca action count --id <id of the campaign>
|
|
112
|
+
|
|
113
|
+
$ proca action count --name <name of the campaign>
|
|
114
|
+
```
|
|
115
|
+
|
|
85
116
|
## `proca action list [TITLE]`
|
|
86
117
|
|
|
87
118
|
```
|
|
88
119
|
USAGE
|
|
89
|
-
$ proca action list [TITLE] -o <organisation name> [--
|
|
90
|
-
| -n <the_short_name> | -x <value>] [-c <campaign title>] [--limit <value>] [--optin]
|
|
120
|
+
$ proca action list [TITLE] -o <organisation name> [--simplify [--json | --human |
|
|
121
|
+
--csv]] [-i <value> | -n <the_short_name> | -x <value>] [-c <campaign title>] [--limit <value>] [--optin]
|
|
122
|
+
[--testing] [--doi] [--utm]
|
|
91
123
|
|
|
92
124
|
ARGUMENTS
|
|
93
125
|
TITLE name of the campaign, % for wildchar
|
|
@@ -118,8 +150,8 @@ EXAMPLES
|
|
|
118
150
|
|
|
119
151
|
```
|
|
120
152
|
USAGE
|
|
121
|
-
$ proca action replay -o <organisation name> [--
|
|
122
|
-
<the_short_name> | -x <value>] [-c <campaign title>]
|
|
153
|
+
$ proca action replay -o <organisation name> [--simplify [--json | --human | --csv]] [-i
|
|
154
|
+
<value> | -n <the_short_name> | -x <value>] [-c <campaign title>]
|
|
123
155
|
|
|
124
156
|
FLAGS
|
|
125
157
|
-c, --campaign=<campaign title> name of the campaign, % for wildchar
|
|
@@ -142,8 +174,8 @@ EXAMPLES
|
|
|
142
174
|
|
|
143
175
|
```
|
|
144
176
|
USAGE
|
|
145
|
-
$ proca campaign add [TITLE] [--
|
|
146
|
-
-x <value>] [-o <org name>]
|
|
177
|
+
$ proca campaign add [TITLE] [--simplify [--json | --human | --csv]] [-i <value> | -n
|
|
178
|
+
<campaign name> | -x <value>] [-o <org name>]
|
|
147
179
|
|
|
148
180
|
ARGUMENTS
|
|
149
181
|
TITLE title of the campaign
|
|
@@ -170,8 +202,8 @@ delete a campaign
|
|
|
170
202
|
|
|
171
203
|
```
|
|
172
204
|
USAGE
|
|
173
|
-
$ proca campaign delete [--
|
|
174
|
-
<campaign name>]
|
|
205
|
+
$ proca campaign delete [--simplify [--json | --human | --csv]] [-i <organisation name>]
|
|
206
|
+
[-x <value>] [-n <campaign name>]
|
|
175
207
|
|
|
176
208
|
FLAGS
|
|
177
209
|
-i, --id=<organisation name> id of the campaign
|
|
@@ -197,8 +229,8 @@ view a campaign
|
|
|
197
229
|
|
|
198
230
|
```
|
|
199
231
|
USAGE
|
|
200
|
-
$ proca campaign get [ID_NAME_DXID] [--
|
|
201
|
-
<the_short_name> | -x <value>] [--config] [--stats] [--locale <value>]
|
|
232
|
+
$ proca campaign get [ID_NAME_DXID] [--simplify [--json | --human | --csv]] [-i <value>
|
|
233
|
+
| -n <the_short_name> | -x <value>] [--config] [--stats] [--locale <value>]
|
|
202
234
|
|
|
203
235
|
FLAGS
|
|
204
236
|
-i, --id=<value>
|
|
@@ -227,8 +259,8 @@ list all the campaigns
|
|
|
227
259
|
|
|
228
260
|
```
|
|
229
261
|
USAGE
|
|
230
|
-
$ proca campaign list [TITLE] [--
|
|
231
|
-
| -x <value>] [-o <organisation name>] [-t <campaign title>] [--stats]
|
|
262
|
+
$ proca campaign list [TITLE] [--simplify [--json | --human | --csv]] [-i <value> | -n
|
|
263
|
+
<the_short_name> | -x <value>] [-o <organisation name>] [-t <campaign title>] [--stats]
|
|
232
264
|
|
|
233
265
|
ARGUMENTS
|
|
234
266
|
TITLE name of the campaign, % for wildchar
|
|
@@ -260,8 +292,8 @@ create setting to access the server authentication
|
|
|
260
292
|
|
|
261
293
|
```
|
|
262
294
|
USAGE
|
|
263
|
-
$ proca config add [ENVIRONMENT] --token <API-token> [--
|
|
264
|
-
<value> | -n <the_short_name> | -x <value>] [--force] [--url <url>] [--n8n <n8n api>] [--supabase <url>]
|
|
295
|
+
$ proca config add [ENVIRONMENT] --token <API-token> [--simplify [--json | --human |
|
|
296
|
+
--csv]] [-i <value> | -n <the_short_name> | -x <value>] [--force] [--url <url>] [--n8n <n8n api>] [--supabase <url>]
|
|
265
297
|
[--supabase-anon-key <value>] [--supabase-secrey-key <value>]
|
|
266
298
|
|
|
267
299
|
ARGUMENTS
|
|
@@ -301,8 +333,8 @@ get the server config
|
|
|
301
333
|
|
|
302
334
|
```
|
|
303
335
|
USAGE
|
|
304
|
-
$ proca config get [--
|
|
305
|
-
<value>]
|
|
336
|
+
$ proca config get [--simplify [--json | --human | --csv]] [-i <value> | -n
|
|
337
|
+
<the_short_name> | -x <value>]
|
|
306
338
|
|
|
307
339
|
FLAGS
|
|
308
340
|
-i, --id=<value>
|
|
@@ -325,8 +357,8 @@ create setting to access the server authentication
|
|
|
325
357
|
|
|
326
358
|
```
|
|
327
359
|
USAGE
|
|
328
|
-
$ proca config setup [ENVIRONMENT] --token <API-token> [--
|
|
329
|
-
<value> | -n <the_short_name> | -x <value>] [--force] [--url <url>] [--n8n <n8n api>] [--supabase <url>]
|
|
360
|
+
$ proca config setup [ENVIRONMENT] --token <API-token> [--simplify [--json | --human |
|
|
361
|
+
--csv]] [-i <value> | -n <the_short_name> | -x <value>] [--force] [--url <url>] [--n8n <n8n api>] [--supabase <url>]
|
|
330
362
|
[--supabase-anon-key <value>] [--supabase-secrey-key <value>]
|
|
331
363
|
|
|
332
364
|
ARGUMENTS
|
|
@@ -366,8 +398,8 @@ fetch the information about the current user (based on the token)
|
|
|
366
398
|
|
|
367
399
|
```
|
|
368
400
|
USAGE
|
|
369
|
-
$ proca config user [--
|
|
370
|
-
<value>]
|
|
401
|
+
$ proca config user [--simplify [--json | --human | --csv]] [-i <value> | -n
|
|
402
|
+
<the_short_name> | -x <value>]
|
|
371
403
|
|
|
372
404
|
FLAGS
|
|
373
405
|
-i, --id=<value>
|
|
@@ -411,8 +443,8 @@ _See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v6.2.1
|
|
|
411
443
|
|
|
412
444
|
```
|
|
413
445
|
USAGE
|
|
414
|
-
$ proca org add [--
|
|
415
|
-
[--twitter <screen name>]
|
|
446
|
+
$ proca org add [--simplify [--json | --human | --csv]] [-i <value> | -n <org
|
|
447
|
+
name> | -x <value>] [--twitter <screen name>]
|
|
416
448
|
|
|
417
449
|
FLAGS
|
|
418
450
|
-i, --id=<value>
|
|
@@ -436,8 +468,8 @@ view a org crm synchroniser
|
|
|
436
468
|
|
|
437
469
|
```
|
|
438
470
|
USAGE
|
|
439
|
-
$ proca org crm [--
|
|
440
|
-
[--synchronize]
|
|
471
|
+
$ proca org crm [--simplify [--json | --human | --csv]] (-i <value> | -n <org
|
|
472
|
+
name> | -x <value>) [--synchronize]
|
|
441
473
|
|
|
442
474
|
FLAGS
|
|
443
475
|
-i, --id=<value>
|
|
@@ -461,8 +493,8 @@ view a org
|
|
|
461
493
|
|
|
462
494
|
```
|
|
463
495
|
USAGE
|
|
464
|
-
$ proca org get [--
|
|
465
|
-
[--config] [--keys] [--campaigns] [--widgets] [--users]
|
|
496
|
+
$ proca org get [--simplify [--json | --human | --csv]] [-i <value> | -n <org
|
|
497
|
+
name> | -x <value>] [--config] [--keys] [--campaigns] [--widgets] [--users]
|
|
466
498
|
|
|
467
499
|
FLAGS
|
|
468
500
|
-i, --id=<value>
|
|
@@ -493,8 +525,8 @@ let a user join an organisation with a role
|
|
|
493
525
|
|
|
494
526
|
```
|
|
495
527
|
USAGE
|
|
496
|
-
$ proca org join -o <org name> [--
|
|
497
|
-
<the_short_name> | -x <value>] [--user <value>] [--role owner|campaigner|coordinator|translator]
|
|
528
|
+
$ proca org join -o <org name> [--simplify [--json | --human | --csv]] [-i <value>
|
|
529
|
+
| -n <the_short_name> | -x <value>] [--user <value>] [--role owner|campaigner|coordinator|translator]
|
|
498
530
|
|
|
499
531
|
FLAGS
|
|
500
532
|
-i, --id=<value>
|
|
@@ -808,14 +840,47 @@ DESCRIPTION
|
|
|
808
840
|
|
|
809
841
|
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.15/src/commands/plugins/update.ts)_
|
|
810
842
|
|
|
843
|
+
## `proca supporter count`
|
|
844
|
+
|
|
845
|
+
counter of supporters
|
|
846
|
+
|
|
847
|
+
```
|
|
848
|
+
USAGE
|
|
849
|
+
$ proca supporter count [ID_NAME_DXID] [--simplify [--json | --human | --csv]] [-i <value>
|
|
850
|
+
| -n <the_short_name> | -x <value>] [--org] [--area] [--number --without <value>]
|
|
851
|
+
|
|
852
|
+
FLAGS
|
|
853
|
+
-i, --id=<value>
|
|
854
|
+
-n, --name=<the_short_name> name
|
|
855
|
+
-x, --dxid=<value> dxid
|
|
856
|
+
--area segment by area
|
|
857
|
+
--number just return the number to add to the partner's counter
|
|
858
|
+
--org segment by partner
|
|
859
|
+
--without=<value> total to add to the partner's counter
|
|
860
|
+
|
|
861
|
+
OUTPUT FLAGS
|
|
862
|
+
--csv Format output as csv
|
|
863
|
+
--human Format output to be read on screen by a human [default]
|
|
864
|
+
--json Format output as json
|
|
865
|
+
--simplify flatten and filter to output only the most important attributes, mostly relevant for json
|
|
866
|
+
|
|
867
|
+
DESCRIPTION
|
|
868
|
+
counter of supporters
|
|
869
|
+
|
|
870
|
+
EXAMPLES
|
|
871
|
+
$ proca supporter count --id <id of the campaign>
|
|
872
|
+
|
|
873
|
+
$ proca supporter count --name <name of the campaign>
|
|
874
|
+
```
|
|
875
|
+
|
|
811
876
|
## `proca user get`
|
|
812
877
|
|
|
813
878
|
fetch the information about a user
|
|
814
879
|
|
|
815
880
|
```
|
|
816
881
|
USAGE
|
|
817
|
-
$ proca user get [--
|
|
818
|
-
<the_short_name>] [--email <value>] [-o <org name>]
|
|
882
|
+
$ proca user get [--simplify [--json | --human | --csv]] [-i <value>] [-x <value>]
|
|
883
|
+
[-n <the_short_name>] [--email <value>] [-o <org name>]
|
|
819
884
|
|
|
820
885
|
FLAGS
|
|
821
886
|
-i, --id=<value> id of the user
|
|
@@ -843,8 +908,8 @@ leave a org
|
|
|
843
908
|
|
|
844
909
|
```
|
|
845
910
|
USAGE
|
|
846
|
-
$ proca user leave --email <user email> -o <org name> [--
|
|
847
|
-
<value> | -n <the_short_name> | -x <value>]
|
|
911
|
+
$ proca user leave --email <user email> -o <org name> [--simplify [--json | --human |
|
|
912
|
+
--csv]] [-i <value> | -n <the_short_name> | -x <value>]
|
|
848
913
|
|
|
849
914
|
FLAGS
|
|
850
915
|
-i, --id=<value>
|
|
@@ -872,8 +937,8 @@ list all the users
|
|
|
872
937
|
|
|
873
938
|
```
|
|
874
939
|
USAGE
|
|
875
|
-
$ proca user list -o <value> [--
|
|
876
|
-
<the_short_name> | -x <value>]
|
|
940
|
+
$ proca user list -o <value> [--simplify [--json | --human | --csv]] [-i <value> |
|
|
941
|
+
-n <the_short_name> | -x <value>]
|
|
877
942
|
|
|
878
943
|
FLAGS
|
|
879
944
|
-i, --id=<value>
|
|
@@ -898,8 +963,8 @@ EXAMPLES
|
|
|
898
963
|
|
|
899
964
|
```
|
|
900
965
|
USAGE
|
|
901
|
-
$ proca widget add -c <campaign name> [--
|
|
902
|
-
default <campaign>/<org>/<lang> | -x <value>] [-o <en>] [-l <en>]
|
|
966
|
+
$ proca widget add -c <campaign name> [--simplify [--json | --human | --csv]] [-i
|
|
967
|
+
<value> | -n by default <campaign>/<org>/<lang> | -x <value>] [-o <en>] [-l <en>]
|
|
903
968
|
|
|
904
969
|
FLAGS
|
|
905
970
|
-c, --campaign=<campaign name> (required) name of the campaign
|
|
@@ -922,8 +987,8 @@ view a widget
|
|
|
922
987
|
|
|
923
988
|
```
|
|
924
989
|
USAGE
|
|
925
|
-
$ proca widget get [ID_NAME_DXID] [--
|
|
926
|
-
<the_short_name> | -x <value>] [--config]
|
|
990
|
+
$ proca widget get [ID_NAME_DXID] [--simplify [--json | --human | --csv]] [-i <value>
|
|
991
|
+
| -n <the_short_name> | -x <value>] [--config]
|
|
927
992
|
|
|
928
993
|
FLAGS
|
|
929
994
|
-i, --id=<value>
|
|
@@ -950,8 +1015,8 @@ list all the widgets of an org or campaign
|
|
|
950
1015
|
|
|
951
1016
|
```
|
|
952
1017
|
USAGE
|
|
953
|
-
$ proca widget list [--
|
|
954
|
-
<value>] [-o <organisation name>] [-c <campaign name>] [--config]
|
|
1018
|
+
$ proca widget list [--simplify [--json | --human | --csv]] [-i <value> | -n
|
|
1019
|
+
<the_short_name> | -x <value>] [-o <organisation name>] [-c <campaign name>] [--config]
|
|
955
1020
|
|
|
956
1021
|
FLAGS
|
|
957
1022
|
-c, --campaign=<campaign name> widgets of the campaign (coordinator or partner)
|
package/package.json
CHANGED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Args, Flags } from "@oclif/core";
|
|
2
|
+
import Command from "#src/procaCommand.mjs";
|
|
3
|
+
import { gql, query } from "#src/urql.mjs";
|
|
4
|
+
|
|
5
|
+
export default class CounterGet extends Command {
|
|
6
|
+
ignored = ["share_confirmed"];
|
|
7
|
+
secondary = ["share"];
|
|
8
|
+
|
|
9
|
+
static description = "counter of actions";
|
|
10
|
+
|
|
11
|
+
static examples = [
|
|
12
|
+
"<%= config.bin %> <%= command.id %> --id <id of the campaign>",
|
|
13
|
+
"<%= config.bin %> <%= command.id %> --name <name of the campaign>",
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
static args = this.multiid();
|
|
17
|
+
static flags = {
|
|
18
|
+
// flag with no value (-f, --force)
|
|
19
|
+
...this.flagify({ multiid: true }),
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
fetch = async (params) => {
|
|
23
|
+
const GetCounterDocument = gql`
|
|
24
|
+
query GetCounter($name: String, $id: Int) {
|
|
25
|
+
campaign(name: $name, id: $id) {
|
|
26
|
+
stats {
|
|
27
|
+
actionCount {actionType, count}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
`;
|
|
32
|
+
const result = await query(GetCounterDocument, params);
|
|
33
|
+
return result.campaign.stats;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
simplify = (d) => {
|
|
37
|
+
const result = { sharer: undefined };
|
|
38
|
+
let primary = 0;
|
|
39
|
+
let secondary = 0;
|
|
40
|
+
d.actionCount.forEach((type) => {
|
|
41
|
+
if (this.ignored.includes(type.actionType)) return;
|
|
42
|
+
if (this.secondary.includes(type.actionType)) {
|
|
43
|
+
secondary += type.count;
|
|
44
|
+
} else {
|
|
45
|
+
primary += type.count;
|
|
46
|
+
}
|
|
47
|
+
result[type.actionType] = type.count;
|
|
48
|
+
});
|
|
49
|
+
if (primary) result.sharer = `${Math.round((100 * secondary) / primary)}%`;
|
|
50
|
+
return result;
|
|
51
|
+
};
|
|
52
|
+
table = (r) => {
|
|
53
|
+
super.table(r, null, null);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
async run() {
|
|
57
|
+
const { args, flags } = await this.parse();
|
|
58
|
+
const data = await this.fetch(flags);
|
|
59
|
+
return this.output(data);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { Args, Flags } from "@oclif/core";
|
|
2
|
+
import Command from "#src/procaCommand.mjs";
|
|
3
|
+
import { gql, query } from "#src/urql.mjs";
|
|
4
|
+
|
|
5
|
+
export default class CounterGet extends Command {
|
|
6
|
+
static description = "counter of supporters";
|
|
7
|
+
|
|
8
|
+
static examples = [
|
|
9
|
+
"<%= config.bin %> <%= command.id %> --id <id of the campaign>",
|
|
10
|
+
"<%= config.bin %> <%= command.id %> --name <name of the campaign>",
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
static args = this.multiid();
|
|
14
|
+
static flags = {
|
|
15
|
+
// flag with no value (-f, --force)
|
|
16
|
+
...this.flagify({ multiid: true }),
|
|
17
|
+
org: Flags.boolean({
|
|
18
|
+
description: "segment by partner",
|
|
19
|
+
default: false,
|
|
20
|
+
}),
|
|
21
|
+
area: Flags.boolean({
|
|
22
|
+
description: "segment by area",
|
|
23
|
+
default: false,
|
|
24
|
+
}),
|
|
25
|
+
without: Flags.string({
|
|
26
|
+
description: "total to add to the partner's counter",
|
|
27
|
+
}),
|
|
28
|
+
number: Flags.boolean({
|
|
29
|
+
description: "just return the number to add to the partner's counter",
|
|
30
|
+
dependsOn: ["without"],
|
|
31
|
+
}),
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
fetchExcluding = async (params) => {
|
|
35
|
+
const GetCounterDocument = gql`
|
|
36
|
+
query GetCounter($name: String, $id: Int, $without: String!) {
|
|
37
|
+
campaign(name: $name, id: $id) {
|
|
38
|
+
stats {
|
|
39
|
+
supporterCount
|
|
40
|
+
supporterCountByOthers (orgName: $without)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}`;
|
|
44
|
+
|
|
45
|
+
const result = await query(GetCounterDocument, params);
|
|
46
|
+
return result.campaign.stats;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
fetch = async (params) => {
|
|
50
|
+
const GetCounterDocument = gql`
|
|
51
|
+
query GetCounter($name: String, $id: Int, $org: Boolean = false, $area: Boolean = false) {
|
|
52
|
+
campaign(name: $name, id: $id) {
|
|
53
|
+
stats {
|
|
54
|
+
supporterCount
|
|
55
|
+
supporterCountByOrg @include(if: $org) { org { name } count }
|
|
56
|
+
supporterCountByArea @include(if: $area) { area count }
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}`;
|
|
60
|
+
|
|
61
|
+
const result = await query(GetCounterDocument, params);
|
|
62
|
+
return result.campaign.stats;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
simplify = (d) => {
|
|
66
|
+
const result = { total: d.supporterCount };
|
|
67
|
+
d.supporterCountByOrg
|
|
68
|
+
?.sort((a, b) => b.count - a.count)
|
|
69
|
+
.forEach((org) => {
|
|
70
|
+
result[org.org.name] = org.count;
|
|
71
|
+
});
|
|
72
|
+
d.supporterCountByArea
|
|
73
|
+
?.sort((a, b) => b.count - a.count)
|
|
74
|
+
.forEach((area) => {
|
|
75
|
+
result[area.area] = area.count;
|
|
76
|
+
});
|
|
77
|
+
if (d.supporterCountByOthers) {
|
|
78
|
+
result[`without ${this.flags.without}`] = d.supporterCountByOthers;
|
|
79
|
+
}
|
|
80
|
+
return result;
|
|
81
|
+
};
|
|
82
|
+
table = (r) => {
|
|
83
|
+
super.table(r, null, null);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
async run() {
|
|
87
|
+
const { args, flags } = await this.parse();
|
|
88
|
+
if (flags.without) {
|
|
89
|
+
const data = await this.fetchExcluding(flags);
|
|
90
|
+
if (flags.number) return console.log(data.supporterCountByOthers);
|
|
91
|
+
return this.output(data);
|
|
92
|
+
}
|
|
93
|
+
const data = await this.fetch(flags);
|
|
94
|
+
return this.output(data);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Args, Flags } from "@oclif/core";
|
|
2
2
|
import { error, stdout, ux } from "@oclif/core/ux";
|
|
3
|
-
import { gql, mutation } from "#src/urql.mjs";
|
|
4
3
|
import Command from "#src/procaCommand.mjs";
|
|
4
|
+
import { gql, mutation } from "#src/urql.mjs";
|
|
5
5
|
|
|
6
6
|
export default class WidgetAdd extends Command {
|
|
7
7
|
//static args = { path: { description: "" } };
|
package/src/procaCommand.mjs
CHANGED
|
@@ -22,7 +22,7 @@ export class ProcaCommand extends Command {
|
|
|
22
22
|
json: Flags.boolean({
|
|
23
23
|
helpGroup: "OUTPUT", // Optional, groups it under a specific help section if desired
|
|
24
24
|
description: "Format output as json",
|
|
25
|
-
exclusive: ["human", "
|
|
25
|
+
exclusive: ["human", "csv"],
|
|
26
26
|
}),
|
|
27
27
|
csv: Flags.boolean({
|
|
28
28
|
description: "Format output as csv",
|
|
@@ -103,14 +103,13 @@ export class ProcaCommand extends Command {
|
|
|
103
103
|
|
|
104
104
|
async catch(err) {
|
|
105
105
|
// Check if the error was caused by a missing flag or wrong argument format
|
|
106
|
-
|
|
106
|
+
this.error(err.toString());
|
|
107
107
|
if (
|
|
108
108
|
err.message.includes("Unexpected argument") ||
|
|
109
109
|
err.message.includes("flag")
|
|
110
110
|
) {
|
|
111
111
|
// Try to adjust the argument as a flag
|
|
112
112
|
const argv = process.argv;
|
|
113
|
-
console.log(argv);
|
|
114
113
|
if (argv.includes("param")) {
|
|
115
114
|
// Adjusting the argument 'param' to be a flag `-id`
|
|
116
115
|
const paramIndex = argv.indexOf("param");
|
|
@@ -214,7 +213,9 @@ export class ProcaCommand extends Command {
|
|
|
214
213
|
|
|
215
214
|
async output(data) {
|
|
216
215
|
if (this.format === "json") {
|
|
217
|
-
|
|
216
|
+
console.log("json", data);
|
|
217
|
+
if (this.flags.simplify)
|
|
218
|
+
return data?.map(this.simplify) || this.simplify(data);
|
|
218
219
|
return data;
|
|
219
220
|
}
|
|
220
221
|
if (this.format === "csv") {
|