Skip to content

Commit 34d9a50

Browse files
Initial commit
0 parents  commit 34d9a50

File tree

6 files changed

+756
-0
lines changed

6 files changed

+756
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
testProject

README.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# [Fastify SWC Server Bootstrap CLI Tool](https://www.npmjs.com/package/fastify-swc-typescript-server-bootstrap-cli)
2+
3+
## Overview
4+
5+
This [CLI](https://en.wikipedia.org/wiki/Command-line_interface) tool streamlines the creation of new server projects using [Fastify](https://fastify.dev/) with [SWC](https://swc.rs/) and [Jest](https://jestjs.io/).
6+
7+
## Install globally
8+
9+
### npm
10+
11+
```bash
12+
npm i -g fastify-swc-typescript-server-bootstrap-cli
13+
```
14+
15+
## Usage
16+
17+
After installation, bootstrap a new Fastify SWC server project using the command:
18+
19+
```bash
20+
fastify-swc-server [project-name]
21+
```
22+
23+
Replace `[project-name]` with the name you wish to give to your new project. This command will create a new directory with the specified name, clone the Fastify SWC server setup, and configure the project accordingly.
24+
25+
### Example
26+
27+
To create a new project named `my-server-app`, run:
28+
29+
```bash
30+
fastify-swc-server my-server-app
31+
```
32+
33+
## What it Does Currently
34+
35+
- Clones a Fastify SWC server template from [this repository](https://github.com/matt-development-work/fastify-swc-typescript-server).
36+
- Removes the original `.git` directory from the cloned repository and initializes a new git repository, allowing for a clean version control start.
37+
- Updates the `package.json` with the specified project name and clears the author field.
38+
- More customizations to be added...

init.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env node
2+
const shell = require("shelljs");
3+
const fs = require("fs");
4+
const path = require("path");
5+
6+
const projectName = process.argv[2]; // Get project name from command line argument
7+
8+
if (!projectName) {
9+
console.error("Please specify a project name.");
10+
process.exit(1);
11+
}
12+
13+
// Clone the repository
14+
shell.exec(
15+
`git clone [email protected]:matt-development-work/fastify-swc-typescript-server.git ${projectName}`
16+
);
17+
18+
// Navigate to the cloned directory
19+
shell.cd(projectName);
20+
21+
// Remove the original .git directory
22+
shell.rm("-rf", ".git");
23+
24+
// Initialize a new git repository
25+
shell.exec("git init");
26+
27+
// Update package.json
28+
const packageJsonPath = path.join(process.cwd(), "package.json");
29+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
30+
packageJson.name = projectName; // Update the project name
31+
packageJson.author = ""; // Clear the author
32+
33+
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2)); // Write back to package.json

package.json

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "fastify-swc-typescript-server-bootstrap-cli",
3+
"version": "1.0.0",
4+
"description": "A CLI tool for bootstrapping Fastify SWC server projects.",
5+
"main": "init.js",
6+
"scripts": {
7+
"test": "mocha 'tests/**/*.js'"
8+
},
9+
"dependencies": {
10+
"shelljs": "^0.8.5"
11+
},
12+
"devDependencies": {
13+
"chai": "^4.3.10",
14+
"mocha": "^10.2.0"
15+
},
16+
"bin": {
17+
"fastify-swc-server": "init.js"
18+
},
19+
"repository": {
20+
"type": "git",
21+
"url": "git+https://github.com/matt-development-work/fastify-swc-typescript-server-bootstrap-cli.git"
22+
}
23+
}

0 commit comments

Comments
 (0)