Skip to content

Commit

Permalink
feat: lang select
Browse files Browse the repository at this point in the history
  • Loading branch information
vltansky committed Jun 7, 2020
1 parent b56b832 commit 3e8c068
Show file tree
Hide file tree
Showing 4 changed files with 760 additions and 25 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
require("./cli")().catch(console.error);
require("./lib/cli")().catch(console.error);
39 changes: 16 additions & 23 deletions cli.js → lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const yargs_parser = require("yargs-parser");
const path = require("path");
const chalk = require("chalk");
const langs = require("./countries.json");
const prompts = require("prompts");
const semver = require("semver");
const ora = require("ora");
Expand Down Expand Up @@ -66,31 +67,23 @@ const onLoad = async (targetDir, version) => {

const questions = [
{
type: "confirm",
name: "jquery",
message: "Remove jQuery?",
initial: true,
type: "autocomplete",
name: "lang",
message: "Select language",
choices: langs,
},
// {
// type: 'confirm',
// name: 'docs',
// message: 'Include docs?',
// }
];

const { jquery } = await prompts(questions);

if (jquery) {
try {
const indexFile = targetDir + "/index.html";
const sourceHTML = await fs.readFile(indexFile, "utf-8");
const resultHTML = sourceHTML.replace(
/(<script>window\.jQuery.*<\/script>|<script src=".*jquery.*<\/script>)/gi,
""
);
await fs.writeFile(indexFile, resultHTML);
} catch (err) {
throw new Error(err);
}
const { lang } = await prompts(questions);
try {
const indexFile = targetDir + "/index.html";
const sourceHTML = await fs.readFile(indexFile, "utf-8");
const resultHTML = sourceHTML.replace(
/(<html.*lang=)\"([^"]*)\"/gi,
`$1"${lang}"`
);
await fs.writeFile(indexFile, resultHTML);
} catch (err) {
throw new Error(err);
}
};
Loading

0 comments on commit 3e8c068

Please sign in to comment.