fmp-frontend 0.0.1
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/index.js +87 -0
- package/package.json +18 -0
package/index.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { fileURLToPath } from "node:url";
|
|
2
|
+
import { downloadTemplate } from "giget";
|
|
3
|
+
import { Command } from "commander";
|
|
4
|
+
import * as p from "@clack/prompts";
|
|
5
|
+
import { execa } from "execa";
|
|
6
|
+
import fs from "node:fs/promises";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
|
|
9
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
10
|
+
const __dirname = path.dirname(__filename);
|
|
11
|
+
|
|
12
|
+
const program = new Command();
|
|
13
|
+
|
|
14
|
+
function getPackageManager() {
|
|
15
|
+
const userAgent = process.env.npm_config_user_agent || "";
|
|
16
|
+
if (userAgent.startsWith("yarn")) return "yarn";
|
|
17
|
+
if (userAgent.startsWith("pnpm")) return "pnpm";
|
|
18
|
+
if (userAgent.startsWith("bun")) return "bun";
|
|
19
|
+
return "npm";
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function getPackageManagerRunningCommand(pm) {
|
|
23
|
+
return pm === "npm" ? "run " : "";
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
program.name("fmp-frontend").action(async () => {
|
|
27
|
+
p.intro("Creating your project...");
|
|
28
|
+
|
|
29
|
+
const projectName = await p.text({
|
|
30
|
+
message: "Project name:",
|
|
31
|
+
placeholder: "my-app",
|
|
32
|
+
defaultValue: "my-app",
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
if (p.isCancel(projectName)) {
|
|
36
|
+
p.cancel("Operation cancelled.");
|
|
37
|
+
process.exit(0);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const targetDir = path.join(process.cwd(), String(projectName));
|
|
41
|
+
const s = p.spinner();
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
// 1. Download template
|
|
45
|
+
s.start("Downloading template...");
|
|
46
|
+
await downloadTemplate("gh:jhael07/tanstack-router-template", {
|
|
47
|
+
dir: targetDir,
|
|
48
|
+
force: true,
|
|
49
|
+
});
|
|
50
|
+
s.stop("Template downloaded!");
|
|
51
|
+
|
|
52
|
+
// 2. Customize package.json
|
|
53
|
+
const pkgPath = path.join(targetDir, "package.json");
|
|
54
|
+
|
|
55
|
+
// Check if package.json exists before reading
|
|
56
|
+
try {
|
|
57
|
+
const pkgRaw = await fs.readFile(pkgPath, "utf-8");
|
|
58
|
+
const pkg = JSON.parse(pkgRaw);
|
|
59
|
+
pkg.name = String(projectName);
|
|
60
|
+
await fs.writeFile(pkgPath, JSON.stringify(pkg, null, 2));
|
|
61
|
+
} catch (err) {
|
|
62
|
+
throw new Error(
|
|
63
|
+
`Could not update package.json at ${pkgPath}: ${err.message}`,
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// 3. Install dependencies
|
|
68
|
+
const pm = getPackageManager();
|
|
69
|
+
s.start("Installing dependencies...");
|
|
70
|
+
await execa(pm, ["install"], { cwd: targetDir });
|
|
71
|
+
s.stop("Dependencies installed!");
|
|
72
|
+
|
|
73
|
+
const runningCommand = getPackageManagerRunningCommand(pm);
|
|
74
|
+
p.outro(
|
|
75
|
+
`Project ready! Run:\n cd ${projectName} && ${pm} ${runningCommand}dev`,
|
|
76
|
+
);
|
|
77
|
+
} catch (error) {
|
|
78
|
+
s.stop("Failed!");
|
|
79
|
+
// Prints the exact underlying error message
|
|
80
|
+
p.cancel(
|
|
81
|
+
`Error: ${error instanceof Error ? error.message : String(error)}`,
|
|
82
|
+
);
|
|
83
|
+
process.exit(1);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
program.parse(process.argv);
|
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "fmp-frontend",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"bin": {
|
|
6
|
+
"fmp-frontend": "./index.js"
|
|
7
|
+
},
|
|
8
|
+
"files": [
|
|
9
|
+
"index.js"
|
|
10
|
+
],
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@clack/prompts": "^1.7.0",
|
|
13
|
+
"commander": "^15.0.0",
|
|
14
|
+
"execa": "^10.0.0",
|
|
15
|
+
"giget": "^3.3.1",
|
|
16
|
+
"standard-version": "^9.5.0"
|
|
17
|
+
}
|
|
18
|
+
}
|