@magicpages/ghost-typesense-cli 0.0.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.
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
package/dist/index.js ADDED
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/index.ts
4
+ import { Command } from "commander";
5
+ import { readFileSync } from "fs";
6
+ import { resolve } from "path";
7
+ import chalk from "chalk";
8
+ import ora from "ora";
9
+ import { validateConfig } from "@magicpages/ghost-typesense-config";
10
+ import { GhostTypesenseManager } from "@magicpages/ghost-typesense-core";
11
+ var program = new Command();
12
+ program.name("ghost-typesense").description("CLI tool for managing Ghost content in Typesense").version("1.0.0");
13
+ program.command("init").description("Initialize Typesense collection with schema from config").requiredOption("-c, --config <path>", "Path to config file").action(async (options) => {
14
+ try {
15
+ const spinner = ora("Reading configuration...").start();
16
+ const configPath = resolve(process.cwd(), options.config);
17
+ const configContent = readFileSync(configPath, "utf-8");
18
+ const config = validateConfig(JSON.parse(configContent));
19
+ spinner.text = "Initializing Typesense collection...";
20
+ const manager = new GhostTypesenseManager(config);
21
+ await manager.initializeCollection();
22
+ spinner.succeed("Collection initialized successfully");
23
+ } catch (error) {
24
+ ora().fail(chalk.red(`Failed to initialize collection: ${error.message}`));
25
+ process.exit(1);
26
+ }
27
+ });
28
+ program.command("sync").description("Sync all Ghost posts to Typesense").requiredOption("-c, --config <path>", "Path to config file").action(async (options) => {
29
+ try {
30
+ const spinner = ora("Reading configuration...").start();
31
+ const configPath = resolve(process.cwd(), options.config);
32
+ const configContent = readFileSync(configPath, "utf-8");
33
+ const config = validateConfig(JSON.parse(configContent));
34
+ spinner.text = "Syncing posts to Typesense...";
35
+ const manager = new GhostTypesenseManager(config);
36
+ await manager.indexAllPosts();
37
+ spinner.succeed("Posts synced successfully");
38
+ } catch (error) {
39
+ ora().fail(chalk.red(`Failed to sync posts: ${error.message}`));
40
+ process.exit(1);
41
+ }
42
+ });
43
+ program.command("clear").description("Clear all documents from Typesense collection").requiredOption("-c, --config <path>", "Path to config file").action(async (options) => {
44
+ try {
45
+ const spinner = ora("Reading configuration...").start();
46
+ const configPath = resolve(process.cwd(), options.config);
47
+ const configContent = readFileSync(configPath, "utf-8");
48
+ const config = validateConfig(JSON.parse(configContent));
49
+ spinner.text = "Clearing collection...";
50
+ const manager = new GhostTypesenseManager(config);
51
+ await manager.clearCollection();
52
+ spinner.succeed("Collection cleared successfully");
53
+ } catch (error) {
54
+ ora().fail(chalk.red(`Failed to clear collection: ${error.message}`));
55
+ process.exit(1);
56
+ }
57
+ });
58
+ program.parse();
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@magicpages/ghost-typesense-cli",
3
+ "version": "0.0.0",
4
+ "description": "CLI tool for managing Ghost content in Typesense",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "bin": {
8
+ "ghost-typesense": "dist/index.js"
9
+ },
10
+ "files": [
11
+ "dist"
12
+ ],
13
+ "scripts": {
14
+ "build": "tsup src/index.ts --format esm --dts",
15
+ "clean": "rimraf dist",
16
+ "dev": "tsup src/index.ts --format esm --dts --watch",
17
+ "lint": "eslint src --ext .ts",
18
+ "test": "vitest run",
19
+ "typecheck": "tsc --noEmit"
20
+ },
21
+ "dependencies": {
22
+ "@magicpages/ghost-typesense-config": "*",
23
+ "@magicpages/ghost-typesense-core": "*",
24
+ "commander": "^12.0.0",
25
+ "ora": "^8.0.1",
26
+ "chalk": "^5.3.0"
27
+ },
28
+ "devDependencies": {
29
+ "@types/node": "^20.11.17",
30
+ "tsup": "^8.0.1",
31
+ "rimraf": "^5.0.5",
32
+ "vitest": "^1.2.2",
33
+ "typescript": "^5.3.3"
34
+ },
35
+ "publishConfig": {
36
+ "access": "public"
37
+ },
38
+ "license": "MIT"
39
+ }