@shuyun-ep-team/scripts
Version:
为项目提供相应的脚本,使其减少繁琐的配置。
37 lines • 1.51 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const camelcase_1 = __importDefault(require("camelcase"));
const decamelize_1 = __importDefault(require("decamelize"));
const json_1 = require("../src/utils/json");
function jsonCommentParser(data, plugin) {
const json = json_1.parseJson(data);
const commentedLines = data.match(/\s*\/\/\s*(.*)\n(.*?)[,\n]/gu) || [];
const commentMap = commentedLines
.map(str => {
const [, comment, prop] = str.trim().match(/\/\/\s*(.*?)\n\s*"(.*?)":/u) || [];
return { comment, prop };
})
.reduce((prev, { comment, prop }) => Object.assign(prev, {
[prop]: comment
}), {});
return Reflect.ownKeys(json).map(key => ({
prop: plugin && plugin.prop ? plugin.prop(key) : key,
val: json[key],
comment: plugin && plugin.comment && commentMap[key]
? plugin.comment(commentMap[key])
: commentMap[key]
}));
}
exports.jsonCommentParser = jsonCommentParser;
function propModifyVarsPlugin(prop) {
return decamelize_1.default(prop, '-').replace(/(\d+)/g, '-$1');
}
exports.propModifyVarsPlugin = propModifyVarsPlugin;
function propCamelcasePlugin(prop) {
return camelcase_1.default(prop, { pascalCase: true });
}
exports.propCamelcasePlugin = propCamelcasePlugin;
//# sourceMappingURL=json.js.map