@ankhorage/infra 0.2.1 → 0.3.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.
Files changed (70) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +43 -2
  3. package/dist/ankh.provider.d.ts +10 -0
  4. package/dist/ankh.provider.d.ts.map +1 -0
  5. package/dist/ankh.provider.js +27 -0
  6. package/dist/ankh.provider.js.map +1 -0
  7. package/dist/cli.d.ts +10 -0
  8. package/dist/cli.d.ts.map +1 -0
  9. package/dist/cli.js +39 -0
  10. package/dist/cli.js.map +1 -0
  11. package/dist/commandContext.d.ts +12 -0
  12. package/dist/commandContext.d.ts.map +1 -0
  13. package/dist/commandContext.js +15 -0
  14. package/dist/commandContext.js.map +1 -0
  15. package/dist/commands.d.ts +95 -0
  16. package/dist/commands.d.ts.map +1 -0
  17. package/dist/commands.js +256 -0
  18. package/dist/commands.js.map +1 -0
  19. package/dist/infraValidation.d.ts +3 -0
  20. package/dist/infraValidation.d.ts.map +1 -0
  21. package/dist/infraValidation.js +58 -0
  22. package/dist/infraValidation.js.map +1 -0
  23. package/dist/metadata/index.d.ts +2 -0
  24. package/dist/metadata/index.d.ts.map +1 -0
  25. package/dist/metadata/index.js +2 -0
  26. package/dist/metadata/index.js.map +1 -0
  27. package/dist/packageMetadata.d.ts +10 -0
  28. package/dist/packageMetadata.d.ts.map +1 -0
  29. package/dist/packageMetadata.js +17 -0
  30. package/dist/packageMetadata.js.map +1 -0
  31. package/dist/project.d.ts +14 -0
  32. package/dist/project.d.ts.map +1 -0
  33. package/dist/project.js +202 -0
  34. package/dist/project.js.map +1 -0
  35. package/dist/projectInfrastructure.d.ts +22 -0
  36. package/dist/projectInfrastructure.d.ts.map +1 -0
  37. package/dist/projectInfrastructure.js +120 -0
  38. package/dist/projectInfrastructure.js.map +1 -0
  39. package/dist/readme-usage.d.ts +2 -0
  40. package/dist/readme-usage.d.ts.map +1 -0
  41. package/dist/readme-usage.js +30 -0
  42. package/dist/readme-usage.js.map +1 -0
  43. package/dist/runtime.d.ts +26 -0
  44. package/dist/runtime.d.ts.map +1 -0
  45. package/dist/runtime.js +87 -0
  46. package/dist/runtime.js.map +1 -0
  47. package/dist/testSupport.d.ts +24 -0
  48. package/dist/testSupport.d.ts.map +1 -0
  49. package/dist/testSupport.js +73 -0
  50. package/dist/testSupport.js.map +1 -0
  51. package/package.json +18 -3
  52. package/src/ankh.provider.test.ts +32 -0
  53. package/src/ankh.provider.ts +53 -0
  54. package/src/cli.test.ts +137 -0
  55. package/src/cli.ts +67 -0
  56. package/src/commandContext.ts +27 -0
  57. package/src/commands.test.ts +219 -0
  58. package/src/commands.ts +404 -0
  59. package/src/infraValidation.ts +90 -0
  60. package/src/metadata/index.ts +7 -0
  61. package/src/package.test.ts +27 -0
  62. package/src/packageMetadata.ts +24 -0
  63. package/src/project.test.ts +218 -0
  64. package/src/project.ts +270 -0
  65. package/src/projectInfrastructure.test.ts +207 -0
  66. package/src/projectInfrastructure.ts +177 -0
  67. package/src/readme-usage.ts +30 -0
  68. package/src/runtime.test.ts +124 -0
  69. package/src/runtime.ts +127 -0
  70. package/src/testSupport.ts +112 -0
@@ -0,0 +1,112 @@
1
+ import type { AppManifest } from '@ankhorage/contracts';
2
+ import { promises as fs } from 'fs';
3
+ import os from 'os';
4
+ import path from 'path';
5
+
6
+ import type { InfraCommandContext } from './commandContext.js';
7
+
8
+ export interface CapturedCommandContext {
9
+ readonly context: InfraCommandContext;
10
+ readonly stderr: { value: string };
11
+ readonly stdout: { value: string };
12
+ }
13
+
14
+ export function createCapturedCommandContext(
15
+ cwd: string,
16
+ version = '0.2.1',
17
+ ): CapturedCommandContext {
18
+ const stdout = { value: '' };
19
+ const stderr = { value: '' };
20
+
21
+ return {
22
+ stdout,
23
+ stderr,
24
+ context: {
25
+ cwd,
26
+ env: process.env,
27
+ version,
28
+ writeStdout(text: string) {
29
+ stdout.value += text;
30
+ },
31
+ writeStderr(text: string) {
32
+ stderr.value += text;
33
+ },
34
+ },
35
+ };
36
+ }
37
+
38
+ export async function createWorkspaceFixture(
39
+ args: {
40
+ readonly manifest?: AppManifest;
41
+ readonly manifestFile?: 'invalid-json' | 'missing';
42
+ readonly projectId?: string;
43
+ } = {},
44
+ ): Promise<{
45
+ readonly appsRoot: string;
46
+ readonly projectId: string;
47
+ readonly projectPath: string;
48
+ readonly rootPath: string;
49
+ }> {
50
+ const rootPath = await fs.mkdtemp(path.join(os.tmpdir(), 'ankhorage-infra-'));
51
+ const appsRoot = path.join(rootPath, 'apps');
52
+ const projectId = args.projectId ?? 'shop';
53
+ const projectPath = path.join(appsRoot, projectId);
54
+
55
+ await fs.mkdir(projectPath, { recursive: true });
56
+ await fs.writeFile(
57
+ path.join(projectPath, 'package.json'),
58
+ JSON.stringify({ name: projectId, version: '1.0.0' }, null, 2),
59
+ 'utf8',
60
+ );
61
+
62
+ if (args.manifestFile === 'invalid-json') {
63
+ await fs.writeFile(path.join(projectPath, 'ankh.config.json'), '{invalid', 'utf8');
64
+ } else if (args.manifestFile !== 'missing') {
65
+ await fs.writeFile(
66
+ path.join(projectPath, 'ankh.config.json'),
67
+ `${JSON.stringify(args.manifest ?? createAppManifest(projectId), null, 2)}\n`,
68
+ 'utf8',
69
+ );
70
+ }
71
+
72
+ return {
73
+ appsRoot,
74
+ projectId,
75
+ projectPath,
76
+ rootPath,
77
+ };
78
+ }
79
+
80
+ export function createAppManifest(
81
+ projectId: string,
82
+ infra: AppManifest['infra'] = { plugins: [] },
83
+ ): AppManifest {
84
+ return {
85
+ metadata: {
86
+ name: projectId,
87
+ slug: projectId,
88
+ version: '1.0.0',
89
+ themeId: 'default',
90
+ },
91
+ themes: [],
92
+ activeThemeId: 'default',
93
+ infra,
94
+ navigator: {
95
+ type: 'stack',
96
+ routes: [{ name: 'index', screenId: 'index' }],
97
+ },
98
+ screens: {},
99
+ settings: {
100
+ localization: {
101
+ defaultLocale: 'en',
102
+ locales: ['en'],
103
+ },
104
+ authFlow: {
105
+ signInRoute: '/sign-in',
106
+ signOutRoute: '/sign-out',
107
+ postSignInRoute: '/',
108
+ unauthorizedRoute: '/sign-in',
109
+ },
110
+ },
111
+ };
112
+ }