@amazon-codecatalyst/blueprint-component.source-repositories

中文文档
0.3.159发布于 2026/08/24Apache-2.0TypeScriptCommonJS近 30 天下载 6852

这是代码解析源寄存器的表示.

中文使用文档
文档目录6 节
  1. 正在添加文件
  2. 添加通用文件
  3. 复制文件
  4. 瞄准多个文件
  5. 例1:建立一个新的存储库
  6. 例2:将文件和/或工作流程添加到现有的存储库中
import {...} from '@amazon-codecatalyst/blueprint-component.source-repositories'

仓库和源代码组件

一个寄存器被编码解码器用来存储一些代码. 它需要一个名字作为输入. 大多数组件被存储在一个寄存器中, 如源代码 文件、工作流程以及诸如MDE工作空间等其他组件。 源存储器组件还导出用于管理文件的组件 和静态资产.

const repository = new SourceRepository(this, {
  title: 'my-new-repository-title',
});

仓库有命名限制 见完整文档。 。 。 .

正在添加文件

我们可以将一些文本文件写入仓库 SourceFile 构造。 这种操作是最常见的使用案例之一,需要 仓库、 文件路径和一些文本内容。 如果一个寄存器内不存在文件路径, 此组件将创建所有所需的文件夹 还有!

new SourceFile(repository, `path/to/my/file/in/repo/file.txt`, 'my file contents');

注:所有文件构造都是上-写-胜. 如果您在同一仓库内将两个文件写入同一位置, 则最后一个执行会 覆盖那里的一切。 您可以使用此特性来“ layer” 生成的代码, 并且在代码蓝图上扩展时特别有用 也许已经产生了.

添加通用文件

有时我们想将任意的位点写入我们的寄存器. 我们可以从缓冲器读取并使用 File 构造.

new File(repository, `path/to/my/file/in/repo/file.img`, new Buffer(...));

new File(repository, `path/to/my/file/in/repo/new-img.img`, new StaticAsset('path/to/image.png').content());

复制文件

用一些生成的代码开始最简单的方式是复制-复制一些起动码,然后在该底片上再生成更多的代码. 为了这个 我们可以把密码放进去 static-assets 目录,然后用 StaticAsset 构造。 这个案子的路径 总是从根开始 static-assets 目录.

const starterCode = new StaticAsset('path/to/file/file.txt')
const starterCodeText = new StaticAsset('path/to/file/file.txt').toString()
const starterCodeRawContent = new StaticAsset('path/to/image/hello.png').content()

const starterCodePath = new StaticAsset('path/to/image/hello.png').path()
// starterCodePath is equal to 'path/to/image/hello.png'

子类 StaticAsset 实值 SubstitionAsset。此功能完全相同,但允许我们在文件上运行一个胡子子符号 换句话说.

const starterCodeText = new SubstitionAsset('path/to/file/file.txt').subsitite({
  'my_variable': 'subbed value1',
  'another_variable': 'subbed value2'
})

这对复制和替换样式的生成非常有用。 注:在无法解释文本的文件上运行子进程通常 将产生错误.

瞄准多个文件

静态资产支持通过静态函数锁定目标 StaticAsset 及其子类 findAll(...),这将返回一个列表 静态资产预先装入他们的路径,内容,以及更多的. 我们可以用这个锁上 File 用于复制- 粘贴在 static-assets 目录.

StaticAsset.findAll().forEach(item => {
  new File(repository, item.path(), item.content());
});

或者我们可以瞄准 .md 特定文件夹下的文件及其子文件夹 static-assets 并替换每个文件中相同的变量.

SubstitionAsset.findAll('my-folder/**/*.md').forEach(item => {
  new SourceFile(repository, item.path(), item.subsitite({
    'my_variable': 'subbed value1',
    'another_variable': 'subbed value2'
  }));
});

例1:建立一个新的存储库

存储器组件用于在生成的项目中创建一个新存储器:

import { SourceRepository } from '@amazon-codecatalyst/blueprint-component.source-repositories';
...
const repository = new SourceRepository(this, { title: 'myRepo' });

然后可以向创建的仓库添加文件或工作流程 :

例2:将文件和/或工作流程添加到现有的存储库中

import { SourceFile } from '@amazon-codecatalyst/blueprint-component.source-repositories';
import { Workflow } from '@amazon-codecatalyst/blueprint-component.workflows';
...
new SourceFile(repository, 'README.md', 'This is the content of my readme');
new Workflow(this, repository, {/**...workflowDefinition...**/});

将上述两个代码合并后,将产生一个名为 myRepo 带有源文件 README.md 以及编码仪 工作流程在根.

版本与发布记录

@amazon-codecatalyst/blueprint-component.source-repositories 共发布 159 个版本,首次发布于 2023/09/26;过去 12 个月发布了 4 个版本。

版本发布日期距今
0.3.159latest2026/08/242 个月前
0.3.1582026/08/222 个月前
0.3.1572026/08/152 个月前
0.3.1562026/07/074 个月前
0.3.1552025/01/081.8 年前
0.3.1542024/10/022 年前

关于 @amazon-codecatalyst/blueprint-component.source-repositories 的常见问题

@amazon-codecatalyst/blueprint-component.source-repositories 是什么?

这是代码解析源寄存器的表示.

如何安装 @amazon-codecatalyst/blueprint-component.source-repositories?

在项目目录运行 npm install @amazon-codecatalyst/blueprint-component.source-repositories,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@amazon-codecatalyst/blueprints.blueprint(*)、projen(*)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@amazon-codecatalyst/blueprint-component.source-repositories 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@amazon-codecatalyst/blueprint-component.source-repositories 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@amazon-codecatalyst/blueprint-component.source-repositories 可以商用吗?

@amazon-codecatalyst/blueprint-component.source-repositories 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@amazon-codecatalyst/blueprint-component.source-repositories 的下载量有多少?

根据 npm 官方下载统计,@amazon-codecatalyst/blueprint-component.source-repositories 在 2026/10/06 – 2026/11/04 这 30 天内被下载 6,852 次,日均约 228 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@amazon-codecatalyst/blueprint-component.source-repositories 还在维护吗?

最新版本 0.3.159 发布于 2026/08/24(2 个月前);至今共发布 159 个版本,其中过去 12 个月发布了 4 个;首次发布于 2023/09/26。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。