Skip to content

Commit e5c0901

Browse files
authored
fix: support sls yml override (#13)
1 parent 6608139 commit e5c0901

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

__tests__/parse.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,27 @@ inputs:
166166
});
167167
});
168168

169+
test(`should success parse ${filename} file override by slsOptions `, async () => {
170+
const res = parse({
171+
rootDir: __dirname,
172+
input: configFile,
173+
override: true,
174+
slsOptionsJson:
175+
'{"org": "orgDemo","app": "appDemo","stage": "dev","component": "express","name": "expressDemoTest","inputs":{"src":"./","region":"ap-guangzhou"}}',
176+
});
177+
expect(res).toEqual({
178+
org: 'orgDemo',
179+
app: 'appDemo',
180+
stage: 'dev',
181+
component: 'express',
182+
name: 'expressDemoTest',
183+
inputs: {
184+
src: './',
185+
region: 'ap-guangzhou',
186+
},
187+
});
188+
});
189+
169190
test(`should success parse ${filename} file using layerOptions`, async () => {
170191
const res = parse({
171192
rootDir: __dirname,

src/cli/parse.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ export function parse({
131131
slsOptionsJson = '{}',
132132
layerOptionsJson,
133133
component,
134+
override = false,
134135
debug = false,
135136
}: ParseOptions): AnyObject {
136137
let inputPath = '';
@@ -153,7 +154,9 @@ export function parse({
153154
}
154155

155156
const { data: parseObj, type } = readAndParse(inputPath, autoCreate);
156-
let slsOptions = mergeObject(parseObj, JSON.parse(slsOptionsJson));
157+
let slsOptions = override
158+
? JSON.parse(slsOptionsJson)
159+
: mergeObject(parseObj, JSON.parse(slsOptionsJson));
157160

158161
slsOptions = generateLayerYaml(rootDir, slsOptions, layerOptionsJson);
159162

src/typings/parse.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export interface ParseOptions {
77
layerOptionsJson?: string;
88
autoCreate?: boolean;
99
component?: string;
10+
override?: boolean;
1011
// debug mode
1112
debug?: boolean;
1213
}

0 commit comments

Comments
 (0)