1
0
Code Issues Pull Requests Packages Projects Releases Wiki Activity GitHub Gitee

Done with pushy bundle

This commit is contained in:
tdzl2003 2016-02-23 13:17:46 +08:00
parent 56495062c4
commit 8408354320
3 changed files with 57 additions and 15 deletions

View File

@ -5,3 +5,4 @@
/.nvmrc /.nvmrc
/.travis.yml /.travis.yml
/local-cli/src /local-cli/src
/react-native-pushy-cli

View File

@ -3,9 +3,50 @@
*/ */
import * as path from 'path'; import * as path from 'path';
import { mkdir } from 'mkdir-recursive'; import { mkdir as mkdirRecurisve } from 'mkdir-recursive';
import { getRNVersion } from './utils'; import { getRNVersion } from './utils';
import * as fs from 'fs';
import * as tar from 'tar';
import fstream from 'fstream';
function mkdir(dir){
return new Promise((resolve, reject) => {
mkdirRecurisve(dir, err => {
if (err) {
reject(err);
} else {
resolve();
}
});
});
}
function pack(dir, output){
return mkdir(path.dirname(output))
.then(()=>{
return new Promise((resolve, reject) => {
const dest = fs.createWriteStream(output);
var packer = tar.Pack({
noProprietary: true,
fromBase: true,
})
.on('error', err => {
reject(err);
})
.on('end', () => {
resolve();
});
fstream.Reader({ path: dir, type: "Directory" })
.on('error', err => {
reject(err);
})
.pipe(packer)
.pipe(dest);
});
})
}
export const commands = { export const commands = {
bundle: async function({options}){ bundle: async function({options}){
@ -22,19 +63,13 @@ export const commands = {
throw new Error('Platform must be specified.'); throw new Error('Platform must be specified.');
} }
await mkdir(intermediaDir);
const { version, major, minor} = getRNVersion(); const { version, major, minor} = getRNVersion();
console.log('Bundling with React Native version: ', version); console.log('Bundling with React Native version: ', version);
await new Promise((resolve, reject) => { await mkdir(intermediaDir);
mkdir(intermediaDir, err => {
if (err) {
reject(err);
} else {
resolve();
}
});
});
require(path.resolve('node_modules/react-native/packager/babelRegisterOnly'))([ require(path.resolve('node_modules/react-native/packager/babelRegisterOnly'))([
/private-cli\/src/, /private-cli\/src/,
@ -44,7 +79,7 @@ export const commands = {
const bundle = require(path.resolve('node_modules/react-native/local-cli/bundle/bundle')); const bundle = require(path.resolve('node_modules/react-native/local-cli/bundle/bundle'));
const defaultConfig = require(path.resolve('node_modules/react-native/local-cli/default.config')); const defaultConfig = require(path.resolve('node_modules/react-native/local-cli/default.config'));
bundle([ await bundle([
'--entry-file', '--entry-file',
entryFile, entryFile,
'--platform', '--platform',
@ -54,9 +89,13 @@ export const commands = {
'--bundle-output', '--bundle-output',
`${intermediaDir}/index.bundlejs`, `${intermediaDir}/index.bundlejs`,
'--assets-dest', '--assets-dest',
`${intermediaDir}/assets`, `${intermediaDir}`,
'--verbose', '--verbose',
'' + !!verbose, '' + !!verbose,
], Config.get(path.resolve('node_modules/react-native/local-cli'), defaultConfig)); ], Config.get(path.resolve('node_modules/react-native/local-cli'), defaultConfig));
console.log('Packing');
await pack(intermediaDir, output);
} }
}; };

View File

@ -39,7 +39,9 @@ exports.run = function () {
loadSession() loadSession()
.then(()=>commands[argv.command](argv)) .then(()=>commands[argv.command](argv))
.catch(err=>{setTimeout(()=>{ .catch(err=>{
throw err; setTimeout(()=>{
})}); throw err;
});
});
}; };