@tolinax/ayoune-cli 2024.2.7 → 2024.2.9

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 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
- import path from "path";
7
- import { readFile } from "fs/promises";
8
- import * as process from "process";
9
- //Create new command instance
10
- //@ts-ignore
11
- const pkg = JSON.parse(await readFile(path.join(process.cwd(), "package.json"), "utf8"));
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);
@@ -6,6 +6,7 @@ import { promptEntry } from "../prompts/promptEntry.js";
6
6
  import { handleCollectionOperation } from "../operations/handleCollectionOperation.js";
7
7
  import { localStorage } from "../helpers/localStorage.js";
8
8
  import { parseInteger } from "../helpers/parseInt.js";
9
+ import { handleGetOperation } from "../operations/handleGetOperation.js";
9
10
  export function createModulesCommand(program) {
10
11
  program
11
12
  .command("modules")
@@ -27,7 +28,11 @@ export function createModulesCommand(program) {
27
28
  const { result } = await handleListOperation(module, collection, opts);
28
29
  entry = await promptEntry(result);
29
30
  }
30
- await handleCollectionOperation(module, collection, entry, operation);
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);
31
36
  }
32
37
  catch (e) {
33
38
  console.error(e);
@@ -4,7 +4,12 @@ import { handleEditOperation } from "./handleEditOperation.js";
4
4
  import { handleEditRawOperation } from "./handleEditRawOperation.js";
5
5
  import { spinner } from "../../index.js";
6
6
  import { promptDefaultAction } from "../prompts/promptDefaultAction.js";
7
- export async function handleCollectionOperation(module, collection, entry, operation) {
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) {
8
13
  spinner.start({ text: "", color: "magenta" });
9
14
  const res = await apiCallHandler(`${module}/${collection.toLowerCase()}/${entry}?responseFormat=table`);
10
15
  const editContent = res.payload;
@@ -21,6 +26,16 @@ export async function handleCollectionOperation(module, collection, entry, opera
21
26
  case "edit raw":
22
27
  await handleEditRawOperation(module, collection, editContent);
23
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;
24
39
  default:
25
40
  break;
26
41
  }
@@ -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,25 +1,25 @@
1
- // Operation handling functions
2
- import { apiCallHandler } from "../api/apiCallHandler.js";
3
- import { spinner } from "../../index.js";
4
- import { handleResponseFormatOptions } from "../helpers/handleResponseFormatOptions.js";
5
- export async function handleGetOperation(module, collection, opts) {
6
- spinner.start({
7
- text: `Getting entries in [${collection}]`,
8
- color: "magenta",
9
- });
10
- let res = await apiCallHandler(`${module}/${collection.toLowerCase()}`, "get", null, {
11
- page: opts.page,
12
- responseFormat: opts.responseFormat,
13
- limit: opts.limit,
14
- from: opts.from,
15
- fields: opts.fields,
16
- hideMeta: opts.hideMeta,
17
- verbosity: opts.verbosity,
18
- });
19
- let { plainResult, result, meta, content } = handleResponseFormatOptions(opts, res);
20
- spinner.success({
21
- text: `Got ${opts.limit} entries of ${meta.pageInfo.totalEntries} : Page ${meta.pageInfo.page} of ${meta.pageInfo.totalPages}`,
22
- });
23
- spinner.stop();
24
- return { data: plainResult, content, result, meta };
25
- }
1
+ // Operation handling functions
2
+ import { apiCallHandler } from "../api/apiCallHandler.js";
3
+ import { spinner } from "../../index.js";
4
+ import { handleResponseFormatOptions } from "../helpers/handleResponseFormatOptions.js";
5
+ export async function handleGetOperation(module, collection, opts) {
6
+ spinner.start({
7
+ text: `Getting entries in [${collection}]`,
8
+ color: "magenta",
9
+ });
10
+ let res = await apiCallHandler(`${module}/${collection.toLowerCase()}`, "get", null, {
11
+ page: opts.page,
12
+ responseFormat: opts.responseFormat,
13
+ limit: opts.limit,
14
+ from: opts.from,
15
+ fields: opts.fields,
16
+ hideMeta: opts.hideMeta,
17
+ verbosity: opts.verbosity,
18
+ });
19
+ let { plainResult, result, meta, content } = handleResponseFormatOptions(opts, res);
20
+ spinner.success({
21
+ text: `Got ${opts.limit} entries of ${meta.pageInfo.totalEntries} : Page ${meta.pageInfo.page} of ${meta.pageInfo.totalPages}`,
22
+ });
23
+ spinner.stop();
24
+ return { data: plainResult, content, result, meta };
25
+ }
@@ -0,0 +1,11 @@
1
+ import inquirer from "inquirer";
2
+ export async function promptFilePath() {
3
+ const { path } = await inquirer.prompt([
4
+ {
5
+ type: "fuzzypath",
6
+ name: "path",
7
+ message: "Select a target directory:",
8
+ },
9
+ ]);
10
+ return path;
11
+ }
@@ -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
+ }
@@ -0,0 +1,12 @@
1
+ import inquirer from "inquirer";
2
+ export async function promptFileName(name) {
3
+ const { fileName } = await inquirer.prompt([
4
+ {
5
+ type: "text",
6
+ name: "fileName",
7
+ message: "Specify a file name",
8
+ default: name,
9
+ },
10
+ ]);
11
+ return fileName;
12
+ }
@@ -0,0 +1,11 @@
1
+ import inquirer from "inquirer";
2
+ export async function promptFilePath() {
3
+ const { path } = await inquirer.prompt([
4
+ {
5
+ type: "fuzzypath",
6
+ name: "path",
7
+ message: "Select a target directory:",
8
+ },
9
+ ]);
10
+ return path;
11
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tolinax/ayoune-cli",
3
- "version": "2024.2.7",
3
+ "version": "2024.2.9",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./index.js",