msdkx is a flexible and scalable monorepo setup powered by Turborepo and pnpm, designed to manage multiple applications and packages efficiently. It includes a custom CLI tool that allows you to scaffold new projects from predefined templates, supporting various frameworks and styling options. Additionally, the CLI offers the flexibility to choose your preferred package manager (pnpm, npm, or Yarn).
- Prerequisites
- Installation
- Monorepo Structure
- Using the msdkx CLI
- Templates
- Publishing Packages
- Advanced Usage
- Troubleshooting
- Contributing
- License
Before setting up the msdkx monorepo, ensure you have the following installed on your machine:
- Node.js (v14 or later): Download Node.js
- pnpm: A fast, disk space-efficient package manager.
npm install -g pnpm
- Git: Version control system. Download Git
- Yarn (optional): If you prefer using Yarn as your package manager.
npm install -g yarn
-
Clone the Repository
git clone https://github.com/alphadevking/msdkx.git cd msdkx
-
Install Dependencies
pnpm install
-
Build the CLI
Navigate to the CLI package and build it.
cd packages/cli pnpm build
-
Link the CLI Globally
This allows you to use the
msdkx
command anywhere on your system.pnpm link --global
The msdkx monorepo is organized to separate applications and reusable packages, ensuring scalability and maintainability.
msdkx/
├── apps/
│ ├── next-app-router/
│ │ ├── package.json
│ │ ├── pages/
│ │ ├── public/
│ │ └── ...
│ ├── next-pages-router/
│ │ ├── package.json
│ │ ├── pages/
│ │ ├── public/
│ │ └── ...
│ └── vite-app/
│ ├── package.json
│ ├── src/
│ ├── public/
│ └── ...
├── packages/
│ ├── templates/
│ │ ├── next-app-router-tailwind/
│ │ │ ├── package.json.ejs
│ │ │ ├── tailwind.config.js
│ │ │ ├── postcss.config.js
│ │ │ ├── styles/
│ │ │ │ └── globals.css.ejs
│ │ │ └── ...
│ │ ├── next-app-router-css/
│ │ │ ├── package.json.ejs
│ │ │ ├── styles/
│ │ │ │ └── globals.css.ejs
│ │ │ └── ...
│ │ ├── next-pages-router-tailwind/
│ │ │ ├── package.json.ejs
│ │ │ ├── tailwind.config.js
│ │ │ ├── postcss.config.js
│ │ │ ├── styles/
│ │ │ │ └── globals.css.ejs
│ │ │ └── ...
│ │ ├── next-pages-router-css/
│ │ │ ├── package.json.ejs
│ │ │ ├── styles/
│ │ │ │ └── globals.css.ejs
│ │ │ └── ...
│ │ ├── vite-tailwind/
│ │ │ ├── package.json.ejs
│ │ │ ├── tailwind.config.js
│ │ │ ├── postcss.config.js
│ │ │ ├── src/
│ │ │ │ └── main.css.ejs
│ │ │ └── ...
│ │ └── vite-css/
│ │ ├── package.json.ejs
│ │ ├── src/
│ │ │ └── main.css
│ │ └── ...
│ ├── ui/
│ │ ├── package.json
│ │ ├── src/
│ │ └── ...
│ └── ...
├── node_modules/
├── package.json
├── pnpm-workspace.yaml
└── turbo.json
- apps/: Contains your application projects.
- packages/: Contains reusable packages and templates.
- templates/: Predefined templates for scaffolding new applications.
- ui/: Example of a reusable UI library.
The msdkx CLI tool allows you to scaffold new applications from predefined templates within the monorepo. It supports multiple frameworks, styling options, and package managers.
To create a new application, use the create
command followed by your desired application name.
msdkx create <app-name>
Example:
msdkx create my-new-app
Interactive Prompts:
-
Choose a Framework:
Next.js (App Router)
Next.js (Pages Router)
Vite
-
Add TailwindCSS?
Yes
No
-
Choose a Package Manager:
pnpm
npm
yarn
Example Flow:
$ msdkx create my-new-app
? Choose a framework: Next.js (App Router)
? Add TailwindCSS? Yes
? Choose a package manager: pnpm
What Happens Next:
-
Template Selection:
- Based on your choices, the CLI selects the appropriate template from
packages/templates/
.
- Based on your choices, the CLI selects the appropriate template from
-
Project Scaffolding:
- Copies the selected template to a new directory named
my-new-app
.
- Copies the selected template to a new directory named
-
Template Processing:
- Renders any EJS templates, injecting dynamic values like the project name.
-
Dependency Installation:
- Installs dependencies using your chosen package manager (
pnpm
,npm
, oryarn
).
- Installs dependencies using your chosen package manager (
-
Git Initialization (Optional):
- Prompts you to initialize a Git repository for your new project.
-
Completion:
- Displays a success message with next steps.
Next Steps:
Navigate to your new project directory and start the development server.
cd my-new-app
pnpm dev
# or
npm run dev
# or
yarn dev
Templates are located in the packages/templates/
directory. Each template corresponds to a specific combination of framework and styling option.
-
Next.js (App Router) + TailwindCSS
- Directory:
packages/templates/next-app-router-tailwind/
- Directory:
-
Next.js (App Router) + CSS
- Directory:
packages/templates/next-app-router-css/
- Directory:
-
Next.js (Pages Router) + TailwindCSS
- Directory:
packages/templates/next-pages-router-tailwind/
- Directory:
-
Next.js (Pages Router) + CSS
- Directory:
packages/templates/next-pages-router-css/
- Directory:
-
Vite + TailwindCSS
- Directory:
packages/templates/vite-tailwind/
- Directory:
-
Vite + CSS
- Directory:
packages/templates/vite-css/
- Directory:
-
More Coming Soon
You can modify or add new templates by creating new directories under packages/templates/
following the existing structure. Ensure each template includes necessary configuration files and EJS templates for dynamic content.
Example: Adding a New Template
To add a new template for Next.js (App Router) + Styled-Components
:
-
Create Template Directory
mkdir -p packages/templates/next-app-router-styled-components
-
Populate Template Files
package.json.ejs
styled-components.config.js
- Any other necessary files.
-
Update CLI
Modify the CLI script to include the new template option in the
create
command.
Each package and application within the monorepo can be published to npm, allowing you to reuse and share them across different projects.
-
Navigate to the Package Directory
cd packages/ui
-
Ensure
package.json
is Configured{ "name": "@msdkx/ui", "version": "0.1.0", "main": "dist/index.js", "types": "dist/index.d.ts", "scripts": { "build": "tsc --build", "lint": "eslint .", "test": "jest" }, "dependencies": { "react": "^18.0.0" }, "devDependencies": { "typescript": "^4.0.0", "eslint": "^7.0.0", "jest": "^27.0.0" } }
-
Build the Package
pnpm build
-
Publish to npm
pnpm publish --access public
Notes:
- Ensure the package name is unique and scoped appropriately.
- Set
"private": false
inpackage.json
if you intend to publish.
In another project, install the published package using your preferred package manager.
pnpm add @msdkx/ui
# or
npm install @msdkx/ui
# or
yarn add @msdkx/ui
Then, import and use it in your code.
import { Button } from '@msdkx/ui';
function App() {
return <Button>Click me</Button>;
}
export default App;
You can extend the CLI to support additional features such as:
- Adding More Commands: For example,
add-package
,remove-app
, etc. - Handling Environment Variables: Injecting environment-specific configurations.
- Integrating with CI/CD: Automate deployments or testing after scaffolding.
Utilize pnpm's workspace features to manage dependencies across packages efficiently. Ensure that shared dependencies are hoisted appropriately to minimize duplication.
Use EJS templating to inject dynamic content into your templates.
Example: package.json.ejs
{
"name": "<%= projectName %>",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"next": "latest",
"react": "latest",
"react-dom": "latest"
},
"devDependencies": {
"tailwindcss": "^3.0.0",
"postcss": "^8.0.0",
"autoprefixer": "^10.0.0"
}
}
During scaffolding, <%= projectName %>
will be replaced with the actual project name.
-
Package Manager Not Installed
Error:
Error: pnpm is not installed on your system. Please install it and try again.
Solution: Install the required package manager.
npm install -g pnpm # or npm install -g yarn
-
Template Not Found
Error:
Template "next-app-router-tailwind" does not exist.
Solution: Ensure the template exists in
packages/templates/
. Add the missing template if necessary. -
Directory Already Exists
Error:
Directory "my-new-app" already exists. Please choose a different project name.
Solution: Choose a unique project name or remove the existing directory.
If you encounter issues not covered here, consider:
- Checking Logs: Review the console output for error messages.
- Reinstalling Dependencies: Sometimes, reinstalling can resolve conflicts.
pnpm install
- Contacting Support: Reach out to the project maintainers or open an issue on the repository.
Contributions are welcome! To contribute:
-
Fork the Repository
git clone https://github.com/alphadevking/msdkx.git cd msdkx
-
Create a New Branch
git checkout -b feature/new-feature
-
Make Your Changes
-
Commit Your Changes
git commit -m "Add new feature"
-
Push to Your Fork
git push origin feature/new-feature
-
Open a Pull Request
Describe your changes and submit for review.
This project is licensed under the MIT License.