vyriy 0.3.8 → 0.3.9

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.
@@ -0,0 +1,98 @@
1
+ import { json, packageVersion, publishedPackageJson } from '../config.js';
2
+ const getWorkspacePath = (workspacePlan) => workspacePlan.kind === 'lambda' && workspacePlan.name === 'api'
3
+ ? `workspaces/lambda/${workspacePlan.name}`
4
+ : `workspaces/${workspacePlan.name}`;
5
+ const getWorkspacePackageName = ({ packageScope, workspacePlan, }) => workspacePlan.kind === 'lambda' && workspacePlan.name === 'api'
6
+ ? `${packageScope}/lambda-api-workspace`
7
+ : `${packageScope}/${workspacePlan.name}-workspace`;
8
+ const isApiWorkspace = (workspacePlan) => [
9
+ 'api',
10
+ 'lambda',
11
+ 'fargate',
12
+ ].includes(workspacePlan.kind);
13
+ const createApiWorkspaceDependencies = (workspacePlan) => isApiWorkspace(workspacePlan)
14
+ ? {
15
+ '@vyriy/handler': packageVersion(publishedPackageJson.version),
16
+ '@vyriy/server': packageVersion(publishedPackageJson.version),
17
+ }
18
+ : {};
19
+ const createApiHandlerFile = (workspacePath) => ({
20
+ path: `${workspacePath}/handler.ts`,
21
+ content: `import { api } from '@vyriy/handler';
22
+
23
+ export const handler = api(async (event) => ({
24
+ statusCode: 200,
25
+ body: JSON.stringify({
26
+ path: event.path,
27
+ }),
28
+ }));
29
+ `,
30
+ });
31
+ const createApiServerFile = ({ entrypoint, workspacePath, }) => ({
32
+ path: `${workspacePath}/${entrypoint}`,
33
+ content: `import { server } from '@vyriy/server';
34
+
35
+ import { handler } from './handler.js';
36
+
37
+ server(handler);
38
+ `,
39
+ });
40
+ const createDockerfile = (workspacePath) => ({
41
+ path: `${workspacePath}/Dockerfile`,
42
+ content: `FROM node:24-alpine
43
+
44
+ WORKDIR /app
45
+
46
+ COPY package.json yarn.lock .yarnrc.yml ./
47
+ COPY .yarn ./.yarn
48
+ COPY packages ./packages
49
+ COPY workspaces ./workspaces
50
+
51
+ RUN corepack enable && yarn install --immutable
52
+ RUN yarn build
53
+
54
+ CMD ["node", "workspaces/api/index.js"]
55
+ `,
56
+ });
57
+ const createApiWorkspaceFiles = (plan, workspacePlan) => {
58
+ const workspacePath = getWorkspacePath(workspacePlan);
59
+ const isLambda = workspacePlan.kind === 'lambda';
60
+ return [
61
+ createApiHandlerFile(workspacePath),
62
+ createApiServerFile({ entrypoint: isLambda ? 'server.ts' : 'index.ts', workspacePath }),
63
+ {
64
+ path: `${workspacePath}/${workspacePlan.name}.test.ts`,
65
+ content: "import { describe, expect, it } from '@jest/globals';\n\nimport { handler } from './handler.js';\n\ndescribe('api workspace', () => {\n it('exports a handler', () => {\n expect(handler).toEqual(expect.any(Function));\n });\n});\n",
66
+ },
67
+ ...(plan.features.includes('docker') && !isLambda ? [createDockerfile(workspacePath)] : []),
68
+ ];
69
+ };
70
+ export const createWorkspaceFiles = (plan, workspacePlan) => {
71
+ const workspacePath = getWorkspacePath(workspacePlan);
72
+ const dependencies = createApiWorkspaceDependencies(workspacePlan);
73
+ return [
74
+ {
75
+ path: `${workspacePath}/package.json`,
76
+ content: json({
77
+ name: getWorkspacePackageName({ packageScope: plan.packageScope, workspacePlan }),
78
+ version: '0.0.0',
79
+ private: true,
80
+ type: 'module',
81
+ main: workspacePlan.kind === 'lambda' ? 'server.js' : 'index.js',
82
+ ...(Object.keys(dependencies).length > 0 ? { dependencies } : {}),
83
+ }),
84
+ },
85
+ ...(isApiWorkspace(workspacePlan)
86
+ ? createApiWorkspaceFiles(plan, workspacePlan)
87
+ : [
88
+ {
89
+ path: `${workspacePath}/index.ts`,
90
+ content: 'export type WorkspaceName = string;\n',
91
+ },
92
+ {
93
+ path: `${workspacePath}/${workspacePlan.name}.test.ts`,
94
+ content: "import { describe, expect, it } from '@jest/globals';\n\ndescribe('workspace', () => {\n it('has a test harness', () => {\n expect(true).toBe(true);\n });\n});\n",
95
+ },
96
+ ]),
97
+ ];
98
+ };
@@ -169,12 +169,16 @@ export const askProjectPlan = async ({ defaults = {}, input = stdin, output = st
169
169
  output.write(' 3. github\n');
170
170
  const defaultCiProvider = defaults.ciProvider ?? 'none';
171
171
  const ciProvider = parseCiProvider(await promptWithDefault(question, 'CI/CD provider number or name', defaultCiProvider), defaultCiProvider);
172
- output.write('\nInfrastructure:\n');
173
- output.write(' 1. Docker\n');
174
- output.write(' 2. AWS\n');
175
- const defaultInfrastructure = getDefaultInfrastructureInput(defaults.features);
176
- const featuresAnswer = await promptWithDefault(question, 'Infrastructure number or name', defaultInfrastructure);
177
- const features = parseInfrastructure(featuresAnswer, defaultInfrastructure);
172
+ const features = isApiPreset(preset)
173
+ ? await (async () => {
174
+ output.write('\nInfrastructure:\n');
175
+ output.write(' 1. Docker\n');
176
+ output.write(' 2. AWS\n');
177
+ const defaultInfrastructure = getDefaultInfrastructureInput(defaults.features);
178
+ const featuresAnswer = await promptWithDefault(question, 'Infrastructure number or name', defaultInfrastructure);
179
+ return parseInfrastructure(featuresAnswer, defaultInfrastructure);
180
+ })()
181
+ : [];
178
182
  const plan = createProjectPlanFromPreset({
179
183
  projectName,
180
184
  targetDirectory,