Skip to content

Commit

Permalink
1. feat(cli) add admin-app application template
Browse files Browse the repository at this point in the history
2. feat(cli) deployment command no longer checks mode when skipping build
3. feat(cli) supports automatic identification of favicon.ico in the root directory of the project
4. feat(cli) supports generating resource manifest.json to facilitate access to the micro front-end system
5. feat(cli) front-end application supports SPA
6. feat(serve-static) optimizes the static resource caching strategy, js, css, pictures and other resources are permanently cached by default, and the HTML file is cached for 5 seconds
7. fix(cli) Fix the sourcemap file contains the local path information of the packaged user
8. fix(cli) Fix the problem of infinite loop when loading configuration file based on mode
9. fix(fc-adapter) Fix the version/alias of the custom domain name binding does not follow the deployment environment1. feat(cli) add admin-app application template
2. feat(cli) deployment command no longer checks mode when skipping build
3. feat(cli) supports automatic identification of favicon.ico in the root directory of the project
4. feat(cli) supports generating resource manifest.json to facilitate access to the micro front-end system
5. feat(cli) front-end application supports SPA
6. feat(serve-static) optimizes the static resource caching strategy, js, css, pictures and other resources are permanently cached by default, and the HTML file is cached for 5 seconds
7. fix(cli) Fix the sourcemap file contains the local path information of the packaged user
8. fix(cli) Fix the problem of infinite loop when loading configuration file based on mode
9. fix(fc-adapter) Fix the version/alias of the custom domain name binding does not follow the deployment environment1. feat(cli) add admin-app application template
2. feat(cli) deployment command no longer checks mode when skipping build
3. feat(cli) supports automatic identification of favicon.ico in the root directory of the project
4. feat(cli) supports generating resource manifest.json to facilitate access to the micro front-end system
5. feat(cli) front-end application supports SPA
6. feat(serve-static) optimizes the static resource caching strategy, js, css, pictures and other resources are permanently cached by default, and the HTML file is cached for 5 seconds
7. fix(cli) Fix the sourcemap file contains the local path information of the packaged user
8. fix(cli) Fix the problem of infinite loop when loading configuration file based on mode
9. fix(fc-adapter) Fix the version/alias of the custom domain name binding does not follow the deployment environment1. feat(cli) add admin-app application template
2. feat(cli) deployment command no longer checks mode when skipping build
3. feat(cli) supports automatic identification of favicon.ico in the root directory of the project
4. feat(cli) supports generating resource manifest.json to facilitate access to the micro front-end system
5. feat(cli) front-end application supports SPA
6. feat(serve-static) optimizes the static resource caching strategy, js, css, pictures and other resources are permanently cached by default, and the HTML file is cached for 5 seconds
7. fix(cli) Fix the sourcemap file contains the local path information of the packaged user
8. fix(cli) Fix the problem of infinite loop when loading configuration file based on mode
9. fix(fc-adapter) Fix the version/alias of the custom domain name binding does not follow the deployment environment1. feat(cli) add admin-app application template
2. feat(cli) deployment command no longer checks mode when skipping build
3. feat(cli) supports automatic identification of favicon.ico in the root directory of the project
4. feat(cli) supports generating resource manifest.json to facilitate access to the micro front-end system
5. feat(cli) front-end application supports SPA
6. feat(serve-static) optimizes the static resource caching strategy, js, css, pictures and other resources are permanently cached by default, and the HTML file is cached for 5 seconds
7. fix(cli) Fix the sourcemap file contains the local path information of the packaged user
8. fix(cli) Fix the problem of infinite loop when loading configuration file based on mode
9. fix(fc-adapter) Fix the version/alias of the custom domain name binding does not follow the deployment environment1. feat(cli) add admin-app application template
2. feat(cli) deployment command no longer checks mode when skipping build
3. feat(cli) supports automatic identification of favicon.ico in the root directory of the project
4. feat(cli) supports generating resource manifest.json to facilitate access to the micro front-end system
5. feat(cli) front-end application supports SPA
6. feat(serve-static) optimizes the static resource caching strategy, js, css, pictures and other resources are permanently cached by default, and the HTML file is cached for 5 seconds
7. fix(cli) Fix the sourcemap file contains the local path information of the packaged user
8. fix(cli) Fix the problem of infinite loop when loading configuration file based on mode
9. fix(fc-adapter) Fix the version/alias of the custom domain name binding does not follow the deployment environment1. feat(cli) add admin-app application template
2. feat(cli) deployment command no longer checks mode when skipping build
3. feat(cli) supports automatic identification of favicon.ico in the root directory of the project
4. feat(cli) supports generating resource manifest.json to facilitate access to the micro front-end system
5. feat(cli) front-end application supports SPA
6. feat(serve-static) optimizes the static resource caching strategy, js, css, pictures and other resources are permanently cached by default, and the HTML file is cached for 5 seconds
7. fix(cli) Fix the sourcemap file contains the local path information of the packaged user
8. fix(cli) Fix the problem of infinite loop when loading configuration file based on mode
9. fix(fc-adapter) Fix the version/alias of the custom domain name binding does not follow the deployment environment1. feat(cli) add admin-app application template
2. feat(cli) deployment command no longer checks mode when skipping build
3. feat(cli) supports automatic identification of favicon.ico in the root directory of the project
4. feat(cli) supports generating resource manifest.json to facilitate access to the micro front-end system
5. feat(cli) front-end application supports SPA
6. feat(serve-static) optimizes the static resource caching strategy, js, css, pictures and other resources are permanently cached by default, and the HTML file is cached for 5 seconds
7. fix(cli) Fix the sourcemap file contains the local path information of the packaged user
8. fix(cli) Fix the problem of infinite loop when loading configuration file based on mode
9. fix(fc-adapter) Fix the version/alias of the custom domain name binding does not follow the deployment environment1. feat(cli) add admin-app application template
2. feat(cli) deployment command no longer checks mode when skipping build
3. feat(cli) supports automatic identification of favicon.ico in the root directory of the project
4. feat(cli) supports generating resource manifest.json to facilitate access to the micro front-end system
5. feat(cli) front-end application supports SPA
6. feat(serve-static) optimizes the static resource caching strategy, js, css, pictures and other resources are permanently cached by default, and the HTML file is cached for 5 seconds
7. fix(cli) Fix the sourcemap file contains the local path information of the packaged user
8. fix(cli) Fix the problem of infinite loop when loading configuration file based on mode
9. fix(fc-adapter) Fix the version/alias of the custom domain name binding does not follow the deployment environment1. feat(cli) add admin-app application template
2. feat(cli) deployment command no longer checks mode when skipping build
3. feat(cli) supports automatic identification of favicon.ico in the root directory of the project
4. feat(cli) supports generating resource manifest.json to facilitate access to the micro front-end system
5. feat(cli) front-end application supports SPA
6. feat(serve-static) optimizes the static resource caching strategy, js, css, pictures and other resources are permanently cached by default, and the HTML file is cached for 5 seconds
7. fix(cli) Fix the sourcemap file contains the local path information of the packaged user
8. fix(cli) Fix the problem of infinite loop when loading configuration file based on mode
9. fix(fc-adapter) Fix the version/alias of the custom domain name binding does not follow the deployment environment1. feat(cli) add admin-app application template
2. feat(cli) deployment command no longer checks mode when skipping build
3. feat(cli) supports automatic identification of favicon.ico in the root directory of the project
4. feat(cli) supports generating resource manifest.json to facilitate access to the micro front-end system
5. feat(cli) front-end application supports SPA
6. feat(serve-static) optimizes the static resource caching strategy, js, css, pictures and other resources are permanently cached by default, and the HTML file is cached for 5 seconds
7. fix(cli) Fix the sourcemap file contains the local path information of the packaged user
8. fix(cli) Fix the problem of infinite loop when loading configuration file based on mode
9. fix(fc-adapter) Fix the version/alias of the custom domain name binding does not follow the deployment environment
  • Loading branch information
muxiangqiu committed Jun 23, 2020
1 parent 5113eee commit 3397c8d
Show file tree
Hide file tree
Showing 107 changed files with 2,788 additions and 164 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"request": "launch",
"name": "malagu serve",
"program": "${workspaceRoot}/node_modules/@malagu/cli/bin/malagu-serve",
// "args": ["-s"],
// "args": ["-m", "release"],
"env": {
"NODE_ENV": "development"
},
Expand Down
2 changes: 2 additions & 0 deletions dev-packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
},
"dependencies": {
"@yarnpkg/lockfile": "^1.1.0",
"assets-webpack-plugin": "^5.0.2",
"axios": "^0.19.2",
"chalk": "^2.4.2",
"clean-webpack-plugin": "^3.0.0",
Expand Down Expand Up @@ -79,6 +80,7 @@
"webpack-filter-warnings-plugin": "^1.2.1",
"webpack-merge": "^4.2.1",
"webpack-node-externals": "^1.7.2",
"workbox-webpack-plugin": "^5.1.3",
"worker-loader": "^2.0.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion dev-packages/cli/src/deploy/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ program
dev: false,
prod: program.prod
});
if (!program.skipBuild || mode.length > 1) {
if (!program.skipBuild) {
await new BuildManager(ctx).build();
}
const hookExecutor = new HookExecutor();
Expand Down
3 changes: 2 additions & 1 deletion dev-packages/cli/src/init/init-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,14 @@ export class InitManager {
}

protected async selectTemplate(): Promise<void> {
const spinner = ora({ text: 'loading...', discardStdin: false }).start();
const answers = await inquirer.prompt([{
name: 'item',
type: 'autocomplete',
pageSize: 12,
message: 'Select a template to init',
source: async (answersSoFar: any, input: string) => {
if (!this.source) {
const spinner = ora({ text: 'loading...', discardStdin: false }).start();
const options = {
url: SEARCH_TEMPLATE_REPO_URI,
timeout: 5000,
Expand Down
2 changes: 2 additions & 0 deletions dev-packages/cli/src/init/templates.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
export const templates: any = {
'scf-sample-app': '{{ templatePath }}/scf/sample-app',
'scf-admin-app': '{{ templatePath }}/scf/admin-app',
'scf-backend-app': '{{ templatePath }}/scf/backend-app',
'scf-database-app': '{{ templatePath }}/scf/database-app',
'scf-multi-component': '{{ templatePath }}/scf/multi-component',
'fc-sample-app': '{{ templatePath }}/fc/sample-app',
'fc-admin-app': '{{ templatePath }}/fc/admin-app',
'fc-backend-app': '{{ templatePath }}/fc/backend-app',
'fc-database-app': '{{ templatePath }}/fc/database-app',
'fc-multi-component': '{{ templatePath }}/fc/multi-component',
Expand Down
4 changes: 3 additions & 1 deletion dev-packages/cli/src/package/component-config-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@ export class ComponentPackageLoader {
for (let i = 0; i < mode.length; i++) {
const m = mode[i];
const configForMode = this.loadConfig(nodePackage, m);
configMap.set(m, configForMode);
configMap.set(m, configForMode || {});
if (configForMode) {
config = mergeWith(config, configForMode, customizer);
const modeForConfig = this.getMode(configForMode);
const diffMode = this.diffMode(modeForConfig, configMap);
if (diffMode.length > 0) {
if (i < mode.length - 1) {
mode.splice(0, i + 1);
} else {
mode = [];
}
return this.doLoad(nodePackage, this.mergeMode(diffMode, mode), configMap, config);
}
Expand Down
2 changes: 1 addition & 1 deletion dev-packages/cli/src/webpack/config/base-config-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class BaseConfigFactory {
})
]
},
devtool: dev ? 'eval-cheap-source-map' : undefined,
devtool: dev ? 'source-map' : undefined,
stats: 'errors-only',
resolve: {
extensions: [ '.tsx', '.ts', '.js' ]
Expand Down
6 changes: 4 additions & 2 deletions dev-packages/cli/src/webpack/config/config-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { HookExecutor } from '../../hook/hook-executor';
import { EntryConfigFactory } from './entry-config-factory';
import { OutputConfigFactory } from './output-config-factory';
import { DevServerConfigFactory } from './dev-server-config-factory';
import { CopyWepackPluginConfigFactory, EnvironmentPluginConfigFactory,
ForkTsCheckerWebpackPluginConfigFactory, HardSourceWebpackPluginConfigFactory,
import { CopyWepackPluginConfigFactory, EnvironmentPluginConfigFactory, WorkboxWebpackPluginConfigFactory,
ForkTsCheckerWebpackPluginConfigFactory, HardSourceWebpackPluginConfigFactory, AssetsWebpackPluginConfigFactory,
HtmlWebpackTagsPluginConfigFactory, HtmlWebpackPluginConfigFactory, CleanWebpackPluginConfigFactory } from './plugin-config-factory';
import { FRONTEND_TARGET, BACKEND_TARGET } from '../../constants';
import { MalaguYamlConfigFactory } from './malagu-yaml-config-factory';
Expand All @@ -35,6 +35,8 @@ export class ConfigFactory {
new MalaguYamlConfigFactory(),
new HtmlWebpackPluginConfigFactory(),
new HtmlWebpackTagsPluginConfigFactory(),
new WorkboxWebpackPluginConfigFactory(),
new AssetsWebpackPluginConfigFactory(),
new CleanWebpackPluginConfigFactory()
];

Expand Down
4 changes: 2 additions & 2 deletions dev-packages/cli/src/webpack/config/output-config-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getHomePath } from '../utils';

export class OutputConfigFactory {
create(config: any, context: HookContext, target: string) {
const { pkg } = context;
const { pkg, dev } = context;
const outputPath = path.join(getHomePath(pkg, target), 'dist');

const baseOutputConfig = {
Expand All @@ -19,7 +19,7 @@ export class OutputConfigFactory {
...baseOutputConfig,
filename: 'index.js',
libraryTarget: 'umd',
devtoolModuleFilenameTemplate: '[absolute-resource-path]'
devtoolModuleFilenameTemplate: dev ? '[absolute-resource-path]' : undefined
}
};
} else {
Expand Down
60 changes: 59 additions & 1 deletion dev-packages/cli/src/webpack/config/plugin-config-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
const HtmlWebpackTagsPlugin = require('html-webpack-tags-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const AssetsWebpackPlugin = require('assets-webpack-plugin');
const WorkboxWebpackPlugin = require('workbox-webpack-plugin');

export class CopyWepackPluginConfigFactory {
create(config: any, context: HookContext, target: string) {
Expand Down Expand Up @@ -116,9 +118,65 @@ export class HardSourceWebpackPluginConfigFactory {
export class HtmlWebpackPluginConfigFactory {
create(config: any, context: HookContext, target: string) {
const { pkg } = context;
const faviconPath = path.join(pkg.projectPath, 'favicon.ico');
const exists = existsSync(faviconPath);
return {
plugins: [
new HtmlWebpackPlugin({ ...{ title: 'Malagu App' }, ...getWebpackConfig(pkg, FRONTEND_TARGET).htmlWebpackPlugin || {} }),
new HtmlWebpackPlugin({
title: 'Malagu App',
favicon: exists ? faviconPath : undefined,
...getWebpackConfig(pkg, FRONTEND_TARGET).htmlWebpackPlugin || {}
}),
]
};
}

support(context: HookContext, target: string): boolean {
return FRONTEND_TARGET === target;
}
}

export class WorkboxWebpackPluginConfigFactory {
create(config: any, context: HookContext, target: string) {
const { pkg } = context;
const pluginConfig = getWebpackConfig(pkg, FRONTEND_TARGET).workboxWebpackPlugin || {};
return {
plugins: [
new WorkboxWebpackPlugin.GenerateSW({
clientsClaim: true,
skipWaiting: true,
...pluginConfig
})
]
};
}

support(context: HookContext, target: string): boolean {
return FRONTEND_TARGET === target;
}
}

export class AssetsWebpackPluginConfigFactory {
create(config: any, context: HookContext, target: string) {
const { pkg } = context;
const pluginConfig = getWebpackConfig(pkg, FRONTEND_TARGET).assetsWebpackPlugin || {};
const outputPath = path.join(getHomePath(pkg, FRONTEND_TARGET), 'dist');
const metadata = {
version: pkg.pkg.version,
name: pkg.pkg.name,
description: pkg.pkg.description,
auther: pkg.pkg.author,
icons: pkg.pkg.icons
};
return {
plugins: [
new AssetsWebpackPlugin({
filename: 'manifest.json',
metadata,
path: outputPath,
prettyPrint: true,
...pluginConfig
})
]
};
}
Expand Down
13 changes: 12 additions & 1 deletion dev-packages/cli/src/webpack/loader/component-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,18 @@ module.exports.container = Promise.resolve()
if (reason) {
console.error(reason);
}
});`;
});
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
const baseURI = document.getElementsByTagName('script')[0].baseURI;
navigator.serviceWorker.register(baseURI + 'service-worker.js').then(registration => {
console.log('SW registered: ', registration);
}).catch(registrationError => {
console.log('SW registration failed: ', registrationError);
});
});
}`;
}

function generateBackendComponents(modules: string[]) {
Expand Down
22 changes: 22 additions & 0 deletions dev-packages/cli/templates/fc/admin-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.DS_Store
node_modules
dist
lib
.malagu
.env
*.log
.idea
.metadata
*.iml
jdt.ls-java-project
lerna-debug.log
.nyc_output
coverage
errorShots
.browser_modules
**/docs/api
package-backup.json
.history
.Trash-*
packages/plugin/typedoc
plugins
19 changes: 19 additions & 0 deletions dev-packages/cli/templates/fc/admin-app/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "malagu serve",
"program": "${workspaceRoot}/node_modules/@malagu/cli/bin/malagu-serve",
"cwd": "${workspaceFolder}",
"sourceMaps": true,
"env": {
"NODE_ENV": "development"
},
"smartStep": true,
"internalConsoleOptions": "openOnSessionStart",
"outputCapture": "std"
}
]
}
55 changes: 55 additions & 0 deletions dev-packages/cli/templates/fc/admin-app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# 开发说明

以下使用 yarn 工具来说明,你也可以使用 npm。

## 安装依赖

```shell
# 通过 malagu init 初始化应用的时候已经自动安装了依赖,所以你只需要安装你额外需要的依赖即可

$ yarn add xxxx
```

## 本地运行

```shell
# 启动本地服务,端口默认 3000
# 在终端中会输出本地服务的 URL 链接

$ yarn start # 或者执行 malagu serve 命令
```

## 构建部署

模板默认提供了四套隔离环境:本地(local)、测试(test)、预发(pre)、线上(release)。每个环境对于这一个 malagu 配置文件,类似 malagu-test.yml。而 malagu.yml 文件一般用于放所有环境的公共配置。如果你不需要这么多得环境隔离,删掉相关的配置文件即可。第一次部署的时候可能会提示你填写相关云厂商 ak 信息。如果是 Vercel 云平台的模板,会提示你需要登录到 Vercel 平台。你也可以在项目通过 .env 提供云厂商的 ak 信息。

```shell

$ yarn deploy # 部署到测试环境
$ yarn deploy:test # 部署到测试环境
$ yarn deploy:pre # 部署到预发环境
$ yarn deploy:release # 部署到线上环境

```

## 关于 Malagu Framework

Malagu 是基于 TypeScript 的 Serverless First、可扩展和组件化的应用框架。

**主要特点:**

1. 基于 TypeScript
1. 零配置
1. NodeJs 版 Spring Boot
1. Serverless First
1. 组件化
1. 前后端一体化
1. 面向切面编程(AOP)
1. 集成了 ORM 框架
1. 命令工具插件化
1. 支持适配任意前端框架

**相关链接**

* [框架项目地址](https://github.com/cellbang/malagu)
* [框架详细文档](https://www.yuque.com/cellbang/malagu)
Binary file added dev-packages/cli/templates/fc/admin-app/favicon.ico
Binary file not shown.
4 changes: 4 additions & 0 deletions dev-packages/cli/templates/fc/admin-app/malagu-pre.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
deployConfig:
name: pre # 预发环境
# customDomain:
# name: pre.xxx.com # 需要绑定自定义域名才能正常访问
4 changes: 4 additions & 0 deletions dev-packages/cli/templates/fc/admin-app/malagu-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
deployConfig:
name: release # 线上环境
# customDomain:
# name: xxx.com # 需要绑定自定义域名才能正常访问
4 changes: 4 additions & 0 deletions dev-packages/cli/templates/fc/admin-app/malagu-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
deployConfig:
name: test # 测试环境
# customDomain:
# name: test.xxx.com # 需要绑定自定义域名才能正常访问
3 changes: 3 additions & 0 deletions dev-packages/cli/templates/fc/admin-app/malagu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 依赖的公共前端 UI 框从 CDN 上加载
# mode: cdn

36 changes: 36 additions & 0 deletions dev-packages/cli/templates/fc/admin-app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "app3",
"keywords": [
"malagu-component"
],
"version": "0.0.0",
"license": "MIT",
"files": [
"lib",
"src"
],
"dependencies": {
"@malagu/rpc": "latest",
"@malagu/react": "latest",
"@malagu/material-ui": "latest",
"@malagu/serve-static": "latest",
"@malagu/fc-adapter": "latest"
},
"devDependencies": {
"@malagu/cli": "latest",
"rimraf": "^2.6.3",
"@types/react": "^16.9.38",
"@types/react-dom": "^16.8.5",
"@types/react-router": "^5.1.7",
"@types/react-router-dom": "^5.1.5"
},
"scripts": {
"clean": "rimraf lib dist .malagu",
"build": "malagu build",
"start": "malagu serve",
"deploy": "malagu deploy -m test",
"deploy:test": "malagu deploy -m test",
"deploy:pre": "malagu deploy -m pre",
"deploy:release": "malagu deploy -m release"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './main';
Loading

0 comments on commit 3397c8d

Please sign in to comment.