Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Signed-off-by: zxypro1 <[email protected]>
  • Loading branch information
zxypro1 committed Jul 7, 2024
1 parent 14e7d7f commit 8f028b7
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/engine/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@serverless-devs/engine",
"version": "0.1.4-beta.3",
"version": "0.1.4-beta.4",
"description": "a engine lib for serverless-devs",
"main": "lib/index.js",
"scripts": {
Expand Down
10 changes: 7 additions & 3 deletions packages/engine/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,11 @@ class Engine {
each(this.options.env, (value, key) => {
process.env[key] = value;
});
const { steps: _steps } = this.spec;
const { steps: _steps, allSteps } = this.spec;
// 参数校验
await this.validate();
this.context.steps = await this.download(_steps);
this.context.allSteps = allSteps ? await this.download(allSteps) : [];
}

/**
Expand Down Expand Up @@ -118,6 +119,9 @@ class Engine {
this.context.steps = map(this.context.steps, item => {
return { ...item, stepCount: uniqueId(), status: STEP_STATUS.PENDING, done: false };
});
this.context.allSteps = map(this.context.allSteps, item => {
return { ...item, stepCount: uniqueId(), status: STEP_STATUS.PENDING, done: false };
});
const res: IContext = await new Promise(async resolve => {
// Every states object has two fixed states, "init" and "final".
const states: any = {
Expand Down Expand Up @@ -359,7 +363,7 @@ class Engine {
}
if (isEmpty(resourceNames)) return;
const resourcesItems: IStepOptions[] = map(Array.from(resourceNames), (name) => {
return this.context.steps.find((obj) => obj.projectName === name) as IStepOptions;
return this.context.allSteps.find((obj) => obj.projectName === name) as IStepOptions;
});
await Promise.all(map(resourcesItems, async (item) => {
if (!item) return;
Expand Down Expand Up @@ -389,7 +393,7 @@ class Engine {
__runtime: this.options.verify ? 'engine' : 'parse',
__steps: this.context.steps,
} as Record<string, any>;
for (const obj of this.context.steps) {
for (const obj of this.context.allSteps) {
data.resources[obj.projectName] = {
output: obj.output || {},
props: obj.props || {},
Expand Down
1 change: 1 addition & 0 deletions packages/engine/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export interface IContext {
error: IEngineError[]; // 记录step的错误信息
output: Record<string, any>; // 记录step的输出
credential: Record<string, any>; // 尝试获取到的密钥信息
allSteps: IStepOptions[]; // 记录所有step
}

export type IEngineError = Error | AssertionError | DevsError;
2 changes: 1 addition & 1 deletion packages/parse-spec/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@serverless-devs/parse-spec",
"version": "0.0.28-beta.3",
"version": "0.0.28-beta.4",
"description": "a parse yaml spec lib for serverless-devs",
"main": "lib/index.js",
"scripts": {
Expand Down
5 changes: 3 additions & 2 deletions packages/parse-spec/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,10 @@ class ParseSpec {
// 再次解析参数,比如projectNames
this.parseArgv();
if (!this.yaml.use3x) return this.v1();
const { steps, content, originSteps } = await new ParseContent(this.yaml.content, this.getParsedContentOptions(this.yaml.path)).start();
const { steps, content, originSteps, allSteps } = await new ParseContent(this.yaml.content, this.getParsedContentOptions(this.yaml.path)).start();
const services = get(this.yaml.content, 'services', {});
if (isEmpty(steps) && !isEmpty(services)) {
this.options.logger.tips('Check https://manual.serverless-devs.com/user-guide/spec/ for more details. Use the \'s cli fc3 s2tos3\' command for automatic YAML transformation.');
this.options.logger.tips('Check https://docs.serverless-devs.com/user-guide/spec/ for more details. Use the \'s cli fc3 s2tos3\' command for automatic YAML transformation.');
throw new DevsError(`Keyword 'services' has been replaced by 'resources' in 3.0.0 YAML.`, {
trackerType: ETrackerType.parseException,
});
Expand All @@ -221,6 +221,7 @@ class ParseSpec {
const result = {
steps: this.record.projectName ? steps : this.doFlow(steps, originSteps),
yaml: this.yaml,
allSteps: allSteps,
...this.record,
};
debug(`parse result: ${JSON.stringify(result)}`);
Expand Down
20 changes: 11 additions & 9 deletions packages/parse-spec/src/parse-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import path from 'path';
import getInputs from './get-inputs';
import { IStep } from './types';
import { getCredential } from './utils';
import { each, get, omit, set, pickBy, cloneDeep, isEmpty } from 'lodash';
import { each, get, omit, set, pickBy, cloneDeep, isEmpty, find } from 'lodash';
const compile = require('@serverless-devs/art-template/lib/devs-compile');
const extend2 = require('extend2');
const debug = require('@serverless-cd/debug')('serverless-devs:parse-spec');
Expand Down Expand Up @@ -78,11 +78,10 @@ class ParseContent {
...this.content,
...getInputs(rest, this.getCommonMagic()),
};
const steps = [];
const originSteps = [];
// projectName 存在,说明指定了项目
const temp = this.options.projectName ? { [this.options.projectName]: resources[this.options.projectName] } : resources;
for (const project in temp) {
// support resources.info, all steps are needed
const allSteps = [];
const allOriginSteps = [];
for (const project in resources) {
const element = resources[project];
const component = compile(get(element, 'component'), this.getCommonMagic());
let template = get(this.content.template, get(element, 'extend.name'), {});
Expand Down Expand Up @@ -114,22 +113,25 @@ class ParseContent {
[project]: real,
},
};
steps.push({
allSteps.push({
...real,
projectName: project,
component,
access,
credential: this.credential,
});
originSteps.push({
allOriginSteps.push({
...element,
projectName: project,
component,
access,
credential: this.credential,
});
}
return { steps, content: this.content, originSteps };
// projectName 存在,说明指定了项目
const steps = this.options.projectName ? [find(allSteps, (item) => item.projectName === this.options.projectName)] : allSteps;
const originSteps = this.options.projectName ? [find(allOriginSteps, (item) => item.projectName === this.options.projectName)] : allOriginSteps;
return { steps, content: this.content, originSteps, allSteps };
}
private getAccess() {
// 全局的 -a > env.yaml 的 access > s.yaml 的 access > default
Expand Down
1 change: 1 addition & 0 deletions packages/parse-spec/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export interface IYaml {
export type ISpec = IRecord & {
steps: IStep[];
yaml: IYaml;
allSteps?: IStep[];
};
export interface IRecord {
projectName?: string;
Expand Down

0 comments on commit 8f028b7

Please sign in to comment.