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

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

This is a representation of a codecatalyst source repository.

原始使用文档
文档目录6 节
  1. Adding a file
  2. Adding a generic file
  3. Copying files
  4. Targetting multiple files
  5. Example 1: Creating a new repository
  6. Example 2: Adding file(s) and/or workflow(s) to an existing…
import {...} from '@amazon-codecatalyst/blueprint-component.source-repositories'

Repository & Source Code Component

A repository is used by codecatalyst to store some code. It takes a name as input. Most components are stored in a repository, such as source code files, workflows, as well as other components such as MDE workspaces. The source-repository component also exports components used for managing files and static assets.

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

Repositories have naming constraints see full documentation.

Adding a file

We can write some text file to a repository with the SourceFile construct. This operation is one of the most common use cases and takes a repository, a filepath, and some text contents. If the file path doesn't exist within a repository, this component will create all the needed folders too!

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

Note: all the file constructs are last-write-wins. If you write two files to the same location within the same repository, the last execution will overwrite whatever is there. You can use this feature to "layer" generated code, and its especially useful when extending over the code blueprints may have generated.

Adding a generic file

Sometimes we want to write arbitrary bits to our repository. We can read from a buffer and use the File construct.

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());

Copying files

The easiest way to get started with some generated code is to copy-paste some starter code and then generate more code on top of that base. For this we can place our code inside the static-assets directory and then target that code with the StaticAsset construct. The pathing in this case will always start at the root of the static-assets directory.

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'

A subclass of StaticAsset is SubstitionAsset. This functions exactly the same way but allows us to run a mustache subsitition over the file instead.

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

This can be really useful for doing copy-and-replace style generation. Note: running subsitite over files that aren't text interpretable is usually going to produce errors.

Targetting multiple files

Static Assets support glob targetting through a static function on StaticAsset and its subclasses called findAll(...), this will return a list of static assets preloaded with their paths, contents, and more. We can chain this with File constructions to copy-paste everything in the static-assets directory.

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

or we can target just .md files under a specific folder and its subfolders in static-assets and substitute the same variables in each file.

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

Example 1: Creating a new repository

Repository component is used to create a new repository in a generated project:

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

You can then add files or workflows to the created repository:

Example 2: Adding file(s) and/or workflow(s) to an existing repository

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...**/});

Combining the above two pieces of code would generate a single repository named myRepo with a source file README.md as well as a codecatalyst workflow at the root.

版本与发布记录

@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 是什么?

This is a representation of a codecatalyst source repository.

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