1
0
Code Issues Pull Requests Packages Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
tdzl2003 2016-02-23 00:36:23 +08:00
parent 8bc608581c
commit 56495062c4
16 changed files with 254 additions and 63 deletions

29
.eslintrc Normal file
View File

@ -0,0 +1,29 @@
{
"extends": "eslint-config-airbnb/base",
"parser": "babel-eslint",
"env": {
"browser": true,
"node": true,
"mocha": true
},
"rules": {
// Disable for console/alert
"no-console": 0,
"no-alert": 0,
"indent": [2, 2, {"SwitchCase": 1}]
},
"plugins": [
"import"
],
"settings": {
"import/parser": "babel-eslint",
"import/resolve": {
"moduleDirectory": ["node_modules", "src"]
}
},
"globals": {
"__DEV__": true,
"__OPTION__": true
}
}

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
/.idea
/node_modules
/local-cli/lib
/react-native-pushy-cli/node_modules
/react-native-pushy-cli/lib

7
.npmignore Normal file
View File

@ -0,0 +1,7 @@
/.idea
/.babelrc
/.npmignore
/.eslintrc
/.nvmrc
/.travis.yml
/local-cli/src

14
local-cli/.babelrc Normal file
View 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"
]
}

View File

@ -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": {
}
}
}
}

View File

@ -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
View 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
View 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;
})});
};

View File

@ -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
View 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,
};
}

View File

@ -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)));
}

View File

@ -0,0 +1,6 @@
{
"plugins": [
"transform-es2015-modules-commonjs",
"transform-strict-mode"
]
}

View File

@ -0,0 +1,7 @@
/.idea
/src
/.babelrc
/.npmignore
/.eslintrc
/.nvmrc
/.travis.yml

View File

@ -4,10 +4,11 @@
"description": "Command tools for javaScript updater with `pushy` service for react native apps.",
"main": "index.js",
"bin": {
"pushy": "cli.js"
"pushy": "lib/cli.js"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"prepublish": "node_modules/.bin/babel src --out-dir lib"
},
"repository": {
"type": "git",
@ -25,7 +26,9 @@
"url": "https://github.com/reactnativecn/react-native-pushy/issues"
},
"homepage": "https://github.com/reactnativecn/react-native-pushy/tree/master/react-native-pushy-cli",
"dependencies": {
"babel-register": "^6.5.2"
"devDependencies": {
"babel-cli": "^6.5.1",
"babel-plugin-transform-es2015-modules-commonjs": "^6.5.2",
"babel-plugin-transform-strict-mode": "^6.5.2"
}
}

View File

@ -3,11 +3,10 @@
* Created by tdzl2003 on 2/13/16.
*/
var path = require('path');
var fs = require('fs');
import * as path from 'path';
import * as fs from 'fs-promise';
var CLI_MODULE_PATH = function() {
const CLI_MODULE_PATH = function() {
return path.resolve(
process.cwd(),
'node_modules',
@ -16,7 +15,7 @@ var CLI_MODULE_PATH = function() {
);
};
var PACKAGE_JSON_PATH = function() {
const PACKAGE_JSON_PATH = function() {
return path.resolve(
process.cwd(),
'node_modules',
@ -27,18 +26,8 @@ var PACKAGE_JSON_PATH = function() {
checkForVersionCommand();
require('babel-register')({
'plugins': [
'transform-async-to-generator',
'transform-strict-mode',
'transform-object-rest-spread',
'transform-es2015-parameters',
'transform-es2015-destructuring',
],
});
var cli;
var cliPath = CLI_MODULE_PATH();
let cli;
const cliPath = CLI_MODULE_PATH();
if (fs.existsSync(cliPath)) {
cli = require(cliPath);
}
@ -53,7 +42,7 @@ if (cli) {
function checkForVersionCommand() {
if (process.argv.indexOf('-v') >= 0 || process.argv[2] === 'version') {
console.log('react-native-pushy-cli: ' + require('./package.json').version);
console.log('react-native-pushy-cli: ' + require('../package.json').version);
try {
console.log('react-native-pushy: ' + require(PACKAGE_JSON_PATH()).version);
} catch (e) {