@zhxiaogg/fluorite-cli 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 ADDED
@@ -0,0 +1,74 @@
1
+ # @zhxiaogg/fluorite-cli
2
+
3
+ Code generator from YAML schema definitions - generates Rust and TypeScript code.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install -D @zhxiaogg/fluorite-cli
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Generate TypeScript
14
+
15
+ ```bash
16
+ npx fluorite ts --inputs ./schemas/*.yaml --output ./src/generated
17
+ ```
18
+
19
+ ### Generate Rust
20
+
21
+ ```bash
22
+ npx fluorite rust --inputs ./schemas/*.yaml --output ./src/generated
23
+ ```
24
+
25
+ ## Options
26
+
27
+ ### TypeScript (`ts`)
28
+
29
+ | Option | Default | Description |
30
+ |--------|---------|-------------|
31
+ | `--inputs` | required | Input YAML files |
32
+ | `--output` | required | Output directory |
33
+ | `--single-file` | false | Generate all types in a single file |
34
+ | `--any-type` | unknown | Type to use for Any fields |
35
+ | `--readonly` | false | Generate readonly properties |
36
+
37
+ ### Rust (`rust`)
38
+
39
+ | Option | Default | Description |
40
+ |--------|---------|-------------|
41
+ | `--inputs` | required | Input YAML files |
42
+ | `--output` | required | Output directory |
43
+ | `--single-file` | true | Generate all types in a single file |
44
+ | `--any-type` | fluorite::Any | Type to use for Any fields |
45
+ | `--derives` | | Custom derives (comma-separated) |
46
+ | `--extra-derives` | | Additional derives |
47
+ | `--generate-new` | true | Generate derive_new |
48
+ | `--visibility` | public | Type visibility |
49
+
50
+ ## Example package.json
51
+
52
+ ```json
53
+ {
54
+ "scripts": {
55
+ "generate": "fluorite ts --inputs ./schemas/*.yaml --output ./src/generated",
56
+ "build": "npm run generate && tsc"
57
+ },
58
+ "devDependencies": {
59
+ "@zhxiaogg/fluorite-cli": "^0.1.0"
60
+ }
61
+ }
62
+ ```
63
+
64
+ ## Building from Source
65
+
66
+ If pre-built binaries are not available for your platform:
67
+
68
+ ```bash
69
+ git clone https://github.com/zhxiaogg/fluorite.git
70
+ cd fluorite
71
+ cargo build --release --package fluorite_codegen
72
+ ```
73
+
74
+ The binary will be at `target/release/fluorite`.
package/bin/fluorite ADDED
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+ echo "Error: Pre-built binaries not yet available."
3
+ echo "Please build from source: cargo build --release --package fluorite_codegen"
4
+ exit 1
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/env node
2
+ // bin/fluorite.js - Wrapper that invokes the Rust binary
3
+
4
+ const { spawn } = require('child_process');
5
+ const path = require('path');
6
+ const fs = require('fs');
7
+
8
+ // Platform-specific package mapping
9
+ const PLATFORM_PACKAGES = {
10
+ 'darwin-x64': '@zhxiaogg/fluorite-darwin-x64',
11
+ 'darwin-arm64': '@zhxiaogg/fluorite-darwin-arm64',
12
+ 'linux-x64': '@zhxiaogg/fluorite-linux-x64',
13
+ 'linux-arm64': '@zhxiaogg/fluorite-linux-arm64',
14
+ 'win32-x64': '@zhxiaogg/fluorite-win32-x64',
15
+ };
16
+
17
+ function getBinaryPath() {
18
+ const ext = process.platform === 'win32' ? '.exe' : '';
19
+ const platformKey = `${process.platform}-${process.arch}`;
20
+
21
+ // Try platform-specific package first
22
+ const packageName = PLATFORM_PACKAGES[platformKey];
23
+ if (packageName) {
24
+ try {
25
+ const packagePath = require.resolve(`${packageName}/package.json`);
26
+ const packageDir = path.dirname(packagePath);
27
+ const binaryPath = path.join(packageDir, 'bin', `fluorite${ext}`);
28
+ if (fs.existsSync(binaryPath)) {
29
+ return binaryPath;
30
+ }
31
+ } catch (e) {
32
+ // Package not installed, fall through to local binary
33
+ }
34
+ }
35
+
36
+ // Fallback to local binary (for development or manual installation)
37
+ const localBinaryPath = path.join(__dirname, `fluorite${ext}`);
38
+ if (fs.existsSync(localBinaryPath)) {
39
+ return localBinaryPath;
40
+ }
41
+
42
+ return null;
43
+ }
44
+
45
+ const binaryPath = getBinaryPath();
46
+
47
+ if (!binaryPath) {
48
+ const platformKey = `${process.platform}-${process.arch}`;
49
+ console.error('Error: fluorite binary not found.');
50
+ console.error('');
51
+ console.error(`Platform: ${platformKey}`);
52
+ console.error('');
53
+ if (PLATFORM_PACKAGES[platformKey]) {
54
+ console.error('Try reinstalling the package:');
55
+ console.error(' npm uninstall @zhxiaogg/fluorite-cli');
56
+ console.error(' npm install @zhxiaogg/fluorite-cli');
57
+ } else {
58
+ console.error(`Your platform (${platformKey}) is not supported.`);
59
+ console.error('');
60
+ console.error('You can build from source instead:');
61
+ console.error(' cargo install fluorite_codegen');
62
+ }
63
+ process.exit(1);
64
+ }
65
+
66
+ const child = spawn(binaryPath, process.argv.slice(2), {
67
+ stdio: 'inherit'
68
+ });
69
+
70
+ child.on('error', (err) => {
71
+ console.error('Failed to execute fluorite:', err.message);
72
+ process.exit(1);
73
+ });
74
+
75
+ child.on('exit', (code) => {
76
+ process.exit(code ?? 0);
77
+ });
package/install.js ADDED
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env node
2
+ // install.js - Post-install script for @zhxiaogg/fluorite-cli
3
+ // Binary is provided via optionalDependencies (platform-specific packages)
4
+
5
+ const fs = require('fs');
6
+ const path = require('path');
7
+
8
+ const PLATFORM_PACKAGES = {
9
+ 'darwin-x64': '@zhxiaogg/fluorite-darwin-x64',
10
+ 'darwin-arm64': '@zhxiaogg/fluorite-darwin-arm64',
11
+ 'linux-x64': '@zhxiaogg/fluorite-linux-x64',
12
+ 'linux-arm64': '@zhxiaogg/fluorite-linux-arm64',
13
+ 'win32-x64': '@zhxiaogg/fluorite-win32-x64',
14
+ };
15
+
16
+ function checkBinaryInstalled() {
17
+ const platformKey = `${process.platform}-${process.arch}`;
18
+ const packageName = PLATFORM_PACKAGES[platformKey];
19
+
20
+ if (!packageName) {
21
+ console.warn(`Warning: No pre-built binary available for ${platformKey}`);
22
+ console.warn('You can build from source: cargo install fluorite_codegen');
23
+ return;
24
+ }
25
+
26
+ try {
27
+ const ext = process.platform === 'win32' ? '.exe' : '';
28
+ const packagePath = require.resolve(`${packageName}/package.json`);
29
+ const packageDir = path.dirname(packagePath);
30
+ const binaryPath = path.join(packageDir, 'bin', `fluorite${ext}`);
31
+
32
+ if (fs.existsSync(binaryPath)) {
33
+ console.log(`fluorite binary installed successfully for ${platformKey}`);
34
+ } else {
35
+ console.warn(`Warning: Binary not found in ${packageName}`);
36
+ console.warn('Try reinstalling: npm uninstall @zhxiaogg/fluorite-cli && npm install @zhxiaogg/fluorite-cli');
37
+ }
38
+ } catch (e) {
39
+ // Platform package not installed - this can happen if npm skipped the optional dependency
40
+ console.warn(`Warning: Platform package ${packageName} not installed`);
41
+ console.warn('This may happen if npm skipped the optional dependency.');
42
+ console.warn('');
43
+ console.warn('Alternative installation methods:');
44
+ console.warn(' 1. cargo install fluorite_codegen');
45
+ console.warn(' 2. Download binary from https://github.com/zhxiaogg/fluorite/releases');
46
+ }
47
+ }
48
+
49
+ checkBinaryInstalled();
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@zhxiaogg/fluorite-cli",
3
+ "version": "0.2.0",
4
+ "description": "Code generator from YAML/Fluorite schema definitions - generates Rust and TypeScript",
5
+ "bin": {
6
+ "fluorite": "./bin/fluorite.js"
7
+ },
8
+ "scripts": {
9
+ "postinstall": "node install.js"
10
+ },
11
+ "keywords": [
12
+ "codegen",
13
+ "typescript",
14
+ "rust",
15
+ "schema",
16
+ "yaml",
17
+ "idl"
18
+ ],
19
+ "author": "zhxiaogg",
20
+ "license": "MIT",
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "https://github.com/zhxiaogg/fluorite.git"
24
+ },
25
+ "engines": {
26
+ "node": ">=16.0.0"
27
+ },
28
+ "optionalDependencies": {
29
+ "@zhxiaogg/fluorite-darwin-x64": "0.2.0",
30
+ "@zhxiaogg/fluorite-darwin-arm64": "0.2.0",
31
+ "@zhxiaogg/fluorite-linux-x64": "0.2.0",
32
+ "@zhxiaogg/fluorite-linux-arm64": "0.2.0",
33
+ "@zhxiaogg/fluorite-win32-x64": "0.2.0"
34
+ }
35
+ }