Skip to content

Commit dc0ceed

Browse files
committed
integrate the new feature
1 parent c33843d commit dc0ceed

4 files changed

Lines changed: 18 additions & 3 deletions

File tree

packages/cli/src/deploy/handler.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,15 @@ async function deployHandler(
6262
config.endpoint = process.env['OPENFN_ENDPOINT'];
6363
}
6464

65+
const rawSpec = await fs.readFile(config.specPath, 'utf-8');
66+
const convertedSpec = await maybeConvertV2spec(rawSpec);
67+
if (convertedSpec !== rawSpec) {
68+
logger.debug(
69+
'Detected v2 spec file! This will be converted into the legacy format and validation will be skipped.'
70+
);
71+
config.spec = convertedSpec;
72+
}
73+
6574
logger.debug('Deploying with config', config);
6675
logger.info(`Deploying`);
6776

packages/deploy/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { confirm } from '@inquirer/prompts';
22
import { inspect } from 'node:util';
33
import { DeployConfig, ProjectState } from './types';
44
import { readFile, writeFile } from 'fs/promises';
5-
import { parseAndValidate } from './validator';
5+
import { parseAndValidate, parseSpec } from './validator';
66
import jsondiff from 'json-diff';
77
import {
88
mergeProjectPayloadIntoState,
@@ -108,8 +108,8 @@ export async function getSpec(path: string) {
108108

109109
export async function deploy(config: DeployConfig, logger: Logger) {
110110
const [state, spec] = await Promise.all([
111-
getState(config.statePath),
112-
getSpec(config.specPath),
111+
config.state ?? getState(config.statePath),
112+
config.spec ? parseSpec(config.spec) : getSpec(config.specPath),
113113
]);
114114

115115
logger.debug('spec', spec);

packages/deploy/src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,6 @@ export interface DeployConfig {
193193
requireConfirmation: boolean;
194194
dryRun: boolean;
195195
apiKey: string | null;
196+
spec?: string;
197+
state?: ProjectState;
196198
}

packages/deploy/src/validator.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import { ProjectSpec } from './types';
33
import { readFile } from 'fs/promises';
44
import path from 'path';
55

6+
export function parseSpec(input: string) {
7+
return { errors: [] as Error[], doc: YAML.parse(input) as ProjectSpec };
8+
}
9+
610
export interface Error {
711
context: any;
812
message: string;

0 commit comments

Comments
 (0)