reading settings from manifest

8 views
Skip to first unread message

Patrick Klug

unread,
Apr 11, 2013, 3:56:46 AM4/11/13
to node-...@googlegroups.com
Since node-webkit will already parse the manifest file, is there any way I can access the data from within my JS code?

Esa-Matti Suuronen

unread,
Apr 11, 2013, 3:59:00 AM4/11/13
to node-...@googlegroups.com
On Thu, Apr 11, 2013 at 10:56 AM, Patrick Klug <patric...@gmail.com> wrote:
> Since node-webkit will already parse the manifest file, is there any way I
> can access the data from within my JS code?

Just require it?

require("./package.json");


--
Esa-Matti Suuronen
esa-...@suuronen.org
http://esa-matti.suuronen.org

Chaobin Zhang

unread,
Apr 11, 2013, 4:01:16 AM4/11/13
to node-...@googlegroups.com
Please wait this pull request to merge: https://github.com/rogerwang/node-webkit/pull/559. Then you can use our js api to access it.

By the way, you can try read it using node fs module, or try Esa-Matti Suuronen's suggesstion.

HTH 


On Thu, Apr 11, 2013 at 3:56 PM, Patrick Klug <patric...@gmail.com> wrote:
Since node-webkit will already parse the manifest file, is there any way I can access the data from within my JS code?

--
You received this message because you are subscribed to the Google Groups "node-webkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-webkit...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
------------------
Best Regards 

----------------------------------------------------------------
@zhchbin Chaobin Zhang (张朝滨)

Patrick Klug

unread,
Apr 11, 2013, 4:03:18 AM4/11/13
to node-...@googlegroups.com
sounds great. thanks!

khebs trio

unread,
Apr 13, 2013, 4:30:16 AM4/13/13
to node-...@googlegroups.com
I did this, i have no idea yet if this works when it is compiled though:

/**
 * Get File Contents Sync Mode
 *
 * @param {string} path
 * @return {string}
 */
exports.getContents = function (path) {
var fs = require("fs"),
file = fs.readFileSync(path, "utf8");
return file;
};

/**
 * Get Package Content Info
 *
 * @param {string} path "core.language" = "en"
 * @param {string} defaultValue
 * @return {mixed}
 */
exports.getPackageInfo = function(path, defaultValue) {
var ioFile = require('system/io/File.js');
var d = JSON.parse(ioFile.getContents(process.cwd() + "/package.json"));
if (path != null) {
var segments = path.split('.'), 
o = d;

for (var prop in segments) {
if (o[segments[prop]]) {
o = o[segments[prop]];
} else {
o = null;
}
}

if (o === Object(o)) {
return o;

o = $.trim(o)
return o != "" ? o : defaultValue;
} else {
return d;
}
}; 
Reply all
Reply to author
Forward
0 new messages