Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
JC-Coder committed Mar 7, 2024
2 parents fd77c69 + 8adf86f commit a690443
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 40 deletions.
6 changes: 5 additions & 1 deletion cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
promptOrm,
promptProjectName,
promptProjectStack,
promptDependenciesInstall
} from "./src/utils/prompts.js";
import { createFrontendProject } from "./src/utils/create-frontend-project.js";
import { validateProjectName } from "./src/utils/helper.js";
Expand All @@ -40,6 +41,7 @@ async function startProject() {
let database;
let orm;
let language;
let installDependencies;

const initialMsg = `Simplify Project Setup with the. ${chalk.green(
toolName,
Expand Down Expand Up @@ -81,8 +83,10 @@ async function startProject() {
orm = await promptOrm(database);
}
}
installDependencies = await promptDependenciesInstall();


await createBackendProject(projectName, framework, database, orm);
await createBackendProject(projectName, framework, database, orm, installDependencies);
}
}

Expand Down
45 changes: 17 additions & 28 deletions src/utils/create-backend-project.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,6 @@ import crypto from "crypto";
import { processDependenciesInstall } from "./helper.js";
import { sendStat } from "./stat.js";

/**
* loader
*/
let stages = [{ message: "Creating Project ...", duration: 2000 }];

async function startSpinner() {
for (const stage of stages) {
const spinner = ora(stage.message).start();
await new Promise((resolve) => setTimeout(resolve, stage.duration));
spinner.succeed(stage.message.replace("...", " completed."));
}

stages = [{ message: "Creating Project ...", duration: 2000 }];
}

/**
* function to create backend projects
Expand All @@ -63,7 +49,9 @@ export async function createBackendProject(
framework,
database,
orm,
installDependencies
) {
const spinner = ora('Creating Project ...').start();
try {
const destinationPath = path.join(
process.cwd(),
Expand All @@ -90,7 +78,8 @@ export async function createBackendProject(
);

if (database) {
stages.push({ message: "Adding Database Module ...", duration: 1000 });
spinner.succeed();
spinner.start('Adding Database Module ...');

switch (database) {
case "mongodb":
Expand Down Expand Up @@ -159,7 +148,7 @@ export async function createBackendProject(
// update packageJsonFile
createAndUpdateFile(
`${destinationPath}/package.json`,
JSON.stringify(packageJson),
JSON.stringify(packageJson, null, " "),
);
} else if (framework === "expressjs") {
let database_config = "";
Expand All @@ -180,7 +169,8 @@ export async function createBackendProject(
);

if (database) {
stages.push({ message: "Adding Database Module ...", duration: 1000 });
spinner.succeed();
spinner.start('Adding Database Module ...');

// create schema folder
createFolder(`${destinationPath}/src/modules/schemas`);
Expand Down Expand Up @@ -240,7 +230,7 @@ export async function createBackendProject(
// add package json file
createAndUpdateFile(
`${destinationPath}/package.json`,
JSON.stringify(ExpressJsPackageJsonTemplate),
JSON.stringify(ExpressJsPackageJsonTemplate, null, " "),
);
} else if (framework === "django") {
// django does not support some file namings so the name has to be parsed into a valid python identifier.
Expand Down Expand Up @@ -336,10 +326,8 @@ export async function createBackendProject(
if (shell.which("git")) {
// initialize git for the final source

stages.push({
message: "Initializing git ...",
duration: 1000,
});
spinner.succeed();
spinner.start("Initializing git ...");

shell.cd(`${destinationPath}`);
shell.exec(`git init`);
Expand All @@ -350,19 +338,20 @@ export async function createBackendProject(
}

// process dependencies install
await processDependenciesInstall(framework, destinationPath);
if (installDependencies) {
spinner.succeed()
spinner.start("Installing dependencies ...")
await processDependenciesInstall(framework, destinationPath);
}

// success message
stages.push({
message: `Backend project created successfully! : ${destinationPath}`,
duration: 1000,
});
spinner.succeed()
spinner.succeed(`Backend project created successfully! : ${destinationPath}`)

// send stat
sendStat("startease", framework).then(() => {
})

await startSpinner();
} catch (e) {
console.log(`Error Creating Backend Project: ${e}`);
}
Expand Down
12 changes: 1 addition & 11 deletions src/utils/helper.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import shell, { exit } from "shelljs";
import { promptDependenciesInstall } from "./prompts.js";
import isOnline from "is-online";

/**
Expand Down Expand Up @@ -28,26 +27,17 @@ export async function isConnectedToInternet() {
* process dependencies install
*/
export async function processDependenciesInstall(framework, destinationPath) {
const installDep = await promptDependenciesInstall();

if (!installDep) {
return;
}

// check user has internet connection
if (await isConnectedToInternet()) {
console.log("===== Installing Dependencies ...... ===== ");

shell.cd(`${destinationPath}`);
switch (framework) {
case "expressjs":
shell.cd(`${destinationPath}`);
shell.exec(`npm install`);
shell.exec(`npm run format:fix`);
shell.cd("-");
break;

case "nestjs":
shell.cd(`${destinationPath}`);
shell.exec(`npm install`);
shell.exec(`npm run format`);
shell.cd("-");
Expand Down

0 comments on commit a690443

Please sign in to comment.