proca 0.1.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/README.md +214 -0
- package/package.json +66 -0
- package/proca-cli +8 -0
- package/src/commands/campaign/get.mjs +121 -0
- package/src/commands/campaign/list.mjs +165 -0
- package/src/commands/campaign/queries.graphql +19 -0
- package/src/commands/config/add.mjs +108 -0
- package/src/commands/org/get.mjs +97 -0
- package/src/config.mjs +31 -0
- package/src/generated/schema.json +10677 -0
- package/src/index.mjs +1 -0
- package/src/procaCommand.mjs +158 -0
- package/src/queries/campaign.mjs +21 -0
- package/src/urql.mjs +46 -0
- package/src/util/flags.mjs +39 -0
- package/theme.json +29 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { Args, Flags } from "@oclif/core";
|
|
2
|
+
import { error, stdout, ux } from "@oclif/core/ux";
|
|
3
|
+
import Command from "#src/procaCommand.mjs";
|
|
4
|
+
//import {FragmentSummary,} from "#src/queries/org.mjs";
|
|
5
|
+
import { gql, query } from "#src/urql.mjs";
|
|
6
|
+
|
|
7
|
+
export default class OrgGet extends Command {
|
|
8
|
+
actionTypes = new Set();
|
|
9
|
+
|
|
10
|
+
static args = {};
|
|
11
|
+
|
|
12
|
+
static description = "view a org";
|
|
13
|
+
|
|
14
|
+
static examples = ["<%= config.bin %> <%= command.id %> <name of the ngo>"];
|
|
15
|
+
|
|
16
|
+
static flags = {
|
|
17
|
+
// flag with no value (-f, --force)
|
|
18
|
+
...super.globalFlags,
|
|
19
|
+
name: Flags.string({
|
|
20
|
+
char: "n",
|
|
21
|
+
description: "name of the org",
|
|
22
|
+
helpValue: "<org name>",
|
|
23
|
+
}),
|
|
24
|
+
config: Flags.boolean({
|
|
25
|
+
description: "display the config",
|
|
26
|
+
default: false,
|
|
27
|
+
allowNo: true,
|
|
28
|
+
}),
|
|
29
|
+
keys: Flags.boolean({
|
|
30
|
+
default: true,
|
|
31
|
+
allowNo: true,
|
|
32
|
+
}),
|
|
33
|
+
campaigns: Flags.boolean({
|
|
34
|
+
default: true,
|
|
35
|
+
allowNo: true,
|
|
36
|
+
}),
|
|
37
|
+
widgets: Flags.boolean({
|
|
38
|
+
default: true,
|
|
39
|
+
allowNo: true,
|
|
40
|
+
}),
|
|
41
|
+
users: Flags.boolean({
|
|
42
|
+
default: true,
|
|
43
|
+
allowNo: true,
|
|
44
|
+
}),
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
Get = async (name) => {
|
|
48
|
+
const GetOrgDocument = gql`
|
|
49
|
+
query GetOrg($name: String!, $withCampaigns: Boolean = true) {
|
|
50
|
+
org (name: $name) {
|
|
51
|
+
id name title
|
|
52
|
+
config
|
|
53
|
+
campaigns @include(if: $withCampaigns) {id, name, title, org {name}}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
`;
|
|
57
|
+
const result = await query(GetOrgDocument, {
|
|
58
|
+
name: name,
|
|
59
|
+
// withStats: this.flags.stats,
|
|
60
|
+
});
|
|
61
|
+
return result.org;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
simplify = (d) => {
|
|
65
|
+
const result = {
|
|
66
|
+
id: d.id,
|
|
67
|
+
Name: d.name,
|
|
68
|
+
Title: d.title,
|
|
69
|
+
};
|
|
70
|
+
if (this.flags.stats) {
|
|
71
|
+
result["#Supporters"] = d.stats.supporterCount;
|
|
72
|
+
|
|
73
|
+
this.actionTypes.forEach((type) => {
|
|
74
|
+
const action = d.stats.actionCount.find(
|
|
75
|
+
(action) => action.actionType === type,
|
|
76
|
+
);
|
|
77
|
+
if (action) result[`#${type}`] = action.count;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return result;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
table = (r) => {
|
|
84
|
+
r.config = JSON.parse(r.config);
|
|
85
|
+
super.table(this.simplify(r), null, null);
|
|
86
|
+
if (this.flags.config) {
|
|
87
|
+
r.config.locales = undefined;
|
|
88
|
+
this.prettyJson(r.config);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
async run() {
|
|
93
|
+
const { args, flags } = await this.parse();
|
|
94
|
+
const data = await this.Get(flags.name);
|
|
95
|
+
return this.output(data);
|
|
96
|
+
}
|
|
97
|
+
}
|
package/src/config.mjs
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { config as dotenv } from "dotenv";
|
|
4
|
+
|
|
5
|
+
export const getFilename = (folder, env = "default") =>
|
|
6
|
+
join(folder, `${env}.env`);
|
|
7
|
+
|
|
8
|
+
export const load = (folder, env = "default") => {
|
|
9
|
+
const file = getFilename(folder, env);
|
|
10
|
+
const config = dotenv({ path: file });
|
|
11
|
+
return {
|
|
12
|
+
token: config.parsed.PROCA_TOKEN,
|
|
13
|
+
url: config.parsed.REACT_APP_API_URL,
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const get = (file) => {
|
|
18
|
+
try {
|
|
19
|
+
const userConfig = readFileSync(file, "utf8");
|
|
20
|
+
return userConfig;
|
|
21
|
+
} catch (e) {
|
|
22
|
+
if (e.code === "ENOENT" && onMissing) {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
throw e;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const write = (file, content) => {
|
|
30
|
+
writeFileSync(file, content);
|
|
31
|
+
};
|