@promakeai/cli 0.7.1 → 0.8.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.
@@ -1,49 +1,49 @@
1
- import { useEffect } from "react";
2
- import constants from "@/constants/constants.json";
3
- interface UsePageTitleOptions {
4
- title?: string;
5
- description?: string;
6
- appendSiteName?: boolean;
7
- }
8
-
9
- export const usePageTitle = (options: UsePageTitleOptions = {}) => {
10
- useEffect(() => {
11
- if (!constants) return;
12
-
13
- const { title, description, appendSiteName = true } = options;
14
-
15
- // Set page title
16
- let pageTitle = title || constants.site.name;
17
- if (title && appendSiteName) {
18
- pageTitle = `${title} | ${constants.site.name}`;
19
- }
20
- document.title = pageTitle;
21
-
22
- // Set meta description
23
- const metaDescription = description || constants.site.description;
24
- let descriptionElement = document.querySelector('meta[name="description"]');
25
-
26
- if (!descriptionElement) {
27
- descriptionElement = document.createElement("meta");
28
- descriptionElement.setAttribute("name", "description");
29
- document.head.appendChild(descriptionElement);
30
- }
31
-
32
- descriptionElement.setAttribute("content", metaDescription);
33
-
34
- // Set favicon if provided
35
- if (constants.site.favicon) {
36
- const faviconElement = document.querySelector(
37
- "#favicon",
38
- ) as HTMLLinkElement;
39
- if (faviconElement) {
40
- faviconElement.href = constants.site.favicon;
41
- }
42
- }
43
- }, [options]);
44
-
45
- return {
46
- siteName: constants?.site?.name || "",
47
- siteDescription: constants?.site?.description || "",
48
- };
49
- };
1
+ import { useEffect } from "react";
2
+ import constants from "@/constants/constants.json";
3
+ interface UsePageTitleOptions {
4
+ title?: string;
5
+ description?: string;
6
+ appendSiteName?: boolean;
7
+ }
8
+
9
+ export const usePageTitle = (options: UsePageTitleOptions = {}) => {
10
+ useEffect(() => {
11
+ if (!constants) return;
12
+
13
+ const { title, description, appendSiteName = true } = options;
14
+
15
+ // Set page title
16
+ let pageTitle = title || constants.site.name;
17
+ if (title && appendSiteName) {
18
+ pageTitle = `${title} | ${constants.site.name}`;
19
+ }
20
+ document.title = pageTitle;
21
+
22
+ // Set meta description
23
+ const metaDescription = description || constants.site.description;
24
+ let descriptionElement = document.querySelector('meta[name="description"]');
25
+
26
+ if (!descriptionElement) {
27
+ descriptionElement = document.createElement("meta");
28
+ descriptionElement.setAttribute("name", "description");
29
+ document.head.appendChild(descriptionElement);
30
+ }
31
+
32
+ descriptionElement.setAttribute("content", metaDescription);
33
+
34
+ // Set favicon if provided
35
+ if (constants.site.favicon) {
36
+ const faviconElement = document.querySelector(
37
+ "#favicon",
38
+ ) as HTMLLinkElement;
39
+ if (faviconElement) {
40
+ faviconElement.href = constants.site.favicon;
41
+ }
42
+ }
43
+ }, [options]);
44
+
45
+ return {
46
+ siteName: constants?.site?.name || "",
47
+ siteDescription: constants?.site?.description || "",
48
+ };
49
+ };
@@ -1,8 +1,10 @@
1
1
  import path from "path";
2
+ import { execSync } from "child_process";
2
3
  import tailwindcss from "@tailwindcss/vite";
3
4
  import react from "@vitejs/plugin-react";
4
- import { defineConfig, type Plugin } from "vite";
5
+ import { defineConfig, loadEnv, type Plugin } from "vite";
5
6
  import { inspectorDebugger } from "@promakeai/inspector/plugin";
7
+ import type { IncomingMessage } from "http";
6
8
 
7
9
  // Plugin: Restart dev server when lang files are added or changed
