comparator = function (file1, file2) { var path1 = path.create(file1.path) var path2 = path.create(file2.path) var numericPath1 = parseInt(path1.basename(path1.extname()), 10) var numericPath2 = parseInt(path2.basename(path2.extname()), 10) var greater = numericPath1 > numericPath2 var same = numericPath1 === numericPath2 return same ? 0 : greater ? 1 : -1 }
return function loadMarkdown(data, file) { const templateName = data.template; if (!isNonEmptyString(templateName)) { throw new Error('Markdown loader expects data.template to be present'); } const templatePathParts = baseTemplatePathParts.concat(`${templateName}.hbs`.split('/')); let templateFile = Filepath.root(); templateFile = templateFile.append.apply(templateFile, templatePathParts); if (!templateFile.isFile()) { throw new Error(`Template at ${templateFile} must be a file`); } const fp = Filepath.create(file.path); return fp.read().then((text) => { const { content } = separateFrontMatter(text); let hydratedMarkdown; try { hydratedMarkdown = preTemplate(content)(data); } catch (err) { throw new StackedError( `Error "${err.message}" while executing template on markdown file ${file.path}`, err ); } let html = ''; try { html = marked(hydratedMarkdown); } catch (err) { throw new StackedError( `Error "${err.message}" while executing markdown for file ${file.path}`, err ); } const newData = Object.assign({}, data, { content: html }); return templateFile.read().then((templateSourceText) => { let utf8; try { utf8 = template(templateSourceText)(newData); } catch (err) { throw new StackedError( `Error "${err.message}" while executing template ${templateFile}`, err ); } return { buff: Buffer.from(utf8), mimeType: 'text/html' }; }); }); };
exports.run = function () { program .version(module.exports.version) .usage('[options] <gpxFile>') .option('-s, --split [value]', 'Split track by given point count', parseInt) .option('-w, --waypoints [value]', 'Make waypoint for every speciffied Km', parseInt) .option('-o, --output <value>', 'Converted GPX destination file', false) .option('-b, --backup', 'Do backup', false) .option('-d, --decimals [value]', 'Decimal digits precision for lat/long', parseInt) .option('-p, --postfix <value>', 'Postfix added to converted file name', '-split') .option('--noNameFix', 'Do not shorten track name', false) .option('--noSplit', 'Do not split track') .option('--noWaypoints', 'Do not make waypoints') .action(function (gpxFile) { fileToProcess = gpxFile; }) .parse(process.argv); //---------------------------------------------------------------------- program.fileToProcess = fileToProcess; program.version = module.exports.version; //---------------------------------------------------------------------- if (!program.fileToProcess) { console.log(chalk.underline.yellow("Please specify GPX file to process")); program.outputHelp(); process.exit(); } else { var file = filepath.create(program.fileToProcess); if (!file.exists()) { console.log(chalk.underline.yellow("Specified input GPX file does not exists! ") + chalk.white(program.fileToProcess)); process.exit(); } console.log(chalk.green("Splitting file: ") + chalk.white(program.fileToProcess)); var spliter = new GpxSplit(program); Q.fcall(spliter.read.bind(spliter)) .then(spliter.process.bind(spliter)) .then(spliter.save.bind(spliter)) .done(); } }
return function createTemplateEngine(app, config) { const hbs = Handlebars.create(); const defaultOptions = options.defaultOptions || {}; if (isNonEmptyString(options.partials)) { const dir = Filepath.create(options.partials); if (!dir.isDirectory()) { throw new Error(`options.partials "${options.partials}" must be a directory path.`); } const basePartsLength = dir.split().length; dir.recurse((listing) => { if (listing.isFile()) { const parts = listing.dir().split().slice(basePartsLength); parts.push(listing.basename('.hbs')); const name = parts.join('/'); const source = listing.read({ sync: true }); hbs.registerPartial(name, source); } }); } if (options.helpers) { Object.entries(options.helpers).forEach(([ key, createHelper ]) => { hbs.registerHelper(key, createHelper(app, config)); }); } return function compileTemplate(rawText, opts = {}) { return hbs.compile(rawText, mergeDeep(opts, defaultOptions)); }; };
exports.run = function (script, task) { require(filepath.create(script).toString()); return treadmill.run(task); };
isNonEmptyString } = require('./lib/utils'); const CONFIG = require('./config'); const commands = { path(argv) { const [ fp ] = argv; if (!isNonEmptyString(fp)) { throw new Error('Command "path" expects argv[0] to be a path string'); } const entry = Filepath.create(fp); const pipe = CONFIG.pipes.filter(({ test }) => { return test.test(entry.path); })[0]; if (!pipe) { throw new Error(`No pipe for entry path ${entry}`); } const loaders = pipe.loaders.map(({ test, loader }) => { return { test, load: loader(null, CONFIG) }; }); const seed = {};