From 3452e6c743b2271c2395eab5489a2aa357a0f463 Mon Sep 17 00:00:00 2001 From: Julien Oculi Date: Mon, 15 Jan 2024 22:55:53 +0100 Subject: [PATCH] refactor: rename mod.ts to main.ts --- main.ts | 32 ++++++++++++++++++++++++++++++++ mod.ts | 34 ---------------------------------- 2 files changed, 32 insertions(+), 34 deletions(-) create mode 100644 main.ts delete mode 100644 mod.ts diff --git a/main.ts b/main.ts new file mode 100644 index 0000000..2973548 --- /dev/null +++ b/main.ts @@ -0,0 +1,32 @@ +import { Redmine } from 'bluemine' +import * as CSV from 'std:csv' +import { CsvEntry } from "./type.ts" +import { createUsers } from './src/create_users.ts' +import { appendToGroup } from './src/append_to_group.ts' + +const endpoint = Deno.env.get('ENDPOINT') +const apiKey = Deno.env.get('API_KEY') + +if (apiKey === undefined) { + throw new Error( + 'Redmine REST API key is missing, please define API_KEY', + ) +} +if (endpoint === undefined) { + throw new Error( + 'Redmine REST endpoint is missing, please define ENDPOINT', + ) +} + +const redmine = new Redmine({ endpoint, apiKey }) + +const file = await Deno.readTextFile( + prompt('Full path of the CSV file ?: ') ?? '', +) + +const csv = CSV.parse(file.replaceAll(';', ','), { + skipFirstRow: true, +}) as CsvEntry[] + +createUsers(redmine, csv) +appendToGroup(redmine, csv, prompt('Enter a group name ?: ') ?? '') diff --git a/mod.ts b/mod.ts deleted file mode 100644 index fc1c319..0000000 --- a/mod.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { Redmine } from 'bluemine' -import * as CSV from 'std:csv' -import { CsvEntry } from './type.ts' -import { createUsers } from './src/create_users.ts' -import { appendToGroup } from './src/append_to_group.ts' - -if (import.meta.main) { - const endpoint = Deno.env.get('ENDPOINT') - const apiKey = Deno.env.get('API_KEY') - - if (apiKey === undefined) { - throw new Error( - 'Redmine REST API key is missing, please define API_KEY', - ) - } - if (endpoint === undefined) { - throw new Error( - 'Redmine REST endpoint is missing, please define ENDPOINT', - ) - } - - const redmine = new Redmine({ endpoint, apiKey }) - - const file = await Deno.readTextFile( - prompt('Full path of the CSV file ?: ') ?? '', - ) - - const csv = CSV.parse(file.replaceAll(';', ','), { - skipFirstRow: true, - }) as CsvEntry[] - - createUsers(redmine, csv) - appendToGroup(redmine, csv, prompt('Enter a group name ?: ') ?? '') -}