Skip to content

Commit b52b92c

Browse files
committed
feat: lang arg + test
1 parent ba6dd51 commit b52b92c

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-11
lines changed

lib/cli.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ const onLoad = async (targetDir, version, argv) => {
7676
const questions = [
7777
{
7878
type: "autocomplete",
79-
name: "lang",
79+
name: "langChoice",
8080
message: "Select language",
8181
choices: langListOut,
8282
suggest: async (input, choices) => {
@@ -86,15 +86,17 @@ const onLoad = async (targetDir, version, argv) => {
8686
},
8787
},
8888
];
89-
90-
let { lang } = await prompts(questions);
91-
if (lang === "custom") {
92-
let { customLang } = await prompts({
93-
type: "text",
94-
name: "customLang",
95-
message: "Enter custom language code",
96-
});
97-
lang = customLang;
89+
let lang = argv.lang || null;
90+
if (!lang) {
91+
let { langChoice } = await prompts(questions);
92+
if (langChoice === "custom") {
93+
let { customLang } = await prompts({
94+
type: "text",
95+
name: "customLang",
96+
message: "Enter custom language code",
97+
});
98+
langChoice = customLang;
99+
}
98100
}
99101
try {
100102
const indexFile = targetDir + "/index.html";

tests/test.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@ const cases = [
3434
const versionFolder = (version = null) =>
3535
version ? `./out/${version}` : defaultDir;
3636

37-
const runCli = async ({ version = null, dir = null, skip = false }) => {
37+
const runCli = async ({
38+
version = null,
39+
dir = null,
40+
skip = false,
41+
lang = null,
42+
}) => {
3843
let argvs = [];
3944
let prevCwd;
4045
if (dir) {
@@ -51,6 +56,9 @@ const runCli = async ({ version = null, dir = null, skip = false }) => {
5156
if (skip) {
5257
argvs.push("-y");
5358
}
59+
if (lang) {
60+
argvs.push("--lang=" + lang);
61+
}
5462

5563
await cli(argvs);
5664
if (prevCwd) {
@@ -158,3 +166,15 @@ describe("Unexpected errors", () => {
158166
}
159167
});
160168
});
169+
170+
describe("lang", () => {
171+
test("lang", async () => {
172+
await runCli({
173+
lang: "en-US",
174+
dir: "./out/lang_en-US",
175+
});
176+
const fileContent = await fs.readFile("./out/lang_en-US/index.html");
177+
expect(fileContent.indexOf(`lang="en-US"`) > -1).toBe(true);
178+
// await fs.remove(versionFolder(version));
179+
});
180+
});

0 commit comments

Comments
 (0)