UNPKG

@serpent/common-cli

Version:

通用的 cli 相关的函数

24 lines (20 loc) 565 B
'use strict'; var fs = require('fs'); var context = require('./context-e98d804e.cjs'); /** * 获取 json 文件的内容,如果没有或者解析 json 失败则返回 undefined */ function tryReadJsonFile(absJsonPath) { if (context.existsFile(absJsonPath)) { try { return readJsonFile(absJsonPath); } catch (e) { } } return; } function readJsonFile(absJsonPath) { return JSON.parse(fs.readFileSync(absJsonPath).toString()); } exports.readJsonFile = readJsonFile; exports.tryReadJsonFile = tryReadJsonFile;