34 | );
35 | }
36 |
37 | export default App;
38 |
--------------------------------------------------------------------------------
/packages/monitor/monitor-sdk-browser/src/paint/types.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * File: paint.ts
3 | * Description: 绘制相关类型定义
4 | * Created: 2021-08-26 22:22:32
5 | * Author: yuzhanglong
6 | * Email: yuzl1123@163.com
7 | */
8 | import type { MonitorOptions } from '../types';
9 |
10 | export interface PaintReportData {
11 | // FP
12 | firstPaint: Record
13 | // FCP
14 | firstContentfulPaint: Record
15 | // 汇报时间戳
16 | timeStamp: number
17 | }
18 |
19 | export interface LargestContentfulPaint {
20 | duration: number
21 | element: Element
22 | entryType: string
23 | id: string
24 | loadTime: number
25 | name: string
26 | renderTime: number
27 | size: number
28 | startTime: number
29 | url: string
30 | }
31 |
32 | export interface LargestContentfulPaintReportData {
33 | // LCP
34 | largestContentfulPaint: LargestContentfulPaint
35 | // 汇报时间戳
36 | timeStamp: number
37 | }
38 |
39 | export type PaintMonitorOptions = MonitorOptions;
40 |
--------------------------------------------------------------------------------
/packages/monitor/monitor-sdk-browser/src/utils/get-url-data.ts:
--------------------------------------------------------------------------------
1 | import type { UrlData } from '../types';
2 | import { getBrowserWindow } from './browser-interfaces';
3 | import { assignKeysBetweenObjects } from './assign-keys-between-objects';
4 |
5 | export const getUrlData = (url: string): UrlData => {
6 | // 支持 url
7 | const keys: string[] = ['hash', 'host', 'hostname', 'href', 'origin', 'pathname', 'port', 'protocol', 'search'];
8 |
9 | const res = {
10 | url,
11 | hash: '',
12 | host: '',
13 | hostname: '',
14 | href: '',
15 | origin: '',
16 | pathname: '',
17 | port: '',
18 | protocol: '',
19 | search: '',
20 | };
21 |
22 | const w = getBrowserWindow();
23 |
24 | // 这里不推荐用浏览器内置的 URL 实例,而是利用原生 a 标签的特性来实现
25 | // 因为像下面 img 标签这样的错误,拿到的 "url" 是不规范的,使用 new URL() 会抛出异常
26 | //
27 | if (w && w.document) {
28 | const a = document.createElement('a');
29 | a.href = url;
30 | assignKeysBetweenObjects(a, res, keys);
31 | }
32 | return res;
33 | };
34 |
--------------------------------------------------------------------------------
/packages/i18n/i18n-webpack-plugin/examples/my-app/src/app.tsx:
--------------------------------------------------------------------------------
1 | import ReactDOM from "react-dom";
2 | import { BrowserRouter } from "react-router-dom";
3 | import React, { Suspense } from "react";
4 | import { renderRoutes } from "react-router-config";
5 | import { routes } from "~src/routes";
6 | import "./utils/init-common";
7 | import "@attachments/utils/src/browser/css/common.css";
8 |
9 | // @ts-ignore
10 | window.intl = (a, b) => {
11 | return a + JSON.stringify(b);
12 | };
13 |
14 | const App = () => {
15 | return (
16 |
17 |
18 | {renderRoutes(routes)}
19 |
20 |
21 | );
22 | };
23 |
24 |
25 | const reactRenderer = () => {
26 | ReactDOM.render((
27 |
28 |
29 |
30 | ), document.getElementById("my-app"));
31 | };
32 |
33 | const beforeAppStart = async () => {
34 | return true;
35 | };
36 |
37 | beforeAppStart()
38 | .then(() => {
39 | reactRenderer();
40 | });
41 |
42 |
43 |
--------------------------------------------------------------------------------
/packages/proxy/src/middlewares/url-middleware.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * File: resolve-req-url.ts
3 | * Description: req 参数的 url 属性不包含主机名,我们要进行额外的加工,注意,后面关于 url 的一切参数都从这边获取
4 | * Created: 2021-08-11 15:04:19
5 | * Author: yuzhanglong
6 | * Email: yuzl1123@163.com
7 | */
8 | import type { ProxyServerContext, ProxyServerMiddleware } from '../types';
9 |
10 | export function createUrlMiddleWare(): ProxyServerMiddleware {
11 | return async (ctx: ProxyServerContext, next) => {
12 | const { incomingRequestData, protocol } = ctx;
13 |
14 | if (!protocol)
15 | throw new Error('[@attachments/proxy] please give us a protocol!');
16 |
17 | const host = incomingRequestData.headers.host || '';
18 | // origin 指 协议 + 主机的形式
19 | const origin = `${protocol}://${host}`;
20 | // req.url 为 nodejs 的 API,指的是 url 串除了 origin 一部分(search、params 所在的地方)
21 | ctx.urlInstance = new URL(incomingRequestData.url, origin);
22 |
23 | // 略去 80 端口
24 | if (ctx.urlInstance.port === '80')
25 | ctx.urlInstance.port = '';
26 |
27 | await next();
28 | };
29 | }
30 |
--------------------------------------------------------------------------------
/packages/monitor/monitor-sdk-browser/src/xhr/types.ts:
--------------------------------------------------------------------------------
1 | import type { BaseObject, MonitorOptions, UrlData } from '../types';
2 |
3 | // xhr 监控结果记录数据
4 | export interface XHRReportData {
5 | // 请求数据,包括 url 相关参数
6 | request: UrlData & {
7 | // 请求方法
8 | method: string
9 | // 通过 setRequestHeaders 添加的请求头
10 | headers: Record
11 | body: string
12 | }
13 | performance: Record
14 | duration: number
15 | response: {
16 | status: number
17 | timestamp: number
18 | headers: Record
19 | body: string
20 | }
21 | }
22 |
23 | // xhr 监控选项
24 | export type XHRMonitorOptions = MonitorOptions;
25 |
26 | // xhr 监控实例暂存数据记录,挂在在用户初始化的 XMLHttpRequest 上
27 | interface XHRMonitorRecode {
28 | url?: string
29 | method?: string
30 | startTime?: number
31 | requestHeaders?: BaseObject
32 | requestData?: Parameters[0]
33 | }
34 |
35 | export interface PatchedXMLHttpRequest extends XMLHttpRequest {
36 | // 记录信息
37 | monitorRecords: XHRMonitorRecode
38 | }
39 |
--------------------------------------------------------------------------------
/packages/assets/src/templates/typescript-project/package.json.hbs:
--------------------------------------------------------------------------------
1 | {
2 | "name": "{{package project-name}}",
3 | "version": "0.0.0",
4 | "description": "> TODO: add description",
5 | "author": "> TODO: add author",
6 | "homepage": "",
7 | "license": "MIT",
8 | "main": "lib/index.js",
9 | "module": "esm/index.js",
10 | "files": [
11 | "src",
12 | "esm",
13 | "lib"
14 | ],
15 | "scripts": {
16 | "dev:start": "tsc -w",
17 | "build:cjs": "rimraf ./lib && tsc --module commonjs --outDir lib",
18 | "build:esm": "rimraf ./esm && tsc --module ESNext --outDir esm",
19 | "build": "npm-run-all --parallel build:*",
20 | "lint": "eslint --ext js,jsx,ts,tsx src",
21 | "test": "jest"
22 | },
23 | "devDependencies": {
24 | "@attachments/eslint-plugin": "^0.1.0",
25 | "@types/jest": "^26.0.24",
26 | "@types/node": "^16.4.6",
27 | "eslint": "^7.31.0",
28 | "jest": "^27.0.6",
29 | "npm-run-all": "^4.1.5",
30 | "prettier": "^2.4.1",
31 | "rimraf": "^3.0.2",
32 | "ts-jest": "^27.0.4",
33 | "ts-node": "^10.1.0",
34 | "typescript": "^4.3.5"
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 YuZhanglong
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/packages/assets/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 YuZhanglong
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/packages/hooks/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 YuZhanglong
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/packages/proxy/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 YuZhanglong
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/packages/utils/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 YuZhanglong
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/packages/i18n/i18n-core/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 YuZhanglong
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/packages/i18n/babel-plugin-i18n/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 YuZhanglong
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/packages/i18n/i18n-webpack-plugin/examples/my-app/src/utils/create-micro-app.tsx:
--------------------------------------------------------------------------------
1 | import React, { useEffect, useRef } from 'react';
2 | import { MicroApp, MicroAppRef } from '@mf-lite/core/esm/browser/micro-app';
3 | import { MICRO_APPS, MicroAppConfig } from '~src/common/const';
4 |
5 |
6 | export const getMicroApp = (name: string): MicroAppConfig => {
7 | const item = MICRO_APPS.find(res => res.name === name);
8 | if (!item) {
9 | throw new Error(`the micro app ${name} is not exist!`);
10 | }
11 | return item;
12 | };
13 |
14 |
15 | export const createMicroApp = (name: string) => {
16 | return () => {
17 | const ref = useRef(null);
18 |
19 | const microAppConfig = {
20 | name: name,
21 | entry: getMicroApp(name).url,
22 | }
23 |
24 | useEffect(() => {
25 | if (ref.current?.appStore) {
26 | ref.current?.appStore.microApp?.loadPromise
27 | .then(() => {
28 | console.log('micro app loaded!');
29 | });
30 | }
31 | }, []);
32 |
33 | return (
34 |
37 | );
38 | };
39 | };
40 |
--------------------------------------------------------------------------------
/packages/assets/src/configurations/node-plop/ts-project-generator.ts:
--------------------------------------------------------------------------------
1 | import * as path from 'path';
2 | import type * as plop from 'node-plop';
3 | import { createAddConfigAction, createAddManyTemplatesAction } from '../../utils';
4 |
5 | const project = function (plop: plop.NodePlopAPI) {
6 | plop.setGenerator('typescript package', {
7 | description: 'generate a typescript package',
8 | prompts: [
9 | {
10 | type: 'input',
11 | name: 'project-name',
12 | message: 'Please enter the name of the package:',
13 | },
14 | ],
15 | actions: [
16 | // ts basic template
17 | createAddManyTemplatesAction('typescript-project', path.resolve(process.cwd(), '{{project-name}}')),
18 | // eslint config
19 | createAddConfigAction('eslintrc.js.hbs', path.resolve(process.cwd(), '{{project-name}}', '.eslintrc.js')),
20 | // jest config
21 | createAddConfigAction('jest.config.js.hbs', path.resolve(process.cwd(), '{{project-name}}', 'jest.config.js')),
22 | ],
23 | });
24 |
25 | plop.setHelper('package', (name) => {
26 | return `@attachments/${name}`;
27 | });
28 | };
29 |
30 | export default project;
31 |
--------------------------------------------------------------------------------
/packages/assets/src/templates/micro-frontend/base-app/src/utils/create-micro-app.tsx.hbs:
--------------------------------------------------------------------------------
1 | import React, { useEffect, useRef } from 'react';
2 | import { MicroApp, MicroAppRef } from '@mf-lite/core/esm/browser/micro-app';
3 | import { MICRO_APPS, MicroAppConfig } from '~src/common/const';
4 |
5 |
6 | export const getMicroApp = (name: string): MicroAppConfig => {
7 | const item = MICRO_APPS.find(res => res.name === name);
8 | if (!item) {
9 | throw new Error(`the micro app ${name} is not exist!`);
10 | }
11 | return item;
12 | };
13 |
14 |
15 | export const createMicroApp = (name: string) => {
16 | return () => {
17 | const ref = useRef(null);
18 |
19 | const microAppConfig = {
20 | name: name,
21 | entry: getMicroApp(name).url,
22 | }
23 |
24 | useEffect(() => {
25 | if (ref.current?.appStore) {
26 | ref.current?.appStore.microApp?.loadPromise
27 | .then(() => {
28 | console.log('micro app loaded!');
29 | });
30 | }
31 | }, []);
32 |
33 | return (
34 |
37 | );
38 | };
39 | };
40 |
--------------------------------------------------------------------------------
/packages/i18n/i18n-webpack-plugin/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 YuZhanglong
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/packages/monitor/monitor-sdk-browser/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 YuZhanglong
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/packages/utils/src/node/load-ts-config-file.ts:
--------------------------------------------------------------------------------
1 | import type { Service } from 'ts-node';
2 | import { interopRequireDefault } from './interop-require-default';
3 |
4 | /**
5 | * 加载 typescript 文件,常用于加载一些配置文件
6 | *
7 | * @author yuzhanglong
8 | * @date 2021-10-10 22:21:31
9 | */
10 | export const loadTsConfigFile = async (configPath: string): Promise => {
11 | let tsNodeService: Service;
12 |
13 | // Register TypeScript compiler instance
14 | try {
15 | tsNodeService = require('ts-node').register({
16 | compilerOptions: {
17 | module: 'CommonJS',
18 | },
19 | });
20 | }
21 | catch (e) {
22 | if (e.code === 'MODULE_NOT_FOUND') {
23 | throw new Error(
24 | `'ts-node' is required for the TypeScript configuration files. Make sure it is installed\nError: ${e.message}`,
25 | );
26 | }
27 |
28 | throw e;
29 | }
30 |
31 | tsNodeService.enabled(true);
32 |
33 | let configObject = interopRequireDefault(require(configPath)).default;
34 |
35 | // 配置文件是一个函数,调用之
36 | if (typeof configObject === 'function')
37 | configObject = await configObject();
38 |
39 | tsNodeService.enabled(false);
40 |
41 | return configObject;
42 | };
43 |
--------------------------------------------------------------------------------
/packages/assets/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@attachments/assets",
3 | "version": "0.4.0",
4 | "license": "MIT",
5 | "description": "common resource tool packages, such as the CSS and project templates",
6 | "author": "yuzhanglong ",
7 | "homepage": "https://github.com/yuzhanglong/attachments",
8 | "files": [
9 | "src",
10 | "lib",
11 | "esm"
12 | ],
13 | "bin": {
14 | "attachments": "./lib/attachments.js"
15 | },
16 | "scripts": {
17 | "test": "attachments generate ts",
18 | "dev:start": "tsc -w",
19 | "build:cjs": "rimraf ./lib && tsc --module commonjs --outDir lib",
20 | "build:esm": "rimraf ./esm && tsc --module ESNext --outDir esm",
21 | "build": "npm-run-all --parallel build:*",
22 | "typescript-template": "cd playground && plop --plopfile ../lib/configurations/node-plop/ts-project-generator.js",
23 | "micro-app-template": "cd playground && plop --plopfile ../lib/configurations/node-plop/micro-fe-generator.js"
24 | },
25 | "dependencies": {
26 | "@attachments/utils": "^0.4.0",
27 | "commander": "^8.2.0",
28 | "execa": "^5.1.1",
29 | "minimist": "^1.2.5",
30 | "node-plop": "^0.26.3",
31 | "plop": "^2.7.6"
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/packages/assets/src/templates/micro-frontend/micro-app/src/pages/home.tsx.hbs:
--------------------------------------------------------------------------------
1 | import React, { useState } from 'react';
2 | import { renderRoutes } from 'react-router-config';
3 | import { RouteComponentProps } from 'react-router';
4 | import './home.less';
5 |
6 | interface HomeProps extends RouteComponentProps {
7 |
8 | }
9 |
10 | const Home: React.FC = (props) => {
11 | // @ts-ignore
12 | const { route, history, location } = props;
13 | const [currentPage, setCurrentPage] = useState<'one' | 'two'>(
14 | location.pathname === '/page-two' ? 'two' : 'one'
15 | );
16 |
17 | const handleButtonClick = () => {
18 | const nextPage = currentPage === 'one' ? 'two' : 'one';
19 | setCurrentPage(nextPage);
20 | history.push(`page-${nextPage}`);
21 | };
22 |
23 | return (
24 |