maxserver 0.0.3 ā 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -8
- package/bin/init.js +66 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -15,17 +15,16 @@
|
|
|
15
15
|
- **HTTPS** support (when configured)
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
---
|
|
19
18
|
|
|
20
|
-
##
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
### Install
|
|
22
|
+
npm install maxserver
|
|
23
|
+
|
|
24
|
+
### Install with template
|
|
25
|
+
npx maxserver [appname]
|
|
21
26
|
|
|
22
|
-
```bash
|
|
23
|
-
npx @max-matinpalo/maxserver my-app
|
|
24
|
-
cd my-app
|
|
25
|
-
npm run dev
|
|
26
|
-
```
|
|
27
27
|
|
|
28
|
-
---
|
|
29
28
|
|
|
30
29
|
## Setup
|
|
31
30
|
maxserver(options) forwards options to fastify(options).
|
package/bin/init.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import { fileURLToPath } from "url";
|
|
6
|
+
import { execSync } from "child_process";
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
function main() {
|
|
10
|
+
const { projectName, targetDir, templateDir } = resolveArgs();
|
|
11
|
+
|
|
12
|
+
if (fs.existsSync(targetDir)) {
|
|
13
|
+
console.error(`ā Error: Directory "${projectName}" already exists.`);
|
|
14
|
+
process.exit(1);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
console.log(`š Creating "${projectName}"...`);
|
|
19
|
+
fs.cpSync(templateDir, targetDir, { recursive: true });
|
|
20
|
+
|
|
21
|
+
fixDotfiles(targetDir);
|
|
22
|
+
patchPackageJson(targetDir, projectName);
|
|
23
|
+
|
|
24
|
+
process.chdir(targetDir);
|
|
25
|
+
console.log("š¦ Installing dependencies...");
|
|
26
|
+
execSync("npm install", { stdio: "inherit" });
|
|
27
|
+
|
|
28
|
+
console.log("\nā
Done! Your project is ready. š");
|
|
29
|
+
} catch (err) {
|
|
30
|
+
console.error("ā Init failed:", err.message);
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
function resolveArgs() {
|
|
37
|
+
const base = path.dirname(fileURLToPath(import.meta.url));
|
|
38
|
+
const name = process.argv[2] || "maxserver";
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
projectName: name,
|
|
42
|
+
targetDir: path.resolve(process.cwd(), name),
|
|
43
|
+
templateDir: path.resolve(base, "../templates")
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
function fixDotfiles(dir) {
|
|
49
|
+
for (const f of ["env", "gitignore", "vscode"]) {
|
|
50
|
+
const src = path.join(dir, f);
|
|
51
|
+
if (fs.existsSync(src)) fs.renameSync(src, path.join(dir, "." + f));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
function patchPackageJson(dir, name) {
|
|
57
|
+
const pkgPath = path.join(dir, "package.json");
|
|
58
|
+
if (!fs.existsSync(pkgPath)) return;
|
|
59
|
+
|
|
60
|
+
let content = fs.readFileSync(pkgPath, "utf8");
|
|
61
|
+
content = content.replace(/__NAME__/g, name);
|
|
62
|
+
fs.writeFileSync(pkgPath, content);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
main();
|