Skip to content

Commit

Permalink
Merge branch 'miniprogram' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
liximomo committed Sep 18, 2021
2 parents f7c7cb6 + a2141fc commit 3c7582e
Show file tree
Hide file tree
Showing 475 changed files with 9,324 additions and 1,097 deletions.
49 changes: 49 additions & 0 deletions CODESTYLE.md
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.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Core components.

Core runtime of application.

### runtime-react
### platform-react

React runtime for application.

Expand Down
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

- [ ] @shuvi/core
- [ ] app (liximomo)
- [ ] @shuvi/runtime-react
- [ ] @shuvi/platform-react
- [ ] dynamic (liximomo)
- [ ] head (kayne)
- [x] @shuvi/utils (zhengyutay)
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"scripts": {
"dev": "lerna run dev --stream --parallel",
"clean": "lerna exec rimraf lib esm shuvi-app --stream --parallel",
"shuvi": "node ./packages/shuvi/lib/cli/cli.js",
"shuvi": "SHUVI_DEV_DISABLE_CACHE=true node ./packages/shuvi/lib/cli/cli.js",
"build": "lerna run build --stream",
"jest": "jest",
"test": "yarn test:fixtures && yarn test:unit",
Expand Down Expand Up @@ -57,7 +57,7 @@
"lint-staged": "^10.1.2",
"lodash": "^4.17.15",
"memfs": "^3.1.2",
"node-sass": "^4.14.1",
"node-sass": "^6.0.1",
"npm-run-all": "^4.1.5",
"prettier": "^2.0.4",
"puppeteer-core": "4.0.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/app/core/apiRoutes.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Runtime } from '@shuvi/types';
import { Runtime } from '@shuvi/service';

declare const apiRoutes: Runtime.IApiRouteConfig[];

Expand Down
17 changes: 14 additions & 3 deletions packages/app/core/client/application.d.ts
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;
2 changes: 0 additions & 2 deletions packages/app/core/client/history.d.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/app/core/platform.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Runtime } from '@shuvi/types';
import { Runtime } from '@shuvi/service';

export declare const getRoutes: Runtime.IGetRoutes;
export declare const view: Runtime.IViewClient;
Expand Down
4 changes: 2 additions & 2 deletions packages/app/core/plugins.d.ts
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;
2 changes: 1 addition & 1 deletion packages/app/core/routes.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Runtime } from '@shuvi/types';
import { Runtime } from '@shuvi/service';

declare const routes: Runtime.IAppRouteConfig[];

Expand Down
2 changes: 1 addition & 1 deletion packages/app/core/runtimeConfig.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IRuntimeConfig } from '@shuvi/types';
import { IRuntimeConfig } from '@shuvi/service/lib/api';

declare const runtimneConfig: IRuntimeConfig | null;

Expand Down
2 changes: 1 addition & 1 deletion packages/app/core/server/application.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Runtime } from '@shuvi/types';
import { Runtime } from '@shuvi/service';

import IApplicationModule = Runtime.IApplicationModule;

Expand Down
2 changes: 1 addition & 1 deletion packages/app/core/setRuntimeConfig.d.ts
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;
2 changes: 1 addition & 1 deletion packages/app/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Runtime } from '@shuvi/types';
import { Runtime } from '@shuvi/service';

export declare function getPageData<T = unknown>(
key: string,
Expand Down
3 changes: 2 additions & 1 deletion packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"node": ">= 12.0.0"
},
"dependencies": {
"@shuvi/types": "^0.0.1-rc.32"
"@shuvi/runtime-core": "^0.0.1-rc.32",
"@shuvi/service": "^0.0.1-rc.32"
}
}
2 changes: 1 addition & 1 deletion packages/app/user/document.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Runtime } from '@shuvi/types';
import { Runtime } from '@shuvi/service';

declare const document: Runtime.IDocumentModule;

Expand Down
4 changes: 2 additions & 2 deletions packages/app/user/plugin.d.ts
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;
2 changes: 1 addition & 1 deletion packages/app/user/server.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Runtime } from '@shuvi/types';
import { Runtime } from '@shuvi/service';

declare const server: Runtime.IServerModule;

Expand Down
4 changes: 4 additions & 0 deletions packages/hook/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.log
.DS_Store
node_modules
dist
1 change: 1 addition & 0 deletions packages/hook/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# @shuvi/hook
26 changes: 26 additions & 0 deletions packages/hook/package.json
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": {}
}
9 changes: 9 additions & 0 deletions packages/hook/src/AsyncParallelHook.ts
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;
};
21 changes: 21 additions & 0 deletions packages/hook/src/AsyncSeriesBailHook.ts
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;
};
14 changes: 14 additions & 0 deletions packages/hook/src/AsyncSeriesHook.ts
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;
};
22 changes: 22 additions & 0 deletions packages/hook/src/AsyncSeriesWaterfallHook.ts
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];
};
Loading

0 comments on commit 3c7582e

Please sign in to comment.