UNPKG

@ainc/script

Version:

Script compiler for typescript

32 lines 1.12 kB
/** ***************************************** * Created by edonet@163.com * Created on 2022-01-01 20:45:29 ***************************************** */ 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.json = void 0; /** ***************************************** * 加载依赖 ***************************************** */ const fs = require("fs"); const stripBOM_1 = require("@ainc/fs/dist/helpers/stripBOM"); const stripComments_1 = require("@ainc/fs/dist/helpers/stripComments"); /** ***************************************** * 解析【JSON】文件 ***************************************** */ function json(script, filename) { const names = ['tsconfig.json', 'jsconfig.json', '.config.json', 'rc.json']; const jsonc = !!names.find(name => filename.endsWith(name)); const code = fs.readFileSync(filename, 'utf8'); const normalized = jsonc ? (0, stripComments_1.stripComments)(code) : (0, stripBOM_1.stripBOM)(code); // 解析内容 script.exports = JSON.parse(normalized.trim() || '{}'); } exports.json = json; //# sourceMappingURL=json.js.map