Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ node_modules/

# Build output
dist/
dist-compiler/
build/
*.tsbuildinfo
.tsup/
.compiler-pack-staging/
*.tgz

# Test / coverage
coverage/
Expand Down
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,42 @@ import {
with a skeleton, channel list, and optional post-processor.
6. **Backend-agnostic semantics** — the same semantic reasoning targets
Vega-Lite, ECharts, and Chart.js through separate assembly functions.

## Using as a standalone compiler package

The Vega-Lite compilation pipeline (`assembleVegaLite` + core semantics) can be
packaged independently as `@microsoft/flint-chart-compiler` for use in peer
projects that only need spec generation without the full library.

### Build the tarball

```bash
npm run pack:compiler
# → produces microsoft-flint-chart-compiler-0.1.0.tgz
```

### Install in a sister repository

```bash
pnpm add ../flint-chart/microsoft-flint-chart-compiler-0.1.0.tgz
```

### Import

```ts
import { assembleVegaLite } from '@microsoft/flint-chart-compiler';
import type { ChartAssemblyInput } from '@microsoft/flint-chart-compiler/core';

const spec = assembleVegaLite(input);
```

The package exposes three subpath exports:

| Import path | Contents |
|-------------|----------|
| `@microsoft/flint-chart-compiler` | All core + Vega-Lite exports |
| `@microsoft/flint-chart-compiler/core` | Types, semantic types, layout, decisions |
| `@microsoft/flint-chart-compiler/vegalite` | `assembleVegaLite`, templates, instantiation |

Additional backends (`assembleECharts`, `assembleChartjs`) can be added to this
package in the future without breaking existing consumers.
58 changes: 58 additions & 0 deletions compiler.package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"name": "@microsoft/flint-chart-compiler",
"version": "0.1.0",
"description": "Compiles Flint chart specifications into Vega-Lite specs. Core compilation engine extracted from flint-chart.",
"keywords": [
"flint",
"visualization",
"charts",
"vega-lite",
"compiler",
"semantic-types"
],
"license": "MIT",
"author": "Microsoft Corporation",
"homepage": "https://github.com/microsoft/flint-chart#readme",
"repository": {
"type": "git",
"url": "https://github.com/microsoft/flint-chart.git"
},
"type": "module",
"sideEffects": false,
"main": "./dist-compiler/index.cjs",
"module": "./dist-compiler/index.js",
"types": "./dist-compiler/index.d.ts",
"exports": {
".": {
"types": "./dist-compiler/index.d.ts",
"import": "./dist-compiler/index.js",
"require": "./dist-compiler/index.cjs"
},
"./core": {
"types": "./dist-compiler/core/index.d.ts",
"import": "./dist-compiler/core/index.js",
"require": "./dist-compiler/core/index.cjs"
},
"./vegalite": {
"types": "./dist-compiler/vegalite/index.d.ts",
"import": "./dist-compiler/vegalite/index.js",
"require": "./dist-compiler/vegalite/index.cjs"
}
},
"files": [
"dist-compiler",
"README.md",
"LICENSE"
],
"peerDependencies": {
"vega-lite": "^5.0.0 || ^6.0.0"
},
"peerDependenciesMeta": {
"vega-lite": {
"optional": true
}
},
"engines": {
"node": ">=18"
}
}
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@
"release": "npm publish --access public",
"site": "npm --prefix site run dev",
"site:build": "npm --prefix site run build",
"mcp:build": "npm --prefix agents/mcp-server run build"
"mcp:build": "npm --prefix agents/mcp-server run build",
"pack:compiler": "node scripts/pack-compiler.mjs"
},
"peerDependencies": {
"chart.js": "^4.0.0",
Expand Down
72 changes: 72 additions & 0 deletions scripts/pack-compiler.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* scripts/pack-compiler.mjs
*
* Builds and packs the @microsoft/flint-chart-compiler package as a .tgz.
*
* Usage: node scripts/pack-compiler.mjs
*
* Steps:
* 1. Run tsup with the compiler config to produce dist-compiler/
* 2. Create a staging directory with dist-compiler/, package.json, README, LICENSE
* 3. Run `pnpm pack` in the staging directory
* 4. Move the .tgz to the repo root
* 5. Clean up staging directory
*/

import { execSync } from 'node:child_process';
import { cpSync, mkdirSync, rmSync, readdirSync, renameSync, existsSync } from 'node:fs';
import { resolve, join } from 'node:path';

const ROOT = resolve(import.meta.dirname, '..');
const STAGING = join(ROOT, '.compiler-pack-staging');
const DIST_COMPILER = join(ROOT, 'dist-compiler');
const TSUP_BIN = join(ROOT, 'node_modules', '.bin', 'tsup');

function run(cmd, opts = {}) {
console.log(`> ${cmd}`);
execSync(cmd, { stdio: 'inherit', cwd: ROOT, shell: true, ...opts });
}

// Step 1: Build compiler output
console.log('\n📦 Building @microsoft/flint-chart-compiler...\n');
run(`"${TSUP_BIN}" --config tsup.config.compiler.ts`);

// Step 2: Create staging directory
console.log('\n📁 Staging package...\n');
if (existsSync(STAGING)) {
rmSync(STAGING, { recursive: true });
}
mkdirSync(STAGING, { recursive: true });

// Copy dist-compiler/ into staging as dist-compiler/
cpSync(DIST_COMPILER, join(STAGING, 'dist-compiler'), { recursive: true });

// Copy package.json, README, LICENSE
cpSync(join(ROOT, 'compiler.package.json'), join(STAGING, 'package.json'));
cpSync(join(ROOT, 'README.md'), join(STAGING, 'README.md'));
cpSync(join(ROOT, 'LICENSE'), join(STAGING, 'LICENSE'));

// Step 3: Pack
console.log('\n🎁 Running pnpm pack...\n');
run('pnpm pack', { cwd: STAGING });

// Step 4: Move .tgz to root
const tgzFiles = readdirSync(STAGING).filter(f => f.endsWith('.tgz'));
if (tgzFiles.length === 0) {
console.error('❌ No .tgz file produced!');
process.exit(1);
}

const tgzName = tgzFiles[0];
const dest = join(ROOT, tgzName);
if (existsSync(dest)) {
rmSync(dest);
}
renameSync(join(STAGING, tgzName), dest);

// Step 5: Clean up
rmSync(STAGING, { recursive: true });

console.log(`\n✅ Package ready: ${tgzName}`);
console.log(`\n Install in sister repo with:`);
console.log(` pnpm add ../flint-chart/${tgzName}\n`);
15 changes: 15 additions & 0 deletions src/compiler-index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

/**
* @module @microsoft/flint-chart-compiler
*
* Compiles a Flint specification into a chart library spec.
* Currently supports Vega-Lite; ECharts and Chart.js to be added later.
*/

// Core: types, semantic types, decisions, layout, overflow
export * from './core';

// Vega-Lite backend: assembleVegaLite, templates, spec instantiation
export * from './vegalite';
18 changes: 18 additions & 0 deletions tsup.config.compiler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { defineConfig } from 'tsup';

export default defineConfig({
entry: {
index: 'src/compiler-index.ts',
'core/index': 'src/core/index.ts',
'vegalite/index': 'src/vegalite/index.ts',
},
outDir: 'dist-compiler',
format: ['esm', 'cjs'],
dts: true,
sourcemap: true,
clean: true,
splitting: false,
treeshake: true,
target: 'es2020',
external: ['vega', 'vega-lite'],
});
Loading