mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-12-27 18:40:28 +00:00
b768dc332b
Introducing new filters that can be used under Node.js
49 lines
1.2 KiB
JavaScript
49 lines
1.2 KiB
JavaScript
/*\
|
|
title: $:/core/modules/utils/edition-info.js
|
|
type: application/javascript
|
|
module-type: utils-node
|
|
|
|
Information about the available editions
|
|
|
|
\*/
|
|
(function(){
|
|
|
|
/*jslint node: true, browser: true */
|
|
/*global $tw: false */
|
|
"use strict";
|
|
|
|
var fs = require("fs"),
|
|
path = require("path");
|
|
|
|
var editionInfo;
|
|
|
|
exports.getEditionInfo = function() {
|
|
if(!editionInfo) {
|
|
// Enumerate the edition paths
|
|
var editionPaths = $tw.getLibraryItemSearchPaths($tw.config.editionsPath,$tw.config.editionsEnvVar);
|
|
editionInfo = {};
|
|
for(var editionIndex=0; editionIndex<editionPaths.length; editionIndex++) {
|
|
var editionPath = editionPaths[editionIndex];
|
|
// Enumerate the folders
|
|
var entries = fs.readdirSync(editionPath);
|
|
for(var entryIndex=0; entryIndex<entries.length; entryIndex++) {
|
|
var entry = entries[entryIndex];
|
|
// Check if directories have a valid tiddlywiki.info
|
|
if(!editionInfo[entry] && $tw.utils.isDirectory(path.resolve(editionPath,entry))) {
|
|
var info;
|
|
try {
|
|
info = JSON.parse(fs.readFileSync(path.resolve(editionPath,entry,"tiddlywiki.info"),"utf8"));
|
|
} catch(ex) {
|
|
}
|
|
if(info) {
|
|
editionInfo[entry] = info;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return editionInfo;
|
|
};
|
|
|
|
})();
|