Teach tmtheme.js how to convert a non-built-in theme

You can now pass a .tmTheme file on the command line to have it converted.
This commit is contained in:
Adam Roben 2014-11-20 10:56:32 -05:00
commit f471e54ef0

View file

@ -282,9 +282,13 @@ var themes = {
"xcode": "Xcode_default"
};
function convertTheme(name) {
function convertBuiltinTheme(name) {
return convertTheme(name, __dirname + "/tmthemes/" + themes[name] + ".tmTheme", __dirname + "/../lib/ace/theme");
}
function convertTheme(name, tmThemePath, outputDirectory) {
console.log("Converting " + name);
var tmTheme = fs.readFileSync(__dirname + "/tmthemes/" + themes[name] + ".tmTheme", "utf8");
var tmTheme = fs.readFileSync(tmThemePath, "utf8");
parseTheme(tmTheme, function(theme) {
var styles = extractStyles(theme);
@ -305,7 +309,7 @@ function convertTheme(name) {
// this way, we preserve all hand-modified rules in the <theme>.css rules,
// (because some exist, for collab1 and ace_indentation_guide
try {
var outThemeCss = fs.readFileSync(__dirname + "/../lib/ace/theme/" + name + ".css");
var outThemeCss = fs.readFileSync(outputDirectory + "/" + name + ".css");
var oldRules = cssParse(outThemeCss).stylesheet.rules;
var newRules = cssParse(css).stylesheet.rules;
@ -342,13 +346,25 @@ function convertTheme(name) {
isDark: styles.isDark
});
fs.writeFileSync(__dirname + "/../lib/ace/theme/" + name + ".js", js);
fs.writeFileSync(__dirname + "/../lib/ace/theme/" + name + ".css", css);
fs.writeFileSync(outputDirectory + "/" + name + ".js", js);
fs.writeFileSync(outputDirectory + "/" + name + ".css", css);
})
}
for (var name in themes) {
convertTheme(name);
if (process.argv.length > 1) {
var args = process.argv.splice(2);
if (args.length < 3) {
console.error("Usage: node tmtheme.js [theme_name, path/to/theme.tmTheme path/to/output/directory]");
process.exit(1);
}
var name = args[0];
var themePath = args[1];
var outputDirectory = args[2];
convertTheme(name, themePath, outputDirectory);
} else {
for (var name in themes) {
convertBuiltinTheme(name);
}
}
var sortedUnsupportedScopes = {};