Skip to content

Commit

Permalink
fix: fix create command
Browse files Browse the repository at this point in the history
  • Loading branch information
pviti committed Sep 4, 2024
1 parent 7288d1e commit afe721f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
23 changes: 21 additions & 2 deletions src/base.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { clColor, clToken, clUpdate, clFilter, clOutput, clUtil, clApi } from '@commercelayer/cli-core'
import type { ApiMode, KeyValRel, KeyValString } from '@commercelayer/cli-core'
import { Command, Flags, Args } from '@oclif/core'
import { existsSync, readFileSync } from 'fs'
import { existsSync, readFileSync, writeFileSync } from 'fs'
import axios from 'axios'
import { type InputType, gunzipSync } from 'zlib'
import commercelayer, { type CommerceLayerClient, CommerceLayerStatic } from '@commercelayer/sdk'
import commercelayer, { type CommerceLayerClient, CommerceLayerStatic, type Export } from '@commercelayer/sdk'
import { rename } from 'fs/promises'
import type { CommandError } from '@oclif/core/lib/interfaces'
import notifier from 'node-notifier'
import * as cliux from '@commercelayer/cli-ux'
import { join } from 'path'


const pkg: clUpdate.Package = require('../package.json')
Expand Down Expand Up @@ -177,6 +178,24 @@ export abstract class ExportCommand extends BaseCommand {
}


protected async singleExportFile(exp: Export, flags: any): Promise<string> {

const tmpDir = this.config.cacheDir
const format = this.getFileFormat(flags)

// Export just completed, no need to refresh attachment url
const fileExport = await this.getExportedFile(exp.attachment_url, flags)

const tmpFile = join(tmpDir, `${exp.id}-tmp.${format}`)

writeFileSync(tmpFile, fileExport, { encoding })
if (flags.keep) writeFileSync(tmpFile.replace('-tmp', ''), fileExport, { encoding })

return tmpFile

}


protected async saveOutput(tempFile: string, flags: any): Promise<string | undefined> {

try {
Expand Down
18 changes: 0 additions & 18 deletions src/commands/exports/all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,24 +436,6 @@ export default class ExportsAll extends ExportCommand {
}


private async singleExportFile(exp: Export, flags: any): Promise<string> {

const tmpDir = this.config.cacheDir
const format = this.getFileFormat(flags)

// Export just completed, no need to refresh attachment url
const fileExport = await this.getExportedFile(exp.attachment_url, flags)

const tmpFile = join(tmpDir, `${exp.id}-tmp.${format}`)

writeFileSync(tmpFile, fileExport, { encoding })
if (flags.keep) writeFileSync(tmpFile.replace('-tmp', ''), fileExport, { encoding })

return tmpFile

}


private async mergeExportFiles(exports: Export[], flags: any): Promise<string> {

const tmpDir = this.config.cacheDir
Expand Down
3 changes: 2 additions & 1 deletion src/commands/exports/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ export default class ExportsCreate extends ExportCommand {
if (exp.status === 'completed') this.log(`\nExported ${clColor.yellowBright(exp.records_count || 0)} ${resDesc}`)
else this.error(`Export ${exp?.id} ended with errors`)

const outputFile = await this.saveOutput(exp, flags)
const tmpOutputFile = await this.singleExportFile(exp, flags)
const outputFile = await this.saveOutput(tmpOutputFile, flags)

// Notification
const finishMessage = `Export of ${exp.records_count} ${resDesc} is finished!`
Expand Down

0 comments on commit afe721f

Please sign in to comment.