
Security News
GitHub Actions Checkout Now Blocks Risky pull_request_target Checkouts
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.
cocos-pkgjson
Advanced tools
a pkgJson tool, convert plist file to json data. It can be custom pkgLoader used directly
a pkgJson tool, convert plist file to json data. It can be custom pkgLoader used directly
这是一个用于生成pkgJson的工具:将.plist文件中的数据提取出来,生成cocos底层SpriteFrame的数据结构,这样在加载.pkgJson之后,使用cc._pkgJsonLoader即可直接使用数据。避免了像在加载plist文件后,还需要解析plist数据才能生成底层需要的结构。简单言之:将解析plist的数据提前,减少网络请求,加快数据获取。
有这个想法写这个工具也是由于看到了这篇文章:cc.spriteFrameCache 改造说明,但是官方并没有提供pkgJson文件的生成方式,而且个人在生成pkgJson的同时,也在官方的原基础做了一次优化,生成的pkgJson一次到位,cc._pkgJsonLoader只负责将数据存储在cc.loader.cache中即可。
parse spriteFrame
parse plist content to json
Install using npm:
npm i cocos-pkgjson
Then require() the cocos-pkgjson module in your file:
const fs = require('fs');
const pkgJson = require('cocos-pkgjson');
// Here I use fs.readFileSync get .plist file content
let content = fs.readFileSync("test.plist", "utf8");
console.log(JSON.stringify(pkgJson.parse(content)));
/**
* content: Data to be parse
* type: type of parse
* "frame": parse spriteFrame, default
* "other": only parse content to Json
*/
parse(content, type);
String result:
{"_inited":true,"frames":{"0.png":{"rect":{"x":1,"y":55,"width":64,"height":49},"rotated":false,"offset":{"x":0,"y":0},"size":{"width":64,"height":49},"aliases":[]},"1.png":{"rect":{"x":1,"y":1,"width":67,"height":52},"rotated":false,"offset":{"x":0,"y":0},"size":{"width":67,"height":52},"aliases":[]}},"meta":{"image":"radio.png"}}
Json result:

cc._pkgJsonLoader = {
load: function (realUrl, url, res, cb) {
var self = this, locLoader = cc.loader, cache = locLoader.cache;
locLoader.loadJson(realUrl, function (err, pkg) {
if (err) return cb(err);
var dir = cc.path.dirname(url);
for (var key in pkg) {
var filePath = cc.path.join(dir, key);
cache[filePath] = pkg[key];
}
cb(null, true);
});
}
};
cc.loader.register(["pkgJson"], cc._pkgJsonLoader);
FAQs
a pkgJson tool, convert plist file to json data. It can be custom pkgLoader used directly
The npm package cocos-pkgjson receives a total of 6 weekly downloads. As such, cocos-pkgjson popularity was classified as not popular.
We found that cocos-pkgjson demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.

Product
Socket MCP now lets AI assistants review org alerts, investigate threats using the Socket threat feed, and inspect package files in addition to dependency scoring.