Created
May 28, 2016 18:15
-
-
Save timpulver/0d01285952b97deb70df6104cc316a4b to your computer and use it in GitHub Desktop.
Watches a markdown-folder for changes and re-generates .icml (InCopy / Adobe InDesign CC) files on every change
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var exec = require('child_process').exec; | |
var chokidar = require('chokidar'); | |
/* | |
* Watches a folder for changes in markdown (*.md) files and compiles them to ICML (Adobe InDesign CC / InCopy format) | |
* | |
* Dependencies: | |
* - Install Pandoc: pandoc.org | |
* - Run "npm install chokidar" | |
* | |
* Infos on how to use the files in InDesign: http://networkcultures.org/digitalpublishing/2014/10/08/markdown-to-indesign-with-pandoc-via-icml/ | |
* | |
* Run this script like this: | |
* - Navigate to the folder containing the script, e.g. "cd /Users/me/scripts" | |
* - Run the script: "node pandoc_watch.js" | |
*/ | |
// folder to watch, relative to working directory, change it to point | |
// to your markdown files, can be absolute as well | |
var folder = '../../Buch/Text'; | |
console.log('Watching folder ' + folder + ' for changes in markdown (*.md) files...'); | |
chokidar.watch(folder) | |
.on('change', handleFileChange); | |
function handleFileChange(file){ | |
var iExt = file.indexOf(".md"); | |
if(iExt === -1) { return; } | |
console.log('File ' + file + ' has changed, compiling to ICML...'); | |
var outputFile = file.substring(0, iExt) + ".icml"; | |
var cmd = 'pandoc -s -f markdown -t icml -o ' + outputFile + " " + file; | |
exec(cmd, function(error, stdout, stderr) { | |
if(error) { | |
console.log('Error converting document: ' + error); | |
} else { | |
console.log("Done."); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment