@shuvi/platform-shared 1.0.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/esm/shared/application.d.ts +82 -0
  2. package/esm/shared/application.js +87 -0
  3. package/esm/shared/applicationTypes.d.ts +45 -0
  4. package/esm/shared/applicationTypes.js +1 -0
  5. package/esm/shared/helper/getAppData.d.ts +20 -0
  6. package/esm/shared/helper/getAppData.js +26 -0
  7. package/esm/shared/helper/getFilesOfRoute.d.ts +10 -0
  8. package/esm/shared/helper/getFilesOfRoute.js +30 -0
  9. package/esm/shared/helper/getPageData.d.ts +1 -0
  10. package/esm/shared/helper/getPageData.js +13 -0
  11. package/esm/shared/helper/getPublicPath.d.ts +1 -0
  12. package/esm/shared/helper/getPublicPath.js +6 -0
  13. package/esm/shared/helper/index.d.ts +5 -0
  14. package/esm/shared/helper/index.js +5 -0
  15. package/esm/shared/helper/router.d.ts +4 -0
  16. package/esm/shared/helper/router.js +60 -0
  17. package/esm/shared/index.d.ts +9 -0
  18. package/esm/shared/index.js +10 -0
  19. package/esm/shared/lifecycle.d.ts +46 -0
  20. package/esm/shared/lifecycle.js +40 -0
  21. package/esm/shared/loader/index.d.ts +3 -0
  22. package/esm/shared/loader/index.js +3 -0
  23. package/esm/shared/loader/loader.d.ts +9 -0
  24. package/esm/shared/loader/loader.js +114 -0
  25. package/esm/shared/loader/loaderManager.d.ts +16 -0
  26. package/esm/shared/loader/loaderManager.js +49 -0
  27. package/esm/shared/loader/types.d.ts +73 -0
  28. package/esm/shared/loader/types.js +1 -0
  29. package/esm/shared/models/error.d.ts +13 -0
  30. package/esm/shared/models/error.js +32 -0
  31. package/esm/shared/response.d.ts +51 -0
  32. package/esm/shared/response.js +126 -0
  33. package/esm/shared/router.d.ts +1 -0
  34. package/esm/shared/router.js +1 -0
  35. package/esm/shared/routerTypes.d.ts +28 -0
  36. package/esm/shared/routerTypes.js +1 -0
  37. package/esm/shared/shuvi-singleton-runtimeConfig.d.ts +12 -0
  38. package/esm/shared/shuvi-singleton-runtimeConfig.js +19 -0
  39. package/esm/shuvi-app/application.d.ts +4 -0
  40. package/esm/shuvi-app/application.js +34 -0
  41. package/esm/shuvi-app/shared.d.ts +1 -0
  42. package/esm/shuvi-app/shared.js +1 -0
  43. package/esm/shuvi-app/shuvi-runtime-app.d.ts +14 -0
  44. package/esm/shuvi-app/shuvi-runtime-app.js +1 -0
  45. package/esm/shuvi-app/shuvi-runtime-index.d.ts +10 -0
  46. package/esm/shuvi-app/shuvi-runtime-index.js +9 -0
  47. package/lib/node/index.d.ts +2 -0
  48. package/lib/node/index.js +18 -0
  49. package/lib/node/paths.d.ts +3 -0
  50. package/lib/node/paths.js +12 -0
  51. package/lib/node/platform/index.d.ts +16 -0
  52. package/lib/node/platform/index.js +23 -0
  53. package/lib/node/platform/plugins/main/hooks.d.ts +9 -0
  54. package/lib/node/platform/plugins/main/hooks.js +12 -0
  55. package/lib/node/platform/plugins/main/index.d.ts +16 -0
  56. package/lib/node/platform/plugins/main/index.js +32 -0
  57. package/lib/node/platform/plugins/main/shuvi-app.d.ts +8 -0
  58. package/lib/node/platform/plugins/main/shuvi-app.js +2 -0
  59. package/lib/node/platform/runtimeFiles.d.ts +11 -0
  60. package/lib/node/platform/runtimeFiles.js +47 -0
  61. package/lib/node/project/file-presets/files/app/core/entry.js.d.ts +3 -0
  62. package/lib/node/project/file-presets/files/app/core/entry.js.js +52 -0
  63. package/lib/node/project/file-presets/files/app/core/error.js.d.ts +2 -0
  64. package/lib/node/project/file-presets/files/app/core/error.js.js +9 -0
  65. package/lib/node/project/file-presets/files/app/core/platform.js.d.ts +3 -0
  66. package/lib/node/project/file-presets/files/app/core/platform.js.js +9 -0
  67. package/lib/node/project/file-presets/files/app/core/polyfill.js.d.ts +3 -0
  68. package/lib/node/project/file-presets/files/app/core/polyfill.js.js +6 -0
  69. package/lib/node/project/file-presets/files/app/core/runtimeConfig.js.d.ts +3 -0
  70. package/lib/node/project/file-presets/files/app/core/runtimeConfig.js.js +12 -0
  71. package/lib/node/project/file-presets/files/app/core/setPublicRuntimeConfig.js.d.ts +2 -0
  72. package/lib/node/project/file-presets/files/app/core/setPublicRuntimeConfig.js.js +7 -0
  73. package/lib/node/project/file-presets/files/app/core/setRuntimeConfig.js.d.ts +2 -0
  74. package/lib/node/project/file-presets/files/app/core/setRuntimeConfig.js.js +7 -0
  75. package/lib/node/project/file-presets/files/app/user/app.js.d.ts +3 -0
  76. package/lib/node/project/file-presets/files/app/user/app.js.js +15 -0
  77. package/lib/node/project/file-presets/files/app/user/error.js.d.ts +3 -0
  78. package/lib/node/project/file-presets/files/app/user/error.js.js +15 -0
  79. package/lib/node/project/file-presets/index.d.ts +4 -0
  80. package/lib/node/project/file-presets/index.js +58 -0
  81. package/lib/node/project/index.d.ts +2 -0
  82. package/lib/node/project/index.js +7 -0
  83. package/lib/node/project/projectContext.d.ts +13 -0
  84. package/lib/node/project/projectContext.js +16 -0
  85. package/lib/node/route/helpers.d.ts +20 -0
  86. package/lib/node/route/helpers.js +199 -0
  87. package/lib/node/route/index.d.ts +1 -0
  88. package/lib/node/route/index.js +7 -0
  89. package/lib/node/route/route.d.ts +37 -0
  90. package/lib/node/route/route.js +212 -0
  91. package/lib/shared/application.d.ts +82 -0
  92. package/lib/shared/application.js +91 -0
  93. package/lib/shared/applicationTypes.d.ts +45 -0
  94. package/lib/shared/applicationTypes.js +2 -0
  95. package/lib/shared/helper/getAppData.d.ts +20 -0
  96. package/lib/shared/helper/getAppData.js +30 -0
  97. package/lib/shared/helper/getFilesOfRoute.d.ts +10 -0
  98. package/lib/shared/helper/getFilesOfRoute.js +34 -0
  99. package/lib/shared/helper/getPageData.d.ts +1 -0
  100. package/lib/shared/helper/getPageData.js +17 -0
  101. package/lib/shared/helper/getPublicPath.d.ts +1 -0
  102. package/lib/shared/helper/getPublicPath.js +10 -0
  103. package/lib/shared/helper/index.d.ts +5 -0
  104. package/lib/shared/helper/index.js +24 -0
  105. package/lib/shared/helper/router.d.ts +4 -0
  106. package/lib/shared/helper/router.js +68 -0
  107. package/lib/shared/index.d.ts +9 -0
  108. package/lib/shared/index.js +28 -0
  109. package/lib/shared/lifecycle.d.ts +46 -0
  110. package/lib/shared/lifecycle.js +45 -0
  111. package/lib/shared/loader/index.d.ts +3 -0
  112. package/lib/shared/loader/index.js +19 -0
  113. package/lib/shared/loader/loader.d.ts +9 -0
  114. package/lib/shared/loader/loader.js +122 -0
  115. package/lib/shared/loader/loaderManager.d.ts +16 -0
  116. package/lib/shared/loader/loaderManager.js +53 -0
  117. package/lib/shared/loader/types.d.ts +73 -0
  118. package/lib/shared/loader/types.js +2 -0
  119. package/lib/shared/models/error.d.ts +13 -0
  120. package/lib/shared/models/error.js +35 -0
  121. package/lib/shared/response.d.ts +51 -0
  122. package/lib/shared/response.js +134 -0
  123. package/lib/shared/router.d.ts +1 -0
  124. package/lib/shared/router.js +11 -0
  125. package/lib/shared/routerTypes.d.ts +28 -0
  126. package/lib/shared/routerTypes.js +2 -0
  127. package/lib/shared/shuvi-singleton-runtimeConfig.d.ts +12 -0
  128. package/lib/shared/shuvi-singleton-runtimeConfig.js +26 -0
  129. package/package.json +90 -0
  130. package/shuvi-app-extensions.d.ts +58 -0
  131. package/template/document.ejs +10 -0
@@ -0,0 +1,16 @@
1
+ declare function createLoaderManager(): {
2
+ getAllData(): Record<string, any>;
3
+ getData(id: string): any;
4
+ setDatas(obj: Record<string, any>): void;
5
+ subscribe(cb: Function): () => void;
6
+ clearAllData(): void;
7
+ };
8
+ export declare const getLoaderManager: () => {
9
+ getAllData(): Record<string, any>;
10
+ getData(id: string): any;
11
+ setDatas(obj: Record<string, any>): void;
12
+ subscribe(cb: Function): () => void;
13
+ clearAllData(): void;
14
+ };
15
+ export declare type LoaderManager = ReturnType<typeof createLoaderManager>;
16
+ export {};
@@ -0,0 +1,49 @@
1
+ let loaderManager;
2
+ function createLoaderManager() {
3
+ const datas = new Map();
4
+ const subscribers = [];
5
+ return {
6
+ getAllData() {
7
+ let res = {};
8
+ for (const [id, data] of datas.entries()) {
9
+ res[id] = data;
10
+ }
11
+ return res;
12
+ },
13
+ getData(id) {
14
+ if (!datas.has(id)) {
15
+ return null;
16
+ }
17
+ return datas.get(id);
18
+ },
19
+ setDatas(obj) {
20
+ for (const [id, data] of Object.entries(obj)) {
21
+ datas.set(id, data);
22
+ }
23
+ subscribers.forEach(fn => fn());
24
+ },
25
+ // setData(id: string, data: any) {
26
+ // datas.set(id, data);
27
+ // subscribers.forEach(fn => fn());
28
+ // },
29
+ subscribe(cb) {
30
+ subscribers.push(cb);
31
+ return () => {
32
+ const index = subscribers.indexOf(cb);
33
+ if (index >= 0) {
34
+ subscribers.splice(index, 1);
35
+ }
36
+ };
37
+ },
38
+ clearAllData() {
39
+ datas.clear();
40
+ }
41
+ };
42
+ }
43
+ export const getLoaderManager = () => {
44
+ if (loaderManager) {
45
+ return loaderManager;
46
+ }
47
+ loaderManager = createLoaderManager();
48
+ return loaderManager;
49
+ };
@@ -0,0 +1,73 @@
1
+ import { IURLQuery, IURLParams } from '../routerTypes';
2
+ import { IAppContext, IRequest } from '../applicationTypes';
3
+ import { Response } from '../response';
4
+ export interface LoaderContextOptions {
5
+ isServer: boolean;
6
+ req?: IRequest;
7
+ query: IURLQuery;
8
+ getAppContext: () => IAppContext;
9
+ }
10
+ export declare type RedirectFunction = (to: string, status?: number) => any;
11
+ export interface ErrorFunction {
12
+ (): any;
13
+ (msg: string): any;
14
+ (msg: string, statusCode?: number): any;
15
+ }
16
+ /**
17
+ * route component getInitialProps params `context`
18
+ */
19
+ export interface IRouteLoaderContext {
20
+ /**
21
+ * is running on server, if server is true, client will be false
22
+ */
23
+ isServer: boolean;
24
+ /**
25
+ * current url path
26
+ */
27
+ pathname: string;
28
+ /**
29
+ * the query string of current url
30
+ *
31
+ * eg. url /x?name=xx
32
+ * ```ts
33
+ * {name:xx}
34
+ * ```
35
+ */
36
+ query: IURLQuery;
37
+ /**
38
+ * the params of current url
39
+ *
40
+ * eg. url /x?name=xx path /:lng
41
+ * ```ts
42
+ * {lng:x}
43
+ * ```
44
+ */
45
+ params: IURLParams;
46
+ /**
47
+ * redirect function
48
+ *
49
+ * ```ts
50
+ * redirect('/target')
51
+ * redirect('/target', 301)
52
+ * ```
53
+ */
54
+ redirect: RedirectFunction;
55
+ /**
56
+ * throw error if necessary
57
+ * ```ts
58
+ * error('custom error describe', 502)
59
+ * ```
60
+ */
61
+ error: ErrorFunction;
62
+ /**
63
+ * server only
64
+ */
65
+ req?: IRequest;
66
+ /**
67
+ * Application context object, which is accessiable during the entire lifecycle of application
68
+ */
69
+ appContext: IAppContext;
70
+ }
71
+ export declare type Loader<T extends {} = {}> = (loaderContenxt: IRouteLoaderContext) => Promise<T | void | undefined> | T | void | undefined;
72
+ export declare type NormalizedLoader = (loaderContenxt: IRouteLoaderContext) => Promise<Response | undefined>;
73
+ export declare type LoaderDataRecord = Record<string, any>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,13 @@
1
+ import { IErrorState, IError } from '../applicationTypes';
2
+ export declare const errorModel: import("@shuvi/redox").Model<"error", IErrorState, {}, {
3
+ setError(_state: IErrorState, error?: IError): {
4
+ error: IError | undefined;
5
+ };
6
+ }, {
7
+ error(payload?: IError): void;
8
+ clear(): void;
9
+ }, {
10
+ getError(): IError | undefined;
11
+ hasError(): boolean;
12
+ }>;
13
+ export declare type ErrorModel = typeof errorModel;
@@ -0,0 +1,32 @@
1
+ import { defineModel } from '@shuvi/redox';
2
+ import { SHUVI_ERROR } from '@shuvi/shared/lib/constants';
3
+ const DEFAULT_ERRORSTATE = {
4
+ error: undefined
5
+ };
6
+ export const errorModel = defineModel({
7
+ name: 'error',
8
+ state: DEFAULT_ERRORSTATE,
9
+ reducers: {
10
+ setError(_state, error) {
11
+ return Object.assign(Object.assign({}, _state), { error: error });
12
+ }
13
+ },
14
+ actions: {
15
+ error(payload) {
16
+ this.setError(payload || SHUVI_ERROR.APP_ERROR);
17
+ },
18
+ clear() {
19
+ if (this.hasError) {
20
+ this.setError(undefined);
21
+ }
22
+ }
23
+ },
24
+ views: {
25
+ getError() {
26
+ return this.error;
27
+ },
28
+ hasError() {
29
+ return typeof this.error !== 'undefined';
30
+ }
31
+ }
32
+ });
@@ -0,0 +1,51 @@
1
+ declare type HeaderRecord = Record<string, string>;
2
+ declare type HeaderArray = [string, string][];
3
+ export interface ResponseOptions {
4
+ status?: number;
5
+ statusText?: string;
6
+ headers?: HeaderRecord;
7
+ }
8
+ declare class Headers {
9
+ private _map;
10
+ constructor(init?: HeaderRecord | HeaderArray);
11
+ append(name: string, value: string): void;
12
+ delete(name: string): void;
13
+ get(name: string): string | null;
14
+ has(name: string): boolean;
15
+ set(name: string, value: string): void;
16
+ forEach(callback: (value: string, name: string, t: this) => void, thisArg?: any): void;
17
+ keys(): {
18
+ next: () => {
19
+ done: boolean;
20
+ value: any;
21
+ };
22
+ };
23
+ value(): {
24
+ next: () => {
25
+ done: boolean;
26
+ value: any;
27
+ };
28
+ };
29
+ entries(): {
30
+ next: () => {
31
+ done: boolean;
32
+ value: any;
33
+ };
34
+ };
35
+ }
36
+ export declare type ResponseType = 'text' | 'json' | 'redirect' | 'plain';
37
+ export interface Response {
38
+ readonly data: string;
39
+ readonly status: number;
40
+ readonly statusText: string;
41
+ readonly headers: Headers;
42
+ }
43
+ export declare const isResponse: (obj: any) => obj is Response;
44
+ export declare const isJson: (obj: any) => obj is Response;
45
+ export declare const isText: (obj: any) => obj is Response;
46
+ export declare const isRedirect: (obj: any) => obj is Response;
47
+ export declare function response(data: any, options?: ResponseOptions): Response;
48
+ export declare function json(data: any): Response;
49
+ export declare function text(data: string, options?: ResponseOptions): Response;
50
+ export declare function redirect(to: string, status?: number): Response;
51
+ export {};
@@ -0,0 +1,126 @@
1
+ const supportIterator = 'Symbol' in global && 'iterator' in Symbol;
2
+ function normalizeName(name) {
3
+ if (typeof name !== 'string') {
4
+ name = String(name);
5
+ }
6
+ if (/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(name) || name === '') {
7
+ throw new TypeError('Invalid character in header field name: "' + name + '"');
8
+ }
9
+ return name.toLowerCase();
10
+ }
11
+ function normalizeValue(value) {
12
+ if (typeof value !== 'string') {
13
+ value = String(value);
14
+ }
15
+ return value;
16
+ }
17
+ // Build a destructive iterator for the value list
18
+ function iteratorFor(items) {
19
+ var iterator = {
20
+ next: function () {
21
+ var value = items.shift();
22
+ return { done: value === undefined, value: value };
23
+ }
24
+ };
25
+ if (supportIterator) {
26
+ iterator[Symbol.iterator] = function () {
27
+ return iterator;
28
+ };
29
+ }
30
+ return iterator;
31
+ }
32
+ class Headers {
33
+ constructor(init) {
34
+ this._map = {};
35
+ if (init instanceof Headers) {
36
+ init.forEach((value, name) => {
37
+ this.append(name, value);
38
+ });
39
+ }
40
+ else if (Array.isArray(init)) {
41
+ init.forEach(header => this.append(header[0], header[1]));
42
+ }
43
+ else if (init) {
44
+ Object.keys(init).forEach(name => {
45
+ this.append(name, init[name]);
46
+ });
47
+ }
48
+ }
49
+ append(name, value) {
50
+ name = normalizeName(name);
51
+ value = normalizeValue(value);
52
+ var oldValue = this._map[name];
53
+ this._map[name] = oldValue ? oldValue + ', ' + value : value;
54
+ }
55
+ delete(name) {
56
+ delete this._map[normalizeName(name)];
57
+ }
58
+ get(name) {
59
+ name = normalizeName(name);
60
+ return this.has(name) ? this._map[name] : null;
61
+ }
62
+ has(name) {
63
+ return this._map.hasOwnProperty(normalizeName(name));
64
+ }
65
+ set(name, value) {
66
+ this._map[normalizeName(name)] = normalizeValue(value);
67
+ }
68
+ forEach(callback, thisArg) {
69
+ for (var name in Object.keys(this._map)) {
70
+ callback.call(thisArg, this._map[name], name, this);
71
+ }
72
+ }
73
+ keys() {
74
+ const items = [];
75
+ this.forEach((_value, name) => items.push(name));
76
+ return iteratorFor(items);
77
+ }
78
+ value() {
79
+ const items = [];
80
+ this.forEach(value => items.push(value));
81
+ return iteratorFor(items);
82
+ }
83
+ entries() {
84
+ const items = [];
85
+ this.forEach((value, name) => items.push([name, value]));
86
+ return iteratorFor(items);
87
+ }
88
+ }
89
+ if (supportIterator) {
90
+ Headers.prototype[Symbol.iterator] = Headers.prototype.entries;
91
+ }
92
+ class ResponseImpl {
93
+ constructor(data, type, options = {}) {
94
+ this.__shuvi_resp_type__ = type;
95
+ this.data = data;
96
+ this.status = options.status || 200;
97
+ this.statusText = options.statusText || '';
98
+ this.headers = new Headers(options.headers);
99
+ }
100
+ }
101
+ function createTypeCreator(type) {
102
+ return (obj) => {
103
+ return obj && obj.__shuvi_resp_type__ === type;
104
+ };
105
+ }
106
+ export const isResponse = (obj) => obj && typeof obj.__shuvi_resp_type__ === 'string';
107
+ export const isJson = createTypeCreator('json');
108
+ export const isText = createTypeCreator('text');
109
+ export const isRedirect = createTypeCreator('redirect');
110
+ export function response(data, options) {
111
+ return new ResponseImpl(data, 'plain', options);
112
+ }
113
+ export function json(data) {
114
+ return new ResponseImpl(data, 'json');
115
+ }
116
+ export function text(data, options) {
117
+ return new ResponseImpl(data, 'text', options);
118
+ }
119
+ export function redirect(to, status = 302) {
120
+ return new ResponseImpl('', 'redirect', {
121
+ status,
122
+ headers: {
123
+ Location: to
124
+ }
125
+ });
126
+ }
@@ -0,0 +1 @@
1
+ export { IRouter, PathRecord, matchPathname, rankRouteBranches, parseQuery, createRouter, createBrowserHistory, createHashHistory, createMemoryHistory } from '@shuvi/router';
@@ -0,0 +1 @@
1
+ export { matchPathname, rankRouteBranches, parseQuery, createRouter, createBrowserHistory, createHashHistory, createMemoryHistory } from '@shuvi/router';
@@ -0,0 +1,28 @@
1
+ import { ParsedQuery, IParams, IRouteRecord } from '@shuvi/router';
2
+ export { IRouter, IRoute, IRouteMatch } from '@shuvi/router';
3
+ export declare type IURLQuery = ParsedQuery;
4
+ export declare type IURLParams = IParams;
5
+ export interface IPageRouteRecord extends IRouteRecord {
6
+ id: string;
7
+ component?: any;
8
+ children?: IPageRouteRecord[];
9
+ path: string;
10
+ fullPath?: string;
11
+ __componentSource__?: never;
12
+ __componentSourceWithAffix__?: string;
13
+ __import__?: never;
14
+ __resolveWeak__?: () => any;
15
+ [x: string]: any;
16
+ }
17
+ export interface IRawPageRouteRecord extends IRouteRecord {
18
+ id: string;
19
+ component?: any;
20
+ children?: IRawPageRouteRecord[];
21
+ path: string;
22
+ fullPath: string;
23
+ __componentSource__: string;
24
+ __componentSourceWithAffix__: string;
25
+ __import__: () => Promise<any>;
26
+ __resolveWeak__: () => any;
27
+ [x: string]: any;
28
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ import { IRuntimeConfig } from '@shuvi/service/lib/core';
2
+ /**
3
+ * getRuntimeConfig function
4
+ *
5
+ * @returns runtimeConfig
6
+ */
7
+ export declare function getRuntimeConfig(): {
8
+ [x: string]: string;
9
+ };
10
+ export declare function getPublicRuntimeConfig(): IRuntimeConfig | null;
11
+ export declare function setRuntimeConfig(config: IRuntimeConfig): void;
12
+ export declare function setPublicRuntimeConfig(config: IRuntimeConfig): void;
@@ -0,0 +1,19 @@
1
+ let runtimeConfig;
2
+ let publicRuntimeConfig;
3
+ /**
4
+ * getRuntimeConfig function
5
+ *
6
+ * @returns runtimeConfig
7
+ */
8
+ export function getRuntimeConfig() {
9
+ return Object.assign(Object.assign({}, (runtimeConfig || {})), (publicRuntimeConfig || {}));
10
+ }
11
+ export function getPublicRuntimeConfig() {
12
+ return publicRuntimeConfig;
13
+ }
14
+ export function setRuntimeConfig(config) {
15
+ runtimeConfig = config;
16
+ }
17
+ export function setPublicRuntimeConfig(config) {
18
+ publicRuntimeConfig = config;
19
+ }
@@ -0,0 +1,4 @@
1
+ import { Application } from '../shared/application';
2
+ import { IApplicationOptions } from './shared';
3
+ export { Application };
4
+ export default function application(options: IApplicationOptions): Application;
@@ -0,0 +1,34 @@
1
+ import * as customApp from '@shuvi/app/user/app';
2
+ import { pluginRecord } from '@shuvi/app/core/plugins';
3
+ import { Application } from '../shared/application';
4
+ import { createRuntimePlugin } from './shared';
5
+ export { Application };
6
+ function getPlugins(runtime, pluginRecords) {
7
+ const plugins = [];
8
+ const keys = Object.keys(pluginRecords);
9
+ for (let index = 0; index < keys.length; index++) {
10
+ const name = keys[index];
11
+ const plugin = pluginRecords[name];
12
+ plugins.push([plugin.plugin, plugin.options]);
13
+ }
14
+ const pluginConstructor = {};
15
+ const methods = [
16
+ 'appComponent',
17
+ 'appContext',
18
+ 'init',
19
+ 'dispose'
20
+ ];
21
+ for (let index = 0; index < methods.length; index++) {
22
+ const method = methods[index];
23
+ if (typeof runtime[method] === 'function') {
24
+ //@ts-ignore
25
+ pluginConstructor[method] = runtime[method];
26
+ }
27
+ }
28
+ plugins.push([createRuntimePlugin(pluginConstructor)]);
29
+ return plugins;
30
+ }
31
+ export default function application(options) {
32
+ const application = new Application(Object.assign(Object.assign({}, options), { plugins: getPlugins(customApp, pluginRecord) }));
33
+ return application;
34
+ }
@@ -0,0 +1 @@
1
+ export * from '../shared';
@@ -0,0 +1 @@
1
+ export * from '../shared';
@@ -0,0 +1,14 @@
1
+ /**
2
+ * export for users
3
+ *
4
+ * eg:
5
+ * import {} from '@shuvi/runtime/app'
6
+ *
7
+ */
8
+ import { IAppModule as _IAppModule } from '../shared/lifecycle';
9
+ declare type AppModule = Required<_IAppModule>;
10
+ export declare type InitFunction = AppModule['init'];
11
+ export declare type AppComponentFunction = AppModule['appComponent'];
12
+ export declare type AppContextFunction = AppModule['appContext'];
13
+ export declare type DisposeFunction = AppModule['dispose'];
14
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ /**
2
+ * export for users
3
+ *
4
+ * eg:
5
+ * import {} from '@shuvi/runtime'
6
+ *
7
+ */
8
+ export { createRuntimePlugin } from '../shared/lifecycle';
9
+ export { getPageData } from '../shared/helper/getPageData';
10
+ export type { Loader } from '../shared/loader';
@@ -0,0 +1,9 @@
1
+ /**
2
+ * export for users
3
+ *
4
+ * eg:
5
+ * import {} from '@shuvi/runtime'
6
+ *
7
+ */
8
+ export { createRuntimePlugin } from '../shared/lifecycle';
9
+ export { getPageData } from '../shared/helper/getPageData';
@@ -0,0 +1,2 @@
1
+ export * from './platform';
2
+ export * from './route';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./platform"), exports);
18
+ __exportStar(require("./route"), exports);
@@ -0,0 +1,3 @@
1
+ export declare const PackageDir: string;
2
+ export declare const resolvePluginFile: (pluginName: string, ...paths: string[]) => string;
3
+ export declare const resolvePkgFile: (...paths: string[]) => string;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.resolvePkgFile = exports.resolvePluginFile = exports.PackageDir = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ exports.PackageDir = path_1.default.resolve(__dirname, '..', '..');
9
+ const resolvePluginFile = (pluginName, ...paths) => path_1.default.join(exports.PackageDir, 'lib', 'node', 'platform', 'plugins', pluginName, ...paths);
10
+ exports.resolvePluginFile = resolvePluginFile;
11
+ const resolvePkgFile = (...paths) => path_1.default.join(exports.PackageDir, ...paths);
12
+ exports.resolvePkgFile = resolvePkgFile;
@@ -0,0 +1,16 @@
1
+ export * from './runtimeFiles';
2
+ export declare const SharedPlugins: {
3
+ core: import("@shuvi/hook").IPluginInstance<{
4
+ afterInit: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
5
+ afterBuild: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
6
+ afterDestroy: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
7
+ afterBundlerDone: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").BundlerDoneExtra, void, void>;
8
+ afterBundlerTargetDone: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").BundlerTargetDoneExtra, void, void>;
9
+ configWebpack: import("@shuvi/hook").AsyncSeriesWaterfallHook<import("@shuvi/service/lib/core/lifecycleTypes").WebpackChainType, import("@shuvi/service/lib/core/lifecycleTypes").ConfigWebpackAssistant>;
10
+ addExtraTarget: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").ExtraTargetAssistant, void, import("@shuvi/service/lib/core/lifecycleTypes").TargetChain>;
11
+ addResource: import("@shuvi/hook").AsyncParallelHook<void, void, import("@shuvi/service/lib/core/lifecycleTypes").Resources | import("@shuvi/service/lib/core/lifecycleTypes").Resources[]>;
12
+ addRuntimeFile: import("@shuvi/hook").AsyncParallelHook<void, import("@shuvi/service/lib/core/lifecycleTypes").AddRuntimeFileUtils, import("@shuvi/service/lib/project/index").FileOptions<any, any> | import("@shuvi/service/lib/project/index").FileOptions<any, any>[]>;
13
+ addRuntimeService: import("@shuvi/hook").AsyncParallelHook<void, void, import("@shuvi/service/lib/core/lifecycleTypes").RuntimeService | import("@shuvi/service/lib/core/lifecycleTypes").RuntimeService[]>;
14
+ } & import("@shuvi/runtime").CustomCorePluginHooks, import("@shuvi/service").IPluginContext>;
15
+ types: string;
16
+ }[];
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.SharedPlugins = void 0;
21
+ const main_1 = __importDefault(require("./plugins/main"));
22
+ __exportStar(require("./runtimeFiles"), exports);
23
+ exports.SharedPlugins = [main_1.default];
@@ -0,0 +1,9 @@
1
+ import { IRuntimeConfig } from '@shuvi/service/lib/core';
2
+ export declare const extendedHooks: {
3
+ addEntryCode: import("@shuvi/hook").AsyncParallelHook<void, void, string | string[]>;
4
+ addPolyfill: import("@shuvi/hook").AsyncParallelHook<void, void, string | string[]>;
5
+ modifyRuntimeConfig: import("@shuvi/hook").AsyncSeriesWaterfallHook<{
6
+ public: IRuntimeConfig;
7
+ server: IRuntimeConfig;
8
+ }, void>;
9
+ };
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extendedHooks = void 0;
4
+ const hook_1 = require("@shuvi/hook");
5
+ const addEntryCode = (0, hook_1.createAsyncParallelHook)();
6
+ const addPolyfill = (0, hook_1.createAsyncParallelHook)();
7
+ const modifyRuntimeConfig = (0, hook_1.createAsyncSeriesWaterfallHook)();
8
+ exports.extendedHooks = {
9
+ addEntryCode,
10
+ addPolyfill,
11
+ modifyRuntimeConfig
12
+ };
@@ -0,0 +1,16 @@
1
+ declare const _default: {
2
+ core: import("@shuvi/hook").IPluginInstance<{
3
+ afterInit: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
4
+ afterBuild: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
5
+ afterDestroy: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
6
+ afterBundlerDone: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").BundlerDoneExtra, void, void>;
7
+ afterBundlerTargetDone: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").BundlerTargetDoneExtra, void, void>;
8
+ configWebpack: import("@shuvi/hook").AsyncSeriesWaterfallHook<import("@shuvi/service/lib/core/lifecycleTypes").WebpackChainType, import("@shuvi/service/lib/core/lifecycleTypes").ConfigWebpackAssistant>;
9
+ addExtraTarget: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").ExtraTargetAssistant, void, import("@shuvi/service/lib/core/lifecycleTypes").TargetChain>;
10
+ addResource: import("@shuvi/hook").AsyncParallelHook<void, void, import("@shuvi/service/lib/core/lifecycleTypes").Resources | import("@shuvi/service/lib/core/lifecycleTypes").Resources[]>;
11
+ addRuntimeFile: import("@shuvi/hook").AsyncParallelHook<void, import("@shuvi/service/lib/core/lifecycleTypes").AddRuntimeFileUtils, import("@shuvi/service/lib/project/index").FileOptions<any, any> | import("@shuvi/service/lib/project/index").FileOptions<any, any>[]>;
12
+ addRuntimeService: import("@shuvi/hook").AsyncParallelHook<void, void, import("@shuvi/service/lib/core/lifecycleTypes").RuntimeService | import("@shuvi/service/lib/core/lifecycleTypes").RuntimeService[]>;
13
+ } & import("@shuvi/runtime").CustomCorePluginHooks, import("@shuvi/service").IPluginContext>;
14
+ types: string;
15
+ };
16
+ export default _default;