Skip to content

Commit

Permalink
add output dir flag
Browse files Browse the repository at this point in the history
  • Loading branch information
idleberg committed Dec 25, 2023
1 parent 6055f72 commit 03b568e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/actions/convert.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { basename, extname } from "node:path";
import { basename, dirname, extname, join } from "node:path";
import { convertFile, defaultOptions } from "./shared";
import { glob } from 'glob';
import { writeFile } from 'node:fs/promises';
Expand Down Expand Up @@ -70,12 +70,13 @@ async function __convert(inputFiles, options = defaultOptions) {
return;
}

const presetDir = options?.outdir || dirname(avsFile);
const presetName = basename(avsFile, presetExtension);
const start = performance.now();

try {
const webvs = await convertFile(avsFile, options);
await writeFile(`${presetName}.webvs`, JSON.stringify(webvs, null, options.indent), 'utf-8');
await writeFile(`${join(presetDir, presetName)}.webvs`, JSON.stringify(webvs, null, options.indent), 'utf-8');

if (!options.quiet) {
console.log(logSymbols.success, `Converted ${colors.cyan(`${presetName}.avs`)} ${Utils.formatDuration(start)}`);
Expand Down
2 changes: 2 additions & 0 deletions src/actions/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ type Options = {
indent?: number,
debug?: boolean,
details?: boolean,
outdir?: string,
quiet?: boolean,
summary?: false
watch?: boolean,
Expand All @@ -16,6 +17,7 @@ export const defaultOptions: Options = {
debug: false,
details: false,
quiet: false,
outdir: process.cwd(),
watch: false
}

Expand Down
1 change: 1 addition & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export function main() {
.description('convert presets to JSON format, supports glob patterns')
.option('-D, --debug', 'print additional debug information', false)
.option('-i, --indent <n>', 'specify default indentation JSON', i => parseInt(i, 10), 2)
.option('-o, --outdir <dir>', 'set a custom output directory')
.option('-q, --quiet', 'print errors only')
.option('-w, --watch', 'only convert changed files')
.action(async (args, options) => {
Expand Down

0 comments on commit 03b568e

Please sign in to comment.