@babelx/cli 0.1.0 → 0.2.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.
package/README.md CHANGED
@@ -12,20 +12,36 @@ Official CLI for BabelX - AI-powered translation and i18n management.
12
12
 
13
13
  ## Installation
14
14
 
15
+ ### Via npm (Recommended)
16
+
15
17
  ```bash
16
- # Install globally via npm
18
+ # Install globally
17
19
  npm install -g @babelx/cli
18
20
 
19
- # Or use npx (no installation)
21
+ # Or use npx (no installation required)
20
22
  npx @babelx/cli --version
21
-
22
- # Or install via bun
23
- bun install -g @babelx/cli
24
23
  ```
25
24
 
26
- ### Requirements
25
+ The npm package automatically downloads the correct binary for your platform during installation.
26
+
27
+ ### Supported Platforms
28
+
29
+ - **macOS** (Intel & Apple Silicon)
30
+ - **Linux** (x64 & ARM64)
31
+ - **Windows** (x64)
32
+
33
+ ### Manual Binary Download
27
34
 
28
- - [Node.js](https://nodejs.org) >= 18.0.0 **or** [Bun](https://bun.sh) >= 1.0.0
35
+ You can also download pre-built binaries from [GitHub Releases](https://github.com/babelxdev/bx-cli/releases):
36
+
37
+ ```bash
38
+ # Download for your platform and add to PATH
39
+ # Linux/macOS:
40
+ chmod +x bx-linux-x64
41
+ sudo mv bx-linux-x64 /usr/local/bin/bx
42
+
43
+ # Windows: Add bx-windows-x64.exe to your PATH
44
+ ```
29
45
 
30
46
  ## Quick Start
31
47
 
package/bin/bx ADDED
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * BabelX CLI - Binary wrapper
4
+ * Detects platform and runs the appropriate binary
5
+ */
6
+
7
+ const { spawn } = require('child_process');
8
+ const path = require('path');
9
+ const fs = require('fs');
10
+ const os = require('os');
11
+
12
+ function getPlatform() {
13
+ const platform = os.platform();
14
+ const arch = os.arch();
15
+
16
+ const platformMap = {
17
+ 'darwin': 'darwin',
18
+ 'linux': 'linux',
19
+ 'win32': 'windows'
20
+ };
21
+
22
+ const archMap = {
23
+ 'x64': 'x64',
24
+ 'arm64': 'arm64'
25
+ };
26
+
27
+ const p = platformMap[platform];
28
+ const a = archMap[arch];
29
+
30
+ if (!p || !a) {
31
+ console.error(`Unsupported platform: ${platform} ${arch}`);
32
+ process.exit(1);
33
+ }
34
+
35
+ return `${p}-${a}`;
36
+ }
37
+
38
+ function getBinaryPath() {
39
+ const platform = getPlatform();
40
+ const binDir = path.join(__dirname, '..', 'vendor');
41
+ const binName = platform.startsWith('windows') ? 'bx.exe' : 'bx';
42
+ const binPath = path.join(binDir, platform, binName);
43
+
44
+ return binPath;
45
+ }
46
+
47
+ function main() {
48
+ const binaryPath = getBinaryPath();
49
+
50
+ // Check if binary exists
51
+ if (!fs.existsSync(binaryPath)) {
52
+ console.error('BabelX CLI binary not found.');
53
+ console.error(`Expected path: ${binaryPath}`);
54
+ console.error('');
55
+ console.error('Please run: npm install @babelx/cli');
56
+ console.error('Or download the binary manually from GitHub releases.');
57
+ process.exit(1);
58
+ }
59
+
60
+ // Run the binary with all arguments
61
+ const child = spawn(binaryPath, process.argv.slice(2), {
62
+ stdio: 'inherit',
63
+ windowsHide: true
64
+ });
65
+
66
+ child.on('error', (err) => {
67
+ console.error('Failed to start BabelX CLI:', err.message);
68
+ process.exit(1);
69
+ });
70
+
71
+ child.on('exit', (code) => {
72
+ process.exit(code || 0);
73
+ });
74
+ }
75
+
76
+ main();
package/bin/bx.cmd ADDED
@@ -0,0 +1,24 @@
1
+ @echo off
2
+ setlocal
3
+
4
+ set "SCRIPT_DIR=%~dp0"
5
+ set "VENDOR_DIR=%SCRIPT_DIR%..\vendor"
6
+
7
+ :: Detect architecture
8
+ if "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
9
+ set "ARCH=x64"
10
+ ) else (
11
+ echo Unsupported architecture: %PROCESSOR_ARCHITECTURE%
12
+ exit /b 1
13
+ )
14
+
15
+ set "PLATFORM=windows-%ARCH%"
16
+ set "BINARY_PATH=%VENDOR_DIR%\%PLATFORM%\bx.exe"
17
+
18
+ if not exist "%BINARY_PATH%" (
19
+ echo BabelX CLI binary not found: %BINARY_PATH%
20
+ echo Please run: npm install @babelx/cli
21
+ exit /b 1
22
+ )
23
+
24
+ "%BINARY_PATH%" %*
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babelx/cli",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "BabelX CLI - AI-powered translation and i18n management tool",
5
5
  "module": "index.ts",
6
6
  "type": "module",
@@ -21,10 +21,12 @@
21
21
  "localization"
22
22
  ],
