Skip to content

Commit e033656

Browse files
authored
fix: path param in init mode (#465)
1 parent 6cbb8a3 commit e033656

2 files changed

Lines changed: 17 additions & 7 deletions

File tree

.changeset/spicy-trees-rule.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"lingo.dev": patch
3+
---
4+
5+
fix init cmd

packages/cli/src/cli/cmd/init.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Ora from "ora";
33
import { getConfig, saveConfig } from "../utils/config";
44
import { defaultConfig, LocaleCode, resolveLocaleCode, bucketTypes } from "@lingo.dev/_spec";
55
import fs from "fs";
6+
import path from "path";
67
import { spawn } from "child_process";
78
import _ from "lodash";
89
import { confirm } from "@inquirer/prompts";
@@ -67,24 +68,26 @@ export default new InteractiveCommand()
6768
.default("json"),
6869
)
6970
.addOption(
70-
new InteractiveOption("-p, --paths <path...>", "List of paths for the bucket")
71+
new InteractiveOption("-p, --paths [path...]", "List of paths for the bucket")
7172
.argParser((value) => {
73+
if (!value || value.length === 0) return [];
7274
const values = value.includes(",") ? value.split(",") : value.split(" ");
7375

74-
for (const path of values) {
76+
for (const p of values) {
7577
try {
76-
const stats = fs.statSync(path);
78+
const dirPath = path.dirname(p);
79+
const stats = fs.statSync(dirPath);
7780
if (!stats.isDirectory()) {
78-
throw new Error(`${path} is not a directory`);
81+
throw new Error(`${dirPath} is not a directory`);
7982
}
8083
} catch (err) {
81-
throw new Error(`Invalid directory path: ${path}`);
84+
throw new Error(`Invalid path: ${p}`);
8285
}
8386
}
8487

8588
return values;
8689
})
87-
.default("."),
90+
.default([]),
8891
)
8992
.action(async (options) => {
9093
const settings = getSettings(undefined);
@@ -102,7 +105,9 @@ export default new InteractiveCommand()
102105
newConfig.locale.source = options.source;
103106
newConfig.locale.targets = options.targets;
104107
newConfig.buckets = {
105-
[options.bucket]: options.paths,
108+
[options.bucket]: {
109+
include: options.paths || [],
110+
},
106111
};
107112

108113
await saveConfig(newConfig);

0 commit comments

Comments
 (0)