setIgnoreBlur(true);
let replaceInFile = async (filePath, regex, string) => {
let content = await readFile(filePath, "utf-8")
let updatedContent = content.replace(
new RegExp(regex),
string
)
await writeFile(filePath, updatedContent)
}
let removeLine = async (searchArgs, file) => {
for (let n = 0; n < searchArgs.length; n++) {
await $`sed -i .bak /${searchArgs[n]}/d ${file}`;
}
}
let reset = false;
let resetSettings = await arg("Reset settings?", ["no", "yes"]);
if (resetSettings === "yes") {
reset = true;
}
let projectName = await arg("Project name");
projectName = await projectName.toLowerCase().replace(/\s/g, '');
let projectDir = await env("PROJECT_DIR", {
placeholder: "Project directory ~/yourDir",
reset: reset
});
let packageManager = await env("PACKAGE_MANAGER", {
placeholder: "Select a package manager:",
choices: ["npm", "yarn"],
reset: reset
});
if (!which(await packageManager)) {
await terminal(`~/.kit/bin/kit sync-path`);
await div(md("Your PATH had to be set. Please re-run command."));
await exit();
}
cd(home());
mkdir(projectDir);
cd(projectDir);
await $`npx create-react-app ${projectName.toLowerCase()}`;
cd(path.resolve(projectName, "src"));
rm([
`App.test.js`,
`index.css`,
`setUpTests.js`,
`reportWebVitals.js`,
`logo.svg`,
]);
await $`${packageManager} remove web-vitals @testing-library/jest-dom @testing-library/react @testing-library/user-event`
let filePath = path.resolve();
await removeLine(["logo"], "App.js");
await removeLine(["WebVitals", "vitals", "performance"], "index.js");
await download("https://meyerweb.com/eric/tools/css/reset/reset.css", ".");
await replaceInFile(
filePath + "/App.js",
`<header className="App-header">
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>`,
`App`
)
await replaceInFile(
filePath + "/index.js",
`import './index.css'`,
`import './reset.css'`
);
await replaceInFile(
filePath + "/App.css",
/^(?=[\S\s]{10,8000})[\S\s]*$/im,
`
*,
*::before,
*::after {
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}`
);
rm([
`index.js.bak`,
`App.js.bak`
]);
setIgnoreBlur(false);
edit(`${filePath}/../`);