-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: init * feat: init * fix: rename module * fix: init
- Loading branch information
1 parent
28e37e1
commit 6c28afa
Showing
19 changed files
with
353 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# EditorConfig is awesome: http://EditorConfig.org | ||
|
||
# top-most EditorConfig file | ||
root = true | ||
|
||
# Unix-style newlines with a newline ending every file | ||
[*] | ||
end_of_line = lf | ||
insert_final_newline = true | ||
indent_style = space | ||
indent_size = 2 | ||
trim_trailing_whitespace = true | ||
|
||
[*.gradle] | ||
indent_size = 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
node_modules | ||
lib | ||
dist | ||
build | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
extends: ['eslint-config-rax/react', 'eslint-config-rax/typescript'], | ||
globals: {}, | ||
rules: {} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
*~ | ||
*.swp | ||
.DS_Store | ||
npm-debug.log | ||
lerna-debug.log | ||
npm-debug.log* | ||
lib/ | ||
dist/ | ||
build/ | ||
coverage/ | ||
node_modules/ | ||
examples/test | ||
.idea/ | ||
yarn.lock | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,13 @@ | ||
# universal-api | ||
# universal-api | ||
|
||
To extend the capabilities of the Rax system, we provide a series of Universal apis that developers can use to quickly develop multiple applications. | ||
|
||
## quick-start | ||
```bash | ||
$ npm run start | ||
``` | ||
|
||
## build | ||
```bash | ||
$ npm run build | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"packages": [ | ||
"packages/*" | ||
], | ||
"npmClient": "yarn", | ||
"version": "1.0.0", | ||
"command": { | ||
"bootstrap": { | ||
"npmClientArgs": [ | ||
"--no-package-lock" | ||
] | ||
}, | ||
"publish": { | ||
"skipGit": true, | ||
"allowBranch": "master", | ||
"ignoreChanges": [ | ||
"*.md" | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "root", | ||
"private": true, | ||
"scripts": { | ||
"start": "node ./scripts/compile-packages.js --watch", | ||
"build": "node ./scripts/compile-packages.js" | ||
}, | ||
"devDependencies": { | ||
"chalk": "^2.4.2", | ||
"chokidar": "^3.1.0", | ||
"eslint-config-rax": "^0.0.0", | ||
"glob": "^7.1.4", | ||
"lerna": "^3.13.2", | ||
"minimist": "^1.2.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# `universal-network-type` | ||
|
||
> TODO: description | ||
## Usage | ||
|
||
``` | ||
const universalNetworkType = require('universal-network-type'); | ||
// TODO: DEMONSTRATE API | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"plugins": [ | ||
[ | ||
"rax-plugin-component", | ||
{ | ||
"enableTypescript": true, | ||
"targets": ["web", "weex"] | ||
} | ||
] | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* eslint-disable import/no-extraneous-dependencies */ | ||
import { createElement, render } from 'rax'; | ||
import DriverUniversal from 'driver-universal'; | ||
import View from 'rax-view'; | ||
import Text from 'rax-text'; | ||
import NetworkType from '../src'; | ||
|
||
const App = () => { | ||
const handleClick = () => { | ||
NetworkType.getNetworkType(); | ||
}; | ||
return ( | ||
<View onClick={handleClick}> | ||
<Text>click it!</Text> | ||
</View> | ||
); | ||
}; | ||
|
||
render(<App />, document.body, { driver: DriverUniversal }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"name": "universal-network-type", | ||
"version": "1.0.0", | ||
"description": "network type", | ||
"keywords": [ | ||
"rax" | ||
], | ||
"author": "balloonzzq <zqzhuang888@qq.com>", | ||
"homepage": "", | ||
"license": "BSD-3-Clause", | ||
"main": "./lib/index.js", | ||
"directories": { | ||
"lib": "lib" | ||
}, | ||
"files": [ | ||
"lib" | ||
], | ||
"scripts": { | ||
"start": "rax-scripts start", | ||
"build": "rax-scripts build", | ||
"prepublish": "npm run build" | ||
}, | ||
"dependencies": { | ||
"universal-env": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^24.0.12", | ||
"@typescript-eslint/eslint-plugin": "^1.7.0", | ||
"@typescript-eslint/parser": "^1.7.0", | ||
"babel-eslint": "^10.0.1", | ||
"driver-universal": "^1.0.1", | ||
"eslint": "^5.15.1", | ||
"eslint-config-rax": "^0.0.0", | ||
"eslint-plugin-import": "^2.17.2", | ||
"eslint-plugin-react": "^7.12.4", | ||
"rax": "^1.0.4", | ||
"rax-plugin-component": "^0.1.8", | ||
"rax-scripts": "^2.0.1", | ||
"rax-text": "^1.0.1", | ||
"rax-view": "^1.0.2", | ||
"typescript": "^3.4.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { isMiniApp, isWeChatMiniprogram } from 'universal-env'; | ||
import { NetworkType } from './types'; | ||
|
||
let NetworkType: NetworkType = {} as NetworkType; | ||
|
||
if (isMiniApp) { | ||
NetworkType = require('./miniapp/ali').default; | ||
} | ||
|
||
if (isWeChatMiniprogram) { | ||
NetworkType = require('./miniapp/wechat').default; | ||
} | ||
|
||
export default NetworkType; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { getNetworkTypeFactory } from '../factory'; | ||
|
||
declare const my: any; | ||
|
||
const getNetworkType = getNetworkTypeFactory(my); | ||
|
||
export default { | ||
getNetworkType | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Options, NetworkResult } from '../types'; | ||
|
||
export const getNetworkTypeFactory = (api: any) => { | ||
return (options: Options = {}) => { | ||
return new Promise((resolve, reject): void => { | ||
api.getNetworkType({ | ||
success: (res: NetworkResult) => { | ||
options['success'] && options['success'](res); | ||
resolve(res); | ||
}, | ||
fail: (err: any): void => { | ||
options['fail'] && options['fail'](err); | ||
reject(err); | ||
}, | ||
complete: (res: any): void => { | ||
options['complete'] && options['complete'](res); | ||
} | ||
}); | ||
}); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { getNetworkTypeFactory } from '../factory'; | ||
|
||
declare const wx: any; | ||
|
||
const getNetworkType = getNetworkTypeFactory(wx); | ||
|
||
export default { | ||
getNetworkType | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export interface Options { | ||
success?: (res: NetworkResult) => {}; | ||
fail?: (err: any) => {}; | ||
complete?: (res: any) => {}; | ||
} | ||
export interface NetworkResult { | ||
networkType: string; | ||
networkAvailable?: boolean; | ||
} | ||
|
||
export interface NetworkType { | ||
getNetworkType(options?: Options): void | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "esNext", | ||
"target": "es5", | ||
"jsx": "preserve", | ||
"jsxFactory": "createElement", | ||
|
||
"moduleResolution": "node", | ||
"baseUrl": ".", | ||
|
||
"rootDir": "src", | ||
"downlevelIteration": true, | ||
"alwaysStrict": true, | ||
"outDir": "lib", | ||
"strict": true, | ||
"preserveConstEnums": true, | ||
"experimentalDecorators": true, | ||
"noImplicitReturns": true, | ||
"noUnusedLocals": true, | ||
"noImplicitAny": false, | ||
"noImplicitThis": false | ||
}, | ||
"include": ["src/**/*"], | ||
"exclude": ["**/__tests__"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
const compile = require('./compile'); | ||
|
||
compile('packages'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
'use strict'; | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const { spawnSync } = require('child_process'); | ||
|
||
const glob = require('glob'); | ||
const chalk = require('chalk'); | ||
const parseArgs = require('minimist'); | ||
const chokidar = require('chokidar'); | ||
|
||
const SRC_DIR = 'src'; | ||
const BUILD_DIR = 'lib'; | ||
const JS_FILES_PATTERN = '**/*.js'; | ||
const IGNORE_PATTERN = '**/{__tests__,__mocks__}/**'; | ||
|
||
const args = parseArgs(process.argv); | ||
const customPackages = args.packages; | ||
|
||
const fixedWidth = str => { | ||
const WIDTH = 80; | ||
const strs = str.match(new RegExp(`(.{1,${WIDTH}})`, 'g')); | ||
let lastString = strs[strs.length - 1]; | ||
if (lastString.length < WIDTH) { | ||
lastString += Array(WIDTH - lastString.length).join(chalk.dim('.')); | ||
} | ||
return strs.slice(0, -1).concat(lastString).join('\n'); | ||
}; | ||
|
||
function buildPackage(packagesDir, packageDir) { | ||
const srcDir = path.resolve(packageDir, SRC_DIR); | ||
|
||
process.stdout.write( | ||
fixedWidth(`${path.basename(packageDir)}\n`) | ||
); | ||
spawnSync('npm', ['run', 'build'], { | ||
cwd: packageDir | ||
}); | ||
process.stdout.write(`[ ${chalk.green('OK')} ]\n`); | ||
} | ||
|
||
function getPackages(packagesDir, customPackages) { | ||
return fs.readdirSync(packagesDir) | ||
.map(file => path.resolve(packagesDir, file)) | ||
.filter(f => { | ||
if (customPackages) { | ||
const packageName = path.relative(packagesDir, f).split(path.sep)[0]; | ||
return packageName.indexOf(customPackages) !== -1; | ||
} else { | ||
return true; | ||
} | ||
}) | ||
.filter(f => fs.lstatSync(path.resolve(f)).isDirectory()); | ||
} | ||
|
||
module.exports = function compile(packagesName = 'packages') { | ||
const packagesDir = path.resolve(__dirname, `../${packagesName}`); | ||
|
||
if (args.watch) { | ||
// watch packages | ||
const packages = getPackages(packagesDir, customPackages); | ||
const watchPackagesDir = packages.map(dir => path.resolve(dir, SRC_DIR)); | ||
|
||
console.log(chalk.green('watch packages compile', packages)); | ||
|
||
chokidar.watch(watchPackagesDir, { | ||
ignored: IGNORE_PATTERN | ||
}).on('change', (filePath) => { | ||
const packageName = filePath.match( new RegExp(`\/${packagesName}\/([^\/]*)`))[1]; | ||
const packagePath = path.resolve(__dirname, `../${packagesName}/`, packageName); | ||
process.stdout.write(chalk.bold.inverse(`Compiling package ${packageName} \n`)); | ||
try { | ||
buildPackage(packagesDir, packagePath); | ||
} catch (e) {} | ||
process.stdout.write('\n'); | ||
}); | ||
} else { | ||
process.stdout.write(chalk.bold.inverse('Compiling packages\n')); | ||
getPackages(packagesDir, customPackages).forEach(buildPackage.bind(null, packagesDir)); | ||
process.stdout.write('\n'); | ||
} | ||
} | ||
|
||
// spawnSync('mkdir', ['-p', '/Users/balloon/Desktop/workSpace/raxjs/universal-api/packages/universal-network-type/dist']); |