Skip to content

Commit

Permalink
fix: git initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
DoneDeal0 committed Apr 21, 2023
1 parent 8b48f51 commit 1988f06
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 28 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Professional React app generator. Comes with an exposed, unopinionated, high performance configuration.
Jest SWC, Storybook, SWC, Typescript 5, Webpack 5.

<img width="467" alt="Screenshot 2023-04-20 at 16 09 51" src="https://user-images.githubusercontent.com/43271780/233392542-6346ac1d-0f94-4a07-87f3-cf836bf97c22.png">
<img width="483" alt="screenshot" src="https://user-images.githubusercontent.com/43271780/233714020-52d818b3-5080-4b54-b328-b68832661fc3.png">

# GETTING STARTED

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "alright-react-app",
"version": "1.1.9",
"version": "2.0.0",
"description": "Professional React app generator. Shipped with an exposed, unopinionated, highly-performant config. Jest-SWC, Storybook, SWC, Typescript, Webpack 5.",
"main": "index.js",
"author": "DoneDeal0",
Expand Down
4 changes: 2 additions & 2 deletions tasks/create-project.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import inquirer from "inquirer";
import path from "path";
import which from "which";
import { createDirectoryContent } from "./create-directory-content.js";
import { installDependencies, instantiateGit } from "./installation.js";
import { installDependencies, initializeGit } from "./installation.js";
import { preInstallMessage, postInstallMessage } from "./output.js";
import { question } from "./question.js";

Expand All @@ -27,7 +27,7 @@ export async function createProject(directory, __dirname) {
const hasYarn = await which("yarn", { nothrow: true });
const command = hasYarn ? "yarn" : "npm";
preInstallMessage(projectName, command);
await instantiateGit(projectPath);
await initializeGit(projectPath);
await installDependencies(command, projectPath);
const _command = hasYarn ? "yarn" : "npm run";
postInstallMessage(projectName, _command);
Expand Down
38 changes: 22 additions & 16 deletions tasks/installation.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,27 @@ export async function installDependencies(command, projectPath) {
});
}

export async function instantiateGit(projectPath) {
const hasGit = await which("git", { nothrow: true });
if (hasGit) {
const gitConfig = spawn("git", [
"config",
"--global",
"init.defaultBranch",
"main",
]);
await promisify(gitConfig.on.bind(gitConfig))("close");
const gitInit = spawn("git", ["init"], {
cwd: projectPath,
stdio: "ignore",
});
await promisify(gitInit.on.bind(gitInit))("close");
gitMessage();
export async function initializeGit(projectPath) {
try {
const hasGit = await which("git", { nothrow: true });
if (hasGit) {
const gitConfig = spawn("git", [
"config",
"--global",
"init.defaultBranch",
"main",
]);
await promisify(gitConfig.on.bind(gitConfig))("close");
const gitInit = spawn("git", ["init"], {
cwd: projectPath,
stdio: "ignore",
});
await promisify(gitInit.on.bind(gitInit))("close");
gitMessage(hasGit);
} else {
gitMessage(hasGit);
}
} catch (_) {
gitMessage(false);
}
}
21 changes: 16 additions & 5 deletions tasks/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,25 @@ export function preInstallMessage(projectName, command) {
`${chalk.yellow.bold("✓")}`,
`${chalk.yellow.bold(projectName)}'s files and folders have been created`,
"\n",
`${chalk.green.bold("✓")}`,
`${chalk.green.bold(command)} detected`,
"\n"
`${chalk.yellow.bold("✓")}`,
`${chalk.yellow.bold(command)} detected`
);
}

export function gitMessage() {
console.log("\n", `${chalk.yellow.bold("✓")}`, `git Instantiated`);
export function gitMessage(hasGit) {
if (hasGit) {
console.log(
`${chalk.yellow.bold(" ✓")}`,
`${chalk.yellow.bold("git")} initialized`,
"\n"
);
} else {
console.log(
`${chalk.red.bold(" ×")}`,
`${chalk.red.bold("git")} couldn't be initialized`,
"\n"
);
}
}

const runLine = (name) =>
Expand Down
6 changes: 3 additions & 3 deletions template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@storybook/react": "^6.5.16",
"@svgr/webpack": "^7.0.0",
"@swc/cli": "^0.1.62",
"@swc/core": "^1.3.51",
"@swc/core": "^1.3.53",
"@swc/jest": "^0.2.26",
"@types/jest": "^29.5.1",
"@types/react": "^18.0.37",
Expand All @@ -52,8 +52,8 @@
"swc-loader": "^0.2.3",
"terser-webpack-plugin": "^5.3.7",
"typescript": "^5.0.4",
"webpack": "^5.79.0",
"webpack-cli": "^5.0.1",
"webpack": "^5.80.0",
"webpack-cli": "^5.0.2",
"webpack-dev-server": "^4.13.3"
}
}

0 comments on commit 1988f06

Please sign in to comment.