Skip to content

Commit

Permalink
feat!: only use env component after being manually set (#820)
Browse files Browse the repository at this point in the history
* feat!: only use env component after being manually set

Signed-off-by: zxypro1 <1018995004@qq.com>

* update version

Signed-off-by: zxypro1 <1018995004@qq.com>

* security update

Signed-off-by: zxypro1 <1018995004@qq.com>

---------

Signed-off-by: zxypro1 <1018995004@qq.com>
  • Loading branch information
zxypro1 committed Apr 24, 2024
1 parent aa9e1f4 commit 38392d8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@serverless-devs/s",
"version": "3.0.7",
"version": "3.0.8",
"description": "Serverless devs tool, serverless developer tool, supports Alibaba cloud, AWS, azure, baidu cloud, Huawei cloud, Google cloud and Tencent cloud.",
"homepage": "https://www.serverless-devs.com",
"keywords": [
Expand Down
16 changes: 11 additions & 5 deletions src/command/env/command/init/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { ENVIRONMENT_FILE_NAME, ENVIRONMENT_FILE_PATH } from '@serverless-devs/p
import * as utils from '@serverless-devs/utils';
import Credential from '@serverless-devs/credential';
import inquirerPrompt from 'inquirer-autocomplete-prompt';
import { ENV_COMPONENT_KEY } from '@/command/env/constant';
import { ENV_KEYS } from '@/command/env/constant';
import { runEnvComponent } from '@/utils';
import chalk from 'chalk';
Expand All @@ -26,6 +27,7 @@ class Action {
// initialize the basic information of the environment
const { deployInfraStack, ...basicInfo } = await this.getBasicInfo();
const { access, template } = basicInfo;
const { template: t, ...envBasicInfo } = basicInfo;
if (!basicInfo.project) {
const { project } = utils.getYamlContent(template);
basicInfo.project = project;
Expand Down Expand Up @@ -60,6 +62,7 @@ class Action {
const { project: p, ...rest } = await runEnvComponent(inputs, access);
const result = {
access,
...envBasicInfo,
...rest,
};
// 追加内容
Expand All @@ -76,7 +79,7 @@ class Action {
private getPromptOptions() {
const credential = new Credential({ logger });
const access = Object.keys(credential.getAll());
return [
const promptOptions: any[] = [
{
type: 'input',
message: 'Please specify the manifest file of the environment:',
Expand Down Expand Up @@ -162,13 +165,16 @@ class Action {
return access;
},
},
{
];
if (utils.getGlobalConfig(ENV_COMPONENT_KEY)) {
promptOptions.push({
type: 'confirm',
name: 'deployInfraStack',
message: 'Do you want to apply InfraStack now?',
message: 'Do you want to apply InfraStack now? (supported by vendors)',
default: false,
},
];
});
}
return promptOptions;
}
private async getBasicInfo() {
if (this.options.name) {
Expand Down
5 changes: 3 additions & 2 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import yaml from 'js-yaml';
const pkg = require('../../package.json');
import * as utils from '@serverless-devs/utils';
import loadComponent from '@serverless-devs/load-component';
import { ENV_COMPONENT_KEY, ENV_COMPONENT_NAME } from '@/command/env/constant';
import { ENV_COMPONENT_KEY } from '@/command/env/constant';
import Credential from '@serverless-devs/credential';
import { IEnvArgs } from '@/type';
import stripAnsi from 'strip-ansi';
Expand Down Expand Up @@ -120,7 +120,8 @@ export const showOutput = (data: any) => {

// 运行环境组件
export const runEnvComponent = async (args: IEnvArgs, access: any) => {
const componentName = utils.getGlobalConfig(ENV_COMPONENT_KEY, ENV_COMPONENT_NAME);
const componentName = utils.getGlobalConfig(ENV_COMPONENT_KEY);
if (!componentName) return {};
const componentLogger = logger.loggerInstance.__generate(componentName);
const instance = await loadComponent(componentName, { logger: componentLogger });

Expand Down

0 comments on commit 38392d8

Please sign in to comment.