Skip to content

Commit e9f5bc5

Browse files
committed
feat: jquery remove init
1 parent e3dfaba commit e9f5bc5

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

lib/cli.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ const onLoad = async (targetDir, version, argv) => {
7373
return { title: `${v.title} (${v.value})`, value: v.value };
7474
});
7575
langListOut.splice(1, 0, { title: "Enter custom", value: "custom" });
76-
const questions = [
77-
{
76+
let lang = argv.lang;
77+
/* istanbul ignore if */
78+
if (!lang) {
79+
let { langChoice } = await prompts({
7880
type: "autocomplete",
7981
name: "langChoice",
8082
message: "Select language",
@@ -84,12 +86,7 @@ const onLoad = async (targetDir, version, argv) => {
8486
.filter(input, choices, { extract: (el) => el.title })
8587
.map((v) => v.original);
8688
},
87-
},
88-
];
89-
let lang = argv.lang;
90-
/* istanbul ignore if */
91-
if (!lang) {
92-
let { langChoice } = await prompts(questions);
89+
});
9390
if (langChoice === "custom") {
9491
let { customLang } = await prompts({
9592
type: "text",
@@ -100,13 +97,25 @@ const onLoad = async (targetDir, version, argv) => {
10097
}
10198
lang = langChoice || "";
10299
}
100+
let { jquery } = await prompts({
101+
type: "confirm",
102+
name: "jquery",
103+
message: "Remove jQuery?",
104+
initial: true,
105+
});
103106
try {
104107
const indexFile = targetDir + "/index.html";
105108
const sourceHTML = await fs.readFile(indexFile, "utf-8");
106-
const resultHTML = sourceHTML.replace(
109+
let resultHTML = sourceHTML.replace(
107110
/(<html.*lang=)\"([^"]*)\"/gi,
108111
`$1"${lang}"`
109112
);
113+
if (jquery) {
114+
resultHTML = resultHTML.replace(
115+
/(<script>window\.jQuery.*<\/script>|<script src=".*jquery.*<\/script>)/gi,
116+
""
117+
);
118+
}
110119
await fs.writeFile(indexFile, resultHTML);
111120
} catch (err) {
112121
/* istanbul ignore next */

0 commit comments

Comments
 (0)