Skip to content

Commit

Permalink
Y2024
Browse files Browse the repository at this point in the history
  • Loading branch information
vprtsingh committed Sep 8, 2024
1 parent 0e9bb7e commit 7546483
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
2 changes: 0 additions & 2 deletions templates/packages/create-mernjs-app/lib/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ module.exports = async (projectname, { project_type, template }) => {
const sourcePath = `templates/${templates}/${project_typ}`
const gitSourcePath = path.join(__dirname, `utils/gitignore.js`)

const appID = Helpers.generateRadomeString(32)

Helpers.sparseCloneRepo(sourcePath, destinationPath)
.then((success) => {
Helpers.copyGitignoreFile(gitSourcePath, destinationPath)
Expand Down
28 changes: 27 additions & 1 deletion templates/packages/create-mernjs-app/lib/utils/Helpers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fs = require("fs-extra");
const { spawn } = require("child_process");
const https = require('https');
const { exec, spawn } = require("child_process");

function errorMessaage(error) {
console.log(" ");
Expand Down Expand Up @@ -87,4 +87,30 @@ exports.checkForLatestVersion = () => {
reject();
});
});
}

exports.sparseCloneRepo = (subdirectory, destinationPath) => {
const repoUrl = 'https://github.com/mernjs/create-mern-app'; // Hardcoded URL
return new Promise((resolve, reject) => {
const commands = [
`git init ${destinationPath}`, // Initialize a new git repo at destinationPath
`cd ${destinationPath}`, // Move to the destination directory
`git remote add origin ${repoUrl}`, // Add the remote repo URL
`git config core.sparseCheckout true`, // Enable sparse checkout
`echo "${subdirectory}" >> .git/info/sparse-checkout`, // Specify the subdirectory to clone
`git pull origin master`, // Pull from the master branch (or 'main' if necessary)
`mv ${subdirectory}/* ./`, // Move files from the subdirectory to the root
`rm -rf ${subdirectory}`, // Remove the empty subdirectory
`rm -rf templates`,
`rm -rf .git` // Optional: Remove .git to avoid including Git history
].join(' && ');

exec(commands, (error, stdout, stderr) => {
if (error) {
reject(error);
return;
}
resolve(stdout.trim());
});
});
}
2 changes: 1 addition & 1 deletion templates/packages/create-mernjs-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-mernjs-app",
"version": "21.0.38",
"version": "21.0.39",
"description": "The MERN App provides a versatile set of boilerplates that streamline the development process for various applications. Whether you're building a web app, mobile app, desktop app, Chrome extension, or an NPM package in JavaScript, our comprehensive templates will help you get started quickly and efficiently.",
"main": "./index.js",
"scripts": {
Expand Down

0 comments on commit 7546483

Please sign in to comment.