primo-cli 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.
@@ -0,0 +1,129 @@
1
+ import fs from 'fs/promises';
2
+ import path from 'path';
3
+ import os from 'os';
4
+ import { fileURLToPath } from 'url';
5
+ import { createWriteStream } from 'fs';
6
+ import { pipeline } from 'stream/promises';
7
+ import chalk from 'chalk';
8
+ import ora from 'ora';
9
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
10
+ const PRIMO_HOME = path.join(os.homedir(), '.primo');
11
+ const BIN_DIR = path.join(PRIMO_HOME, 'bin');
12
+ const DATA_DIR = path.join(PRIMO_HOME, 'data');
13
+ const VERSION = '0.1.0'; // TODO: fetch latest from GitHub
14
+ // Path to locally built binary (for development)
15
+ // The binary is at palacms/palacms (inside the palacms repo directory)
16
+ const LOCAL_BINARY = path.resolve(__dirname, '..', '..', '..', 'palacms', 'palacms');
17
+ function get_platform() {
18
+ const platform = os.platform();
19
+ const arch = os.arch();
20
+ let osName;
21
+ let archName;
22
+ let ext = '';
23
+ switch (platform) {
24
+ case 'darwin':
25
+ osName = 'darwin';
26
+ break;
27
+ case 'linux':
28
+ osName = 'linux';
29
+ break;
30
+ case 'win32':
31
+ osName = 'windows';
32
+ ext = '.exe';
33
+ break;
34
+ default:
35
+ throw new Error(`Unsupported platform: ${platform}`);
36
+ }
37
+ switch (arch) {
38
+ case 'arm64':
39
+ archName = 'arm64';
40
+ break;
41
+ case 'x64':
42
+ archName = 'amd64';
43
+ break;
44
+ default:
45
+ throw new Error(`Unsupported architecture: ${arch}`);
46
+ }
47
+ return { os: osName, arch: archName, ext };
48
+ }
49
+ function get_download_url(platform) {
50
+ // TODO: Update to actual GitHub releases URL
51
+ const base = 'https://github.com/palacms/palacms/releases/download';
52
+ const filename = `palacms_${platform.os}_${platform.arch}${platform.ext}`;
53
+ return `${base}/v${VERSION}/${filename}`;
54
+ }
55
+ export async function get_binary_path() {
56
+ // Check for locally built binary first (development)
57
+ try {
58
+ await fs.access(LOCAL_BINARY, fs.constants.X_OK);
59
+ return LOCAL_BINARY;
60
+ }
61
+ catch { }
62
+ // Fall back to downloaded binary
63
+ const platform = get_platform();
64
+ return path.join(BIN_DIR, `palacms${platform.ext}`);
65
+ }
66
+ export async function ensure_data_dir(base_dir) {
67
+ const data_dir = path.join(base_dir, '.primo');
68
+ await fs.mkdir(data_dir, { recursive: true });
69
+ return data_dir;
70
+ }
71
+ export async function is_binary_installed() {
72
+ try {
73
+ const binary_path = await get_binary_path();
74
+ await fs.access(binary_path, fs.constants.X_OK);
75
+ return true;
76
+ }
77
+ catch {
78
+ return false;
79
+ }
80
+ }
81
+ export async function ensure_binary() {
82
+ if (await is_binary_installed()) {
83
+ return await get_binary_path();
84
+ }
85
+ // Need to download - get the target path
86
+ const platform = get_platform();
87
+ const binary_path = path.join(BIN_DIR, `palacms${platform.ext}`);
88
+ const spinner = ora('Setting up Pala...').start();
89
+ try {
90
+ // Create directories
91
+ await fs.mkdir(BIN_DIR, { recursive: true });
92
+ const url = get_download_url(platform);
93
+ spinner.text = `Downloading palacms for ${platform.os}/${platform.arch}...`;
94
+ // Download binary
95
+ const response = await fetch(url);
96
+ if (!response.ok) {
97
+ throw new Error(`Download failed: ${response.status} ${response.statusText}`);
98
+ }
99
+ // Save to file
100
+ const file_stream = createWriteStream(binary_path);
101
+ await pipeline(response.body, file_stream);
102
+ // Make executable
103
+ await fs.chmod(binary_path, 0o755);
104
+ spinner.succeed('Pala setup complete');
105
+ return binary_path;
106
+ }
107
+ catch (error) {
108
+ spinner.fail('Setup failed');
109
+ // Provide manual instructions
110
+ console.log('');
111
+ console.log(chalk.yellow('To install manually:'));
112
+ console.log(chalk.dim(' 1. Download palacms from https://github.com/palacms/palacms/releases'));
113
+ console.log(chalk.dim(` 2. Place it in ${BIN_DIR}`));
114
+ console.log(chalk.dim(' 3. Make it executable: chmod +x palacms'));
115
+ console.log('');
116
+ throw error;
117
+ }
118
+ }
119
+ export async function get_binary_version() {
120
+ try {
121
+ const binary_path = get_binary_path();
122
+ const { execSync } = await import('child_process');
123
+ const output = execSync(`"${binary_path}" --version`, { encoding: 'utf-8' });
124
+ return output.trim();
125
+ }
126
+ catch {
127
+ return null;
128
+ }
129
+ }
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "primo-cli",
3
+ "version": "0.1.0",
4
+ "description": "Local development CLI for Primo",
5
+ "type": "module",
6
+ "bin": {
7
+ "primo": "./dist/index.js"
8
+ },
9
+ "scripts": {
10
+ "build": "tsc",
11
+ "dev": "tsc --watch",
12
+ "prepublishOnly": "npm run build"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/palacms/cli.git"
17
+ },
18
+ "homepage": "https://primocms.org",
19
+ "bugs": {
20
+ "url": "https://github.com/palacms/cli/issues"
21
+ },
22
+ "keywords": [
23
+ "primo",
24
+ "cms",
25
+ "svelte",
26
+ "static-site",
27
+ "cli"
28
+ ],
29
+ "author": "Primo",
30
+ "license": "MIT",
31
+ "dependencies": {
32
+ "archiver": "^7.0.1",
33
+ "chalk": "^5.3.0",
34
+ "chokidar": "^3.6.0",
35
+ "commander": "^12.1.0",
36
+ "extract-zip": "^2.0.1",
37
+ "inquirer": "^13.3.0",
38
+ "js-yaml": "^4.1.0",
39
+ "ora": "^8.0.1"
40
+ },
41
+ "devDependencies": {
42
+ "@types/archiver": "^6.0.2",
43
+ "@types/js-yaml": "^4.0.9",
44
+ "@types/node": "^20.11.0",
45
+ "typescript": "^5.3.3"
46
+ },
47
+ "files": [
48
+ "dist"
49
+ ],
50
+ "engines": {
51
+ "node": ">=18.0.0"
52
+ }
53
+ }