8
10
  function langWatchPlugin(): Plugin {
@@ -28,14 +30,88 @@ function langWatchPlugin(): Plugin {
28
30
  };
29
31
  }
30
32
 
33
+ // Helper: Read request body
34
+ function readBody(req: IncomingMessage): Promise<string> {
35
+ return new Promise((resolve) => {
36
+ let data = "";
37
+ req.on("data", (chunk: string) => (data += chunk));
38
+ req.on("end", () => resolve(data));
39
+ });
40
+ }
41
+
42
+ // Plugin: Expose API for running promake commands from the panel
43
+ function promakeApiPlugin(secret?: string): Plugin {
44
+ const ALLOWED_COMMANDS = ["seo", "theme"];
45
+ const ALLOWED_ORIGINS = [
46
+ "https://promake.ai",
47
+ "https://www.promake.ai",
48
+ ];
49
+ const BASE_PATH = secret ? `/__promake/${secret}` : "/__promake";
50
+
51
+ return {
52
+ name: "promake-api",
53
+ configureServer(server) {
54
+ server.middlewares.use(`${BASE_PATH}/run`, async (req, res) => {
55
+ const origin = req.headers.origin || "";
56
+ const allowedOrigin = ALLOWED_ORIGINS.includes(origin) ? origin : ALLOWED_ORIGINS[0];
57
+ res.setHeader("Access-Control-Allow-Origin", allowedOrigin);
58
+ res.setHeader("Access-Control-Allow-Methods", "POST, OPTIONS");
59
+ res.setHeader("Access-Control-Allow-Headers", "Content-Type");
60
+
61
+ if (req.method === "OPTIONS") {
62
+ res.statusCode = 204;
63
+ res.end();
64
+ return;
65
+ }
66
+
67
+ if (req.method !== "POST") {
68
+ res.statusCode = 405;
69
+ res.end();
70
+ return;
71
+ }
72
+
73
+ try {
74
+ const body = await readBody(req);
75
+ const { command, args = [] } = JSON.parse(body);
76
+
77
+ if (!ALLOWED_COMMANDS.includes(command)) {
78
+ res.statusCode = 400;
79
+ res.setHeader("Content-Type", "application/json");
80
+ res.end(JSON.stringify({ error: `Command not allowed: ${command}` }));
81
+ return;
82
+ }
83
+
84
+ const safeArgs = args.map((a: string) => `'${a.replace(/'/g, "'\\''")}'`).join(" ");
85
+ const output = execSync(`promake ${command} ${safeArgs}`, {
86
+ cwd: process.cwd(),
87
+ encoding: "utf-8",
88
+ timeout: 15000,
89
+ });
90
+
91
+ res.setHeader("Content-Type", "application/json");
92
+ res.end(JSON.stringify({ ok: true, output }));
93
+ } catch (e: any) {
94
+ res.statusCode = 500;
95
+ res.setHeader("Content-Type", "application/json");
96
+ res.end(JSON.stringify({ ok: false, error: e.message }));
97
+ }
98
+ });
99
+ },
100
+ };
101
+ }
102
+
31
103
  // https://vite.dev/config/
32
- export default defineConfig(({ mode }) => ({
104
+ export default defineConfig(({ mode }) => {
105
+ const env = loadEnv(mode, process.cwd(), "PROMAKE_");
106
+
107
+ return ({
33
108
  cacheDir: '/tmp/.vite-cache',
34
109
  plugins: [
35
110
  inspectorDebugger({ enabled: mode === "development" }),
36
111
  react(),
37
112
  tailwindcss(),
38
113
  mode === "development" && langWatchPlugin(),
114
+ mode === "development" && promakeApiPlugin(env.PROMAKE_SECRET),
39
115
  ].filter(Boolean),
40
116
  resolve: {
41
117
  alias: {
@@ -66,4 +142,5 @@ export default defineConfig(({ mode }) => ({
66
142
  },
67
143
  },
68
144
  },
69
- }));
145
+ });
146
+ });