Code coverage report for src/api.js

Statements: 83.33% (15 / 18)      Branches: 75% (9 / 12)      Functions: 100% (1 / 1)      Lines: 83.33% (15 / 18)      Ignored: none     

All files » src/ » api.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44    1 1 1 1 1               1         6 6   6         6 6 1   6 1         1            
'use strict';
 
var fs = require('fs');
var path = require('path');
var chalk = require('chalk');
var reactTemplates = require('./reactTemplates');
var convertTemplateToReact = reactTemplates.convertTemplateToReact;
 
/**
 * @param {string} source
 * @param {{modules:string, dryRun:boolean}?} options
 * @param {string} target
 * @param {CONTEXT} context
 */
function convertFile(source, target, options, context) {
//    if (path.extname(filename) !== ".html") {
//        console.log('invalid file, only handle html files');
//        return;// only handle html files
//    }
    options = options || {};
    var fsUtil = require('./fsUtil');
 
    Iif (!options.force && !fsUtil.isStale(source, target)) {
        context.info('target file ' + chalk.cyan(target) + ' is up to date, skipping');
        return;
    }
 
    var html = fs.readFileSync(source).toString();
    if (options.modules === 'none' && !options.name) {
        options.name = reactTemplates.normalizeName(path.basename(source, path.extname(source))) + 'RT';
    }
    var js = convertTemplateToReact(html, options);
    Iif (!options.dryRun) {
        fs.writeFileSync(target, js);
    }
}
 
module.exports = {
//    convertTemplateToReact: convertTemplateToReact,
    convertFile: convertFile,
    context: require('./context'),
    _test: {}
};