postcrm-plugin-cli 0.1.0__tar.gz → 0.1.1__tar.gz

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,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: postcrm-plugin-cli
3
- Version: 0.1.0
3
+ Version: 0.1.1
4
4
  Summary: PostCRM plugin packaging CLI
5
5
  License: PostCRM Plugin CLI License
6
6
 
@@ -65,7 +65,7 @@ pip install postcrm-plugin-cli
65
65
 
66
66
  ## Команды
67
67
 
68
- - `init` - создать каркас плагина с manifest, frontend и backend.
68
+ - `init` - создать каркас плагина с manifest, frontend, backend и скриптом сборки.
69
69
  - `keygen` - создать пару ключей Ed25519 для подписи пакета.
70
70
  - `pack` - собрать и подписать `.postcrm-plugin`.
71
71
  - `validate` - проверить структуру, checksums и manifest пакета.
@@ -79,18 +79,23 @@ postcrm-plugin init ./my-plugin \
79
79
  --publisher postltd
80
80
  ```
81
81
 
82
- В каталоге `my-plugin` появятся `manifest.json`, frontend-приложение с
83
- dev-harness (`frontend/dev/main.ts`, `frontend/vite.dev.config.ts`) и backend
84
- с `backend/requirements.lock`.
82
+ В каталоге `my-plugin` появятся `.gitignore` с исключением `.dev/`,
83
+ `manifest.json`, frontend-приложение с dev-harness (`frontend/dev/main.ts`,
84
+ `frontend/vite.dev.config.ts`), backend с `backend/requirements.lock` и скрипт
85
+ `scripts/build.sh`.
85
86
 
86
87
  ## Сборка и проверка
87
88
 
88
89
  ```bash
89
- postcrm-plugin keygen --private key.pem --public key.pub
90
- postcrm-plugin pack ./my-plugin -o my-plugin.postcrm-plugin -k key.pem --key-id dev
91
- postcrm-plugin validate my-plugin.postcrm-plugin
90
+ cd my-plugin
91
+ bash scripts/build.sh
92
92
  ```
93
93
 
94
+ Скрипт собирает frontend и offline wheels, при первом запуске создает ключ в
95
+ `.dev/`, собирает пакет и запускает `validate`. Пути и параметры подписи можно
96
+ переопределить через `PLUGIN_PRIVATE_KEY`, `PLUGIN_PUBLIC_KEY`, `PLUGIN_KEY_ID`
97
+ и `PLUGIN_OUTPUT`.
98
+
94
99
  ## Разработка в монорепозитории
95
100
 
96
101
  В каталоге `plugin-cli` CLI запускается из Poetry:
@@ -20,7 +20,7 @@ pip install postcrm-plugin-cli
20
20
 
21
21
  ## Команды
22
22
 
23
- - `init` - создать каркас плагина с manifest, frontend и backend.
23
+ - `init` - создать каркас плагина с manifest, frontend, backend и скриптом сборки.
24
24
  - `keygen` - создать пару ключей Ed25519 для подписи пакета.
25
25
  - `pack` - собрать и подписать `.postcrm-plugin`.
26
26
  - `validate` - проверить структуру, checksums и manifest пакета.
@@ -34,18 +34,23 @@ postcrm-plugin init ./my-plugin \
34
34
  --publisher postltd
35
35
  ```
36
36
 
37
- В каталоге `my-plugin` появятся `manifest.json`, frontend-приложение с
38
- dev-harness (`frontend/dev/main.ts`, `frontend/vite.dev.config.ts`) и backend
39
- с `backend/requirements.lock`.
37
+ В каталоге `my-plugin` появятся `.gitignore` с исключением `.dev/`,
38
+ `manifest.json`, frontend-приложение с dev-harness (`frontend/dev/main.ts`,
39
+ `frontend/vite.dev.config.ts`), backend с `backend/requirements.lock` и скрипт
40
+ `scripts/build.sh`.
40
41
 
41
42
  ## Сборка и проверка
42
43
 
43
44
  ```bash
44
- postcrm-plugin keygen --private key.pem --public key.pub
45
- postcrm-plugin pack ./my-plugin -o my-plugin.postcrm-plugin -k key.pem --key-id dev
46
- postcrm-plugin validate my-plugin.postcrm-plugin
45
+ cd my-plugin
46
+ bash scripts/build.sh
47
47
  ```
48
48
 
