Skip to content

Commit

Permalink
- feat(cli) add the malagu.webpack.sourceMaploaderExclude property …
Browse files Browse the repository at this point in the history
…to ignore the warning message that the source map cannot be loaded

- feat(cli) build and release code also generates the `malagu.yml` file to the `.malagu` directory, which can be ignored by the `codeUri` property of the function. The default is to ignore the upload of the `malagu.yml` file to prevent some private information Give way
- feat(fc-adapter) adds the `codeUri` property configuration to the function, and the default value is to ignore the upload of the `malagu.yml` file
- feat(scf-adapter) adds the `codeUri` property configuration to the function, and the default value is to ignore the upload of the `malagu.yml` file
- feat(puppeteer) add @malagu/puppeteer component
- feat(cli) add `puppeteer` application template
- feat(mvc) adds the file view `FileView` to facilitate the implementation of file download related APIs. It also provides a simplified decorator `@File()`, and also provides `@Text()`, `@Json()` , `@Html()` decorator simplifies the ability to use different types of views
  • Loading branch information
muxiangqiu committed Dec 5, 2020
1 parent e5780b3 commit 073c8a4
Show file tree
Hide file tree
Showing 50 changed files with 997 additions and 61 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# Change Log

## v1.8.0

- feat(cli) add the `malagu.webpack.sourceMaploaderExclude` property to ignore the warning message that the source map cannot be loaded
- feat(cli) build and release code also generates the `malagu.yml` file to the `.malagu` directory, which can be ignored by the `codeUri` property of the function. The default is to ignore the upload of the `malagu.yml` file to prevent some private information Give way
- feat(fc-adapter) adds the `codeUri` property configuration to the function, and the default value is to ignore the upload of the `malagu.yml` file
- feat(scf-adapter) adds the `codeUri` property configuration to the function, and the default value is to ignore the upload of the `malagu.yml` file
- feat(puppeteer) add @malagu/puppeteer component
- feat(cli) add `puppeteer` application template
- feat(mvc) adds the file view `FileView` to facilitate the implementation of file download related APIs. It also provides a simplified decorator `@File()`, and also provides `@Text()`, `@Json()` , `@Html()` decorator simplifies the ability to use different types of views

- feat(cli) 添加 `malagu.webpack.sourceMaploaderExclude` 属性,用于忽略 source map 加载不到警告信息
- feat(cli) 构建发布代码也生成 `malagu.yml` 文件到 `.malagu` 目录,可以通过函数的 `codeUri` 属性进行忽略,默认是忽略 `malagu.yml` 文件上传的,防止一些私密信息泄露
- feat(fc-adapter) 为函数添加 `codeUri` 属性配置,且默认值为忽略掉 `malagu.yml` 文件的上传
- feat(scf-adapter) 为函数添加 `codeUri` 属性配置,且默认值为忽略掉 `malagu.yml` 文件的上传
- feat(puppeteer) 添加 @malagu/puppeteer 组件
- feat(cli) 添加 `puppeteer` 应用模板
- feat(mvc) 添加文件视图 `FileView`,方便实现文件下载相关 API,同时也提供简化的装饰器 `@File()`,另外也提供了 `@Text()``@Json()``@Html()` 装饰器简化使用不同类型视图能力

## v1.7.0

