-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add more test and fix stackname not pass issue #5
Signed-off-by: seven <[email protected]>
- Loading branch information
Showing
9 changed files
with
351 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import path from 'node:path'; | ||
import fs from 'node:fs'; | ||
import * as ros from '@alicloud/ros-cdk-core'; | ||
|
||
export const resolveCode = (location: string): string => { | ||
const filePath = path.resolve(process.cwd(), location); | ||
const fileContent = fs.readFileSync(filePath); | ||
|
||
return fileContent.toString('base64'); | ||
}; | ||
|
||
export const replaceVars = <T>(value: T, stage: string): T => { | ||
if (typeof value === 'string') { | ||
const matchVar = value.match(/^\$\{vars\.(\w+)}$/); | ||
const containsVar = value.match(/\$\{vars\.(\w+)}/); | ||
const matchMap = value.match(/^\$\{stages\.(\w+)}$/); | ||
const containsMap = value.match(/\$\{stages\.(\w+)}/); | ||
if (matchVar?.length) { | ||
return ros.Fn.ref(matchVar[1]) as T; | ||
} | ||
if (matchMap?.length) { | ||
return ros.Fn.findInMap('stages', '', matchMap[1]) as T; | ||
} | ||
if (containsMap?.length && containsVar?.length) { | ||
return ros.Fn.sub( | ||
value.replace(/\$\{stages\.(\w+)}/g, '${$1}').replace(/\$\{vars\.(\w+)}/g, '${$1}'), | ||
) as T; | ||
} | ||
if (containsVar?.length) { | ||
return ros.Fn.sub(value.replace(/\$\{vars\.(\w+)}/g, '${$1}')) as T; | ||
} | ||
if (containsMap?.length) { | ||
return ros.Fn.sub(value.replace(/\$\{stages\.(\w+)}/g, '${$1}')) as T; | ||
} | ||
return value; | ||
} | ||
|
||
if (Array.isArray(value)) { | ||
return value.map((item) => replaceVars(item, stage)) as T; | ||
} | ||
|
||
if (typeof value === 'object' && value !== null) { | ||
return Object.fromEntries( | ||
Object.entries(value).map(([key, val]) => [key, replaceVars(val, stage)]), | ||
) as T; | ||
} | ||
|
||
return value; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.