hereya-cli 0.9.2 → 0.11.0
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/README.md +64 -42
- package/dist/backend/common.d.ts +24 -4
- package/dist/backend/local.d.ts +3 -1
- package/dist/backend/local.js +112 -18
- package/dist/commands/workspace/env/set/index.d.ts +13 -0
- package/dist/commands/workspace/env/set/index.js +39 -0
- package/dist/commands/workspace/env/unset/index.d.ts +10 -0
- package/dist/commands/workspace/env/unset/index.js +33 -0
- package/dist/iac/common.d.ts +5 -0
- package/dist/iac/terraform.js +62 -19
- package/dist/infrastructure/aws.d.ts +5 -6
- package/dist/infrastructure/aws.js +114 -244
- package/dist/infrastructure/common.d.ts +24 -0
- package/dist/infrastructure/local.d.ts +3 -3
- package/dist/infrastructure/local.js +12 -28
- package/dist/lib/filesystem.d.ts +1 -0
- package/dist/lib/filesystem.js +10 -1
- package/dist/lib/package/index.d.ts +1 -0
- package/dist/lib/package/index.js +26 -8
- package/oclif.manifest.json +147 -82
- package/package.json +1 -1
- package/dist/commands/remote/exec/index.d.ts +0 -13
- package/dist/commands/remote/exec/index.js +0 -89
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as fs from 'node:fs/promises';
|
|
2
2
|
import * as os from 'node:os';
|
|
3
3
|
import * as path from 'node:path';
|
|
4
|
-
import { simpleGit } from 'simple-git';
|
|
5
4
|
import { getIac } from '../iac/index.js';
|
|
5
|
+
import { downloadPackage } from '../lib/package/index.js';
|
|
6
6
|
export class LocalInfrastructure {
|
|
7
7
|
async bootstrap() {
|
|
8
8
|
console.log('Bootstrapping local infrastructure');
|
|
@@ -11,14 +11,14 @@ export class LocalInfrastructure {
|
|
|
11
11
|
input.parameters = {
|
|
12
12
|
...input.parameters,
|
|
13
13
|
hereyaProjectEnv: JSON.stringify(input.projectEnv ?? {}),
|
|
14
|
-
hereyaProjectRootDir: input.projectRootDir
|
|
14
|
+
hereyaProjectRootDir: input.projectRootDir,
|
|
15
15
|
};
|
|
16
16
|
return this.provision(input);
|
|
17
17
|
}
|
|
18
18
|
async destroy(input) {
|
|
19
19
|
// noinspection DuplicatedCode
|
|
20
20
|
const destPath = path.join(os.homedir(), '.hereya', input.id, input.canonicalName);
|
|
21
|
-
const downloadPath = await
|
|
21
|
+
const downloadPath = await downloadPackage(input.pkgUrl, destPath);
|
|
22
22
|
const iac$ = getIac({ type: input.iacType });
|
|
23
23
|
if (!iac$.supported) {
|
|
24
24
|
return { reason: iac$.reason, success: false };
|
|
@@ -28,7 +28,7 @@ export class LocalInfrastructure {
|
|
|
28
28
|
env: input.env ?? {},
|
|
29
29
|
id: input.id,
|
|
30
30
|
parameters: input.parameters,
|
|
31
|
-
pkgPath: downloadPath
|
|
31
|
+
pkgPath: downloadPath,
|
|
32
32
|
});
|
|
33
33
|
if (!output.success) {
|
|
34
34
|
return { reason: output.reason, success: false };
|
|
@@ -40,7 +40,7 @@ export class LocalInfrastructure {
|
|
|
40
40
|
async provision(input) {
|
|
41
41
|
// noinspection DuplicatedCode
|
|
42
42
|
const destPath = path.join(os.homedir(), '.hereya', input.id, input.canonicalName);
|
|
43
|
-
const downloadPath = await
|
|
43
|
+
const downloadPath = await downloadPackage(input.pkgUrl, destPath);
|
|
44
44
|
const iac$ = getIac({ type: input.iacType });
|
|
45
45
|
if (!iac$.supported) {
|
|
46
46
|
return { reason: iac$.reason, success: false };
|
|
@@ -50,7 +50,7 @@ export class LocalInfrastructure {
|
|
|
50
50
|
env: input.env ?? {},
|
|
51
51
|
id: input.id,
|
|
52
52
|
parameters: input.parameters,
|
|
53
|
-
pkgPath: downloadPath
|
|
53
|
+
pkgPath: downloadPath,
|
|
54
54
|
});
|
|
55
55
|
if (!output.success) {
|
|
56
56
|
return { reason: output.reason, success: false };
|
|
@@ -64,6 +64,9 @@ export class LocalInfrastructure {
|
|
|
64
64
|
console.log(`Saving env to ${input.id}`);
|
|
65
65
|
return { success: true };
|
|
66
66
|
}
|
|
67
|
+
async storeEnv(input) {
|
|
68
|
+
return { success: true, value: input.value };
|
|
69
|
+
}
|
|
67
70
|
async unbootstrap() {
|
|
68
71
|
console.log('Unbootstrapping local infrastructure');
|
|
69
72
|
}
|
|
@@ -71,30 +74,11 @@ export class LocalInfrastructure {
|
|
|
71
74
|
input.parameters = {
|
|
72
75
|
...input.parameters,
|
|
73
76
|
hereyaProjectEnv: JSON.stringify(input.projectEnv ?? {}),
|
|
74
|
-
hereyaProjectRootDir: input.projectRootDir
|
|
77
|
+
hereyaProjectRootDir: input.projectRootDir,
|
|
75
78
|
};
|
|
76
79
|
return this.destroy(input);
|
|
77
80
|
}
|
|
78
|
-
async
|
|
79
|
-
|
|
80
|
-
console.log(`Package already downloaded at ${destPath}`);
|
|
81
|
-
return destPath;
|
|
82
|
-
}
|
|
83
|
-
await fs.mkdir(destPath, { recursive: true });
|
|
84
|
-
console.log(`Downloading package from ${pkgUrl}`);
|
|
85
|
-
// Initialize simple-git
|
|
86
|
-
const git = simpleGit();
|
|
87
|
-
// Clone repository into temp directory
|
|
88
|
-
await git.clone(pkgUrl, destPath, ['--depth=1']);
|
|
89
|
-
return destPath;
|
|
90
|
-
}
|
|
91
|
-
async isNotEmpty(directoryPath) {
|
|
92
|
-
try {
|
|
93
|
-
const files = await fs.readdir(directoryPath);
|
|
94
|
-
return files.length > 0;
|
|
95
|
-
}
|
|
96
|
-
catch {
|
|
97
|
-
return false; // or you can handle the error as needed
|
|
98
|
-
}
|
|
81
|
+
async unstoreEnv(_) {
|
|
82
|
+
return { success: true };
|
|
99
83
|
}
|
|
100
84
|
}
|
package/dist/lib/filesystem.d.ts
CHANGED
package/dist/lib/filesystem.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { access, constants } from 'node:fs/promises';
|
|
1
|
+
import { access, constants, readdir } from 'node:fs/promises';
|
|
2
2
|
export async function getAnyPath(...candidates) {
|
|
3
3
|
const checkAccess = async (index) => {
|
|
4
4
|
if (index >= candidates.length)
|
|
@@ -22,3 +22,12 @@ export async function fileExists(filePath) {
|
|
|
22
22
|
return false;
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
+
export async function isNotEmpty(directoryPath) {
|
|
26
|
+
try {
|
|
27
|
+
const files = await readdir(directoryPath);
|
|
28
|
+
return files.length > 0;
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -6,6 +6,7 @@ export declare const packageManager: PackageManager;
|
|
|
6
6
|
export declare function getPackageManager(): PackageManager;
|
|
7
7
|
export declare function resolvePackage(input: ResolvePackageInput): Promise<ResolvePackageOutput>;
|
|
8
8
|
export declare function getPackageCanonicalName(packageName: string): string;
|
|
9
|
+
export declare function downloadPackage(pkgUrl: string, destPath: string): Promise<string>;
|
|
9
10
|
export type ResolvePackageInput = {
|
|
10
11
|
isDeploying?: boolean;
|
|
11
12
|
package: string;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import * as fs from 'node:fs/promises';
|
|
2
|
+
import { simpleGit } from 'simple-git';
|
|
1
3
|
import * as yaml from 'yaml';
|
|
2
4
|
import { z } from 'zod';
|
|
3
5
|
import { IacType } from '../../iac/common.js';
|
|
4
6
|
import { InfrastructureType } from '../../infrastructure/common.js';
|
|
7
|
+
import { isNotEmpty } from '../filesystem.js';
|
|
5
8
|
import { GitHubPackageManager } from './github.js';
|
|
6
9
|
export const packageManager = new GitHubPackageManager();
|
|
7
10
|
export function getPackageManager() {
|
|
@@ -18,7 +21,7 @@ export async function resolvePackage(input) {
|
|
|
18
21
|
const metadataContentCandidates = (await Promise.all([
|
|
19
22
|
packageManager.getRepoContent({ owner, path: 'hereyarc.yaml', repo }),
|
|
20
23
|
packageManager.getRepoContent({ owner, path: 'hereyarc.yml', repo }),
|
|
21
|
-
])).filter(content$ => content$.found);
|
|
24
|
+
])).filter((content$) => content$.found);
|
|
22
25
|
if (metadataContentCandidates.length === 0) {
|
|
23
26
|
return { found: false, reason: `No hereya metadata file found in ${pkgUrl}` };
|
|
24
27
|
}
|
|
@@ -31,16 +34,16 @@ export async function resolvePackage(input) {
|
|
|
31
34
|
if (input.isDeploying && metadata.onDeploy) {
|
|
32
35
|
return resolvePackage({ package: metadata.onDeploy.pkg });
|
|
33
36
|
}
|
|
34
|
-
if (process.env.HEREYA_OVERRIDE_INFRA) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
37
|
+
// if (process.env.HEREYA_OVERRIDE_INFRA) {
|
|
38
|
+
// metadata.originalInfra = metadata.infra
|
|
39
|
+
// metadata.infra = process.env.HEREYA_OVERRIDE_INFRA as InfrastructureType
|
|
40
|
+
// }
|
|
38
41
|
return {
|
|
39
42
|
canonicalName: getPackageCanonicalName(input.package),
|
|
40
43
|
found: true,
|
|
41
44
|
metadata,
|
|
42
45
|
packageUri: pkgUrl,
|
|
43
|
-
pkgName: input.package
|
|
46
|
+
pkgName: input.package,
|
|
44
47
|
};
|
|
45
48
|
}
|
|
46
49
|
catch (error) {
|
|
@@ -50,14 +53,29 @@ export async function resolvePackage(input) {
|
|
|
50
53
|
export function getPackageCanonicalName(packageName) {
|
|
51
54
|
return packageName.replace('/', '-');
|
|
52
55
|
}
|
|
56
|
+
export async function downloadPackage(pkgUrl, destPath) {
|
|
57
|
+
if (await isNotEmpty(destPath)) {
|
|
58
|
+
console.log(`Package already downloaded at ${destPath}`);
|
|
59
|
+
return destPath;
|
|
60
|
+
}
|
|
61
|
+
await fs.mkdir(destPath, { recursive: true });
|
|
62
|
+
console.log(`Downloading package from ${pkgUrl}`);
|
|
63
|
+
// Initialize simple-git
|
|
64
|
+
const git = simpleGit();
|
|
65
|
+
// Clone repository into temp directory
|
|
66
|
+
await git.clone(pkgUrl, destPath, ['--depth=1']);
|
|
67
|
+
return destPath;
|
|
68
|
+
}
|
|
53
69
|
export const PackageMetadata = z.object({
|
|
54
70
|
dependencies: z.record(z.string()).optional(),
|
|
55
71
|
deploy: z.boolean().optional(),
|
|
56
72
|
iac: z.nativeEnum(IacType),
|
|
57
73
|
infra: z.nativeEnum(InfrastructureType),
|
|
58
|
-
onDeploy: z
|
|
74
|
+
onDeploy: z
|
|
75
|
+
.object({
|
|
59
76
|
pkg: z.string(),
|
|
60
77
|
version: z.string(),
|
|
61
|
-
})
|
|
78
|
+
})
|
|
79
|
+
.optional(),
|
|
62
80
|
originalInfra: z.nativeEnum(InfrastructureType).optional(),
|
|
63
81
|
});
|
package/oclif.manifest.json
CHANGED
|
@@ -504,56 +504,6 @@
|
|
|
504
504
|
"index.js"
|
|
505
505
|
]
|
|
506
506
|
},
|
|
507
|
-
"remote:exec": {
|
|
508
|
-
"aliases": [],
|
|
509
|
-
"args": {
|
|
510
|
-
"pkgPath": {
|
|
511
|
-
"description": "The path to the package to provision or destroy",
|
|
512
|
-
"name": "pkgPath",
|
|
513
|
-
"required": false
|
|
514
|
-
}
|
|
515
|
-
},
|
|
516
|
-
"description": "remotely provision or destroy a package",
|
|
517
|
-
"examples": [
|
|
518
|
-
"<%= config.bin %> <%= command.id %>"
|
|
519
|
-
],
|
|
520
|
-
"flags": {
|
|
521
|
-
"output": {
|
|
522
|
-
"char": "o",
|
|
523
|
-
"description": "The path to store the output env in",
|
|
524
|
-
"name": "output",
|
|
525
|
-
"required": false,
|
|
526
|
-
"hasDynamicHelp": false,
|
|
527
|
-
"multiple": false,
|
|
528
|
-
"type": "option"
|
|
529
|
-
},
|
|
530
|
-
"source": {
|
|
531
|
-
"char": "s",
|
|
532
|
-
"description": "The source of the project to provision or destroy the package for",
|
|
533
|
-
"name": "source",
|
|
534
|
-
"required": false,
|
|
535
|
-
"hasDynamicHelp": false,
|
|
536
|
-
"multiple": false,
|
|
537
|
-
"type": "option"
|
|
538
|
-
}
|
|
539
|
-
},
|
|
540
|
-
"hasDynamicHelp": false,
|
|
541
|
-
"hiddenAliases": [],
|
|
542
|
-
"id": "remote:exec",
|
|
543
|
-
"pluginAlias": "hereya-cli",
|
|
544
|
-
"pluginName": "hereya-cli",
|
|
545
|
-
"pluginType": "core",
|
|
546
|
-
"strict": true,
|
|
547
|
-
"enableJsonFlag": false,
|
|
548
|
-
"isESM": true,
|
|
549
|
-
"relativePath": [
|
|
550
|
-
"dist",
|
|
551
|
-
"commands",
|
|
552
|
-
"remote",
|
|
553
|
-
"exec",
|
|
554
|
-
"index.js"
|
|
555
|
-
]
|
|
556
|
-
},
|
|
557
507
|
"workspace:create": {
|
|
558
508
|
"aliases": [],
|
|
559
509
|
"args": {
|
|
@@ -585,37 +535,6 @@
|
|
|
585
535
|
"index.js"
|
|
586
536
|
]
|
|
587
537
|
},
|
|
588
|
-
"workspace:delete": {
|
|
589
|
-
"aliases": [],
|
|
590
|
-
"args": {
|
|
591
|
-
"name": {
|
|
592
|
-
"description": "name of the workspace to delete",
|
|
593
|
-
"name": "name",
|
|
594
|
-
"required": true
|
|
595
|
-
}
|
|
596
|
-
},
|
|
597
|
-
"description": "Delete a workspace if it exists.",
|
|
598
|
-
"examples": [
|
|
599
|
-
"<%= config.bin %> <%= command.id %> dev"
|
|
600
|
-
],
|
|
601
|
-
"flags": {},
|
|
602
|
-
"hasDynamicHelp": false,
|
|
603
|
-
"hiddenAliases": [],
|
|
604
|
-
"id": "workspace:delete",
|
|
605
|
-
"pluginAlias": "hereya-cli",
|
|
606
|
-
"pluginName": "hereya-cli",
|
|
607
|
-
"pluginType": "core",
|
|
608
|
-
"strict": true,
|
|
609
|
-
"enableJsonFlag": false,
|
|
610
|
-
"isESM": true,
|
|
611
|
-
"relativePath": [
|
|
612
|
-
"dist",
|
|
613
|
-
"commands",
|
|
614
|
-
"workspace",
|
|
615
|
-
"delete",
|
|
616
|
-
"index.js"
|
|
617
|
-
]
|
|
618
|
-
},
|
|
619
538
|
"workspace:env": {
|
|
620
539
|
"aliases": [],
|
|
621
540
|
"args": {
|
|
@@ -666,6 +585,37 @@
|
|
|
666
585
|
"index.js"
|
|
667
586
|
]
|
|
668
587
|
},
|
|
588
|
+
"workspace:delete": {
|
|
589
|
+
"aliases": [],
|
|
590
|
+
"args": {
|
|
591
|
+
"name": {
|
|
592
|
+
"description": "name of the workspace to delete",
|
|
593
|
+
"name": "name",
|
|
594
|
+
"required": true
|
|
595
|
+
}
|
|
596
|
+
},
|
|
597
|
+
"description": "Delete a workspace if it exists.",
|
|
598
|
+
"examples": [
|
|
599
|
+
"<%= config.bin %> <%= command.id %> dev"
|
|
600
|
+
],
|
|
601
|
+
"flags": {},
|
|
602
|
+
"hasDynamicHelp": false,
|
|
603
|
+
"hiddenAliases": [],
|
|
604
|
+
"id": "workspace:delete",
|
|
605
|
+
"pluginAlias": "hereya-cli",
|
|
606
|
+
"pluginName": "hereya-cli",
|
|
607
|
+
"pluginType": "core",
|
|
608
|
+
"strict": true,
|
|
609
|
+
"enableJsonFlag": false,
|
|
610
|
+
"isESM": true,
|
|
611
|
+
"relativePath": [
|
|
612
|
+
"dist",
|
|
613
|
+
"commands",
|
|
614
|
+
"workspace",
|
|
615
|
+
"delete",
|
|
616
|
+
"index.js"
|
|
617
|
+
]
|
|
618
|
+
},
|
|
669
619
|
"workspace:install": {
|
|
670
620
|
"aliases": [],
|
|
671
621
|
"args": {
|
|
@@ -781,7 +731,122 @@
|
|
|
781
731
|
"uninstall",
|
|
782
732
|
"index.js"
|
|
783
733
|
]
|
|
734
|
+
},
|
|
735
|
+
"workspace:env:set": {
|
|
736
|
+
"aliases": [],
|
|
737
|
+
"args": {},
|
|
738
|
+
"description": "set an env var for a workspace",
|
|
739
|
+
"examples": [
|
|
740
|
+
"<%= config.bin %> <%= command.id %> -w my-workspace -n myVar -v my-value -i aws -s"
|
|
741
|
+
],
|
|
742
|
+
"flags": {
|
|
743
|
+
"infra": {
|
|
744
|
+
"char": "i",
|
|
745
|
+
"description": "the infrastructure to store the env var in",
|
|
746
|
+
"name": "infra",
|
|
747
|
+
"required": true,
|
|
748
|
+
"hasDynamicHelp": false,
|
|
749
|
+
"multiple": false,
|
|
750
|
+
"type": "option"
|
|
751
|
+
},
|
|
752
|
+
"name": {
|
|
753
|
+
"char": "n",
|
|
754
|
+
"description": "name of the env var to set",
|
|
755
|
+
"name": "name",
|
|
756
|
+
"required": true,
|
|
757
|
+
"hasDynamicHelp": false,
|
|
758
|
+
"multiple": false,
|
|
759
|
+
"type": "option"
|
|
760
|
+
},
|
|
761
|
+
"sensitive": {
|
|
762
|
+
"char": "s",
|
|
763
|
+
"description": "whether the env var is sensitive",
|
|
764
|
+
"name": "sensitive",
|
|
765
|
+
"allowNo": false,
|
|
766
|
+
"type": "boolean"
|
|
767
|
+
},
|
|
768
|
+
"value": {
|
|
769
|
+
"char": "v",
|
|
770
|
+
"description": "value of the env var to set",
|
|
771
|
+
"name": "value",
|
|
772
|
+
"required": true,
|
|
773
|
+
"hasDynamicHelp": false,
|
|
774
|
+
"multiple": false,
|
|
775
|
+
"type": "option"
|
|
776
|
+
},
|
|
777
|
+
"workspace": {
|
|
778
|
+
"char": "w",
|
|
779
|
+
"description": "name of the workspace to set an env var for",
|
|
780
|
+
"name": "workspace",
|
|
781
|
+
"required": true,
|
|
782
|
+
"hasDynamicHelp": false,
|
|
783
|
+
"multiple": false,
|
|
784
|
+
"type": "option"
|
|
785
|
+
}
|
|
786
|
+
},
|
|
787
|
+
"hasDynamicHelp": false,
|
|
788
|
+
"hiddenAliases": [],
|
|
789
|
+
"id": "workspace:env:set",
|
|
790
|
+
"pluginAlias": "hereya-cli",
|
|
791
|
+
"pluginName": "hereya-cli",
|
|
792
|
+
"pluginType": "core",
|
|
793
|
+
"strict": true,
|
|
794
|
+
"enableJsonFlag": false,
|
|
795
|
+
"isESM": true,
|
|
796
|
+
"relativePath": [
|
|
797
|
+
"dist",
|
|
798
|
+
"commands",
|
|
799
|
+
"workspace",
|
|
800
|
+
"env",
|
|
801
|
+
"set",
|
|
802
|
+
"index.js"
|
|
803
|
+
]
|
|
804
|
+
},
|
|
805
|
+
"workspace:env:unset": {
|
|
806
|
+
"aliases": [],
|
|
807
|
+
"args": {},
|
|
808
|
+
"description": "unset an env var for a workspace",
|
|
809
|
+
"examples": [
|
|
810
|
+
"<%= config.bin %> <%= command.id %> -w my-workspace -n myVar"
|
|
811
|
+
],
|
|
812
|
+
"flags": {
|
|
813
|
+
"name": {
|
|
814
|
+
"char": "n",
|
|
815
|
+
"description": "name of the env var to unset",
|
|
816
|
+
"name": "name",
|
|
817
|
+
"required": true,
|
|
818
|
+
"hasDynamicHelp": false,
|
|
819
|
+
"multiple": false,
|
|
820
|
+
"type": "option"
|
|
821
|
+
},
|
|
822
|
+
"workspace": {
|
|
823
|
+
"char": "w",
|
|
824
|
+
"description": "name of the workspace to unset an env var for",
|
|
825
|
+
"name": "workspace",
|
|
826
|
+
"required": true,
|
|
827
|
+
"hasDynamicHelp": false,
|
|
828
|
+
"multiple": false,
|
|
829
|
+
"type": "option"
|
|
830
|
+
}
|
|
831
|
+
},
|
|
832
|
+
"hasDynamicHelp": false,
|
|
833
|
+
"hiddenAliases": [],
|
|
834
|
+
"id": "workspace:env:unset",
|
|
835
|
+
"pluginAlias": "hereya-cli",
|
|
836
|
+
"pluginName": "hereya-cli",
|
|
837
|
+
"pluginType": "core",
|
|
838
|
+
"strict": true,
|
|
839
|
+
"enableJsonFlag": false,
|
|
840
|
+
"isESM": true,
|
|
841
|
+
"relativePath": [
|
|
842
|
+
"dist",
|
|
843
|
+
"commands",
|
|
844
|
+
"workspace",
|
|
845
|
+
"env",
|
|
846
|
+
"unset",
|
|
847
|
+
"index.js"
|
|
848
|
+
]
|
|
784
849
|
}
|
|
785
850
|
},
|
|
786
|
-
"version": "0.
|
|
851
|
+
"version": "0.11.0"
|
|
787
852
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Command } from '@oclif/core';
|
|
2
|
-
export default class RemoteExec extends Command {
|
|
3
|
-
static args: {
|
|
4
|
-
pkgPath: import("@oclif/core/lib/interfaces/parser.js").Arg<string | undefined, Record<string, unknown>>;
|
|
5
|
-
};
|
|
6
|
-
static description: string;
|
|
7
|
-
static examples: string[];
|
|
8
|
-
static flags: {
|
|
9
|
-
output: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
10
|
-
source: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
11
|
-
};
|
|
12
|
-
run(): Promise<void>;
|
|
13
|
-
}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { Args, Command, Flags } from '@oclif/core';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { getIac } from '../../../iac/index.js';
|
|
4
|
-
import { getInfrastructure } from '../../../infrastructure/index.js';
|
|
5
|
-
import { tryBase64ToJSONString } from '../../../lib/object-utils.js';
|
|
6
|
-
import { save } from '../../../lib/yaml-utils.js';
|
|
7
|
-
export default class RemoteExec extends Command {
|
|
8
|
-
static args = {
|
|
9
|
-
pkgPath: Args.string({
|
|
10
|
-
description: 'The path to the package to provision or destroy',
|
|
11
|
-
required: false,
|
|
12
|
-
}),
|
|
13
|
-
};
|
|
14
|
-
static description = 'remotely provision or destroy a package';
|
|
15
|
-
static examples = [
|
|
16
|
-
'<%= config.bin %> <%= command.id %>',
|
|
17
|
-
];
|
|
18
|
-
static flags = {
|
|
19
|
-
output: Flags.string({
|
|
20
|
-
char: 'o',
|
|
21
|
-
description: 'The path to store the output env in',
|
|
22
|
-
required: false,
|
|
23
|
-
}),
|
|
24
|
-
source: Flags.string({
|
|
25
|
-
char: 's',
|
|
26
|
-
description: 'The source of the project to provision or destroy the package for',
|
|
27
|
-
required: false,
|
|
28
|
-
}),
|
|
29
|
-
};
|
|
30
|
-
async run() {
|
|
31
|
-
const { args, flags } = await this.parse(RemoteExec);
|
|
32
|
-
const workspaceEnv = Object.fromEntries((process.env.HEREYA_WORKSPACE_ENV?.split(',') ?? [])
|
|
33
|
-
.filter(param => param.trim())
|
|
34
|
-
.map(param => param.split('='))
|
|
35
|
-
.map(([key, value]) => [key, tryBase64ToJSONString(value)]));
|
|
36
|
-
const parameters = Object.fromEntries((process.env.HEREYA_PARAMETERS?.split(',') ?? [])
|
|
37
|
-
.filter(param => param.trim())
|
|
38
|
-
.map(param => param.split('='))
|
|
39
|
-
.map(([key, value]) => [key, tryBase64ToJSONString(value)]));
|
|
40
|
-
const id = process.env.HEREYA_ID;
|
|
41
|
-
const iacType = process.env.HEREYA_IAC_TYPE;
|
|
42
|
-
const destroy = process.env.HEREYA_DESTROY === 'true';
|
|
43
|
-
const infraType = process.env.HEREYA_INFRA_TYPE;
|
|
44
|
-
const deploy = process.env.HEREYA_DEPLOY === 'true';
|
|
45
|
-
const source = flags.source ? path.resolve(flags.source) : '';
|
|
46
|
-
if (deploy && !source) {
|
|
47
|
-
return this.error('Deploy packages provisioning requires a source path');
|
|
48
|
-
}
|
|
49
|
-
if (!id || !iacType || !infraType) {
|
|
50
|
-
return this.error(`
|
|
51
|
-
Missing required environment variables:
|
|
52
|
-
HEREYA_ID: ${id}
|
|
53
|
-
HEREYA_IAC_TYPE: ${iacType}
|
|
54
|
-
HEREYA_INFRA_TYPE: ${infraType}
|
|
55
|
-
`);
|
|
56
|
-
}
|
|
57
|
-
const input = {
|
|
58
|
-
env: workspaceEnv, id, parameters, pkgPath: args.pkgPath || process.cwd(),
|
|
59
|
-
};
|
|
60
|
-
if (deploy) {
|
|
61
|
-
input.parameters = {
|
|
62
|
-
...input.parameters,
|
|
63
|
-
hereyaProjectRootDir: source,
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
const iac$ = getIac({ type: iacType });
|
|
67
|
-
if (!iac$.supported) {
|
|
68
|
-
return this.error(iac$.reason);
|
|
69
|
-
}
|
|
70
|
-
const { iac } = iac$;
|
|
71
|
-
const output = await (destroy ? iac.destroy(input) : iac.apply(input));
|
|
72
|
-
if (!output.success) {
|
|
73
|
-
return this.error(output.reason);
|
|
74
|
-
}
|
|
75
|
-
if (flags.output) {
|
|
76
|
-
await save(output.env, flags.output);
|
|
77
|
-
this.log(`Output env saved to ${flags.output}`);
|
|
78
|
-
}
|
|
79
|
-
const infra$ = getInfrastructure({ type: infraType });
|
|
80
|
-
if (!infra$.supported) {
|
|
81
|
-
return this.error(infra$.reason);
|
|
82
|
-
}
|
|
83
|
-
const { infrastructure } = infra$;
|
|
84
|
-
const saveOutput = await infrastructure.saveEnv({ env: output.env, id });
|
|
85
|
-
if (!saveOutput.success) {
|
|
86
|
-
return this.error(saveOutput.reason);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|