GithubHelp home page GithubHelp logo

react-native-unbundle's Introduction

react-native-unBundle

node build.js

build.js

var bundle = require('react-native-unBundle'),
    path = require('path'),
    program = require('commander'),
    fs = require('fs');


function toBool(val){
    try {
        return eval(val);
    }catch (e){

    }
}

function removeFileAll(path) {
    function remove(path,resolve,reject){
        if(fs.existsSync(path)) {
            let files = fs.readdirSync(path);
            files.forEach(function(file, index) {
                const curPath = path + "/" + file;
                fs.statSync(curPath).isDirectory() ? removeFileAll(curPath) : fs.unlinkSync(curPath);       // recurse
            });
            fs.rmdirSync(path);
            resolve(path)
        }else{
            reject(false);
        }
    }

    return new Promise((resolve, reject)=>{
        remove(path,resolve,reject)
    });
};

program
  .version('0.0.1')
    .option('-d, --dev <d>', 'debug', toBool,false )
    .option('-p, --platform <name>', 'Generate environment', 'android')
  .parse(process.argv);




const isIosBundle = program.platform === 'ios';

Promise.resolve()
.then(function () {
  return removeFileAll('build');
})
.then(function () {
  fs.mkdirSync('build');
  isIosBundle && fs.createWriteStream('build/main.jsbundle');
})
.then(function () {
  var path = require('path');
  return bundle(
    {
      dev: program.dev,
      transformer: require.resolve('react-native/packager/transformer'),
      platform: program.platform
    },
    {
      projectRoots: [__dirname],
      blacklistRE: require('react-native/packager/blacklist')()
    },
    {
      entries: `./index.${program.platform}.js`,
      filterEntryFile: function(path){
          var ret = false;

         if(path.indexOf('src') !=-1 && path.indexOf('node_modules') === -1 && path.indexOf(`index.${program.platform}.js`) === -1 && path.indexOf('app.js') === -1){
             ret = true;
         }
         return ret;
      },
      assetsDest: path.join(__dirname, '/build'),
      bundleOutput: function (entry) {
        const packageName = `/libs.${program.platform}.jsbundle`,
              pathJsBundle = isIosBundle ? `/ios${packageName}` : `/android/app/src/main/assets${packageName}`;

        return path.join(__dirname, pathJsBundle)
      },
      moduleBundleOutput: function (entry) {
        var name = 'common';
        if (entry) {
          name = path.basename(path.dirname(entry))
        }
        return path.join(__dirname, `/build/${name}.${program.platform}.jsbundle`)
      }
    }
  )
})
.catch(function (err) {
  console.log(err.stack)
})

react-native-unbundle's People

Contributors

mingkang1993 avatar allennzhang avatar

Stargazers

François Betscha avatar Suri avatar  avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.