Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: path param in init mode #465

Merged
merged 1 commit into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/spicy-trees-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"lingo.dev": patch
---

fix init cmd
19 changes: 12 additions & 7 deletions packages/cli/src/cli/cmd/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Ora from "ora";
import { getConfig, saveConfig } from "../utils/config";
import { defaultConfig, LocaleCode, resolveLocaleCode, bucketTypes } from "@lingo.dev/_spec";
import fs from "fs";
import path from "path";
import { spawn } from "child_process";
import _ from "lodash";
import { confirm } from "@inquirer/prompts";
Expand Down Expand Up @@ -67,24 +68,26 @@ export default new InteractiveCommand()
.default("json"),
)
.addOption(
new InteractiveOption("-p, --paths <path...>", "List of paths for the bucket")
new InteractiveOption("-p, --paths [path...]", "List of paths for the bucket")
.argParser((value) => {
if (!value || value.length === 0) return [];
const values = value.includes(",") ? value.split(",") : value.split(" ");

for (const path of values) {
for (const p of values) {
try {
const stats = fs.statSync(path);
const dirPath = path.dirname(p);
const stats = fs.statSync(dirPath);
if (!stats.isDirectory()) {
throw new Error(`${path} is not a directory`);
throw new Error(`${dirPath} is not a directory`);
}
} catch (err) {
throw new Error(`Invalid directory path: ${path}`);
throw new Error(`Invalid path: ${p}`);
}
}

return values;
})
.default("."),
.default([]),
)
.action(async (options) => {
const settings = getSettings(undefined);
Expand All @@ -102,7 +105,9 @@ export default new InteractiveCommand()
newConfig.locale.source = options.source;
newConfig.locale.targets = options.targets;
newConfig.buckets = {
[options.bucket]: options.paths,
[options.bucket]: {
include: options.paths || [],
},
};

await saveConfig(newConfig);
Expand Down