lib/babel-compile.js
function compileFile(srcFullPath, saveOutFullPath, onlyCopy) {
  var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};

  var content = fs.readFileSync(srcFullPath, 'utf8');

  //when get file content empty, maybe file is locked
  if (!content) {
    return;
  }

  // only copy file content
  if (onlyCopy) {
    fse.copySync(srcFullPath, saveOutFullPath);
    return;
  }

  try {
    var startTime = Date.now();

    var data = compileByBabel(content, {
      filename: srcFullPath
      // sourceMaps: true,
      // sourceFileName: relativePath
    });

    var endTime = Date.now();

    if (options.debug) {
      console.log('Compile file ' + srcFullPath, 'Babel cost ' + (endTime - startTime) + ' ms');
    }

    // save file
    fse.outputFileSync(saveOutFullPath, data.code);

    return true;
  } catch (e) {
    console.error('compile file ' + srcFullPath + ' error', e);
  }

  return false;
}
function compileFile(srcFullPath, saveOutFullPath, onlyCopy) {
  var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};

  var content = fs.readFileSync(srcFullPath, 'utf8');

  //when get file content empty, maybe file is locked
  if (!content) {
    return;
  }

  // only copy file content
  if (onlyCopy) {
    fse.copySync(srcFullPath, saveOutFullPath);
    return;
  }

  try {
    var startTime = Date.now();

    var data = compileByBabel(content, {
      filename: srcFullPath
      // sourceMaps: true,
      // sourceFileName: relativePath
    });

    var endTime = Date.now();

    if (options.debug) {
      console.log('Compile file ' + srcFullPath, 'Babel cost ' + (endTime - startTime) + ' ms');
    }

    // save file
    fse.outputFileSync(saveOutFullPath, data.code);

    return true;
  } catch (e) {
    console.error('compile file ' + srcFullPath + ' error', e);
  }

  return false;
}
function compileFile ( srcFullPath , saveOutFullPath , onlyCopy ) { var options = arguments . length > 3 && arguments [ 3 ] !== undefined ? arguments [ 3 ] : { } ; var content = fs . readFileSync ( srcFullPath , 'utf8' ) ; //when get file content empty, maybe file is locked if ( ! content ) { return ; } // only copy file content if ( onlyCopy ) { fse . copySync ( srcFullPath , saveOutFullPath ) ; return ; } try { var startTime = Date . now ( ) ; var data = compileByBabel ( content , { filename : srcFullPath // sourceMaps: true, // sourceFileName: relativePath } ) ; var endTime = Date . now ( ) ; if ( options . debug ) { console . log ( 'Compile file ' + srcFullPath , 'Babel cost ' + ( endTime - startTime ) + ' ms' ) ; } // save file fse . outputFileSync ( saveOutFullPath , data . code ) ; return true ; } catch ( e ) { console . error ( 'compile file ' + srcFullPath + ' error' , e ) ; } return false ; }
compile single file

@param {String} srcFullPath
@param {String} saveOutFullPath
@param {Boolean} [onlyCopy]
@param {Object} [options]
@param {String} [options.debug] only for debug
compile single file