working
This commit is contained in:
parent
8bc608581c
commit
56495062c4
29
.eslintrc
Normal file
29
.eslintrc
Normal 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
5
.gitignore
vendored
Normal 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
7
.npmignore
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
/.idea
|
||||||
|
/.babelrc
|
||||||
|
/.npmignore
|
||||||
|
/.eslintrc
|
||||||
|
/.nvmrc
|
||||||
|
/.travis.yml
|
||||||
|
/local-cli/src
|
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": {
|
"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":{
|
"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.
|
||||||
*/
|
*/
|
||||||
|
module.exports = require('./lib');
|
||||||
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));
|
|
||||||
};
|
|
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.
|
* Created by tdzl2003 on 2/13/16.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const {question} = require('./utils');
|
import {question} from './utils';
|
||||||
const {
|
const {
|
||||||
post,
|
post,
|
||||||
get,
|
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)));
|
|
||||||
}
|
|
6
react-native-pushy-cli/.babelrc
Normal file
6
react-native-pushy-cli/.babelrc
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"plugins": [
|
||||||
|
"transform-es2015-modules-commonjs",
|
||||||
|
"transform-strict-mode"
|
||||||
|
]
|
||||||
|
}
|
7
react-native-pushy-cli/.npmignore
Normal file
7
react-native-pushy-cli/.npmignore
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
/.idea
|
||||||
|
/src
|
||||||
|
/.babelrc
|
||||||
|
/.npmignore
|
||||||
|
/.eslintrc
|
||||||
|
/.nvmrc
|
||||||
|
/.travis.yml
|
@ -4,10 +4,11 @@
|
|||||||
"description": "Command tools for javaScript updater with `pushy` service for react native apps.",
|
"description": "Command tools for javaScript updater with `pushy` service for react native apps.",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
"pushy": "cli.js"
|
"pushy": "lib/cli.js"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"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": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -25,7 +26,9 @@
|
|||||||
"url": "https://github.com/reactnativecn/react-native-pushy/issues"
|
"url": "https://github.com/reactnativecn/react-native-pushy/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/reactnativecn/react-native-pushy/tree/master/react-native-pushy-cli",
|
"homepage": "https://github.com/reactnativecn/react-native-pushy/tree/master/react-native-pushy-cli",
|
||||||
"dependencies": {
|
"devDependencies": {
|
||||||
"babel-register": "^6.5.2"
|
"babel-cli": "^6.5.1",
|
||||||
|
"babel-plugin-transform-es2015-modules-commonjs": "^6.5.2",
|
||||||
|
"babel-plugin-transform-strict-mode": "^6.5.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,11 +3,10 @@
|
|||||||
* Created by tdzl2003 on 2/13/16.
|
* Created by tdzl2003 on 2/13/16.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var path = require('path');
|
import * as path from 'path';
|
||||||
var fs = require('fs');
|
import * as fs from 'fs-promise';
|
||||||
|
|
||||||
|
const CLI_MODULE_PATH = function() {
|
||||||
var CLI_MODULE_PATH = function() {
|
|
||||||
return path.resolve(
|
return path.resolve(
|
||||||
process.cwd(),
|
process.cwd(),
|
||||||
'node_modules',
|
'node_modules',
|
||||||
@ -16,7 +15,7 @@ var CLI_MODULE_PATH = function() {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
var PACKAGE_JSON_PATH = function() {
|
const PACKAGE_JSON_PATH = function() {
|
||||||
return path.resolve(
|
return path.resolve(
|
||||||
process.cwd(),
|
process.cwd(),
|
||||||
'node_modules',
|
'node_modules',
|
||||||
@ -27,18 +26,8 @@ var PACKAGE_JSON_PATH = function() {
|
|||||||
|
|
||||||
checkForVersionCommand();
|
checkForVersionCommand();
|
||||||
|
|
||||||
require('babel-register')({
|
let cli;
|
||||||
'plugins': [
|
const cliPath = CLI_MODULE_PATH();
|
||||||
'transform-async-to-generator',
|
|
||||||
'transform-strict-mode',
|
|
||||||
'transform-object-rest-spread',
|
|
||||||
'transform-es2015-parameters',
|
|
||||||
'transform-es2015-destructuring',
|
|
||||||
],
|
|
||||||
});
|
|
||||||
|
|
||||||
var cli;
|
|
||||||
var cliPath = CLI_MODULE_PATH();
|
|
||||||
if (fs.existsSync(cliPath)) {
|
if (fs.existsSync(cliPath)) {
|
||||||
cli = require(cliPath);
|
cli = require(cliPath);
|
||||||
}
|
}
|
||||||
@ -53,7 +42,7 @@ if (cli) {
|
|||||||
|
|
||||||
function checkForVersionCommand() {
|
function checkForVersionCommand() {
|
||||||
if (process.argv.indexOf('-v') >= 0 || process.argv[2] === 'version') {
|
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 {
|
try {
|
||||||
console.log('react-native-pushy: ' + require(PACKAGE_JSON_PATH()).version);
|
console.log('react-native-pushy: ' + require(PACKAGE_JSON_PATH()).version);
|
||||||
} catch (e) {
|
} catch (e) {
|
Loading…
Reference in New Issue
Block a user