23
23
  "bin": {
24
- "bx": "./dist/index.js"
24
+ "bx": "./bin/bx"
25
25
  },
26
26
  "files": [
27
- "dist/",
27
+ "bin/",
28
+ "scripts/",
29
+ "vendor/",
28
30
  "LICENSE",
29
31
  "README.md"
30
32
  ],
@@ -56,7 +58,15 @@
56
58
  },
57
59
  "scripts": {
58
60
  "dev": "bun run index.ts",
59
- "build": "bun build index.ts --outdir dist --target node",
61
+ "build": "bun build index.ts --outdir dist --target bun",
62
+ "build:binary": "bun build index.ts --compile --outfile bx",
63
+ "build:binary:all": "npm run build:binary:win && npm run build:binary:linux && npm run build:binary:mac",
64
+ "build:binary:win": "bun build index.ts --compile --target=bun-windows-x64 --outfile dist/bx-win-x64.exe",
65
+ "build:binary:linux": "bun build index.ts --compile --target=bun-linux-x64 --outfile dist/bx-linux-x64",
66
+ "build:binary:linux-arm": "bun build index.ts --compile --target=bun-linux-arm64 --outfile dist/bx-linux-arm64",
67
+ "build:binary:mac": "bun build index.ts --compile --target=bun-darwin-x64 --outfile dist/bx-darwin-x64",
68
+ "build:binary:mac-arm": "bun build index.ts --compile --target=bun-darwin-arm64 --outfile dist/bx-darwin-arm64",
69
+ "postinstall": "node scripts/postinstall.js",
60
70
  "lint:check": "bunx biome check --write --error-on-warnings && bunx tsc --noEmit",
61
71
  "lint:fix": "biome check --write ."
62
72
  }
