-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from npmstudy/dev
Dev
- Loading branch information
Showing
18 changed files
with
272 additions
and
63 deletions.
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
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
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,7 @@ | ||
# @tomrpc/mount | ||
|
||
## 1.0.0 | ||
|
||
### Major Changes | ||
|
||
- init |
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,31 @@ | ||
|
||
# @tomrpc/app | ||
|
||
|
||
tom.json | ||
|
||
``` | ||
{ | ||
name:'hi' | ||
base: import.meta.url | ||
static: 'public' | ||
core: true | ||
view: true | ||
jwt: true | ||
port: 3000 | ||
mount: './fn' | ||
lifeCyle: { | ||
} | ||
} | ||
``` | ||
|
||
|
||
```js | ||
import app from '@tomrpc/app'; | ||
|
||
const rpc = createServer(cfg); | ||
|
||
rpc.start(); | ||
|
||
``` |
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,37 @@ | ||
{ | ||
"name": "@tomrpc/app", | ||
"version": "1.0.0", | ||
"description": "My Awesome lib", | ||
"license": "MIT", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"author": "npmstudy <[email protected]>", | ||
"main": "./dist/index.js", | ||
"module": "./dist/index.mjs", | ||
"types": "./dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"build": "tsup src -- --dts-resolve", | ||
"build:fast": "tsup src", | ||
"dev": "tsup src --watch", | ||
"test": "vitest run", | ||
"test:watch": "vitest watch", | ||
"coverage": "vitest run --coverage" | ||
}, | ||
"keywords": [ | ||
"awesome-keywords" | ||
], | ||
"devDependencies": { | ||
"@vitest/coverage-v8": "^0.34.2", | ||
"happy-dom": "^6.0.4" | ||
}, | ||
"dependencies": { | ||
"@tomrpc/import-dir": "^1.2.4", | ||
"debug": "^4.3.4", | ||
"desm": "^1.3.0", | ||
"flat": "^6.0.1" | ||
} | ||
} |
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 { describe, expect, it } from 'vitest'; | ||
|
||
import mount from '../mount'; | ||
|
||
describe('lib', () => { | ||
it('should render lib', () => { | ||
// expect(lib()).toBe('lib'); | ||
}); | ||
}); |
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 @@ | ||
import debug from 'debug'; | ||
|
||
import mount from './mount'; | ||
import { isFunction } from './utils'; | ||
|
||
const log = debug('@tomrpc/mount'); | ||
|
||
// {a:{a:1, b:2}} | ||
// {a.b:2, a.a:1} | ||
// a.b => /a/b + function | ||
|
||
export default async (rpc, dir) => { | ||
const files = await mount(rpc.base, dir); | ||
|
||
log(files); | ||
|
||
Object.keys(files).forEach((key) => { | ||
if (isFunction(files[key])) { | ||
log('add funtion key=' + key); | ||
rpc.fn(key, files[key]); | ||
} else { | ||
console.dir(`key=${key} is not a function`); | ||
} | ||
}); | ||
}; |
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,20 @@ | ||
import importDir, { join } from '@tomrpc/import-dir'; | ||
import debug from 'debug'; | ||
import { flatten } from 'flat'; | ||
|
||
const log = debug('@tomrpc/mount'); | ||
|
||
// {a:{a:1, b:2}} | ||
// {a.b:2, a.a:1} | ||
// a.b => /a/b + function | ||
|
||
export default async (base, dir) => { | ||
const files = await importDir(join(base, dir), { | ||
recurse: true, | ||
extensions: ['.ts', '.js', '.json'], | ||
}); | ||
|
||
log(files); | ||
|
||
return flatten(files); | ||
}; |
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,6 @@ | ||
import mount from './mount'; | ||
|
||
(async () => { | ||
const files = await mount(import.meta.url, './f'); | ||
console.dir(files); | ||
})(); |
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,18 @@ | ||
const toString = Object.prototype.toString; | ||
|
||
export function isFunction(fn) { | ||
if (!fn) { | ||
return false; | ||
} | ||
const string = toString.call(fn); | ||
return ( | ||
string === '[object Function]' || | ||
(typeof fn === 'function' && string !== '[object RegExp]') || | ||
(typeof window !== 'undefined' && | ||
// IE8 and below | ||
(fn === window.setTimeout || | ||
fn === window.alert || | ||
fn === window.confirm || | ||
fn === window.prompt)) | ||
); | ||
} |
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,8 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"types": [ | ||
"vitest/globals" | ||
] | ||
} | ||
} |
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,12 @@ | ||
import { defineConfig } from 'tsup'; | ||
|
||
export default defineConfig((options) => ({ | ||
entry: 'src/index.ts', | ||
sourcemap: !options.watch, | ||
minify: !options.watch, | ||
dts: true, | ||
format: ['esm'], | ||
loader: { | ||
'.js': 'jsx', | ||
}, | ||
})); |
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,10 @@ | ||
/// <reference types="vitest" /> | ||
|
||
import { defineConfig } from 'vite'; | ||
|
||
export default defineConfig({ | ||
test: { | ||
globals: true, | ||
environment: 'happy-dom', | ||
}, | ||
}); |
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
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,23 @@ | ||
|
||
# @tomrpc/mount | ||
|
||
|
||
```js | ||
import mount from '@tomrpc/mount'; | ||
|
||
|
||
const rpc = createServer({ | ||
base: import.meta.url, | ||
beforeOne: function (ctx: any, key: string) { | ||
console.log(ctx.path); | ||
console.log(ctx.method); | ||
console.log('beforeOne key=' + key); | ||
}, | ||
}); | ||
|
||
rpc.base = import.meta.url; | ||
mount(rpc, './fn'); | ||
|
||
rpc.listen(3000); | ||
|
||
``` |
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
Oops, something went wrong.