Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/native-autolink-codegen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lynx-js/autolink-codegen": minor
---

Add the Native Autolink codegen package.
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ packages/web-platform/** @pupiltong @Sherry-hue
packages/webpack/** @colinaaa @upupming @luhc228
packages/rspeedy/** @colinaaa @upupming @luhc228
packages/i18n/** @luhc228
packages/lynx/autolink-codegen/** @jianliang00
packages/rspeedy/plugin-react/** @upupming
packages/react/** @hzy @HuJean @Yradex
packages/react/transform/** @gaoachao
Expand Down
7 changes: 7 additions & 0 deletions packages/lynx/autolink-codegen/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# @lynx-js/autolink-codegen

## 0.0.0

### Minor Changes

- Initial Native Autolink codegen package.
30 changes: 30 additions & 0 deletions packages/lynx/autolink-codegen/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# @lynx-js/autolink-codegen

Native Autolink code generator for Lynx extensions.

It scans `types/**/*.d.ts` for native module declarations annotated with
`/** @lynxmodule */`, reads `lynx.ext.json`, and generates:

- `generated/<ModuleName>.ts`
- Android `<ModuleName>Spec.java`
- iOS `<ModuleName>Spec.h` and `<ModuleName>Spec.m`

Run it from an extension package:

```bash
npx @lynx-js/autolink-codegen
```

The installed binary name is `lynx-autolink-codegen`, so generated extensions
can use:

```json
{
"scripts": {
"codegen": "lynx-autolink-codegen"
}
}
```

The first version intentionally supports only Native Autolink. Web Autolink and
Web spec generation are outside this package.
41 changes: 41 additions & 0 deletions packages/lynx/autolink-codegen/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "@lynx-js/autolink-codegen",
"version": "0.0.0",
"description": "Native Autolink code generator for Lynx extensions",
"keywords": [
"Lynx",
"Autolink",
"codegen"
],
"repository": {
"type": "git",
"url": "https://github.com/lynx-family/lynx-stack.git",
"directory": "packages/lynx/autolink-codegen"
},
"license": "Apache-2.0",
"sideEffects": false,
"type": "module",
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
},
"bin": {
"lynx-autolink-codegen": "./dist/cli.js"
},
"files": [
"CHANGELOG.md",
"README.md",
"dist"
],
"scripts": {
"build": "rslib build",
"dev": "rslib build --watch",
"test": "vitest run"
},
"packageManager": "pnpm@11.0.8+sha512.4c4097e1dd2d42372c4e7fa5a791ff28fc75a484c7ac192e64b1df0fdef17594ba982f9b4fed9adfb3c757846f565b799b2763fb3733d1de1bcb82cf46684912",
"engines": {
"node": "^20 || ^22 || ^24"
}
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
20 changes: 20 additions & 0 deletions packages/lynx/autolink-codegen/rslib.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2026 The Lynx Authors. All rights reserved.
// Licensed under the Apache License Version 2.0 that can be found in the
// LICENSE file in the root directory of this source tree.
import type { RslibConfig } from '@rslib/core';
import { defineConfig } from '@rslib/core';

const config: RslibConfig = defineConfig({
lib: [
{ format: 'esm', syntax: 'es2022', dts: { bundle: true, tsgo: true } },
],
source: {
entry: {
index: './src/index.ts',
cli: './src/cli.ts',
},
tsconfigPath: './tsconfig.build.json',
},
});

export default config;
90 changes: 90 additions & 0 deletions packages/lynx/autolink-codegen/src/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/usr/bin/env node
// Copyright 2026 The Lynx Authors. All rights reserved.
// Licensed under the Apache License Version 2.0 that can be found in the
// LICENSE file in the root directory of this source tree.
import path from 'node:path';

import type { CodegenOptions } from './index.js';
import { runCodegen } from './index.js';

interface CliOptions {
root?: string;
help: boolean;
}

/**
* Parses command-line arguments for the autolink codegen CLI.
*/
function parseArgs(argv: string[]): CliOptions {
const options: CliOptions = { help: false };

for (let index = 0; index < argv.length; index += 1) {
const arg = argv[index];

if (arg === '--help' || arg === '-h') {
options.help = true;
continue;
}

if (arg === '--root' || arg === '-r') {
const value = argv[index + 1];

if (value === undefined || value.startsWith('-')) {
throw new Error(`${arg} requires a value`);
}

options.root = value;
index += 1;
continue;
}

throw new Error(`Unknown option "${arg ?? ''}"`);
}

return options;
}

/**
* Prints usage information for the autolink codegen CLI.
*/
function printHelp(): void {
console.info(`Usage: lynx-autolink-codegen [--root <dir>]

Generate Native Autolink JS, Android, and iOS specs from types/**/*.d.ts.

Options:
--root, -r <dir> Extension package root. Defaults to the current directory.
--help, -h Show this help message.
`);
}

/**
* Runs code generation from parsed CLI options.
*/
function main(): void {
const cliOptions = parseArgs(process.argv.slice(2));

if (cliOptions.help) {
printHelp();
return;
}

const options: CodegenOptions = {};

if (cliOptions.root !== undefined) {
options.root = path.resolve(cliOptions.root);
}

const files = runCodegen(options);

for (const file of files) {
console.info(`generated ${file.path}`);
}
}

try {
main();
} catch (error: unknown) {
console.error(error instanceof Error ? error.message : String(error));
process.exitCode = 1;
}
Loading
Loading