mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-09-17 23:36:11 +08:00
working
This commit is contained in:
14
local-cli/.babelrc
Normal file
14
local-cli/.babelrc
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"plugins": [
|
||||
"syntax-object-rest-spread",
|
||||
"syntax-async-functions",
|
||||
"transform-es2015-arrow-functions",
|
||||
"transform-async-to-generator",
|
||||
"transform-es2015-modules-commonjs",
|
||||
"transform-es2015-destructuring",
|
||||
"transform-es2015-spread",
|
||||
"transform-object-rest-spread",
|
||||
"transform-es2015-parameters",
|
||||
"transform-strict-mode"
|
||||
]
|
||||
}
|
@@ -17,8 +17,41 @@
|
||||
},
|
||||
"help": {
|
||||
|
||||
},
|
||||
"use": {
|
||||
"description": "Select app created on web and create token for future release."
|
||||
},
|
||||
"build": {
|
||||
"description": "Bundle javascript and copy assets."
|
||||
},
|
||||
"bundle": {
|
||||
"description": "Bundle javascript code only."
|
||||
},
|
||||
"release": {
|
||||
"description": "Push builded file to server."
|
||||
}
|
||||
},
|
||||
"globalOptions":{
|
||||
"dev": {
|
||||
"default": false
|
||||
},
|
||||
"platform": {
|
||||
"hasValue": true
|
||||
},
|
||||
"entryFile": {
|
||||
"default": "index.${platform}.js",
|
||||
"hasValue": true
|
||||
},
|
||||
"intermediaDir": {
|
||||
"default": "build/intermedia/${platform}",
|
||||
"hasValue": true
|
||||
},
|
||||
"output": {
|
||||
"default": "build/output/${platform}.ppk",
|
||||
"hasValue": true
|
||||
},
|
||||
"verbose": {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,28 +1,4 @@
|
||||
/**
|
||||
* Created by tdzl2003 on 2/13/16.
|
||||
* Created by tdzl2003 on 2/22/16.
|
||||
*/
|
||||
|
||||
const {loadSession} = require('./api');
|
||||
const userCommands = require('./user').commands;
|
||||
|
||||
function printUsage({args}) {
|
||||
// const commandName = args[0];
|
||||
// TODO: print usage of commandName, or print global usage.
|
||||
|
||||
console.log('Usage is under development now.')
|
||||
console.log('Visit `https://github.com/reactnativecn/react-native-pushy` for early document.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const commands = {
|
||||
...userCommands,
|
||||
help: printUsage,
|
||||
};
|
||||
|
||||
exports.run = function () {
|
||||
const argv = require('cli-arguments').parse(require('./cli.json'));
|
||||
|
||||
loadSession()
|
||||
.then(()=>commands[argv.command](argv))
|
||||
.catch(err=>console.error(err.stack));
|
||||
};
|
||||
module.exports = require('./lib');
|
62
local-cli/src/bundle.js
Normal file
62
local-cli/src/bundle.js
Normal file
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* Created by tdzl2003 on 2/22/16.
|
||||
*/
|
||||
|
||||
import * as path from 'path';
|
||||
import { mkdir } from 'mkdir-recursive';
|
||||
import { getRNVersion } from './utils';
|
||||
|
||||
|
||||
export const commands = {
|
||||
bundle: async function({options}){
|
||||
const {
|
||||
entryFile,
|
||||
intermediaDir,
|
||||
platform,
|
||||
output,
|
||||
dev,
|
||||
verbose
|
||||
} = options;
|
||||
|
||||
if (!platform) {
|
||||
throw new Error('Platform must be specified.');
|
||||
}
|
||||
|
||||
const { version, major, minor} = getRNVersion();
|
||||
|
||||
console.log('Bundling with React Native version: ', version);
|
||||
|
||||
await new Promise((resolve, reject) => {
|
||||
mkdir(intermediaDir, err => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
require(path.resolve('node_modules/react-native/packager/babelRegisterOnly'))([
|
||||
/private-cli\/src/,
|
||||
/local-cli/,
|
||||
]);
|
||||
const Config = require(path.resolve('node_modules/react-native/local-cli/util/Config'));
|
||||
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'));
|
||||
|
||||
bundle([
|
||||
'--entry-file',
|
||||
entryFile,
|
||||
'--platform',
|
||||
platform,
|
||||
'--dev',
|
||||
'' + !!dev,
|
||||
'--bundle-output',
|
||||
`${intermediaDir}/index.bundlejs`,
|
||||
'--assets-dest',
|
||||
`${intermediaDir}/assets`,
|
||||
'--verbose',
|
||||
'' + !!verbose,
|
||||
], Config.get(path.resolve('node_modules/react-native/local-cli'), defaultConfig));
|
||||
}
|
||||
};
|
45
local-cli/src/index.js
Normal file
45
local-cli/src/index.js
Normal file
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* Created by tdzl2003 on 2/13/16.
|
||||
*/
|
||||
|
||||
const {loadSession} = require('./api');
|
||||
const userCommands = require('./user').commands;
|
||||
import {commands as bundleCommands} from './bundle';
|
||||
|
||||
function printUsage({args}) {
|
||||
// const commandName = args[0];
|
||||
// TODO: print usage of commandName, or print global usage.
|
||||
|
||||
console.log('Usage is under development now.')
|
||||
console.log('Visit `https://github.com/reactnativecn/react-native-pushy` for early document.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const commands = {
|
||||
...userCommands,
|
||||
...bundleCommands,
|
||||
help: printUsage,
|
||||
};
|
||||
|
||||
function translateOptions(options){
|
||||
for (let key in options) {
|
||||
const v = options[key];
|
||||
if (typeof(v) === 'string') {
|
||||
options[key] = v.replace(/\$\{(\w+)\}/, function (v, n){
|
||||
return options[n] || process.env[n] || v;
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exports.run = function () {
|
||||
const argv = require('cli-arguments').parse(require('../cli.json'));
|
||||
|
||||
translateOptions(argv.options);
|
||||
|
||||
loadSession()
|
||||
.then(()=>commands[argv.command](argv))
|
||||
.catch(err=>{setTimeout(()=>{
|
||||
throw err;
|
||||
})});
|
||||
};
|
@@ -2,7 +2,7 @@
|
||||
* Created by tdzl2003 on 2/13/16.
|
||||
*/
|
||||
|
||||
const {question} = require('./utils');
|
||||
import {question} from './utils';
|
||||
const {
|
||||
post,
|
||||
get,
|
28
local-cli/src/utils.js
Normal file
28
local-cli/src/utils.js
Normal file
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* Created by tdzl2003 on 2/13/16.
|
||||
*/
|
||||
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs';
|
||||
|
||||
var read = require('read');
|
||||
|
||||
export function question(query, password) {
|
||||
return new Promise((resolve, reject)=>read({
|
||||
prompt: query,
|
||||
silent: password,
|
||||
replace: password ? '*' : undefined,
|
||||
}, (err, result)=> err ? reject(err) : resolve(result)));
|
||||
}
|
||||
|
||||
export function getRNVersion() {
|
||||
const version = JSON.parse(fs.readFileSync(path.resolve('node_modules/react-native/package.json'))).version;
|
||||
|
||||
// We only care about major and minor version.
|
||||
const match = /^(\d+)\.(\d+)\./.exec(version);
|
||||
return {
|
||||
version,
|
||||
major: match[1] | 0,
|
||||
minor: match[2] | 0,
|
||||
};
|
||||
}
|
@@ -1,13 +0,0 @@
|
||||
/**
|
||||
* Created by tdzl2003 on 2/13/16.
|
||||
*/
|
||||
|
||||
var read = require('read');
|
||||
|
||||
exports.question = function(query, password) {
|
||||
return new Promise((resolve, reject)=>read({
|
||||
prompt: query,
|
||||
silent: password,
|
||||
replace: password ? '*' : undefined,
|
||||
}, (err, result)=> err ? reject(err) : resolve(result)));
|
||||
}
|
Reference in New Issue
Block a user