oblaka-iac 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -2
- package/src/commands/deploy.ts +1 -1
- package/src/commands/input.ts +34 -19
- package/src/commands/resource-processor.ts +2 -2
- package/src/commands/run.ts +8 -0
- package/src/state.ts +5 -3
- package/src/commands/utils/args.ts +0 -20
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oblaka-iac",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"main": "./src/index.ts",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
"format:check": "dprint check",
|
|
21
21
|
"lint": "biome check ./src",
|
|
22
22
|
"lint:fix": "biome check --write ./src",
|
|
23
|
-
"typecheck": "tsc --noEmit"
|
|
23
|
+
"typecheck": "tsc --noEmit",
|
|
24
|
+
"test": "bun test"
|
|
24
25
|
},
|
|
25
26
|
"devDependencies": {
|
|
26
27
|
"@biomejs/biome": "^2.4.6",
|
package/src/commands/deploy.ts
CHANGED
|
@@ -20,7 +20,7 @@ export class CloudflareDeployExecutor implements ResourceApplier {
|
|
|
20
20
|
apiToken: input.apiToken,
|
|
21
21
|
})
|
|
22
22
|
|
|
23
|
-
const stateStore = new KVStateStorage(cfClient, input.stateNamespace)
|
|
23
|
+
const stateStore = new KVStateStorage(cfClient, input.stateNamespace, input.stateNamespaceId)
|
|
24
24
|
const stateKey = { env: input.env }
|
|
25
25
|
const state = await stateStore.get(stateKey)
|
|
26
26
|
|
package/src/commands/input.ts
CHANGED
|
@@ -1,26 +1,41 @@
|
|
|
1
|
-
import { parseArgs } from '
|
|
1
|
+
import { parseArgs } from 'node:util'
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
export const input = (() => {
|
|
4
|
+
const { values, positionals } = parseArgs({
|
|
5
|
+
args: process.argv.slice(2),
|
|
6
|
+
allowPositionals: true,
|
|
7
|
+
options: {
|
|
8
|
+
env: { type: 'string' },
|
|
9
|
+
'state-namespace': { type: 'string' },
|
|
10
|
+
'state-namespace-id': { type: 'string' },
|
|
11
|
+
'account-id': { type: 'string' },
|
|
12
|
+
'api-token': { type: 'string' },
|
|
13
|
+
'dry-run': { type: 'boolean' },
|
|
14
|
+
remote: { type: 'boolean' },
|
|
15
|
+
destroy: { type: 'boolean' },
|
|
16
|
+
validate: { type: 'boolean' },
|
|
17
|
+
'out-state': { type: 'string' },
|
|
18
|
+
},
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
const main = positionals[0]
|
|
22
|
+
if (!main) {
|
|
23
|
+
console.error('Missing config entrypoint argument')
|
|
24
|
+
process.exit(1)
|
|
6
25
|
}
|
|
7
|
-
throw new Error(`Missing required string argument: ${name}`)
|
|
8
|
-
}
|
|
9
26
|
|
|
10
|
-
export const input = (() => {
|
|
11
|
-
const { named, positional } = parseArgs(process.argv.slice(2))
|
|
12
27
|
return {
|
|
13
|
-
main
|
|
14
|
-
env:
|
|
15
|
-
stateNamespace:
|
|
16
|
-
|
|
17
|
-
accountId:
|
|
18
|
-
apiToken:
|
|
19
|
-
dryRun:
|
|
20
|
-
remote:
|
|
21
|
-
destroy:
|
|
22
|
-
validate:
|
|
23
|
-
outStatePath:
|
|
28
|
+
main,
|
|
29
|
+
env: values.env || process.env.CLOUDFLARE_ENV || 'local',
|
|
30
|
+
stateNamespace: values['state-namespace'] || 'cf-state',
|
|
31
|
+
stateNamespaceId: values['state-namespace-id'],
|
|
32
|
+
accountId: values['account-id'] || process.env.CLOUDFLARE_ACCOUNT_ID || '',
|
|
33
|
+
apiToken: values['api-token'] || process.env.CLOUDFLARE_API_TOKEN || '',
|
|
34
|
+
dryRun: values['dry-run'] ?? false,
|
|
35
|
+
remote: values.remote ?? false,
|
|
36
|
+
destroy: values.destroy ?? false,
|
|
37
|
+
validate: values.validate ?? false,
|
|
38
|
+
outStatePath: values['out-state'],
|
|
24
39
|
}
|
|
25
40
|
})()
|
|
26
41
|
|
|
@@ -38,7 +38,7 @@ export class ResourceProcessor {
|
|
|
38
38
|
}
|
|
39
39
|
const configPath = path.join(worker.options.dir, 'wrangler.jsonc')
|
|
40
40
|
const existingConfig = jsoncParser.parse((await tryReadFile(configPath)) || '{}') as Config
|
|
41
|
-
const { bindings, dir, ...workerConfig } = worker
|
|
41
|
+
const { bindings, dir, deleteDurableObjectsOnRemoval, ...workerConfig } = worker.options
|
|
42
42
|
|
|
43
43
|
let config: Config = {
|
|
44
44
|
...workerConfig,
|
|
@@ -56,7 +56,7 @@ export class ResourceProcessor {
|
|
|
56
56
|
config = binding.configureBinding({ config, binding: bindingName, state, env })
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
if (
|
|
59
|
+
if (deleteDurableObjectsOnRemoval !== false) {
|
|
60
60
|
const oldClasses = new Set((existingConfig.durable_objects?.bindings ?? []).map((b: { class_name: string }) => b.class_name))
|
|
61
61
|
const newClasses = new Set((config.durable_objects?.bindings ?? []).map((b: { class_name: string }) => b.class_name))
|
|
62
62
|
const deletedClasses = [...oldClasses].filter(c => !newClasses.has(c))
|
package/src/commands/run.ts
CHANGED
|
@@ -10,6 +10,14 @@ registerSignalHandler()
|
|
|
10
10
|
if (input.validate) {
|
|
11
11
|
await CloudflareValidateExecutor.execute({ input })
|
|
12
12
|
} else if (input.remote) {
|
|
13
|
+
if (!input.accountId) {
|
|
14
|
+
console.error('Missing --account-id or CLOUDFLARE_ACCOUNT_ID environment variable')
|
|
15
|
+
process.exit(1)
|
|
16
|
+
}
|
|
17
|
+
if (!input.apiToken) {
|
|
18
|
+
console.error('Missing --api-token or CLOUDFLARE_API_TOKEN environment variable')
|
|
19
|
+
process.exit(1)
|
|
20
|
+
}
|
|
13
21
|
await CloudflareDeployExecutor.execute({ input })
|
|
14
22
|
} else {
|
|
15
23
|
await CloudflareConfigureExecutor.execute({ input })
|
package/src/state.ts
CHANGED
|
@@ -20,18 +20,20 @@ export class KVStateStorage implements StateStorage {
|
|
|
20
20
|
constructor(
|
|
21
21
|
private readonly cfClient: CloudflareClient,
|
|
22
22
|
private readonly namespace: string,
|
|
23
|
+
namespaceId?: string,
|
|
23
24
|
) {
|
|
25
|
+
this.id = namespaceId
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
private async resolveKvId(): Promise<string> {
|
|
27
29
|
if (this.id) {
|
|
28
30
|
return this.id
|
|
29
31
|
}
|
|
30
|
-
const
|
|
31
|
-
url: `/storage/kv/namespaces`,
|
|
32
|
+
const namespaces = await this.cfClient.fetch<{ title: string; id: string }[]>({
|
|
33
|
+
url: `/storage/kv/namespaces?per_page=1000`,
|
|
32
34
|
method: 'GET',
|
|
33
35
|
})
|
|
34
|
-
const existing =
|
|
36
|
+
const existing = namespaces.find(i => i.title === this.namespace)
|
|
35
37
|
if (existing) {
|
|
36
38
|
this.id = existing.id
|
|
37
39
|
return existing.id
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export const parseArgs = (args: string[]): { named: { [key: string]: string | true }; positional: string[] } => {
|
|
2
|
-
const named: { [key: string]: string | true } = {}
|
|
3
|
-
const positional: string[] = []
|
|
4
|
-
for (let i = 0; i < args.length; i++) {
|
|
5
|
-
const arg = args[i]
|
|
6
|
-
if (arg.startsWith('--')) {
|
|
7
|
-
const key = arg.slice(2)
|
|
8
|
-
const value = args[i + 1]
|
|
9
|
-
if (value && !value.startsWith('--')) {
|
|
10
|
-
named[key] = value
|
|
11
|
-
i++
|
|
12
|
-
} else {
|
|
13
|
-
named[key] = true
|
|
14
|
-
}
|
|
15
|
-
} else {
|
|
16
|
-
positional.push(arg)
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return { named, positional }
|
|
20
|
-
}
|