This repository has been archived by the owner on Jul 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: process * fix: package rootDir
- Loading branch information
Showing
17 changed files
with
342 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
packages/faas-cli-plugin-package/test/fixtures/ts-dir/build.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"entry": "src/index.tsx", | ||
"plugins": [ | ||
"build-plugin-ice-app", | ||
["build-plugin-fusion", { | ||
"themePackage": "@icedesign/theme" | ||
}], | ||
"./build.plugin.js" | ||
] | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/faas-cli-plugin-package/test/fixtures/ts-dir/f.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
service: fc-test | ||
|
||
provider: | ||
name: fc | ||
runtime: nodejs10 | ||
|
||
functions: | ||
test1: | ||
handler: index.handler | ||
events: | ||
- http: true |
18 changes: 18 additions & 0 deletions
18
packages/faas-cli-plugin-package/test/fixtures/ts-dir/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "@icedesign/ts-scaffold9ade4c90-5de3-11e9-aef1-79dc0073b61f", | ||
"version": "1.0.3", | ||
"description": "该模板基于 TypeScript 适用于从 0 到 1 开始搭建项目,内置基础的页面,路由和菜单展示", | ||
"dependencies": { | ||
"@midwayjs/faas": "*", | ||
"react-router-dom": "*", | ||
"tslib": "*" | ||
}, | ||
"scripts": { | ||
"start": "build-scripts start", | ||
"build": "build-scripts build", | ||
"lint": "eslint . --ext '.js,.jsx' --fix" | ||
}, | ||
"engines": { | ||
"node": ">=8.0.0" | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
packages/faas-cli-plugin-package/test/fixtures/ts-dir/src/apis/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { | ||
provide, | ||
func, | ||
FunctionHandler, | ||
inject, | ||
FaaSContext, | ||
} from '@midwayjs/faas'; | ||
|
||
@provide() | ||
@func('index.handler') | ||
export class IndexHandler implements FunctionHandler { | ||
@inject() | ||
ctx: FaaSContext; | ||
/** | ||
* 发布为 hsf 时 | ||
* 这个参数是 ginkgo 固定的,入参出参都为字符串 | ||
* @param event | ||
*/ | ||
async handler(event: string) { | ||
return 'hello'; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
packages/faas-cli-plugin-package/test/fixtures/ts-dir/src/components/Greeting/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from 'react'; | ||
|
||
export interface Props { | ||
name: string; | ||
} | ||
|
||
const Greeting = ({ name }: Props) => { | ||
return ( | ||
<div style={{ textAlign: 'center', fontSize: '40px', fontWeight: 'bold' }}> | ||
Hello, {name} | ||
</div> | ||
); | ||
}; | ||
|
||
export default Greeting; |
77 changes: 77 additions & 0 deletions
77
packages/faas-cli-plugin-package/test/fixtures/ts-dir/src/components/Guide/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import React from 'react'; | ||
import { Button } from '@alifd/next'; | ||
|
||
const Guide = () => { | ||
return ( | ||
<div style={{ width: '400px', margin: '40px auto' }}> | ||
<h2 style={{ textAlign: 'center' }}>使用指南</h2> | ||
<ul> | ||
<li style={styles.item}> | ||
1. 该模板适用于从 0 到 1 开始搭建项目,内置引导页面,路由和菜单展示。 | ||
</li> | ||
<li style={styles.item}>2. 菜单配置: menuConfig.js。</li> | ||
<li style={styles.item}>3. 路由配置: routerConfig.js。</li> | ||
<li style={styles.item}> | ||
4. 通过 GUI 工具{' '} | ||
<a | ||
href="https://alibaba.github.io/ice/iceworks" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
Iceworks | ||
</a>{' '} | ||
创建页面,会同步的更新菜单和路由配置。 | ||
</li> | ||
<li style={styles.item}> | ||
5. 基于{' '} | ||
<a | ||
href="https://alibaba.github.io/ice/block" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
物料 | ||
</a>{' '} | ||
生成的页面将会添加在 pages 目录。 | ||
</li> | ||
<li style={styles.item}> | ||
6. 让前端工程变的轻松便捷, | ||
<a | ||
href="https://alibaba.github.io/ice/docs/iceworks" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
下载 iceworks | ||
</a>{' '} | ||
。 | ||
</li> | ||
</ul> | ||
<div style={{ textAlign: 'center', marginTop: '40px' }}> | ||
<a | ||
href="https://alibaba.github.io/ice/docs/iceworks" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
<Button type="secondary" style={{ marginRight: '20px' }}> | ||
快速开始{' '} | ||
</Button> | ||
</a> | ||
<a | ||
href="https://www.tslang.cn/docs/home.html" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
<Button type="primary">学习 TypeScript</Button> | ||
</a> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
const styles = { | ||
item: { | ||
height: '34px', | ||
lineHeight: '34px', | ||
}, | ||
}; | ||
|
||
export default Guide; |
14 changes: 14 additions & 0 deletions
14
packages/faas-cli-plugin-package/test/fixtures/ts-dir/src/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import ReactDOM from 'react-dom'; | ||
|
||
// 载入默认全局样式 normalize | ||
import '@alifd/next/reset.scss'; | ||
|
||
import router from './router'; | ||
|
||
const ICE_CONTAINER = document.getElementById('ice-container'); | ||
|
||
if (!ICE_CONTAINER) { | ||
throw new Error('当前页面不存在 <div id="ice-container"></div> 节点.'); | ||
} | ||
|
||
ReactDOM.render(router(), ICE_CONTAINER); |
37 changes: 37 additions & 0 deletions
37
packages/faas-cli-plugin-package/test/fixtures/ts-dir/src/layouts/BasicLayout/MainRoutes.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React, { Component } from 'react'; | ||
import { Redirect, Switch, Route } from 'react-router-dom'; | ||
import routerConfig from '../../routerConfig'; | ||
import Guide from '../../components/Guide'; | ||
|
||
class MainRoutes extends Component { | ||
/** | ||
* 渲染路由组件 | ||
*/ | ||
renderNormalRoute = (item, index) => { | ||
return item.component ? ( | ||
<Route | ||
key={index} | ||
path={item.path} | ||
component={item.component} | ||
exact={item.exact} | ||
/> | ||
) : null; | ||
}; | ||
|
||
render() { | ||
return ( | ||
<Switch> | ||
{/* 渲染路由表 */} | ||
{routerConfig.map(this.renderNormalRoute)} | ||
|
||
{/* 首页默认重定向到 /dashboard */} | ||
<Redirect exact from="/" to="/dashboard" /> | ||
|
||
{/* 未匹配到的路由重定向到 <Guide> 组件,实际情况应该重定向到 404 */} | ||
<Route component={Guide} /> | ||
</Switch> | ||
); | ||
} | ||
} | ||
|
||
export default MainRoutes; |
12 changes: 12 additions & 0 deletions
12
packages/faas-cli-plugin-package/test/fixtures/ts-dir/src/layouts/BasicLayout/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React, { Component } from 'react'; | ||
import MainRoutes from './MainRoutes'; | ||
|
||
export default class BasicLayout extends Component { | ||
render() { | ||
return ( | ||
<div style={{ paddingTop: '100px' }}> | ||
<MainRoutes /> | ||
</div> | ||
); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
packages/faas-cli-plugin-package/test/fixtures/ts-dir/src/menuConfig.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// 菜单配置 | ||
|
||
const asideMenuConfig = []; | ||
|
||
export { asideMenuConfig }; |
14 changes: 14 additions & 0 deletions
14
packages/faas-cli-plugin-package/test/fixtures/ts-dir/src/pages/Dashboard/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import React, { Component } from 'react'; | ||
import Guide from '../../components/Guide'; | ||
import Greeting from '../../components/Greeting'; | ||
|
||
export default class Dashboard extends Component { | ||
render() { | ||
return ( | ||
<div> | ||
<Greeting name="TypeScript" /> | ||
<Guide /> | ||
</div> | ||
); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
packages/faas-cli-plugin-package/test/fixtures/ts-dir/src/router.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* 定义应用路由 | ||
*/ | ||
import { HashRouter, Switch, Route } from 'react-router-dom'; | ||
import React from 'react'; | ||
import BasicLayout from './layouts/BasicLayout'; | ||
|
||
const router = () => { | ||
return ( | ||
<HashRouter> | ||
<Switch> | ||
<Route path="/" component={BasicLayout} /> | ||
</Switch> | ||
</HashRouter> | ||
); | ||
}; | ||
|
||
export default router; |
13 changes: 13 additions & 0 deletions
13
packages/faas-cli-plugin-package/test/fixtures/ts-dir/src/routerConfig.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// 以下文件格式为描述路由的协议格式 | ||
// 你可以调整 routerConfig 里的内容 | ||
// 变量名 routerConfig 为 iceworks 检测关键字,请不要修改名称 | ||
import Dashboard from './pages/Dashboard'; | ||
|
||
const routerConfig = [ | ||
{ | ||
path: '/dashboard', | ||
component: Dashboard, | ||
}, | ||
]; | ||
|
||
export default routerConfig; |
3 changes: 3 additions & 0 deletions
3
packages/faas-cli-plugin-package/test/fixtures/ts-dir/src/util.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function foo () { | ||
return 'bar' | ||
} |
28 changes: 28 additions & 0 deletions
28
packages/faas-cli-plugin-package/test/fixtures/ts-dir/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"compileOnSave": false, | ||
"buildOnSave": false, | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"outDir": "build", | ||
"module": "esnext", | ||
"target": "es6", | ||
"jsx": "react", | ||
"moduleResolution": "node", | ||
"allowSyntheticDefaultImports": true, | ||
"lib": ["es6", "dom"], | ||
"sourceMap": true, | ||
"allowJs": true, | ||
"rootDir": "src", | ||
"forceConsistentCasingInFileNames": true, | ||
"noImplicitReturns": true, | ||
"noImplicitThis": true, | ||
"noImplicitAny": false, | ||
"importHelpers": true, | ||
"strictNullChecks": true, | ||
"suppressImplicitAnyIndexErrors": true, | ||
"noUnusedLocals": true, | ||
"skipLibCheck": true | ||
}, | ||
"include": ["src/*"], | ||
"exclude": ["node_modules", "build", "public"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { CommandHookCore, loadSpec } from '@midwayjs/fcli-command-core'; | ||
import { PackagePlugin } from '../src/index'; | ||
import { resolve, join } from 'path'; | ||
import { existsSync, remove } from 'fs-extra'; | ||
import * as assert from 'assert'; | ||
|
||
describe('/test/package-ice.test.ts', () => { | ||
describe('package base midway faas project', () => { | ||
const baseDir = resolve(__dirname, './fixtures/ts-dir'); | ||
|
||
afterEach(async () => { | ||
await remove(join(baseDir, 'serverless.zip')); | ||
await remove(join(baseDir, 'package-lock.json')); | ||
// await remove(join(baseDir, '.serverless')); | ||
await remove(join(baseDir, 'node_modules')); | ||
}); | ||
it('base package', async () => { | ||
const core = new CommandHookCore({ | ||
config: { | ||
servicePath: baseDir, | ||
}, | ||
commands: ['package'], | ||
service: loadSpec(baseDir), | ||
provider: 'aliyun', | ||
options: { | ||
sourceDir: 'src/apis' | ||
}, | ||
log: console, | ||
}); | ||
core.addPlugin(PackagePlugin); | ||
await core.ready(); | ||
await core.invoke(['package']); | ||
const buildPath = join(baseDir, '.serverless'); | ||
assert(existsSync(join(buildPath, 'dist/index.js'))); | ||
assert(!existsSync(join(buildPath, 'dist/apis'))); | ||
}); | ||
}); | ||
}); |