Skip to content

Commit 18c1be5

Browse files
authored
Pre 0.1.56 (#103)
1 parent 19a0115 commit 18c1be5

13 files changed

Lines changed: 133 additions & 35 deletions

File tree

.vscode/launch.json

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,14 @@
7878
"name": "s deploy",
7979
"type": "node",
8080
"request": "launch",
81-
"runtimeExecutable": "/Users/shihuali/workspace/s/bin/s",
81+
"runtimeExecutable": "${userHome}/workspace/devs/s/bin/s",
8282
"runtimeArgs": [
8383
"deploy",
8484
"-y",
8585
"--use-local",
8686
"-t",
8787
"d.yaml",
88-
// "--debug"
88+
"--debug"
8989
],
9090
"console": "integratedTerminal",
9191
"cwd": "${workspaceFolder}/test/fixtures/start-fc-http-nodejs12",
@@ -97,13 +97,13 @@
9797
"name": "global actions",
9898
"type": "node",
9999
"request": "launch",
100-
"runtimeExecutable": "/Users/shihuali/workspace/s/bin/s",
100+
"runtimeExecutable": "${userHome}/workspace/devs/s/bin/s",
101101
"runtimeArgs": [
102102
"deploy",
103103
"-y",
104104
"--use-local",
105105
"-t",
106-
"a.yaml"
106+
"s.yaml"
107107
],
108108
"console": "integratedTerminal",
109109
"cwd": "${workspaceFolder}/test/fixtures/start-fc-http-nodejs14",
@@ -115,7 +115,7 @@
115115
"name": "s -h",
116116
"type": "node",
117117
"request": "launch",
118-
"runtimeExecutable": "/Users/shihuali/workspace/s/bin/s",
118+
"runtimeExecutable": "${userHome}/workspace/devs/s/bin/s",
119119
"runtimeArgs": [
120120
"-h",
121121
],
@@ -129,7 +129,7 @@
129129
"name": "s init",
130130
"type": "node",
131131
"request": "launch",
132-
"runtimeExecutable": "/Users/shihuali/workspace/s/bin/s",
132+
"runtimeExecutable": "${userHome}/workspace/devs/s/bin/s",
133133
"runtimeArgs": [
134134
"init",
135135
"start-fc-event-java8",
@@ -148,7 +148,7 @@
148148
"name": "s verify",
149149
"type": "node",
150150
"request": "launch",
151-
"runtimeExecutable": "/Users/shihuali/workspace/s/bin/s",
151+
"runtimeExecutable": "${userHome}/workspace/devs/s/bin/s",
152152
"runtimeArgs": [
153153
"verify",
154154
],
@@ -157,6 +157,22 @@
157157
"skipFiles": [
158158
"<node_internals>/**",
159159
]
160+
},
161+
{
162+
"name": "this.name",
163+
"type": "node",
164+
"request": "launch",
165+
"runtimeExecutable": "${userHome}/workspace/devs/s/bin/s",
166+
"runtimeArgs": [
167+
"deploy",
168+
"-t",
169+
"a.pre.yaml"
170+
],
171+
"console": "integratedTerminal",
172+
"cwd": "${workspaceFolder}/test/fixtures/start-fc-event-nodejs14",
173+
"skipFiles": [
174+
"<node_internals>/**",
175+
]
160176
}
161177
]
162178
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@serverless-devs/core",
3-
"version": "0.1.55",
3+
"version": "0.1.56",
44
"description": "Serverless Devs Tool Core Component",
55
"keywords": [
66
"Serverless",

publish.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Type: Component
22
Name: core
33
Provider:
44
- 阿里云
5-
Version: 0.1.55
5+
Version: 0.1.56
66
Description: Serverless Devs 核心组件
77
HomePage: https://github.com/Serverless-Devs/core
88
Tags: #标签详情

src/common/constant.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ export const FC_COMPONENT = [
2929

3030
export const COMMON_VARIABLE_TYPE_REG = new RegExp(/\$\{(.*?)\}/, 'g');
3131

32+
export const SPECIALL_VARIABLE_TYPE_REG = new RegExp(/(.*)\((.*)\)/, 'i');
33+
3234
export const ALIYUN_CLI = '${aliyun-cli}';
3335

3436
export const RANDOM_PATTERN = '${default-suffix}';

src/common/downloadRequest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ async function download(url: string, dest: string, options: IOptions = {}) {
4141
file.on('open', () => {
4242
let spin: Ora;
4343
if (getCicdEnv() === 'app_center') {
44-
logger.log(chalk.gray('Downloading...'));
44+
logger.log(`Downloading[${chalk.green(decodeURIComponent(uri.pathname))}]...`);
4545
} else {
4646
spin = spinner(`Downloading: [${chalk.green(decodeURIComponent(uri.pathname))}]`);
4747
}

src/common/execCommand/globalActions/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import fs from 'fs-extra';
2-
import { getActions } from '../utils';
2+
import { getActions, getCurrentPath } from '../utils';
33
import {
44
IActionHook,
55
IGlobalAction,
@@ -115,7 +115,9 @@ class GlobalActions {
115115
}
116116

117117
if (configs.type === 'plugin') {
118-
const instance = await loadComponent(configs.value);
118+
const { spath } = this.config;
119+
const newValue = getCurrentPath(configs.value, spath);
120+
const instance = await loadComponent(fs.existsSync(newValue) ? newValue : configs.value);
119121
const inputs: IGlobalInputs = await this.getInputs();
120122
await instance({ ...inputs, ...this.record }, configs.args);
121123
}

src/common/execCommand/parse.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ import { getCurrentPath } from './utils';
44
import path from 'path';
55
import yaml from 'js-yaml';
66
import { ICredentials } from './interface';
7-
import { COMMON_VARIABLE_TYPE_REG } from '../constant';
7+
import { COMMON_VARIABLE_TYPE_REG, SPECIALL_VARIABLE_TYPE_REG } from '../constant';
88
import { HumanWarning } from '../error';
99

10-
const SPECIALL_VARIABLE_TYPE_REG = new RegExp(/(.*)\((.*)\)/, 'i');
11-
1210
const OTHER_BASIC_DATA_TYPE = ['[object Number]', '[object Boolean]'];
1311

1412
export default class Parse {
@@ -50,7 +48,10 @@ export default class Parse {
5048
if (!isNil(this.globalJsonKeyMap[`services.${variableName}`]))
5149
return this.globalJsonKeyMap[`services.${variableName}`];
5250
const newVariableName = `\${${variableName}}`;
53-
!includes(this.unparsedField, newVariableName) && this.unparsedField.push(newVariableName);
51+
const shouldCollect = startsWith(variableName, 'env.') || startsWith(variableName, 'vars.');
52+
if (shouldCollect && !includes(this.unparsedField, newVariableName)) {
53+
this.unparsedField.push(newVariableName);
54+
}
5455
return newVariableName;
5556
}
5657
if (type === 'Fun' && (funName === 'Env' || funName === 'env')) {

src/common/execCommand/utils.ts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isEmpty, get, assign, keys, split, filter, join, includes } from 'lodash';
1+
import { isEmpty, get, assign, keys, split, filter, join, includes, replace } from 'lodash';
22
import path from 'path';
33
import {
44
IProjectConfig,
@@ -11,6 +11,7 @@ import {
1111
} from './interface';
1212
import { makeUnderLine } from '../../libs';
1313
import { logger } from '../../logger';
14+
import { COMMON_VARIABLE_TYPE_REG, SPECIALL_VARIABLE_TYPE_REG } from '../constant';
1415
import chalk from 'chalk';
1516

1617
export function humanWarning(tips: string) {
@@ -43,6 +44,21 @@ export function getCurrentPath(p: string = './', spath: string) {
4344
return p ? path.join(dir, p) : dir;
4445
}
4546

47+
function parseAction(actionKey: string, method: string) {
48+
const matchResult = replace(actionKey, COMMON_VARIABLE_TYPE_REG, '$1');
49+
const funMatchResult = matchResult.match(SPECIALL_VARIABLE_TYPE_REG);
50+
if (funMatchResult) {
51+
const [start, end] = split(funMatchResult[1], '-');
52+
if (end === 'regex') {
53+
const reg = new RegExp(funMatchResult[2]);
54+
return { action: start as IGlobalActionValue, success: reg.test(method) };
55+
}
56+
}
57+
const [start, end] = split(actionKey, '-');
58+
const action = start as IGlobalActionValue;
59+
return { action, success: end === method };
60+
}
61+
4662
export function getActions(configs: IProjectConfig, { method, spath }): IActionHook[] {
4763
function validate(hook: IActionHook): IActionType {
4864
if ('run' in hook && !('component' in hook) && !('plugin' in hook)) return 'run';
@@ -61,18 +77,17 @@ export function getActions(configs: IProjectConfig, { method, spath }): IActionH
6177
const keyList = keys(actions);
6278
for (const actionKey of keyList) {
6379
const hookList = actions[actionKey];
64-
if(isEmpty(hookList)) continue;
65-
const [start, end] = split(actionKey, '-');
66-
const action = start as IGlobalActionValue;
67-
if (end === method) {
80+
if (isEmpty(hookList)) continue;
81+
const { action, success } = parseAction(actionKey, method);
82+
if (success) {
6883
for (const hookDetail of hookList) {
6984
const type = validate(hookDetail);
7085
if (type === 'run') {
7186
const obj = {
7287
type,
7388
value: hookDetail[type],
7489
path: getCurrentPath(hookDetail.path, spath),
75-
pre: start === 'pre' ? true : false,
90+
pre: action === 'pre' ? true : false,
7691
action,
7792
};
7893
hooks.push(obj);
@@ -82,7 +97,7 @@ export function getActions(configs: IProjectConfig, { method, spath }): IActionH
8297
const obj = {
8398
type,
8499
value: hookDetail[type],
85-
pre: start === 'pre' ? true : false,
100+
pre: action === 'pre' ? true : false,
86101
action,
87102
};
88103
hooks.push(obj);
@@ -92,7 +107,7 @@ export function getActions(configs: IProjectConfig, { method, spath }): IActionH
92107
const obj = {
93108
type,
94109
value: hookDetail[type],
95-
pre: start === 'pre' ? true : false,
110+
pre: action === 'pre' ? true : false,
96111
action,
97112
args: hookDetail.args,
98113
};

src/daemon/constant.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module.exports = {
2-
DEFAULT_CORE_VERSION: '0.1.55',
2+
DEFAULT_CORE_VERSION: '0.1.56',
33
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
extend: a.yaml
2+
3+
vars:
4+
service:
5+
name: dankun-service-test
6+
description: '函数计算样例'

0 commit comments

Comments
 (0)