Skip to content

Commit

Permalink
new import/export command - refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
KarolNet committed Nov 27, 2024
1 parent 1faa8dd commit 4a21ea3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
15 changes: 8 additions & 7 deletions commands/exporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,6 @@ exports.builder = {

async function exporter(directory, flotiqApiUrl, flotiqApiKey, skipContent, ctd) {
try {
const dirStat = await fs.lstat(directory);

if (!dirStat.isDirectory()) {
logger.error(`${directory} exists, but isn't directory`);
return false;
}

const files = await fs.readdir(directory);

if (files.length > 0) {
Expand Down Expand Up @@ -135,6 +128,14 @@ async function exporter(directory, flotiqApiUrl, flotiqApiKey, skipContent, ctd)
return true;
}
async function main(argv) {

const dirStat = await fs.lstat(argv.directory);

if (!dirStat.isDirectory()) {
logger.error(`${argv.directory} exists, but isn't directory`);
return false;
}

await exporter(
argv.directory,
`${config.apiUrl}/api/v1`,
Expand Down
15 changes: 6 additions & 9 deletions commands/importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,7 @@ async function checkIfClear(flotiqApiUrl, headers, CTDs) {
return true
}

async function importer(directory, flotiqApiUrl, flotiqApiKey, skipDefinitions, skipContent, updateDefinitions, disableWebhooks, fixDefinitions,
ctd,
skipCtd,
batch)
async function importer(directory, flotiqApiUrl, flotiqApiKey, skipDefinitions, skipContent, updateDefinitions, disableWebhooks, fixDefinitions, ctd, skipCtd, batch)
{
if (fixDefinitions) {
updateDefinitions = true;
Expand All @@ -115,11 +112,6 @@ async function importer(directory, flotiqApiUrl, flotiqApiKey, skipDefinitions,
batchSize: BATCH_SIZE,
});

if (!directory || !flotiqApiUrl || !flotiqApiKey) {
console.error(`Usage: ${__filename} <import_dir> <api_url> <api_key>`)
return false;
}

try {
await fs.stat(path.resolve(directory))

Expand Down Expand Up @@ -464,6 +456,11 @@ async function importer(directory, flotiqApiUrl, flotiqApiKey, skipDefinitions,
}
}
async function main(argv) {
if (!argv.directory || !argv.flotiqApiKey) {
console.error(`Usage: ${__filename} <import_dir> <api_key>`)
return false;
}

await importer(
argv.directory,
`${config.apiUrl}/api/v1`,
Expand Down

0 comments on commit 4a21ea3

Please sign in to comment.