コード例 #1
0
ファイル: index.js プロジェクト: perrin4869/gulp-redis-lua2js
    .then(lua => {
      const dirname = path.dirname(file.path);
      const basename = path.basename(file.path, path.extname(file.path));

      if (!{}.hasOwnProperty.call(options, 'name') && useFilenameAsName) {
        options.name = basename;
      }

      const js = lua2js(lua, options);

      if (file.isBuffer()) {
        newFile.contents = new Buffer(js);
      } else if (file.isStream()) {
        // start the transformation
        newFile.contents = through();
        newFile.contents.end(js);
      } else {
        throw new PluginError(PLUGIN_NAME, 'Invalid file');
      }

      newFile.path = path.join(dirname, `${basename}.js`);
      // make sure the file goes through the next gulp plugin
      this.push(newFile);

      cb();
    });
コード例 #2
0
  _hook('.lua', (source, filename) => {
    const options = {};
    if (useFilenameAsName) {
      options.name = path.basename(filename, path.extname(filename));
    }

    return lua2js(source, options);
  });