index.js
function run(options) {
  let files, filePromises = [];
  files = options.args || [];

  for (let i = 0; i < files.length; i++) {
    let file = files[i];
    let filePath = path.resolve(cwd, file);

    if (!fs.existsSync(filePath)) {
      continue;
    }

    let stat = fs.statSync(filePath);
    let ext = path.extname(filePath);

    let isConvert = !options.revert && ext === '.ics'
    let isRevert = options.revert && ext === '.json'

    if (!stat.isFile() || (!isConvert && !isRevert)) {
      continue;
    }

    filePromises.push(Q.nfcall(fs.readFile, filePath)
    .then((buffer) => {
      let output;
      let data = buffer.toString();

      if (isConvert) {
        output = convert(data);
        output = JSON.stringify(output, null, "  ");
      } else if (isRevert) {
        output = revert(data);
      }

      let basename = path.basename(filePath, ext);
      let dirname = path.dirname(filePath);
      let compiledExt = isConvert ? '.json' : '.ics';
      let writePath = path.join(dirname, basename) + compiledExt;

      return Q.nfcall(fs.writeFile, writePath, output);
    })
    .fail((error) => {
      throw new Error(error);
    }));
  }

  return Q.all(filePromises);
}
function run(options) {
  let files, filePromises = [];
  files = options.args || [];

  for (let i = 0; i < files.length; i++) {
    let file = files[i];
    let filePath = path.resolve(cwd, file);

    if (!fs.existsSync(filePath)) {
      continue;
    }

    let stat = fs.statSync(filePath);
    let ext = path.extname(filePath);

    let isConvert = !options.revert && ext === '.ics'
    let isRevert = options.revert && ext === '.json'

    if (!stat.isFile() || (!isConvert && !isRevert)) {
      continue;
    }

    filePromises.push(Q.nfcall(fs.readFile, filePath)
    .then((buffer) => {
      let output;
      let data = buffer.toString();

      if (isConvert) {
        output = convert(data);
        output = JSON.stringify(output, null, "  ");
      } else if (isRevert) {
        output = revert(data);
      }

      let basename = path.basename(filePath, ext);
      let dirname = path.dirname(filePath);
      let compiledExt = isConvert ? '.json' : '.ics';
      let writePath = path.join(dirname, basename) + compiledExt;

      return Q.nfcall(fs.writeFile, writePath, output);
    })
    .fail((error) => {
      throw new Error(error);
    }));
  }

  return Q.all(filePromises);
}
function run ( options ) { let files , filePromises = [ ] ; files = options . args || [ ] ; for ( let i = 0 ; i < files . length ; i ++ ) { let file = files [ i ] ; let filePath = path . resolve ( cwd , file ) ; if ( ! fs . existsSync ( filePath ) ) { continue ; } let stat = fs . statSync ( filePath ) ; let ext = path . extname ( filePath ) ; let isConvert = ! options . revert && ext === '.ics' let isRevert = options . revert && ext === '.json' if ( ! stat . isFile ( ) || ( ! isConvert && ! isRevert ) ) { continue ; } filePromises . push ( Q . nfcall ( fs . readFile , filePath ) . then ( ( buffer ) => { let output ; let data = buffer . toString ( ) ; if ( isConvert ) { output = convert ( data ) ; output = JSON . stringify ( output , null , "  " ) ; } else if ( isRevert ) { output = revert ( data ) ; } let basename = path . basename ( filePath , ext ) ; let dirname = path . dirname ( filePath ) ; let compiledExt = isConvert ? '.json' : '.ics' ; let writePath = path . join ( dirname , basename ) + compiledExt ; return Q . nfcall ( fs . writeFile , writePath , output ) ; } ) . fail ( ( error ) => { throw new Error ( error ) ; } ) ) ; } return Q . all ( filePromises ) ; }
Pass in options to parse and generate JSON files
@param {Object} options
@return {Promise}
Pass in options to parse and generate JSON files