MCPcopy Create free account
hub / github.com/Serverless-Devs/Serverless-Devs / writeOutput

Function writeOutput

src/utils/write-out-put.ts:8–25  ·  view source on GitHub ↗
(data: Record<string, any>)

Source from the content-addressed store, hash-verified

6import prettyjson from 'prettyjson';
7
8const writeOutput = (data: Record<string, any>) => {
9 if (isEmpty(data)) return;
10 const argv = process.argv.slice(2);
11 const argvData = utils.parseArgv(argv);
12 const outputFile = get(argvData, 'output-file');
13 if (!outputFile) return;
14 const filePath = utils.getAbsolutePath(outputFile);
15 const output = get(argvData, 'output') || get(argvData, 'output-format');
16 const newMap = {
17 [IOutput.JSON]: JSON.stringify(data, null, 2),
18 [IOutput.YAML]: yaml.dump(data),
19 [IOutput.RAW]: JSON.stringify(data),
20 };
21 const defaultValue = prettyjson.render(data, { keysColor: 'bold', emptyArrayMsg: '[]' });
22 fs.writeFileSync(filePath, get(newMap, output, defaultValue), 'utf-8');
23 // 使用cat命令查看文件时,文件的末尾会显示一个%符号,可能是由于文件的最后一行缺少换行符(\n)导致的
24 fs.appendFileSync(filePath, '\n');
25};
26
27export default writeOutput;

Callers 6

index.tsFile · 0.90
doActionFunction · 0.90
execComponentFunction · 0.90
initMethod · 0.90
doExecCommandMethod · 0.90
index.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected