forked from ipdxco/github-as-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync.ts
More file actions
31 lines (25 loc) · 934 Bytes
/
sync.ts
File metadata and controls
31 lines (25 loc) · 934 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import {Resource, ResourceConstructors} from './resources/resource.js'
import {State} from './terraform/state.js'
import {Id} from './terraform/schema.js'
import {Config} from './yaml/config.js'
export async function runSync(): Promise<void> {
const state = await State.New()
const config = Config.FromPath()
await sync(state, config)
config.save()
}
export async function sync(state: State, config: Config): Promise<void> {
const resources: [Id, Resource][] = []
for (const resourceClass of ResourceConstructors) {
const isIgnored = await state.isIgnored(resourceClass)
if (!isIgnored) {
const oldResources = config.getResources(resourceClass)
const newResources = await resourceClass.FromGitHub(oldResources)
resources.push(...newResources)
}
}
await state.sync(resources)
await state.refresh()
const syncedResources = state.getAllResources()
config.sync(syncedResources)
}