refactor: rename mod.ts to main.ts
This commit is contained in:
parent
4c9cf502d0
commit
3452e6c743
32
main.ts
Normal file
32
main.ts
Normal file
|
@ -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 ?: ') ?? '')
|
34
mod.ts
34
mod.ts
|
@ -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 ?: ') ?? '')
|
||||
}
|
Loading…
Reference in a new issue