@tolinax/ayoune-cli 2024.2.6 → 2024.2.8
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/index.js +11 -16
- package/lib/commands/createListCommand.js +35 -35
- package/lib/commands/createModulesCommand.js +41 -33
- package/lib/operations/handleCollectionOperation.js +42 -27
- package/lib/operations/handleEditRawOperation.js +35 -35
- package/lib/prompts/prompFilePath.js +11 -0
- package/lib/prompts/promptAudits.js +15 -15
- package/lib/prompts/promptFileName.js +12 -0
- package/lib/prompts/promptFilePath.js +11 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
#! /usr/bin/env node
|
|
2
|
-
import { Command } from "commander";
|
|
3
|
-
import { createSpinner } from "nanospinner";
|
|
4
|
-
import { initializeSettings } from "./lib/helpers/initializeSettings.js";
|
|
5
|
-
import { createProgram } from "./lib/commands/createProgram.js";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
//
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const program = new Command();
|
|
13
|
-
initializeSettings();
|
|
14
|
-
//Setup spinner
|
|
15
|
-
export const spinner = createSpinner("Getting data...");
|
|
16
|
-
createProgram(program);
|
|
1
|
+
#! /usr/bin/env node
|
|
2
|
+
import { Command } from "commander";
|
|
3
|
+
import { createSpinner } from "nanospinner";
|
|
4
|
+
import { initializeSettings } from "./lib/helpers/initializeSettings.js";
|
|
5
|
+
import { createProgram } from "./lib/commands/createProgram.js";
|
|
6
|
+
//Create new command instance
|
|
7
|
+
const program = new Command();
|
|
8
|
+
initializeSettings();
|
|
9
|
+
//Setup spinner
|
|
10
|
+
export const spinner = createSpinner("Getting data...");
|
|
11
|
+
createProgram(program);
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import { parseInteger } from "../helpers/parseInt.js";
|
|
2
|
-
import { promptCollectionWithModule } from "../prompts/promptCollectionWithModule.js";
|
|
3
|
-
import { getModuleFromCollection } from "../models/getModuleFromCollection.js";
|
|
4
|
-
import { handleListOperation } from "../operations/handleListOperation.js";
|
|
5
|
-
import { saveFile } from "../helpers/saveFile.js";
|
|
6
|
-
import { localStorage } from "../helpers/localStorage.js";
|
|
7
|
-
export function createListCommand(program) {
|
|
8
|
-
program
|
|
9
|
-
.command("list [collection]")
|
|
10
|
-
.alias("l")
|
|
11
|
-
.description("List entries in collection")
|
|
12
|
-
.option("-p, --page <number>", "Page", parseInteger, 1)
|
|
13
|
-
.option("-l, --limit <number>", "Limit", parseInteger, 20)
|
|
14
|
-
.option("-f, --from <date>", "From date")
|
|
15
|
-
.action(async (collection, options) => {
|
|
16
|
-
try {
|
|
17
|
-
const opts = { ...program.opts(), ...options };
|
|
18
|
-
if (!collection) {
|
|
19
|
-
collection = await promptCollectionWithModule();
|
|
20
|
-
}
|
|
21
|
-
const module = getModuleFromCollection(collection);
|
|
22
|
-
localStorage.setItem("lastModule", module.module);
|
|
23
|
-
localStorage.setItem("lastCollection", collection);
|
|
24
|
-
let result = {};
|
|
25
|
-
let entry = "";
|
|
26
|
-
result = await handleListOperation(module.module, collection, opts);
|
|
27
|
-
if (opts.save) {
|
|
28
|
-
await saveFile("list", opts, result);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
catch (e) {
|
|
32
|
-
console.error(e);
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
}
|
|
1
|
+
import { parseInteger } from "../helpers/parseInt.js";
|
|
2
|
+
import { promptCollectionWithModule } from "../prompts/promptCollectionWithModule.js";
|
|
3
|
+
import { getModuleFromCollection } from "../models/getModuleFromCollection.js";
|
|
4
|
+
import { handleListOperation } from "../operations/handleListOperation.js";
|
|
5
|
+
import { saveFile } from "../helpers/saveFile.js";
|
|
6
|
+
import { localStorage } from "../helpers/localStorage.js";
|
|
7
|
+
export function createListCommand(program) {
|
|
8
|
+
program
|
|
9
|
+
.command("list [collection]")
|
|
10
|
+
.alias("l")
|
|
11
|
+
.description("List entries in collection")
|
|
12
|
+
.option("-p, --page <number>", "Page", parseInteger, 1)
|
|
13
|
+
.option("-l, --limit <number>", "Limit", parseInteger, 20)
|
|
14
|
+
.option("-f, --from <date>", "From date")
|
|
15
|
+
.action(async (collection, options) => {
|
|
16
|
+
try {
|
|
17
|
+
const opts = { ...program.opts(), ...options };
|
|
18
|
+
if (!collection) {
|
|
19
|
+
collection = await promptCollectionWithModule();
|
|
20
|
+
}
|
|
21
|
+
const module = getModuleFromCollection(collection);
|
|
22
|
+
localStorage.setItem("lastModule", module.module);
|
|
23
|
+
localStorage.setItem("lastCollection", collection);
|
|
24
|
+
let result = {};
|
|
25
|
+
let entry = "";
|
|
26
|
+
result = await handleListOperation(module.module, collection, opts);
|
|
27
|
+
if (opts.save) {
|
|
28
|
+
await saveFile("list", opts, result);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
catch (e) {
|
|
32
|
+
console.error(e);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
@@ -1,33 +1,41 @@
|
|
|
1
|
-
import { promptModule } from "../prompts/promptModule.js";
|
|
2
|
-
import { promptCollectionInModule } from "../prompts/promptCollectionInModule.js";
|
|
3
|
-
import { promptOperation } from "../prompts/promptOperation.js";
|
|
4
|
-
import { handleListOperation } from "../operations/handleListOperation.js";
|
|
5
|
-
import { promptEntry } from "../prompts/promptEntry.js";
|
|
6
|
-
import { handleCollectionOperation } from "../operations/handleCollectionOperation.js";
|
|
7
|
-
import { localStorage } from "../helpers/localStorage.js";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
.
|
|
13
|
-
.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
1
|
+
import { promptModule } from "../prompts/promptModule.js";
|
|
2
|
+
import { promptCollectionInModule } from "../prompts/promptCollectionInModule.js";
|
|
3
|
+
import { promptOperation } from "../prompts/promptOperation.js";
|
|
4
|
+
import { handleListOperation } from "../operations/handleListOperation.js";
|
|
5
|
+
import { promptEntry } from "../prompts/promptEntry.js";
|
|
6
|
+
import { handleCollectionOperation } from "../operations/handleCollectionOperation.js";
|
|
7
|
+
import { localStorage } from "../helpers/localStorage.js";
|
|
8
|
+
import { parseInteger } from "../helpers/parseInt.js";
|
|
9
|
+
import { handleGetOperation } from "../operations/handleGetOperation";
|
|
10
|
+
export function createModulesCommand(program) {
|
|
11
|
+
program
|
|
12
|
+
.command("modules")
|
|
13
|
+
.alias("m")
|
|
14
|
+
.description("List modules")
|
|
15
|
+
.option("-p, --page <number>", "Page", parseInteger, 1)
|
|
16
|
+
.option("-l, --limit <number>", "Limit", parseInteger, 20)
|
|
17
|
+
.option("-f, --from <date>", "From date")
|
|
18
|
+
.action(async (options) => {
|
|
19
|
+
try {
|
|
20
|
+
const opts = { ...program.opts(), ...options };
|
|
21
|
+
const module = await promptModule();
|
|
22
|
+
const collection = await promptCollectionInModule(module);
|
|
23
|
+
const operation = await promptOperation();
|
|
24
|
+
localStorage.setItem("lastModule", module);
|
|
25
|
+
localStorage.setItem("lastCollection", collection);
|
|
26
|
+
let entry = "";
|
|
27
|
+
if (operation === "list") {
|
|
28
|
+
const { result } = await handleListOperation(module, collection, opts);
|
|
29
|
+
entry = await promptEntry(result);
|
|
30
|
+
}
|
|
31
|
+
if (operation === "get") {
|
|
32
|
+
const { result } = await handleGetOperation(module, collection, opts);
|
|
33
|
+
entry = await promptEntry(result);
|
|
34
|
+
}
|
|
35
|
+
await handleCollectionOperation(module, collection, entry, opts);
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
console.error(e);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
@@ -1,27 +1,42 @@
|
|
|
1
|
-
// All the remaining operations are classified here
|
|
2
|
-
import { apiCallHandler } from "../api/apiCallHandler.js";
|
|
3
|
-
import { handleEditOperation } from "./handleEditOperation.js";
|
|
4
|
-
import { handleEditRawOperation } from "./handleEditRawOperation.js";
|
|
5
|
-
import { spinner } from "../../index.js";
|
|
6
|
-
import { promptDefaultAction } from "../prompts/promptDefaultAction.js";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
break;
|
|
26
|
-
|
|
27
|
-
|
|
1
|
+
// All the remaining operations are classified here
|
|
2
|
+
import { apiCallHandler } from "../api/apiCallHandler.js";
|
|
3
|
+
import { handleEditOperation } from "./handleEditOperation.js";
|
|
4
|
+
import { handleEditRawOperation } from "./handleEditRawOperation.js";
|
|
5
|
+
import { spinner } from "../../index.js";
|
|
6
|
+
import { promptDefaultAction } from "../prompts/promptDefaultAction.js";
|
|
7
|
+
import yaml from "js-yaml";
|
|
8
|
+
import { promptFilePath } from "../prompts/promptFilePath.js";
|
|
9
|
+
import { promptFileName } from "../prompts/promptFileName.js";
|
|
10
|
+
import path from "path";
|
|
11
|
+
import { writeFile } from "fs/promises";
|
|
12
|
+
export async function handleCollectionOperation(module, collection, entry, opts) {
|
|
13
|
+
spinner.start({ text: "", color: "magenta" });
|
|
14
|
+
const res = await apiCallHandler(`${module}/${collection.toLowerCase()}/${entry}?responseFormat=table`);
|
|
15
|
+
const editContent = res.payload;
|
|
16
|
+
console.log(editContent);
|
|
17
|
+
spinner.success({
|
|
18
|
+
text: `Got entry ${res.payload.name} - Took ${res.meta.responseTime} ms`,
|
|
19
|
+
});
|
|
20
|
+
spinner.stop();
|
|
21
|
+
const action = await promptDefaultAction();
|
|
22
|
+
switch (action) {
|
|
23
|
+
case "edit":
|
|
24
|
+
await handleEditOperation(module, collection, editContent);
|
|
25
|
+
break;
|
|
26
|
+
case "edit raw":
|
|
27
|
+
await handleEditRawOperation(module, collection, editContent);
|
|
28
|
+
break;
|
|
29
|
+
case "describe":
|
|
30
|
+
console.log(yaml.dump(editContent));
|
|
31
|
+
break;
|
|
32
|
+
case "download":
|
|
33
|
+
const folder = await promptFilePath();
|
|
34
|
+
const fileName = await promptFileName(`${collection}_${editContent._id}.${opts.responseFormat}`);
|
|
35
|
+
await writeFile(path.join(folder, fileName), editContent, {
|
|
36
|
+
encoding: "utf8",
|
|
37
|
+
});
|
|
38
|
+
break;
|
|
39
|
+
default:
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import inquirer from "inquirer";
|
|
2
|
-
import { apiCallHandler } from "../api/apiCallHandler.js";
|
|
3
|
-
import { spinner } from "../../index.js";
|
|
4
|
-
export async function handleEditRawOperation(module, collection, result) {
|
|
5
|
-
const { content } = await inquirer.prompt([
|
|
6
|
-
{
|
|
7
|
-
type: "editor",
|
|
8
|
-
name: "content",
|
|
9
|
-
postfix: ".json",
|
|
10
|
-
message: "Edit",
|
|
11
|
-
default: JSON.stringify(result, null, 4),
|
|
12
|
-
},
|
|
13
|
-
]);
|
|
14
|
-
const contentToSave = JSON.parse(content);
|
|
15
|
-
const { save } = await inquirer.prompt([
|
|
16
|
-
{
|
|
17
|
-
type: "confirm",
|
|
18
|
-
name: "save",
|
|
19
|
-
message: "Save changes",
|
|
20
|
-
},
|
|
21
|
-
]);
|
|
22
|
-
if (save) {
|
|
23
|
-
spinner.start({
|
|
24
|
-
text: `Attempting to save [${contentToSave.name}]`,
|
|
25
|
-
color: "magenta",
|
|
26
|
-
});
|
|
27
|
-
const res = await apiCallHandler(`${module}/${collection.toLowerCase()}`, "put", JSON.parse(content));
|
|
28
|
-
result = res.payload;
|
|
29
|
-
console.log(result);
|
|
30
|
-
spinner.success({
|
|
31
|
-
text: `Saved [${contentToSave.name}] - Took ${res.meta.responseTime} ms`,
|
|
32
|
-
});
|
|
33
|
-
spinner.stop();
|
|
34
|
-
}
|
|
35
|
-
}
|
|
1
|
+
import inquirer from "inquirer";
|
|
2
|
+
import { apiCallHandler } from "../api/apiCallHandler.js";
|
|
3
|
+
import { spinner } from "../../index.js";
|
|
4
|
+
export async function handleEditRawOperation(module, collection, result) {
|
|
5
|
+
const { content } = await inquirer.prompt([
|
|
6
|
+
{
|
|
7
|
+
type: "editor",
|
|
8
|
+
name: "content",
|
|
9
|
+
postfix: ".json",
|
|
10
|
+
message: "Edit",
|
|
11
|
+
default: JSON.stringify(result, null, 4),
|
|
12
|
+
},
|
|
13
|
+
]);
|
|
14
|
+
const contentToSave = JSON.parse(content);
|
|
15
|
+
const { save } = await inquirer.prompt([
|
|
16
|
+
{
|
|
17
|
+
type: "confirm",
|
|
18
|
+
name: "save",
|
|
19
|
+
message: "Save changes",
|
|
20
|
+
},
|
|
21
|
+
]);
|
|
22
|
+
if (save) {
|
|
23
|
+
spinner.start({
|
|
24
|
+
text: `Attempting to save [${contentToSave.name}]`,
|
|
25
|
+
color: "magenta",
|
|
26
|
+
});
|
|
27
|
+
const res = await apiCallHandler(`${module}/${collection.toLowerCase()}`, "put", JSON.parse(content));
|
|
28
|
+
result = res.payload;
|
|
29
|
+
console.log(result);
|
|
30
|
+
spinner.success({
|
|
31
|
+
text: `Saved [${contentToSave.name}] - Took ${res.meta.responseTime} ms`,
|
|
32
|
+
});
|
|
33
|
+
spinner.stop();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import inquirer from "inquirer";
|
|
2
|
-
export async function promptAudits(result) {
|
|
3
|
-
const { audit } = await inquirer.prompt([
|
|
4
|
-
{
|
|
5
|
-
type: "list",
|
|
6
|
-
name: "audit",
|
|
7
|
-
message: "Choose a audit:",
|
|
8
|
-
choices: result.map((el) => ({
|
|
9
|
-
name: `${el.action} at ${el.ts} by ${el._userID.first_name} ${el._userID.last_name}`,
|
|
10
|
-
value: el._id,
|
|
11
|
-
})),
|
|
12
|
-
},
|
|
13
|
-
]);
|
|
14
|
-
return audit;
|
|
15
|
-
}
|
|
1
|
+
import inquirer from "inquirer";
|
|
2
|
+
export async function promptAudits(result) {
|
|
3
|
+
const { audit } = await inquirer.prompt([
|
|
4
|
+
{
|
|
5
|
+
type: "list",
|
|
6
|
+
name: "audit",
|
|
7
|
+
message: "Choose a audit:",
|
|
8
|
+
choices: result.map((el) => ({
|
|
9
|
+
name: `${el.action} at ${el.ts} by ${el._userID.first_name} ${el._userID.last_name}`,
|
|
10
|
+
value: el._id,
|
|
11
|
+
})),
|
|
12
|
+
},
|
|
13
|
+
]);
|
|
14
|
+
return audit;
|
|
15
|
+
}
|