create-secra 0.1.0

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.
Files changed (3) hide show
  1. package/README.md +23 -0
  2. package/bin/index.mjs +87 -0
  3. package/package.json +21 -0
package/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # create-secra
2
+
3
+ Use this package to bootstrap a Secra frontend project:
4
+
5
+ ```bash
6
+ pnpm create secra my-app
7
+ ```
8
+
9
+ or
10
+
11
+ ```bash
12
+ npm create secra@latest my-app
13
+ ```
14
+
15
+ By default it pulls the template from:
16
+
17
+ - `BadassFree/secra-plugins-front`
18
+
19
+ You can override the template repo temporarily:
20
+
21
+ ```bash
22
+ SECRA_TEMPLATE=owner/repo pnpm create secra my-app
23
+ ```
package/bin/index.mjs ADDED
@@ -0,0 +1,87 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { spawn } from "node:child_process";
4
+ import { existsSync, readdirSync } from "node:fs";
5
+ import path from "node:path";
6
+ import process from "node:process";
7
+ import degit from "degit";
8
+
9
+ const DEFAULT_TEMPLATE = "BadassFree/secra-plugins-front";
10
+ const targetArg = process.argv[2];
11
+ const targetDir = targetArg && targetArg.trim() ? targetArg.trim() : "secra-app";
12
+ const targetPath = path.resolve(process.cwd(), targetDir);
13
+
14
+ function fail(message) {
15
+ console.error(`[create-secra] ${message}`);
16
+ process.exit(1);
17
+ }
18
+
19
+ function detectPackageManager() {
20
+ const userAgent = process.env.npm_config_user_agent || "";
21
+ if (userAgent.startsWith("pnpm")) return "pnpm";
22
+ if (userAgent.startsWith("yarn")) return "yarn";
23
+ if (userAgent.startsWith("bun")) return "bun";
24
+ return "npm";
25
+ }
26
+
27
+ function runInstall(cwd, manager) {
28
+ const args =
29
+ manager === "npm"
30
+ ? ["install"]
31
+ : manager === "yarn"
32
+ ? []
33
+ : manager === "bun"
34
+ ? ["install"]
35
+ : ["install"];
36
+
37
+ return new Promise((resolve, reject) => {
38
+ const child = spawn(manager, args, {
39
+ cwd,
40
+ stdio: "inherit",
41
+ shell: process.platform === "win32",
42
+ });
43
+ child.on("close", (code) => {
44
+ if (code === 0) resolve();
45
+ else reject(new Error(`Dependency install failed with code ${code}`));
46
+ });
47
+ child.on("error", reject);
48
+ });
49
+ }
50
+
51
+ async function main() {
52
+ const template = process.env.SECRA_TEMPLATE || DEFAULT_TEMPLATE;
53
+ const manager = detectPackageManager();
54
+
55
+ if (existsSync(targetPath)) {
56
+ const files = readdirSync(targetPath);
57
+ if (files.length > 0) {
58
+ fail(`Target directory is not empty: ${targetDir}`);
59
+ }
60
+ }
61
+
62
+ console.log(`[create-secra] Scaffolding from ${template} ...`);
63
+ const emitter = degit(template, {
64
+ cache: false,
65
+ force: true,
66
+ verbose: false,
67
+ });
68
+
69
+ try {
70
+ await emitter.clone(targetPath);
71
+ } catch (error) {
72
+ fail(`Failed to download template. ${error instanceof Error ? error.message : String(error)}`);
73
+ }
74
+
75
+ console.log(`[create-secra] Installing dependencies with ${manager} ...`);
76
+ try {
77
+ await runInstall(targetPath, manager);
78
+ } catch (error) {
79
+ fail(error instanceof Error ? error.message : String(error));
80
+ }
81
+
82
+ console.log(`[create-secra] Done. Next steps:`);
83
+ console.log(` cd ${targetDir}`);
84
+ console.log(` ${manager === "npm" ? "npm run dev" : `${manager} dev`}`);
85
+ }
86
+
87
+ main();
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "create-secra",
3
+ "version": "0.1.0",
4
+ "description": "Create a Secra project from the official template.",
5
+ "type": "module",
6
+ "bin": {
7
+ "create-secra": "bin/index.mjs"
8
+ },
9
+ "files": [
10
+ "bin"
11
+ ],
12
+ "keywords": [
13
+ "create",
14
+ "secra",
15
+ "scaffold"
16
+ ],
17
+ "license": "MIT",
18
+ "dependencies": {
19
+ "degit": "^2.8.4"
20
+ }
21
+ }