# @amazon-codecatalyst/blueprint-component\.source-repositories 中文文档

规范地址：https://npmcn.com/package/%40amazon-codecatalyst/blueprint-component.source-repositories/

版本：0\.3\.159
npm 元数据更新时间：2026-08-24T15:16:49.177Z
中文译文更新时间：2026-11-06T01:57:30.354Z
软件包许可：Apache-2\.0

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40amazon-codecatalyst/blueprint-component.source-repositories
原文对照：https://npmcn.com/package/%40amazon-codecatalyst/blueprint-component.source-repositories/?lang=original

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：119 kB，35 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- 运行依赖：6 个
- peer 依赖：@amazon-codecatalyst/blueprints\.blueprint \*，projen \*
- 首次发布：2023-09-26T14:38:56.766Z
- 最新版本发布：2026-08-24T15:16:48.906Z
- 近 30 天下载量：6852（2026-10-06 至 2026-11-04，npm 官方下载统计）
- 已发布版本数：159（近 12 个月 4 个）

## 中文简介

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

## 安装

```sh
npm install @amazon-codecatalyst/blueprint-component.source-repositories
```

也可以使用：`pnpm add @amazon-codecatalyst/blueprint-component.source-repositories`、`yarn add @amazon-codecatalyst/blueprint-component.source-repositories`、`bun add @amazon-codecatalyst/blueprint-component.source-repositories`

## README

```
import {...} from '@amazon-codecatalyst/blueprint-component.source-repositories'
```

# 仓库和源代码组件

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

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

仓库有命名限制 [见完整文档](https://docs.aws.amazon.com/codecatalyst/latest/userguide/source.html)。 。 。 .

## 正在添加文件

我们可以将一些文本文件写入仓库 `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 是什么？

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

### 如何安装 @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 和提交记录判断。

