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 以及编码仪
工作流程在根.