Skip to content

Commit

Permalink
feat: add output path option
Browse files Browse the repository at this point in the history
  • Loading branch information
lihbr committed Jun 29, 2021
1 parent 920ee8f commit 2f29731
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@ const run = async (): Promise<void> => {
const args = process.argv.slice(2);

let base = "./";
let output = "./";

if (args.length) {
base = args[0];

if (args[1]) {
output = args[1];
}
}

try {
await fetchDicoInternalHandler(base);
await fetchDicoInternalHandler(base, output);
} catch (error) {
if (error instanceof DicoError) {
logger.error(error);
Expand Down
8 changes: 6 additions & 2 deletions src/fetchDicoInternalHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ import { lineBreak, logger } from "./lib";
* Fetch dico internal handler
*
* @param base - Base directory where `dico.config.json` and `dico.data.json` can be found
* @param output - Output directory relative to base where `dico.data.json` can be found
*
* @internal
*/
export const fetchDicoInternalHandler = async (base = "./"): Promise<void> => {
export const fetchDicoInternalHandler = async (
base = "./",
output = "./"
): Promise<void> => {
const configPath = path.join(process.cwd(), base, CONFIG_FILE);
if (!fs.existsSync(configPath)) {
throw new DicoError(messages.ConfigFileNotFound(configPath));
Expand Down Expand Up @@ -54,7 +58,7 @@ export const fetchDicoInternalHandler = async (base = "./"): Promise<void> => {
lineBreak();
}

const dataPath = path.join(process.cwd(), base, DATA_FILE);
const dataPath = path.join(process.cwd(), base, output, DATA_FILE);
let indent = " ";
if (fs.existsSync(dataPath)) {
indent = detectIndent(fs.readFileSync(dataPath, "utf8")).indent || " ";
Expand Down

0 comments on commit 2f29731

Please sign in to comment.