@@ -0,0 +1,158 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Post-install script for @babelx/cli
4
+ * Downloads the appropriate binary for the current platform
5
+ */
6
+
7
+ import {
8
+ chmodSync,
9
+ createWriteStream,
10
+ existsSync,
11
+ mkdirSync,
12
+ readFileSync,
13
+ } from "node:fs";
14
+ import { get } from "node:https";
15
+ import { dirname, join } from "node:path";
16
+ import { fileURLToPath } from "node:url";
17
+
18
+ const GITHUB_REPO = "babelxdev/bx-cli";
19
+
20
+ // ES modules don't have __dirname
21
+ const __filename = fileURLToPath(import.meta.url);
22
+ const __dirname = dirname(__filename);
23
+
24
+ function getPlatform() {
25
+ const platform = process.platform;
26
+ const arch = process.arch;
27
+
28
+ const platformMap = {
29
+ darwin: "darwin",
30
+ linux: "linux",
31
+ win32: "windows",
32
+ };
33
+
34
+ const archMap = {
35
+ x64: "x64",
36
+ arm64: "arm64",
37
+ };
38
+
39
+ const p = platformMap[platform];
40
+ const a = archMap[arch];
41
+
42
+ if (!p || !a) {
43
+ console.error(`❌ Unsupported platform: ${platform} ${arch}`);
44
+ console.error(
45
+ "Supported platforms: darwin-x64, darwin-arm64, linux-x64, linux-arm64, windows-x64",
46
+ );
47
+ process.exit(1);
48
+ }
49
+
50
+ return `${p}-${a}`;
51
+ }
52
+
53
+ function getBinaryName() {
54
+ return process.platform === "win32" ? "bx.exe" : "bx";
55
+ }
56
+
57
+ async function downloadBinary(version, platform, destPath) {
58
+ const binaryExt = process.platform === "win32" ? ".exe" : "";
59
+ const url = `https://github.com/${GITHUB_REPO}/releases/download/v${version}/bx-${platform}${binaryExt}`;
60
+
61
+ console.log(`📦 Downloading BabelX CLI v${version} for ${platform}...`);
62
+ console.log(` URL: ${url}`);
63
+
64
+ return new Promise((resolve, reject) => {
65
+ const file = createWriteStream(destPath);
66
+ get(url, { followRedirects: true }, (response) => {
67
+ if (response.statusCode === 302 || response.statusCode === 301) {
68
+ // Handle redirect
69
+ get(response.headers.location, (res) => {
70
+ res.pipe(file);
71
+ file.on("finish", () => {
72
+ file.close();
73
+ resolve();
74
+ });
75
+ }).on("error", reject);
76
+ } else if (response.statusCode === 200) {
77
+ response.pipe(file);
78
+ file.on("finish", () => {
79
+ file.close();
80
+ resolve();
81
+ });
82
+ } else {
83
+ reject(
84
+ new Error(`HTTP ${response.statusCode}: ${response.statusMessage}`),
85
+ );
86
+ }
87
+ }).on("error", reject);
88
+ });
89
+ }
90
+
91
+ function makeExecutable(filePath) {
92
+ if (process.platform !== "win32") {
93
+ chmodSync(filePath, 0o755);
94
+ }
95
+ }
96
+
97
+ async function main() {
98
+ // Skip in CI environment or if explicitly disabled
99
+ if (process.env.CI || process.env.SKIP_BABELX_BINARY) {
100
+ console.log("⏭️ Skipping binary download (CI environment)");
101
+ return;
102
+ }
103
+
104
+ try {
105
+ // Get package version
106
+ const packageJson = JSON.parse(
107
+ readFileSync(join(__dirname, "..", "package.json"), "utf-8"),
108
+ );
109
+ const version = packageJson.version;
110
+
111
+ const platform = getPlatform();
112
+ const binaryName = getBinaryName();
113
+
114
+ // Create vendor directory
115
+ const vendorDir = join(__dirname, "..", "vendor", platform);
116
+ if (!existsSync(vendorDir)) {
117
+ mkdirSync(vendorDir, { recursive: true });
118
+ }
119
+
120
+ const binaryPath = join(vendorDir, binaryName);
121
+
122
+ // Check if binary already exists
123
+ if (existsSync(binaryPath)) {
124
+ console.log(`✅ BabelX CLI binary already exists for ${platform}`);
125
+ return;
126
+ }
127
+
128
+ // Download binary
129
+ await downloadBinary(version, platform, binaryPath);
130
+
131
+ // Make executable (Unix only)
132
+ makeExecutable(binaryPath);
133
+
134
+ console.log(`✅ BabelX CLI v${version} installed successfully!`);
135
+ console.log(` Binary: ${binaryPath}`);
136
+ } catch (error) {
137
+ // Don't fail installation if binary download fails (e.g., first release)
138
+ if (error.message.includes("404")) {
139
+ console.warn("⚠️ Binary not found for this version yet.");
140
+ console.warn(" The CLI will use the bundled JavaScript version.");
141
+ console.warn(
142
+ ` Check https://github.com/${GITHUB_REPO}/releases for updates.`,
143
+ );
144
+ return; // Don't fail installation
145
+ }
146
+
147
+ console.error("❌ Failed to install BabelX CLI binary:", error.message);
148
+ console.error("");
149
+ console.error("You can try:");
150
+ console.error("1. Check your internet connection");
151
+ console.error("2. Set SKIP_BABELX_BINARY=1 to skip binary download");
152
+ console.error("3. Install manually from GitHub releases:");
153
+ console.error(` https://github.com/${GITHUB_REPO}/releases`);
154
+ // Don't exit with error - allow npm install to continue
155
+ }
156
+ }
157
+
158
+ main();
@@ -0,0 +1,110 @@
1
+ #!/bin/bash
2
+ # Script de release automático para BabelX CLI
3
+ # Uso: ./scripts/release.sh [patch|minor|major]
4
+
5
+ set -e
6
+
7
+ # Cores
8
+ RED='\033[0;31m'
9
+ GREEN='\033[0;32m'
10
+ YELLOW='\033[1;33m'
11
+ NC='\033[0m' # No Color
12
+
13
+ # Verificar se está na pasta correta
14
+ if [ ! -f "package.json" ]; then
15
+ echo -e "${RED}Erro: Execute este script da raiz do projeto bx-cli${NC}"
16
+ exit 1
17
+ fi
18
+
19
+ # Tipo de versão (padrão: patch)
20
+ VERSION_TYPE=${1:-patch}
21
+
22
+ echo -e "${YELLOW}🚀 Iniciando release do BabelX CLI${NC}"
23
+ echo "Tipo de versão: $VERSION_TYPE"
24
+
25
+ # Verificar branch atual
26
+ CURRENT_BRANCH=$(git branch --show-current)
27
+ if [ "$CURRENT_BRANCH" != "main" ] && [ "$CURRENT_BRANCH" != "master" ]; then
28
+ echo -e "${RED}Erro: Você deve estar na branch main ou master${NC}"
29
+ echo "Branch atual: $CURRENT_BRANCH"
30
+ exit 1
31
+ fi
32
+
33
+ # Verificar se há mudanças não commitadas
34
+ if [ -n "$(git status --porcelain)" ]; then
35
+ echo -e "${RED}Erro: Há mudanças não commitadas${NC}"
36
+ echo "Por favor, commit ou stash suas mudanças antes de fazer release."
37
+ git status
38
+ exit 1
39
+ fi
40
+
41
+ # Pull das últimas mudanças
42
+ echo -e "${YELLOW}📥 Atualizando código...${NC}"
43
+ git pull origin $CURRENT_BRANCH
44
+
45
+ # Ler versão atual
46
+ CURRENT_VERSION=$(cat package.json | grep '"version"' | head -1 | sed 's/.*"version": "\(.*\)".*/\1/')
47
+ echo "Versão atual: $CURRENT_VERSION"
48
+
49
+ # Calcular nova versão
50
+ IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"
51
+
52
+ case $VERSION_TYPE in
53
+ major)
54
+ NEW_MAJOR=$((MAJOR + 1))
55
+ NEW_VERSION="$NEW_MAJOR.0.0"
56
+ ;;
57
+ minor)
58
+ NEW_MINOR=$((MINOR + 1))
59
+ NEW_VERSION="$MAJOR.$NEW_MINOR.0"
60
+ ;;
61
+ patch)
62
+ NEW_PATCH=$((PATCH + 1))
63
+ NEW_VERSION="$MAJOR.$MINOR.$NEW_PATCH"
64
+ ;;
65
+ *)
66
+ echo -e "${RED}Erro: Tipo de versão inválido. Use: patch, minor ou major${NC}"
67
+ exit 1
68
+ ;;
69
+ esac
70
+
71
+ echo -e "${GREEN}Nova versão: $NEW_VERSION${NC}"
72
+
73
+ # Perguntar confirmação
74
+ read -p "Deseja continuar com o release v$NEW_VERSION? (y/n) " -n 1 -r
75
+ echo
76
+ if [[ ! $REPLY =~ ^[Yy]$ ]]; then
77
+ echo -e "${YELLOW}Release cancelado.${NC}"
78
+ exit 0
79
+ fi
80
+
81
+ # Atualizar versão no package.json
82
+ echo -e "${YELLOW}📝 Atualizando package.json...${NC}"
83
+ bunx json -I -f package.json -e "this.version='$NEW_VERSION'"
84
+
85
+ # Commit da versão
86
+ echo -e "${YELLOW}📦 Criando commit...${NC}"
87
+ git add package.json
88
+ git commit -m "chore(release): v$NEW_VERSION"
89
+
90
+ # Criar tag
91
+ echo -e "${YELLOW}🏷️ Criando tag v$NEW_VERSION...${NC}"
92
+ git tag -a "v$NEW_VERSION" -m "Release v$NEW_VERSION
93
+
94
+ Changes:
95
+ - See CHANGELOG.md or GitHub Releases for details"
96
+
97
+ # Push para o GitHub
98
+ echo -e "${YELLOW}📤 Enviando para o GitHub...${NC}"
99
+ git push origin $CURRENT_BRANCH
100
+ git push origin "v$NEW_VERSION"
101
+
102
+ echo -e "${GREEN}✅ Release v$NEW_VERSION iniciado!${NC}"
103
+ echo ""
104
+ echo -e "${YELLOW}Próximos passos:${NC}"
105
+ echo "1. O GitHub Actions vai rodar os testes"
106
+ echo "2. Se passar, vai publicar automaticamente no npm"
107
+ echo "3. Acompanhe em: https://github.com/babelxdev/bx-cli/actions"
108
+ echo ""
109
+ echo -e "${YELLOW}Instalar a nova versão:${NC}"
110
+ echo " npm install -g @babelx/cli@$NEW_VERSION"