- feat(core) optimizes the AOP user interface and provides the decorator `@Aspect()`
Expand Down
2 changes: 1 addition & 1 deletion dev-packages/cli/src/external/pack-external-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export async function packExternalModules(context: ConfigurationContext, stats:
const configuration = ConfigurationContext.getConfiguration(BACKEND_TARGET, context.configurations);
const packagerId = config.packager;
const includes = config.includeModules;
const packagerOptions = config.packagerOptions || {};
const packagerOptions = { frozenLockfile: true, nonInteractive: true, ...config.packagerOptions };
const scripts: any[] = packagerOptions.scripts || [];

if (!includes || !configuration) {
Expand Down
1 change: 1 addition & 0 deletions dev-packages/cli/src/init/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const templates: any = {
'database-app': '{{ templatePath }}/database-app',
'admin-app': '{{ templatePath }}/admin-app',
'microservice': '{{ templatePath }}/microservice',
'puppeteer': '{{ templatePath }}/puppeteer',
'multi-component': '{{ templatePath }}/multi-component',
'mycli': '{{ templatePath }}/mycli',
'site': 'https://github.com/cellbang/cellbang-site.git'
Expand Down
8 changes: 7 additions & 1 deletion dev-packages/cli/src/packager/yarn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,18 @@ export class Yarn {

install(cwd: string, packagerOptions: any) {
const command = /^win/.test(process.platform) ? 'yarn.cmd' : 'yarn';
const args = ['install', '--frozen-lockfile', '--non-interactive'];
const args = ['install'];

// Convert supported packagerOptions
if (packagerOptions.ignoreScripts) {
args.push('--ignore-scripts');
}
if (packagerOptions.frozenLockfile) {
args.push('--frozen-lockfile');
}
if (packagerOptions.nonInteractive) {
args.push('--non-interactive');
}
return spawnProcess(command, args, { cwd, stdio: 'inherit' });
}

Expand Down
8 changes: 6 additions & 2 deletions dev-packages/cli/src/webpack/config/base-config-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ const TerserPlugin = require('terser-webpack-plugin');
const nodeExternals = require('webpack-node-externals');
import * as merge from 'webpack-merge';
import * as path from 'path';
import { getWebpackConfig } from '../utils';

export class BaseConfigFactory {

create(config: any, context: CliContext, target: string) {
const { dev, pkg } = context;
const { dev, pkg, cfg } = context;
let sourceMaploaderExclude = getWebpackConfig(cfg, target).sourceMaploaderExclude || {};
sourceMaploaderExclude = Object.keys(sourceMaploaderExclude).map(key => sourceMaploaderExclude[key]);
sourceMaploaderExclude = new RegExp(['jsonc-parser|class-transformer|smart-buffer|socks|agent-base', ...sourceMaploaderExclude].join('|'));
const webpackMode = dev ? 'development' : 'production';
const baseConfig = {
name: target,
Expand Down Expand Up @@ -40,7 +44,7 @@ export class BaseConfigFactory {
test: /\.js$/,
enforce: 'pre',
use: 'source-map-loader',
exclude: /jsonc-parser|class-transformer/
exclude: sourceMaploaderExclude
},
{
test: /\.tsx?$/,
Expand Down
10 changes: 3 additions & 7 deletions dev-packages/cli/src/webpack/config/plugin-config-factory.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as webpack from 'webpack';
import * as path from 'path';
import { CliContext } from '../../context';
import { existsSync, ensureDirSync, writeFileSync, removeSync } from 'fs-extra';
import { existsSync, ensureDirSync, writeFileSync } from 'fs-extra';
import { getWebpackConfig, getConfig, getHomePath, getMalaguConfig, getDevSuccessInfo } from '../utils';
import { FRONTEND_TARGET, CONFIG_FILE } from '../../constants';
import yaml = require('js-yaml');
Expand Down Expand Up @@ -77,16 +77,12 @@ export class CopyWepackPluginConfigFactory {

export class EnvironmentPluginConfigFactory {
create(config: any, context: CliContext, target: string) {
const { cfg, pkg, dev } = context;
const { cfg, pkg } = context;
const c = getConfig(cfg, target);
const homePath = getHomePath(pkg, target);
ensureDirSync(homePath);
const configPath = path.join(homePath, CONFIG_FILE);
if (dev) {
writeFileSync(configPath, yaml.dump(c), { encoding: 'utf8' });
} else {
removeSync(configPath);
}
writeFileSync(configPath, yaml.dump(c), { encoding: 'utf8' });
return {
plugins: [
new webpack.EnvironmentPlugin({
Expand Down
4 changes: 2 additions & 2 deletions dev-packages/cli/templates/backend-app/src/home-controller.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Controller, Get, View, TextView } from '@malagu/mvc/lib/node';
import { Controller, Get, Text } from '@malagu/mvc/lib/node';

@Controller()
export class HomeController {

@Get()
@View(TextView.VIEW_NAME)
@Text()
home(): string {
return 'Welcome to Malagu';
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Controller, Get, View, TextView } from '@malagu/mvc/lib/node';
import { Controller, Get, Text } from '@malagu/mvc/lib/node';

@Controller('/')
export class HomeController {

@Get()
@View(TextView.VIEW_NAME)
@Text()
home(): string {
return 'Welcome to Malagu';
}
Expand Down
25 changes: 25 additions & 0 deletions dev-packages/cli/templates/puppeteer/.github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Malagu Deploy

on: push

jobs:
malagu-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup node
uses: actions/setup-node@v1
with:
node-version: '12'
- uses: bahmutov/npm-install@v1
- run: npm run lint --if-present
- run: npm test
- if: ${{ github.ref == 'refs/heads/master' }}
env: ${{ secrets }}
run: npx malagu deploy -m prod
- if: ${{ github.ref == 'refs/heads/pre' }}
env: ${{ secrets }}
run: npx malagu deploy -m pre
- if: ${{ github.ref != 'refs/heads/master' && github.ref != 'refs/heads/pre' }}
env: ${{ secrets }}
run: npx malagu deploy -m test
23 changes: 23 additions & 0 deletions dev-packages/cli/templates/puppeteer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.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
.local-chromium
20 changes: 20 additions & 0 deletions dev-packages/cli/templates/puppeteer/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "pwa-node",
"request": "launch",
"name": "malagu serve",
"program": "${workspaceRoot}/node_modules/@malagu/cli/bin/malagu",
"args": [ "serve" ],
"cwd": "${workspaceFolder}",
"sourceMaps": true,
"env": {
"NODE_ENV": "development"
},
"smartStep": true,
"internalConsoleOptions": "openOnSessionStart",
"outputCapture": "std"
}
]
}
93 changes: 93 additions & 0 deletions dev-packages/cli/templates/puppeteer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# 开发说明

## 安装依赖

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

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

$ yarn add xxxx
```

## 本地运行

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

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

## 构建部署

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

```bash

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

```

## 关于 Malagu Framework

Malagu 是基于 TypeScript 的 Serverless First、组件化、平台无关的渐进式应用框架。


### 特征

- 约定大于配置,零配置,开箱即用
- TypeScript 版 Spring Boot
- Serverless First
- 平台不锁定
- 支持前后端一体化,前端框架不锁定
- 支持微服务
- 组件化,渐进式
- 命令行工具插件化
- 依赖注入
- 面向切面编程(AOP)
- 集成了流行的 ORM 框架,使用装饰器声明式事务管理
- 支持 OIDC 认证
- 支持 OAuth2 授权
- 使用 rxjs 管理状态
- 提供 REST 和 RPC 两种接口风格

Malagu 名字由来:在我的家乡,谐音“吗啦咕”是小石头的意思,小石头堆砌起来可以建成高楼大厦、道路桥梁,而 Malagu 组件编排可以实现千变万化的应用。

### 快速开始

```bash
# 安装命令行工具
npm install -g yarn
npm install -g @malagu/cli

# 初始化
malagu init project-name
cd project-name # 进入项目根目录

# 运行
malagu serve

# 部署
malagu deploy
```

### 文档

- [介绍](https://www.yuque.com/cellbang/malagu/puw7p0)
- [快速开始](https://www.yuque.com/cellbang/malagu/qmq79k)
- [命令行工具](https://www.yuque.com/cellbang/malagu/xbfpir)
- [控制器](https://www.yuque.com/cellbang/malagu/cbgl7g)
- [数据库操作](https://www.yuque.com/cellbang/malagu/ztbcwq)
- [微服务](https://www.yuque.com/cellbang/malagu/wtiy6s)
- [认证与授权](https://www.yuque.com/cellbang/malagu/qhl0km)
- [云平台适配](https://www.yuque.com/cellbang/malagu/hh1mng)
- [依赖注入](https://www.yuque.com/cellbang/malagu/fw025h)
- [组件设计](https://www.yuque.com/cellbang/malagu/qaqomw)
- [前端架构](https://www.yuque.com/cellbang/malagu/vl9wbw)
- [React 开发](https://www.yuque.com/cellbang/malagu/fum7u8)
- [前后端一体化开发](https://www.yuque.com/cellbang/malagu/fi6lxi)

9 changes: 9 additions & 0 deletions dev-packages/cli/templates/puppeteer/malagu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
targets:
- backend
malagu:
puppeteer:
bucket: headless-lib # 指定存放 headless 相关二进制的 oss 的 Bucket 名称 headless-lib
object: headless-lib.tar.gz # 指定存放 headless 相关二进制的 oss 的 objeck 名称,默认 headless-lib.tar.gz
accessKeyId: xxxxxxxxxxxxxxxxxxxxxxxx # 指定能够访问存放 headless 相关二进制 accessKeyId,至少具有读该 Object 的权限
accessKeySecret: xxxxxxxxxxxxxxxxxxxxxx
region: oss-cn-hangzhou # 指定存放 headless 相关二进制的 oss 的地域,建议与应用部署的地域一致
30 changes: 30 additions & 0 deletions dev-packages/cli/templates/puppeteer/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "puppeteer",
"keywords": [
"malagu-component"
],
"version": "0.0.0",
"license": "MIT",
"files": [
"lib",
"src"
],
"dependencies": {
"@malagu/mvc": "latest",
"@malagu/puppeteer": "latest",
"@malagu/fc-adapter": "latest"
},
"devDependencies": {
"@malagu/cli": "latest",
"rimraf": "^2.6.3"
},
"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:prod": "malagu deploy -m prod"
}
}
11 changes: 11 additions & 0 deletions dev-packages/cli/templates/puppeteer/src/home-controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Controller, Get, Text } from '@malagu/mvc/lib/node';

@Controller()
export class HomeController {

@Get()
@Text()
home(): string {
return 'Welcome to Malagu';
}
}
5 changes: 5 additions & 0 deletions dev-packages/cli/templates/puppeteer/src/module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import './home-controller';
import './puppeteer-controller';
import { autoBind } from '@malagu/core';

export default autoBind();
26 changes: 26 additions & 0 deletions dev-packages/cli/templates/puppeteer/src/puppeteer-controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Autowired } from '@malagu/core';
import { Context } from '@malagu/web/lib/node';
import { Controller, Get, Query, File } from '@malagu/mvc/lib/node';
import { BrowserProvider } from '@malagu/puppeteer';

@Controller()
export class PuppeteerController {

@Autowired(BrowserProvider)
protected readonly browserProvider: BrowserProvider;

@Get('screenshot')
@File()
async screenshot(@Query('url') url?: string) {
const response = Context.getResponse();
response.attachment('download.png');
const browser = await this.browserProvider.provide();
const page = await browser.newPage();
try {
await page.goto(url || 'https://baidu.com', { waitUntil: 'networkidle0' });
return await page.screenshot();
} finally {
await page.close();
}
}
}
Loading

0 comments on commit 073c8a4

Please sign in to comment.