MIT License

技术解读

以下内容由 GitRead 中文社区 编辑团队基于项目 README 与官方资料整理, 结合中文开发者的常见使用场景补充技术选型建议。具体以项目官方文档为准。

深度技术分析:docsforadobe/Types-for-Adobe 项目

项目背景与痛点

Adobe 的应用程序广泛应用于多媒体创作领域,但其脚本接口文档较为分散,且 TypeScript 类型定义的缺乏导致开发者在编程时的类型安全和代码补全体验不佳。例如,开发者在编辑 Photoshop 脚本时,很难保证类型的一致性和准确性,从而增加了开发和调试的工作负担。Types-for-Adobe 这个项目通过提供完善的 TypeScript 类型定义,解决了脚本兼容性和类型安全性的痛点,提高了开发者的工作效率。

核心技术揭秘

技术架构

Types-for-Adobe 项目的核心是为 Adobe 提供一系列强大且可靠的 TypeScript 类型定义接口,支持的软件包括 AfterEffects、Animate、Audition、Illustrator、InDesign、Photoshop 和 Premiere。项目利用了 TypeScript 的模块化和类型系统,通过定义清晰、完善的类型接口来确保代码的可靠性。

架构图
graph TD A[用户编辑脚本] --> B{"编译器类型检查"} B -->|"通过"| C[执行脚本] B -->|"失败"| D[抛出类型错误] C --> E[完成脚本] D --> F[修复代码]

实现原理

Types-for-Adobe 通过解析 Adobe 应用程序的 JavaScript 脚本接口文档,自动生成相应的 TypeScript 类型定义。项目使用了 @types 的形式,通过 d.ts 文件来提供类型定义接口。其主要技术栈包括 TypeScript 自身以及一些代码生成工具,以便于自动化处理类型生成过程。

  • TypeScript:负责开发类型定义文件,通过模块导出各种 Adobe 脚本的类型。
  • TypeScript 模块系统:运用模块化来分离各个脚本类型,确保每个类型的定义独立而完整。
  • 代码生成器:用于从 Adobe 应用程序的脚本接口文档中提取信息,并生成相应的 .d.ts 文件。

代码流

graph TD A[用户输入脚本] --> B[TypeScript 编译过程] B --> C[类型定义匹配] C -->|"匹配成功"| D[确定类型正确性] D --> E[执行脚本] C -->|"匹配失败"| F[报告类型错误] F --> G[类型修正] G --> D

功能亮点与差异

不同于其他只提供基础类型定义的项目,Types-for-Adobe 拥有更全面的类型覆盖,且结合了多个 Adobe 产品的接口,包含所有主要功能模块。项目还提供了丰富的类型注释和文档,确保开发者能够快速上手并且高效使用其所提供的类型定义。此外,项目基于社区的贡献原则,鼓励开发者参与类型定义的维护和更新,保证类型定义的准确性和及时性。

应用场景与落地建议

在生产环境中使用 Types-for-Adobe,开发者需注意以下几点:

  • 保持与最新版本的同步:Adobe 定期更新其应用程序,因此对应的类型定义也需要及时更新。
  • 权限管理:脚本接口访问通常需要特定的权限设置。
  • 性能监控:在大型项目中,脚本执行的性能和资源使用情况需要特别监控。

适合的应用场景包括多媒体创作脚本的开发、复杂脚本逻辑的设计以及需要高度类型的脚本自动化任务。

综合评价

优点:

  • 全面覆盖:提供了 Adobe 各大软件脚本的全面类型定义。
  • 类型完善:精心设计的类型接口可提升代码质量和类型检查能力。
  • 社区驱动:鼓励社区参与和支持,保证类型的准确性和持续性。

缺点:

  • 依赖关系复杂:需要保持与多个 Adobe 应用程序的版本兼容。
  • 更新频率高:Adobe 各产品的更新频率快,需要项目持续维护。

Types-for-Adobe 提供了丰富的类型定义,改进了在使用 Adobe 软件进行开发时的体验,省时省力,极大提升了开发者的生产力。

关于

GitHub 原始描述(英文)

TypeScript types for Adobe: AfterEffects, Animate, Audition, Illustrator, InDesign, Photoshop, Premiere, ScriptUI.

描述取自 GitHub 官方 API,保持仓库作者书写的原文。

简要分析

热度分
933
价值分
429
活跃状态
活跃

语言占比

Shell

README

TypeScript types for Adobe Products

Repository for typedef files for various Adobe Creative Cloud products.

gif


Prerequisites


Your first script for eg. Adobe Illustrator

# create new folder
mkdir my-script
cd my-script

# install types-for-adobe
npm init -y
npm i types-for-adobe

# create tsconfig.json
printf '{"compilerOptions":{"module":"none","noLib":true}}' > tsconfig.json

# create index.ts and change reference types to Adobe product you're targeting
printf '/// <reference types="types-for-adobe/Illustrator/2015.3"/>\nalert(String(app));\n' > index.ts

# compile typescript files
tsc

# open Adobe Illustrator -> File -> Scripts -> Other Script -> and open index.js

FAQ

Where do these typedefs come from?

Everything in this project was generated through one of the following methods:

  1. Using this extendscript-xml-to-typescript converter tool to convert scripting dictionaries to typedef format
    • note that this only works for a few select apps, and has been found to generate incorrect data in some cases
  2. By hand, through referencing Adobe’s official release announcements & developer exploration through the API.

Why are there different versions of docs per version of each host app?

This repo aims to maintain a history of typedefs for each given version of each hostapp.

This way, if you’re developing a tool aimed at, say, Adobe After Effects v18.0, you can have your tool specifically use those typedefs, and know that you’re not using features that were introduced in a later version.

Why does this matter?

For public, commercial tools: with some hostapps, it’s generally accepted that the app’s user base will be spread out among multiple versions of the software. Targeting a slightly older version ensures wider adoption than focusing solely on the latest version.

For internal, proprietary tools: some companies mandate that all artists use a specific (older) version; having separate definitions for that version allows for this specific targeting.

Which should I use?

This really depends on your needs; if you’re hoping to release a commercial tool and assume that all users are using a specific version or newer, use that! If you need to leverage a feature added at a specific point, use those typedefs instead & let your users know this is the minimum supported version.

Why are some release versions missing?

Two possible answers! Either

  1. There haven’t been any API changes for that given version, or
  2. Nobody’s taken the time to add typedefs for that version; feel free to open a PR!

Contributors

Thanks to all of our contributors for helping make this project succeed!

Have something to add? Please open a PR!


Publish New Versions

To publish a new version of this project on npm for use in projects, please follow the steps below:

1. Auth and Access

  • Ensure you are logged in to your npmjs.com account with npm login and follow the prompts to complete your login
  • Ensure your npmjs.com account has access to publish to the npm package, if not, reach out to an admin for access

2. Version and Publish

  • Version up the package.json
  • Run npm publish
  • Push the commit with the new version to GitHub

More typings

评论

暂无评论