0.3.154 • Published 3 months ago

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

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
3 months ago
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.

0.3.154

3 months ago

0.3.153

3 months ago

0.3.152

3 months ago

0.3.151

4 months ago

0.3.150

5 months ago

0.3.141

6 months ago

0.3.140

6 months ago

0.3.143

6 months ago

0.3.142

6 months ago

0.3.145

6 months ago

0.3.144

6 months ago

0.3.147

6 months ago

0.3.146

6 months ago

0.3.149

5 months ago

0.3.148

5 months ago

0.3.130

7 months ago

0.3.132

7 months ago

0.3.131

7 months ago

0.3.134

7 months ago

0.3.133

7 months ago

0.3.136

6 months ago

0.3.135

7 months ago

0.3.138

6 months ago

0.3.137

6 months ago

0.3.139

6 months ago

0.3.121

7 months ago

0.3.120

7 months ago

0.3.123

7 months ago

0.3.122

7 months ago

0.3.125

7 months ago

0.3.124

7 months ago

0.3.127

7 months ago

0.3.126

7 months ago

0.3.129

7 months ago

0.3.128

7 months ago

0.3.119

7 months ago

0.3.118

7 months ago

0.3.117

7 months ago

0.3.116

7 months ago

0.3.115

7 months ago

0.3.114

8 months ago

0.3.112

8 months ago

0.3.113

8 months ago

0.3.111

8 months ago

0.3.110

8 months ago

0.3.109

8 months ago

0.3.108

8 months ago

0.3.107

8 months ago

0.3.105

8 months ago

0.3.106

8 months ago

0.3.103

8 months ago

0.3.104

8 months ago

0.3.101

8 months ago

0.3.102

8 months ago

0.3.100

8 months ago

0.3.99

8 months ago

0.3.98

8 months ago

0.3.97

8 months ago

0.3.96

9 months ago

0.3.95

9 months ago

0.3.94

9 months ago

0.3.93

9 months ago

0.3.92

9 months ago

0.3.91

9 months ago

0.3.90

9 months ago

0.3.89

9 months ago

0.3.88

9 months ago

0.3.87

9 months ago

0.3.86

9 months ago

0.3.85

9 months ago

0.3.84

9 months ago

0.3.82

9 months ago

0.3.81

9 months ago

0.3.79

9 months ago

0.3.80

9 months ago

0.3.78

9 months ago

0.3.77

9 months ago

0.3.76

9 months ago

0.3.75

9 months ago

0.3.74

9 months ago

0.3.73

9 months ago

0.3.72

9 months ago

0.3.71

10 months ago

0.3.70

10 months ago

0.3.69

10 months ago

0.3.68

10 months ago

0.3.67

10 months ago

0.3.66

10 months ago

0.3.65

10 months ago

0.3.64

10 months ago

0.3.63

10 months ago

0.3.62

10 months ago

0.3.61

10 months ago

0.3.60

11 months ago

0.3.59

11 months ago

0.3.58

11 months ago

0.3.57

11 months ago

0.3.53

11 months ago

0.3.52

11 months ago

0.3.55

11 months ago

0.3.54

11 months ago

0.3.51

11 months ago

0.3.50

11 months ago

0.3.49

11 months ago

0.3.48

11 months ago

0.3.47

11 months ago

0.3.46

11 months ago

0.3.42

12 months ago

0.3.41

12 months ago

0.3.45

12 months ago

0.3.44

12 months ago

0.3.43

12 months ago

0.3.40

12 months ago

0.3.39

12 months ago

0.3.38

12 months ago

0.3.37

12 months ago

0.3.36

12 months ago

0.3.35

1 year ago

0.3.34

1 year ago

0.3.33

1 year ago

0.3.31

1 year ago

0.3.32

1 year ago

0.3.30

1 year ago

0.3.29

1 year ago

0.3.28

1 year ago

0.3.27

1 year ago

0.3.26

1 year ago

0.3.25

1 year ago

0.3.24

1 year ago

0.3.23

1 year ago

0.3.22

1 year ago

0.3.21

1 year ago

0.3.20

1 year ago

0.3.19

1 year ago

0.3.18

1 year ago

0.3.17

1 year ago

0.3.16

1 year ago

0.3.15

1 year ago

0.3.14

1 year ago

0.3.13

1 year ago

0.3.12

1 year ago

0.3.11

1 year ago

0.3.10

1 year ago

0.3.9

1 year ago

0.3.8

1 year ago

0.3.7

1 year ago

0.3.6

1 year ago

0.3.5

1 year ago

0.3.4

1 year ago

0.3.3

1 year ago

0.3.2

1 year ago

0.3.1

1 year ago

0.3.0

1 year ago

0.0.0

1 year ago