-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
149 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,88 @@ | ||
const { ensureDir, copy } = require("fs-extra"); | ||
const path = require('path'); | ||
const { exludeFiles } = require("../utils/exlude-files"); | ||
const { spawn } = require('child_process'); | ||
const fs = require('fs-extra'); | ||
const { updatePackageJson } = require("../helper/update-packageJson") | ||
const { hasPackageJson } = require("../utils/check-package") | ||
|
||
const { installDependencies } = require("./install-dependencies") | ||
// use this to see what is been installed | ||
// const runCommand = (command, args, options = {}) => { | ||
// return new Promise((resolve, reject) => { | ||
// const process = spawn(command, args, { stdio: 'inherit', ...options }); | ||
// process.on('close', (code) => { | ||
// if (code !== 0) { | ||
// reject(new Error(`Process exited with code ${code}`)); | ||
// } else { | ||
// resolve(); | ||
// } | ||
// }); | ||
// }); | ||
// }; | ||
|
||
// Function to copy template files to the project directory | ||
async function copyTemplateFiles(templateName, destinationDir, templateDirectory, projectName) { | ||
const { default: chalk } = await import('chalk'); | ||
|
||
const runCommand = (command, args, options = {}) => { | ||
return new Promise((resolve, reject) => { | ||
const process = spawn(command, args, { stdio: 'inherit', ...options }); | ||
process.on('close', (code) => { | ||
if (code !== 0) { | ||
reject(new Error(`Process exited with code ${code}`)); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
}); | ||
}; | ||
const filesToExclude = ['.git', '.env', 'node_modules', 'package-lock.json', 'yarn.lock', '.cartesi']; | ||
|
||
// Function to copy template files to the project directory | ||
async function copyTemplateFiles(templateName, destinationDir, templateDirectory) { | ||
|
||
try { | ||
// Use spawn to run the npm install command and log the progress | ||
runCommand('npm', ['install'], { stdio: 'inherit' }) | ||
// Use spawn to run the npm install command and log the progress | ||
// runCommand('npm', ['install'], { stdio: 'inherit' }) | ||
const templateDir = path.resolve(__dirname,'..', templateDirectory, templateName); | ||
const destDir = path.resolve(process.cwd(), destinationDir); | ||
await ensureDir(destDir); // Ensure template directory exists | ||
// Function to filter out .git, .env, node_modules, and package-lock.json files/directories | ||
exludeFiles(templateDir, destDir) | ||
await copy(templateDir, destDir); | ||
console.log(`✅ Template ${templateName} created successfully!` ) | ||
|
||
if (fs.existsSync(templateDir)) { | ||
const files = fs.readdirSync(templateDir); | ||
const filesToCopy = files.filter(file => !filesToExclude.includes(file)); | ||
filesToCopy.forEach(file => { | ||
const sourceFilePath = path.join(templateDir, file); | ||
const destFilePath = path.join(destDir, file); | ||
|
||
//update the package directory | ||
if(files.includes('package.json')){ | ||
updatePackageJson(projectName, destDir) | ||
} | ||
|
||
// function to update the package.json name to the name of the project | ||
fs.copySync(sourceFilePath, destFilePath); | ||
// await copy(templateDir, destDir); | ||
}); | ||
// console.log(`✅ Starter project successfully created!` ) | ||
// console.log( "Thank you for using CartDevKit! If you have any questions or need further assistance, please refer to the README or reach out to our team.") | ||
// console.log(chalk.magenta("Happy coding! 🎉")) | ||
} else { | ||
console.error('Source directory does not exist.'); | ||
} | ||
} catch (err) { | ||
console.error(`Error copying template files: ${err}`); | ||
} | ||
} | ||
|
||
async function printSuccessMessage() { | ||
const { default: chalk } = await import('chalk'); | ||
|
||
console.log( chalk.green(`🚀 Starter project successfully created!`)); | ||
// console.log(chalk.bold('Before you start the project, please follow these steps:')) | ||
// console.log( chalk.green('Run the following commands from your project folder to start the project:')) | ||
|
||
// console.log(chalk.yellow( | ||
// 'yarn install' | ||
// )) | ||
// console.log('or') | ||
// console.log(chalk.yellow( | ||
// 'npm install' | ||
// )) | ||
// console.log('Depending on your preference') | ||
|
||
console.log(`${chalk.yellow('Thank you for using CartDevKit!')} If you have any questions or need further assistance, please refer to the README or reach out to our team.`); | ||
console.log("") | ||
console.log(chalk.magenta("Happy coding! 🎉")); | ||
console.log("") | ||
|
||
} | ||
|
||
module.exports = { | ||
copyTemplateFiles | ||
copyTemplateFiles, | ||
printSuccessMessage | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const fs = require("fs-extra") | ||
const path = require('path'); | ||
|
||
|
||
const generateReadme = async (projectDir, projectName) => { | ||
const readmeContent = `# ${projectName}\n\nThis project was scaffolded using CartDevKit CLI tool.`; | ||
|
||
fs.writeFile(path.join(projectDir, 'README.md'), readmeContent, (err) => { | ||
if (err) { | ||
console.error(`Error generating README.md: ${err.message}`); | ||
} else { | ||
// console.log('README.md generated successfully.'); | ||
} | ||
}); | ||
|
||
} | ||
|
||
module.exports = { | ||
generateReadme | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const updatePackageJson = (projectName, templateDir) => { | ||
const packageJsonPath = path.join(templateDir, 'package.json'); | ||
|
||
// Check if the package.json file exists | ||
if (!fs.existsSync(packageJsonPath)) { | ||
// console.log(`No package.json found in ${templateDir}, continuing setup...`); | ||
return; | ||
} | ||
|
||
fs.readFile(packageJsonPath, 'utf8', (err, data) => { | ||
if (err) { | ||
// console.error(`Error reading package.json: ${err.message}`); | ||
// return; | ||
console.log('') | ||
} | ||
|
||
const packageJson = JSON.parse(data); | ||
packageJson.name = projectName; | ||
|
||
fs.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf8', (err) => { | ||
if (err) { | ||
console.error(`Error updating package.json: ${err.message}`); | ||
} else { | ||
// console.log('package.json updated successfully.'); | ||
} | ||
}); | ||
}); | ||
}; | ||
|
||
module.exports = { updatePackageJson }; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
"cartesi" | ||
], | ||
"workspaces": [ | ||
"packages/*" | ||
"bin/*" | ||
], | ||
"bin": { | ||
"cartdevkit": "./bin/index.js" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.