49
+ Скрипт собирает frontend и offline wheels, при первом запуске создает ключ в
50
+ `.dev/`, собирает пакет и запускает `validate`. Пути и параметры подписи можно
51
+ переопределить через `PLUGIN_PRIVATE_KEY`, `PLUGIN_PUBLIC_KEY`, `PLUGIN_KEY_ID`
52
+ и `PLUGIN_OUTPUT`.
53
+
49
54
  ## Разработка в монорепозитории
50
55
 
51
56
  В каталоге `plugin-cli` CLI запускается из Poetry:
@@ -198,11 +198,69 @@ Harness открывается по адресу http://localhost:5173. Он р
198
198
  и `ActionButton` с mock-props.
199
199
 
200
200
  Mock-context не ходит в CRM: `api`, `external`, `navigate`, `onEvent` и
201
- `publishEvent` только логируют вызовы в консоль браузера и возвращают
202
- заглушки. Для проверки реальной интеграции с CRM нужен dev-remote override:
203
- запустите `pnpm dev` в плагине и откройте CRM в dev-режиме с параметрами
204
- `?pluginRemote=http://localhost:5173/remoteEntry.js&pluginRemoteName=<remoteName>`.
205
- Подробности - в `docs/plugin-sdk-v1.md`, раздел "Визуальная проверка плагина".
201
+ `publishEvent` только логируют вызовы в консоль браузера.
202
+
203
+ `pnpm dev` запускает harness без Module Federation и не создает
204
+ `remoteEntry.js`. Для dev-remote нужен отдельный Vite-сервер с
205
+ `vite.config.ts` и включенным CORS. Подробности - в `docs/plugin-sdk-v1.md`,
206
+ раздел "Визуальная проверка плагина".
207
+ """
208
+
209
+ BUILD_SCRIPT_TEMPLATE = """#!/usr/bin/env bash
210
+ set -euo pipefail
211
+
212
+ PLUGIN_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
213
+ MANIFEST="$PLUGIN_ROOT/manifest.json"
214
+ PLUGIN_ID="$(python3.12 -c 'import json, sys; print(json.load(open(sys.argv[1], encoding="utf-8"))["id"])' "$MANIFEST")"
215
+ VERSION="$(python3.12 -c 'import json, sys; print(json.load(open(sys.argv[1], encoding="utf-8"))["version"])' "$MANIFEST")"
216
+ PUBLISHER="$(python3.12 -c 'import json, sys; print(json.load(open(sys.argv[1], encoding="utf-8"))["publisher"])' "$MANIFEST")"
217
+ STAGE="$(mktemp -d "${TMPDIR:-/tmp}/postcrm-plugin.XXXXXX")"
218
+ KEY="${PLUGIN_PRIVATE_KEY:-$PLUGIN_ROOT/.dev/dev-key.pem}"
219
+ PUBLIC_KEY="${PLUGIN_PUBLIC_KEY:-$PLUGIN_ROOT/.dev/dev-key.pub}"
220
+ KEY_ID="${PLUGIN_KEY_ID:-$PUBLISHER-dev}"
221
+ OUT="${PLUGIN_OUTPUT:-$PLUGIN_ROOT/.dev/$PLUGIN_ID-$VERSION.postcrm-plugin}"
222
+
223
+ cleanup() {
224
+ rm -rf "$STAGE"
225
+ }
226
+ trap cleanup EXIT
227
+
228
+ mkdir -p "$(dirname "$KEY")" "$(dirname "$PUBLIC_KEY")" "$(dirname "$OUT")"
229
+
230
+ (
231
+ cd "$PLUGIN_ROOT/frontend"
232
+ pnpm install
233
+ pnpm run build
234
+ )
235
+
236
+ mkdir -p "$STAGE/backend/plugin" "$STAGE/backend/wheels" "$STAGE/frontend"
237
+ cp "$MANIFEST" "$STAGE/manifest.json"
238
+ cp -R "$PLUGIN_ROOT/backend/plugin/." "$STAGE/backend/plugin/"
239
+ cp "$PLUGIN_ROOT/backend/requirements.lock" "$STAGE/backend/requirements.lock"
240
+ cp -R "$PLUGIN_ROOT/frontend/dist/." "$STAGE/frontend/"
241
+
242
+ if [ -d "$PLUGIN_ROOT/backend/migrations" ]; then
243
+ cp -R "$PLUGIN_ROOT/backend/migrations" "$STAGE/backend/migrations"
244
+ fi
245
+ if [ -f "$PLUGIN_ROOT/README.md" ]; then
246
+ cp "$PLUGIN_ROOT/README.md" "$STAGE/README.md"
247
+ fi
248
+
249
+ python3.12 -m pip download \\
250
+ -r "$PLUGIN_ROOT/backend/requirements.lock" \\
251
+ -d "$STAGE/backend/wheels" \\
252
+ --platform manylinux2014_x86_64 \\
253
+ --python-version 3.12 \\
254
+ --implementation cp \\
255
+ --abi cp312 \\
256
+ --only-binary=:all:
257
+
258
+ if [ ! -f "$KEY" ]; then
259
+ postcrm-plugin keygen --private "$KEY" --public "$PUBLIC_KEY"
260
+ fi
261
+
262
+ postcrm-plugin pack "$STAGE" -o "$OUT" -k "$KEY" --key-id "$KEY_ID"
263
+ postcrm-plugin validate "$OUT"
206
264
  """
207
265
 
208
266
 
@@ -211,6 +269,10 @@ def cmd_init(args: argparse.Namespace) -> int:
211
269
  target = Path(args.directory)
212
270
  (target / "frontend" / "src").mkdir(parents=True, exist_ok=True)
213
271
  (target / "backend" / "plugin").mkdir(parents=True, exist_ok=True)
272
+ (target / "scripts").mkdir(parents=True, exist_ok=True)
273
+ gitignore = target / ".gitignore"
274
+ if not gitignore.exists():
275
+ gitignore.write_text(".dev/\nbackend/.venv/\n__pycache__/\n*.pyc\n", encoding="utf-8")
214
276
  plugin_id = args.plugin_id
215
277
  plugin_id_slug = plugin_id.replace(".", "_").replace("-", "_")
216
278
  sdk_ui_dependency = f"file:{args.local_sdk}" if args.local_sdk else "^0.1.3"
@@ -250,13 +312,16 @@ def cmd_init(args: argparse.Namespace) -> int:
250
312
  encoding="utf-8",
251
313
  )
252
314
  (target / "backend" / "plugin" / "main.py").write_text(
253
- "from fastapi import APIRouter\n"
254
- "from postcrm_plugin_sdk import create_app\n\n"
255
- "router = APIRouter()\n\n"
315
+ "from fastapi import APIRouter, FastAPI\n"
316
+ "from postcrm_plugin_sdk import create_app as create_sdk_app\n\n"
317
+ "router = APIRouter()\n\n\n"
256
318
  "@router.get('/hello')\n"
257
319
  "async def hello() -> dict[str, str]:\n"
258
- " return {'message': 'hello'}\n\n"
259
- "app = create_app(router=router)\n",
320
+ " return {'message': 'hello'}\n\n\n"
321
+ "def create_app() -> FastAPI:\n"
322
+ ' """Создает приложение с маршрутами плагина для runner-а."""\n'
323
+ " return create_sdk_app(router=router)\n\n\n"
324
+ "app = create_app()\n",
260
325
  encoding="utf-8",
261
326
  )
262
327
  (target / "frontend" / "index.html").write_text(
@@ -322,6 +387,7 @@ def cmd_init(args: argparse.Namespace) -> int:
322
387
  encoding="utf-8",
323
388
  )
324
389
  (target / "frontend" / ".gitignore").write_text("node_modules\ndist\n.quasar\n", encoding="utf-8")
390
+ (target / "frontend" / "pnpm-workspace.yaml").write_text("allowBuilds:\n esbuild: true\n", encoding="utf-8")
325
391
  (target / "frontend" / "vite.dev.config.ts").write_text(
326
392
  "import { defineConfig } from 'vite';\n"
327
393
  "import vue from '@vitejs/plugin-vue';\n\n"
@@ -464,6 +530,11 @@ def cmd_init(args: argparse.Namespace) -> int:
464
530
  "postcrm-plugin-sdk==0.1.3\nuvicorn>=0.30.1\n", encoding="utf-8"
465
531
  )
466
532
  (target / "backend" / "wheels").mkdir(exist_ok=True)
533
+
534
+ build_script = target / "scripts" / "build.sh"
535
+ build_script.write_text(BUILD_SCRIPT_TEMPLATE, encoding="utf-8")
536
+ build_script.chmod(0o755)
537
+
467
538
  print(f"created {target}")
468
539
  return 0
469
540
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "postcrm-plugin-cli"
3
- version = "0.1.0"
3
+ version = "0.1.1"
4
4
  description = "PostCRM plugin packaging CLI"
5
5
  authors = [{ name = "PostCRM" }]
6
6
  license = { file = "LICENSE" }