-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
475 changed files
with
9,324 additions
and
1,097 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Style Guide | ||
|
||
In order to maintain a project's simplicity in the long term, these rules should be followed. | ||
|
||
|
||
## Every file should have it's own type file | ||
|
||
``` | ||
// bad | ||
types.js | ||
a.js | ||
b.js | ||
// good | ||
a.js | ||
a.type.js | ||
b.js | ||
b.type.js | ||
types.js // re-export a.types.js & b.types.js | ||
``` | ||
|
||
### why | ||
|
||
If `a.js` has been deleted, it will be easier to delete it's type. | ||
|
||
|
||
|
||
## Don't access module with subpath | ||
|
||
``` | ||
// bad | ||
|- a | ||
|- a1.js | ||
|- a2.js | ||
import a1 from 'a/a1'; | ||
// good | ||
|- a | ||
|- a1.js | ||
|- a2.js | ||
|- index.js // re-export a1.js & a2.js | ||
import { a1 } from 'a'; | ||
``` | ||
|
||
### why | ||
|
||
Every folder is aslo module, only exports what are necessary and hide everything esle. |
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
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 |
---|---|---|
@@ -1,3 +1,14 @@ | ||
import { Runtime } from '@shuvi/types'; | ||
|
||
export const create: Runtime.ApplicationCreater; | ||
import { IAppRenderFn, IApplication } from '@shuvi/runtime-core' | ||
export interface IApplicationCreaterContext { | ||
routeProps?: { [x: string]: any }; | ||
[x: string]: any; | ||
} | ||
export interface ApplicationCreater { | ||
( | ||
context: IApplicationCreaterContext, | ||
options: { | ||
render: IAppRenderFn; | ||
} | ||
): IApplication; | ||
} | ||
export const create: ApplicationCreater; |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import { Runtime } from '@shuvi/types'; | ||
import { IAppPluginRecord } from '@shuvi/runtime-core'; | ||
|
||
export const pluginRecord: Runtime.IAppPluginRecord; | ||
export const pluginRecord: IAppPluginRecord; |
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
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,3 +1,3 @@ | ||
import { IRuntimeConfig } from '@shuvi/types'; | ||
import { IRuntimeConfig } from '@shuvi/service/lib/api'; | ||
|
||
export default function setRuntimeConfig(config: IRuntimeConfig): 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
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { Runtime } from '@shuvi/types'; | ||
import { IInitAppPlugins } from '@shuvi/runtime-core'; | ||
|
||
declare const initPlugins: Runtime.IInitAppPlugins; | ||
declare const initPlugins: IInitAppPlugins; | ||
|
||
export default initPlugins; |
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,4 @@ | ||
*.log | ||
.DS_Store | ||
node_modules | ||
dist |
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 @@ | ||
# @shuvi/hook |
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,26 @@ | ||
{ | ||
"name": "@shuvi/hook", | ||
"version": "0.0.1-rc.32", | ||
"license": "MIT", | ||
"main": "lib/index.js", | ||
"module": "esm/index.js", | ||
"types": "lib/index.d.ts", | ||
"files": [ | ||
"dist", | ||
"src" | ||
], | ||
"engines": { | ||
"node": ">= 12.0.0" | ||
}, | ||
"scripts": { | ||
"dev": "run-p watch:*", | ||
"watch:esm": "tsc -p tsconfig.build.esm.json -w", | ||
"watch:cjs": "tsc -p tsconfig.build.cjs.json -w", | ||
"prebuild": "rimraf lib esm", | ||
"build": "run-p build:*", | ||
"build:esm": "tsc -p tsconfig.build.esm.json", | ||
"build:cjs": "tsc -p tsconfig.build.cjs.json" | ||
}, | ||
"author": "Zheng Yu Tay", | ||
"dependencies": {} | ||
} |
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 { IHookOpts } from './types'; | ||
|
||
export const executeAsyncParallelHook = async ( | ||
tapFns: IHookOpts['fn'][], | ||
...args: any[] | ||
) => { | ||
const results = await Promise.all(tapFns.map(fn => fn(...args))); | ||
return results; | ||
}; |
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 { IHookOpts } from './types'; | ||
|
||
export const executeAsyncSeriesBailHook = async ( | ||
tapFns: IHookOpts['fn'][], | ||
...args: any[] | ||
) => { | ||
let result: unknown = []; | ||
|
||
for (let i = 0; i < tapFns.length; i++) { | ||
result = tapFns[i](...args); | ||
|
||
if (Promise.resolve(result) === result) { | ||
result = await result; | ||
} | ||
|
||
if (result) { | ||
break; | ||
} | ||
} | ||
return result; | ||
}; |
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 { IHookOpts } from './types'; | ||
|
||
export const executeAsyncSeriesHook = async ( | ||
tapFns: IHookOpts['fn'][], | ||
...args: any[] | ||
) => { | ||
let results: unknown[] = []; | ||
|
||
for (let i = 0; i < tapFns.length; i++) { | ||
results.push(await tapFns[i](...args)); | ||
} | ||
|
||
return results; | ||
}; |
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,22 @@ | ||
import { IHookOpts } from './types'; | ||
|
||
export const executeAsyncSeriesWaterfallHook = async ( | ||
tapFns: IHookOpts['fn'][], | ||
...args: any[] | ||
) => { | ||
for (let i = 0; i < tapFns.length; i++) { | ||
let fn = tapFns[i]; | ||
let promiseResult = await fn(...args); | ||
if (typeof args[0] !== 'undefined') { | ||
if (typeof promiseResult !== 'undefined') { | ||
args[0] = promiseResult; | ||
} else { | ||
console.warn( | ||
`Expected return value from hook "${fn.hookName}" but is undefined` | ||
); | ||
} | ||
} | ||
} | ||
|
||
return args[0]; | ||
}; |
Oops, something went wrong.