├── .eslintrc.json ├── .github └── workflows │ ├── gh-pages.yml │ └── nodejs.yml ├── .gitignore ├── .gitpod.yml ├── .prettierrc.js ├── CHANGELOG.md ├── LICENSE ├── README.en-US.md ├── README.md ├── benchmark ├── bc.test.ts └── cli.js ├── docs ├── .vuepress │ ├── config.js │ └── styles │ │ └── index.styl ├── README.md └── guide │ ├── README.md │ └── yml.md ├── lerna.json ├── package.json ├── packages ├── egg-layer │ ├── CHANGELOG.md │ ├── framework │ │ ├── app │ │ │ └── extend │ │ │ │ └── context.js │ │ ├── config │ │ │ └── config.default.js │ │ └── index.js │ ├── package.json │ ├── src │ │ └── index.ts │ ├── test │ │ ├── fixtures │ │ │ └── eaas │ │ │ │ ├── README.md │ │ │ │ ├── agent.js │ │ │ │ ├── app.js │ │ │ │ ├── app │ │ │ │ ├── controller │ │ │ │ │ └── home.js │ │ │ │ └── router.js │ │ │ │ ├── config │ │ │ │ ├── config.default.js │ │ │ │ └── plugin.js │ │ │ │ ├── index.js │ │ │ │ └── package.json │ │ ├── index.test.ts │ │ └── mock.ts │ └── tsconfig.json ├── faas-cli-command-core │ ├── CHANGELOG.md │ ├── README.md │ ├── benchmark │ │ └── core.js │ ├── package.json │ ├── src │ │ ├── cli.ts │ │ ├── core.ts │ │ ├── errorMap.ts │ │ ├── index.ts │ │ ├── interface │ │ │ ├── commandHookCore.ts │ │ │ ├── plugin.ts │ │ │ └── provider.ts │ │ ├── npm.ts │ │ ├── plugin.ts │ │ ├── pluginManager.ts │ │ └── utils │ │ │ ├── commandLineUsage.ts │ │ │ └── loadSpec.ts │ ├── test │ │ ├── cli.test.ts │ │ ├── core.test.ts │ │ ├── f.yml │ │ ├── fixtures │ │ │ └── userLifecycle │ │ │ │ ├── index.js │ │ │ │ ├── package.json │ │ │ │ └── test.txt │ │ ├── index.test.ts │ │ ├── plugins │ │ │ ├── empty.ts │ │ │ ├── one.common.ts │ │ │ ├── store.get.ts │ │ │ ├── store.set.ts │ │ │ ├── test.invoke.ts │ │ │ └── test.lg.ts │ │ └── utils.test.ts │ └── tsconfig.json ├── faas-cli-plugin-create │ ├── CHANGELOG.md │ ├── README.md │ ├── package.json │ ├── src │ │ ├── categorySelect.ts │ │ ├── index.ts │ │ └── list.ts │ ├── test │ │ ├── create.test.ts │ │ └── helper.ts │ └── tsconfig.json ├── faas-cli-plugin-deploy │ ├── CHANGELOG.md │ ├── package.json │ ├── src │ │ └── index.ts │ └── tsconfig.json ├── faas-cli-plugin-dev-pack │ ├── CHANGELOG.md │ ├── package.json │ ├── src │ │ └── index.ts │ └── tsconfig.json ├── faas-cli-plugin-fc │ ├── CHANGELOG.md │ ├── package.json │ ├── src │ │ ├── index.ts │ │ └── utils.ts │ ├── test │ │ ├── fixtures │ │ │ ├── base-fc │ │ │ │ ├── f.yml │ │ │ │ ├── package.json │ │ │ │ ├── src │ │ │ │ │ └── index.ts │ │ │ │ ├── test │ │ │ │ │ └── deploy.test.ts │ │ │ │ └── tsconfig.json │ │ │ └── eaas │ │ │ │ ├── .travis.yml │ │ │ │ ├── README.md │ │ │ │ ├── agent.js │ │ │ │ ├── app.js │ │ │ │ ├── app │ │ │ │ ├── controller │ │ │ │ │ └── home.js │ │ │ │ └── router.js │ │ │ │ ├── appveyor.yml │ │ │ │ ├── config │ │ │ │ ├── config.default.js │ │ │ │ └── plugin.js │ │ │ │ ├── f.yml │ │ │ │ ├── index.js │ │ │ │ ├── node_modules │ │ │ │ └── .keep │ │ │ │ └── package.json │ │ └── index.test.ts │ └── tsconfig.json ├── faas-cli-plugin-invoke │ ├── CHANGELOG.md │ ├── package.json │ ├── src │ │ ├── index.ts │ │ ├── invoke.ts │ │ └── utils.ts │ ├── test │ │ ├── apigw.test.ts │ │ ├── fixtures │ │ │ ├── baseApp │ │ │ │ ├── package.json │ │ │ │ ├── serverless.yml │ │ │ │ ├── src │ │ │ │ │ └── index.ts │ │ │ │ └── tsconfig.json │ │ │ ├── http-scf │ │ │ │ ├── package.json │ │ │ │ ├── serverless.yml │ │ │ │ ├── src │ │ │ │ │ └── index.ts │ │ │ │ └── tsconfig.json │ │ │ ├── http │ │ │ │ ├── package.json │ │ │ │ ├── serverless.yml │ │ │ │ ├── src │ │ │ │ │ └── index.ts │ │ │ │ └── tsconfig.json │ │ │ ├── ice-faas-ts-pkg-options │ │ │ │ ├── build.json │ │ │ │ ├── f.yml │ │ │ │ ├── package.json │ │ │ │ ├── src │ │ │ │ │ ├── apis │ │ │ │ │ │ └── index.ts │ │ │ │ │ ├── components │ │ │ │ │ │ ├── Greeting │ │ │ │ │ │ │ └── index.tsx │ │ │ │ │ │ └── Guide │ │ │ │ │ │ │ └── index.tsx │ │ │ │ │ ├── index.tsx │ │ │ │ │ ├── layouts │ │ │ │ │ │ └── BasicLayout │ │ │ │ │ │ │ ├── MainRoutes.tsx │ │ │ │ │ │ │ └── index.tsx │ │ │ │ │ ├── menuConfig.ts │ │ │ │ │ ├── pages │ │ │ │ │ │ └── Dashboard │ │ │ │ │ │ │ └── index.tsx │ │ │ │ │ ├── router.tsx │ │ │ │ │ └── routerConfig.ts │ │ │ │ ├── test │ │ │ │ │ └── index.js │ │ │ │ └── tsconfig.json │ │ │ ├── ice-faas-ts-standard │ │ │ │ ├── build.json │ │ │ │ ├── f.yml │ │ │ │ ├── package.json │ │ │ │ ├── src │ │ │ │ │ ├── apis │ │ │ │ │ │ └── index.ts │ │ │ │ │ ├── components │ │ │ │ │ │ ├── Greeting │ │ │ │ │ │ │ └── index.tsx │ │ │ │ │ │ └── Guide │ │ │ │ │ │ │ └── index.tsx │ │ │ │ │ ├── index.tsx │ │ │ │ │ ├── layouts │ │ │ │ │ │ └── BasicLayout │ │ │ │ │ │ │ ├── MainRoutes.tsx │ │ │ │ │ │ │ └── index.tsx │ │ │ │ │ ├── menuConfig.ts │ │ │ │ │ ├── pages │ │ │ │ │ │ └── Dashboard │ │ │ │ │ │ │ └── index.tsx │ │ │ │ │ ├── router.tsx │ │ │ │ │ └── routerConfig.ts │ │ │ │ ├── test │ │ │ │ │ └── index.js │ │ │ │ └── tsconfig.json │ │ │ ├── initializer │ │ │ │ ├── index.js │ │ │ │ ├── package.json │ │ │ │ ├── serverless.yml │ │ │ │ ├── src │ │ │ │ │ └── index.ts │ │ │ │ └── tsconfig.json │ │ │ ├── multiApp │ │ │ │ ├── package.json │ │ │ │ ├── serverless.yml │ │ │ │ ├── src │ │ │ │ │ └── index.ts │ │ │ │ └── tsconfig.json │ │ │ ├── noYaml │ │ │ │ ├── package.json │ │ │ │ ├── serverless.yml │ │ │ │ ├── src │ │ │ │ │ └── index.ts │ │ │ │ └── tsconfig.json │ │ │ └── same-handler-addon │ │ │ │ ├── package.json │ │ │ │ ├── serverless.yml │ │ │ │ ├── src │ │ │ │ └── index.ts │ │ │ │ └── tsconfig.json │ │ ├── http.test.ts │ │ ├── index.test.ts │ │ ├── initialize.test.ts │ │ ├── invoke.js │ │ ├── main.test.ts │ │ ├── multi.test.ts │ │ ├── noyaml.test.ts │ │ └── same-handler-addon.test.ts │ └── tsconfig.json ├── faas-cli-plugin-package │ ├── CHANGELOG.md │ ├── package.json │ ├── src │ │ ├── index.ts │ │ └── utils.ts │ ├── test │ │ ├── aggregation.test.ts │ │ ├── commonPrefix.test.ts │ │ ├── fixtures │ │ │ ├── aggregation │ │ │ │ ├── f.yml │ │ │ │ ├── package.json │ │ │ │ ├── src │ │ │ │ │ └── index.ts │ │ │ │ └── tsconfig.json │ │ │ ├── base-app-pkg-config │ │ │ │ ├── a.json │ │ │ │ ├── app │ │ │ │ │ └── test.js │ │ │ │ ├── b.json │ │ │ │ ├── package.json │ │ │ │ ├── serverless.yml │ │ │ │ ├── src │ │ │ │ │ └── index.ts │ │ │ │ └── tsconfig.json │ │ │ ├── base-app │ │ │ │ ├── copy.js │ │ │ │ ├── package.json │ │ │ │ ├── serverless.yml │ │ │ │ ├── src │ │ │ │ │ └── index.ts │ │ │ │ └── tsconfig.json │ │ │ ├── eaas │ │ │ │ ├── .travis.yml │ │ │ │ ├── README.md │ │ │ │ ├── agent.js │ │ │ │ ├── app.js │ │ │ │ ├── app │ │ │ │ │ ├── controller │ │ │ │ │ │ └── home.js │ │ │ │ │ └── router.js │ │ │ │ ├── appveyor.yml │ │ │ │ ├── config │ │ │ │ │ ├── config.default.js │ │ │ │ │ └── plugin.js │ │ │ │ ├── f.yml │ │ │ │ ├── index.js │ │ │ │ ├── node_modules │ │ │ │ │ └── .keep │ │ │ │ └── package.json │ │ │ ├── ice-faas-ts │ │ │ │ ├── build.json │ │ │ │ ├── f.yml │ │ │ │ ├── package.json │ │ │ │ ├── share │ │ │ │ │ ├── common │ │ │ │ │ │ └── a.js │ │ │ │ │ └── render.html │ │ │ │ ├── src │ │ │ │ │ ├── apis │ │ │ │ │ │ └── index.ts │ │ │ │ │ ├── components │ │ │ │ │ │ ├── Greeting │ │ │ │ │ │ │ └── index.tsx │ │ │ │ │ │ └── Guide │ │ │ │ │ │ │ └── index.tsx │ │ │ │ │ ├── index.tsx │ │ │ │ │ ├── layouts │ │ │ │ │ │ └── BasicLayout │ │ │ │ │ │ │ ├── MainRoutes.tsx │ │ │ │ │ │ │ └── index.tsx │ │ │ │ │ ├── menuConfig.ts │ │ │ │ │ ├── pages │ │ │ │ │ │ └── Dashboard │ │ │ │ │ │ │ └── index.tsx │ │ │ │ │ ├── router.tsx │ │ │ │ │ ├── routerConfig.ts │ │ │ │ │ └── util.ts │ │ │ │ ├── tests │ │ │ │ │ └── index.js │ │ │ │ └── tsconfig.json │ │ │ ├── midway-faas-one │ │ │ │ ├── client │ │ │ │ │ ├── ice.config.js │ │ │ │ │ ├── package.json │ │ │ │ │ ├── src │ │ │ │ │ │ ├── index.tsx │ │ │ │ │ │ └── pages │ │ │ │ │ │ │ └── Demo │ │ │ │ │ │ │ └── index.tsx │ │ │ │ │ └── tsconfig.json │ │ │ │ ├── cloud │ │ │ │ │ ├── f.yml │ │ │ │ │ ├── package.json │ │ │ │ │ ├── src │ │ │ │ │ │ └── ping.ts │ │ │ │ │ └── tsconfig.json │ │ │ │ └── package.json │ │ │ ├── noYaml │ │ │ │ ├── package.json │ │ │ │ ├── serverless.yml │ │ │ │ ├── src │ │ │ │ │ └── index.ts │ │ │ │ └── tsconfig.json │ │ │ ├── plugins │ │ │ │ ├── faas_tmp_out.ts │ │ │ │ ├── test.js │ │ │ │ └── test.ts │ │ │ └── ts-dir │ │ │ │ ├── build.json │ │ │ │ ├── f.yml │ │ │ │ ├── package.json │ │ │ │ ├── src │ │ │ │ ├── apis │ │ │ │ │ └── index.ts │ │ │ │ ├── components │ │ │ │ │ ├── Greeting │ │ │ │ │ │ └── index.tsx │ │ │ │ │ └── Guide │ │ │ │ │ │ └── index.tsx │ │ │ │ ├── index.tsx │ │ │ │ ├── layouts │ │ │ │ │ └── BasicLayout │ │ │ │ │ │ ├── MainRoutes.tsx │ │ │ │ │ │ └── index.tsx │ │ │ │ ├── menuConfig.ts │ │ │ │ ├── pages │ │ │ │ │ └── Dashboard │ │ │ │ │ │ └── index.tsx │ │ │ │ ├── router.tsx │ │ │ │ ├── routerConfig.ts │ │ │ │ └── util.ts │ │ │ │ └── tsconfig.json │ │ ├── noyaml.test.ts │ │ ├── package-ice.test.ts │ │ └── package.test.ts │ └── tsconfig.json ├── faas-cli-plugin-scf │ ├── CHANGELOG.md │ ├── package.json │ ├── src │ │ └── index.ts │ ├── test │ │ ├── fixtures │ │ │ └── base │ │ │ │ ├── f.yml │ │ │ │ ├── package.json │ │ │ │ ├── src │ │ │ │ └── index.ts │ │ │ │ └── tsconfig.json │ │ └── index.test.ts │ └── tsconfig.json ├── faas-cli-plugin-test │ ├── CHANGELOG.md │ ├── package.json │ ├── src │ │ ├── index.ts │ │ ├── mocha-clean.ts │ │ └── test.ts │ ├── test │ │ ├── a.test.ts │ │ └── b.test.ts │ └── tsconfig.json ├── faas-cli │ ├── CHANGELOG.md │ ├── bin │ │ ├── cli.js │ │ └── fun.js │ ├── package.json │ ├── src │ │ └── index.ts │ ├── test │ │ └── index.test.ts │ └── tsconfig.json ├── faas-dev-pack │ ├── CHANGELOG.md │ ├── README.md │ ├── gateway.json │ ├── package.json │ ├── src │ │ ├── common.ts │ │ ├── index.ts │ │ └── interface.ts │ ├── test │ │ ├── fixtures │ │ │ ├── base-fn-apigw │ │ │ │ ├── f.yml │ │ │ │ ├── package.json │ │ │ │ ├── src │ │ │ │ │ └── index.ts │ │ │ │ └── tsconfig.json │ │ │ ├── base-fn-http │ │ │ │ ├── f.yml │ │ │ │ ├── package.json │ │ │ │ ├── src │ │ │ │ │ └── index.ts │ │ │ │ └── tsconfig.json │ │ │ └── ice-demo-repo │ │ │ │ ├── README.md │ │ │ │ ├── f.yml │ │ │ │ ├── ice.config.js │ │ │ │ ├── package.json │ │ │ │ ├── public │ │ │ │ ├── favicon.png │ │ │ │ └── index.html │ │ │ │ ├── src │ │ │ │ ├── apis │ │ │ │ │ ├── index.ts │ │ │ │ │ └── test2.ts │ │ │ │ ├── components │ │ │ │ │ ├── Greeting │ │ │ │ │ │ └── index.tsx │ │ │ │ │ └── Guide │ │ │ │ │ │ └── index.tsx │ │ │ │ ├── index.tsx │ │ │ │ ├── layouts │ │ │ │ │ └── BasicLayout │ │ │ │ │ │ ├── MainRoutes.tsx │ │ │ │ │ │ └── index.tsx │ │ │ │ ├── menuConfig.ts │ │ │ │ ├── pages │ │ │ │ │ └── Dashboard │ │ │ │ │ │ └── index.tsx │ │ │ │ ├── router.tsx │ │ │ │ └── routerConfig.ts │ │ │ │ └── tsconfig.json │ │ └── index.test.ts │ └── tsconfig.json ├── faas-typings │ ├── CHANGELOG.md │ ├── index.d.ts │ ├── package.json │ └── typings │ │ ├── common.ts │ │ ├── fc.ts │ │ └── scf.ts ├── faas-util-ts-compile │ ├── CHANGELOG.md │ ├── package.json │ ├── src │ │ ├── codeAnalysis.ts │ │ ├── index.ts │ │ └── utils.ts │ ├── test │ │ ├── code.test.ts │ │ ├── fixtures │ │ │ ├── baseApp │ │ │ │ └── src │ │ │ │ │ ├── class.ts │ │ │ │ │ └── func.ts │ │ │ └── files │ │ │ │ ├── from │ │ │ │ ├── 1.js │ │ │ │ ├── 1.json │ │ │ │ ├── 1.txt │ │ │ │ └── files │ │ │ │ │ ├── a.ts │ │ │ │ │ └── b.ts │ │ │ │ ├── tmp │ │ │ │ └── .gitkeep │ │ │ │ └── to │ │ │ │ ├── 1.js │ │ │ │ ├── 1.txt │ │ │ │ └── files │ │ │ │ └── b.ts │ │ └── utils.test.ts │ └── tsconfig.json ├── faas │ ├── CHANGELOG.md │ ├── README.md │ ├── index.d.ts │ ├── package.json │ ├── src │ │ ├── config.default.ts │ │ ├── configuration.ts │ │ ├── index.ts │ │ ├── interface.ts │ │ └── starter.ts │ ├── test │ │ ├── configuration.ts │ │ ├── fixtures │ │ │ ├── base-app-configuration │ │ │ │ ├── package.json │ │ │ │ └── src │ │ │ │ │ ├── config.default.ts │ │ │ │ │ ├── config │ │ │ │ │ └── config.prod.ts │ │ │ │ │ ├── configuration.ts │ │ │ │ │ ├── hello.ts │ │ │ │ │ └── lib │ │ │ │ │ └── userManager.ts │ │ │ ├── base-app-handler │ │ │ │ ├── package.json │ │ │ │ └── src │ │ │ │ │ └── index.ts │ │ │ ├── base-app-handler2 │ │ │ │ ├── package.json │ │ │ │ └── src │ │ │ │ │ └── index.ts │ │ │ ├── base-app-inject │ │ │ │ ├── package.json │ │ │ │ └── src │ │ │ │ │ └── index.ts │ │ │ ├── base-app-ioc │ │ │ │ ├── ioc.js │ │ │ │ ├── package.json │ │ │ │ ├── proxy │ │ │ │ │ └── test.ts │ │ │ │ └── src │ │ │ │ │ └── index.ts │ │ │ ├── base-app-middleware │ │ │ │ ├── package.json │ │ │ │ └── src │ │ │ │ │ ├── config.default.ts │ │ │ │ │ ├── configuration.ts │ │ │ │ │ ├── index.ts │ │ │ │ │ └── mw │ │ │ │ │ └── test.ts │ │ │ ├── base-app-new │ │ │ │ ├── package.json │ │ │ │ └── src │ │ │ │ │ ├── index.ts │ │ │ │ │ └── middleware │ │ │ │ │ └── auth.ts │ │ │ ├── base-app-route │ │ │ │ ├── package.json │ │ │ │ └── src │ │ │ │ │ └── index.ts │ │ │ ├── base-app │ │ │ │ ├── package.json │ │ │ │ └── src │ │ │ │ │ └── index.ts │ │ │ └── midway-plugin-mod │ │ │ │ ├── package.json │ │ │ │ ├── src │ │ │ │ ├── articleManager.ts │ │ │ │ ├── configuration.ts │ │ │ │ └── replaceManager.ts │ │ │ │ └── tsconfig.json │ │ └── index.test.ts │ └── tsconfig.json ├── gateway-common-core │ ├── CHANGELOG.md │ ├── README.md │ ├── package.json │ ├── src │ │ ├── gatewaySuit.ts │ │ ├── index.ts │ │ └── interface.ts │ ├── test │ │ ├── index.ts │ │ └── suit.test.ts │ └── tsconfig.json ├── gateway-common-http │ ├── CHANGELOG.md │ ├── README.md │ ├── package.json │ ├── src │ │ ├── common.ts │ │ ├── index.ts │ │ └── utils.ts │ ├── test │ │ ├── fixtures │ │ │ └── ice-demo-repo │ │ │ │ ├── README.md │ │ │ │ ├── f.yml │ │ │ │ ├── ice.config.js │ │ │ │ ├── package.json │ │ │ │ ├── public │ │ │ │ ├── favicon.png │ │ │ │ └── index.html │ │ │ │ ├── src │ │ │ │ ├── apis │ │ │ │ │ ├── index.ts │ │ │ │ │ ├── test2.ts │ │ │ │ │ ├── test3.ts │ │ │ │ │ ├── test4.ts │ │ │ │ │ └── test6.ts │ │ │ │ ├── components │ │ │ │ │ ├── Greeting │ │ │ │ │ │ └── index.tsx │ │ │ │ │ └── Guide │ │ │ │ │ │ └── index.tsx │ │ │ │ ├── index.tsx │ │ │ │ ├── layouts │ │ │ │ │ └── BasicLayout │ │ │ │ │ │ ├── MainRoutes.tsx │ │ │ │ │ │ └── index.tsx │ │ │ │ ├── menuConfig.ts │ │ │ │ ├── pages │ │ │ │ │ └── Dashboard │ │ │ │ │ │ └── index.tsx │ │ │ │ ├── router.tsx │ │ │ │ └── routerConfig.ts │ │ │ │ └── tsconfig.json │ │ └── index.test.ts │ └── tsconfig.json ├── runtime-engine │ ├── CHANGELOG.md │ ├── package.json │ ├── src │ │ ├── bootstrap.ts │ │ ├── engine.ts │ │ ├── error.ts │ │ ├── index.ts │ │ ├── interface.ts │ │ ├── lib │ │ │ ├── debug.ts │ │ │ ├── logger.ts │ │ │ ├── loggerFactory.ts │ │ │ └── parser.ts │ │ ├── lightRuntime.ts │ │ ├── runtime.ts │ │ └── util.ts │ ├── test │ │ ├── fixtures │ │ │ ├── base.ts │ │ │ ├── common │ │ │ │ └── index.ts │ │ │ ├── crash │ │ │ │ └── index.ts │ │ │ ├── error │ │ │ │ └── index.ts │ │ │ ├── extension │ │ │ │ ├── httpEvent.ts │ │ │ │ └── index.ts │ │ │ └── js │ │ │ │ └── index.ts │ │ ├── index.test.ts │ │ ├── layer.test.ts │ │ ├── lib │ │ │ ├── logger.test.ts │ │ │ └── parser.test.ts │ │ ├── perf-events.test.ts │ │ ├── runtime-error.test.ts │ │ ├── runtime-events.test.ts │ │ └── util.test.ts │ └── tsconfig.json ├── runtime-mock │ ├── CHANGELOG.md │ ├── package.json │ ├── src │ │ ├── event.ts │ │ ├── index.ts │ │ ├── runtime.ts │ │ └── trigger.ts │ ├── test │ │ ├── code │ │ │ ├── index.ts │ │ │ └── spec.yml │ │ └── index.test.ts │ └── tsconfig.json ├── serverless-aws-starter │ ├── CHANGELOG.md │ ├── README.md │ ├── package.json │ ├── resource │ │ └── event.json │ ├── src │ │ ├── context.ts │ │ ├── index.ts │ │ ├── interface.ts │ │ └── runtime.ts │ ├── test │ │ └── index.test.ts │ └── tsconfig.json ├── serverless-fc-starter │ ├── CHANGELOG.md │ ├── README.md │ ├── package.json │ ├── resource │ │ └── event_req.json │ ├── src │ │ ├── index.ts │ │ └── runtime.ts │ ├── test │ │ ├── fixtures │ │ │ ├── apigw │ │ │ │ └── index.ts │ │ │ ├── event │ │ │ │ └── index.ts │ │ │ ├── http-json │ │ │ │ └── index.ts │ │ │ └── http │ │ │ │ └── index.ts │ │ └── index.test.ts │ └── tsconfig.json ├── serverless-fc-trigger │ ├── CHANGELOG.md │ ├── package.json │ ├── src │ │ ├── apiGateway.ts │ │ ├── base.ts │ │ ├── cdn.ts │ │ ├── http.ts │ │ ├── index.ts │ │ ├── interface.ts │ │ ├── mns.ts │ │ ├── oss.ts │ │ ├── sls.ts │ │ ├── tableStore.ts │ │ └── timer.ts │ ├── test │ │ ├── fixtures │ │ │ ├── apiGateway │ │ │ │ └── index.ts │ │ │ ├── cdn │ │ │ │ └── index.ts │ │ │ ├── event │ │ │ │ └── index.ts │ │ │ ├── http │ │ │ │ └── index.ts │ │ │ ├── oss │ │ │ │ └── index.ts │ │ │ ├── sls │ │ │ │ └── index.ts │ │ │ └── timer │ │ │ │ └── index.ts │ │ └── index.test.ts │ └── tsconfig.json ├── serverless-http-parser │ ├── CHANGELOG.md │ ├── README.md │ ├── package.json │ ├── src │ │ ├── application.ts │ │ ├── context.ts │ │ ├── http │ │ │ ├── req.ts │ │ │ └── res.ts │ │ ├── index.ts │ │ ├── interface.ts │ │ ├── request.ts │ │ └── response.ts │ ├── test │ │ ├── index.test.ts │ │ └── resource │ │ │ ├── fc_apigw.json │ │ │ ├── fc_apigw_post_form.json │ │ │ ├── fc_apigw_post_gw_filter.json │ │ │ ├── fc_apigw_post_json.json │ │ │ ├── fc_apigw_post_text.json │ │ │ ├── fc_ctx.json │ │ │ ├── fc_http.json │ │ │ ├── scf_apigw.json │ │ │ └── scf_ctx.json │ └── tsconfig.json ├── serverless-invoke │ ├── CHANGELOG.md │ ├── README.md │ ├── package.json │ ├── src │ │ └── index.ts │ ├── test │ │ ├── fixtures │ │ │ ├── baseApp │ │ │ │ ├── package.json │ │ │ │ ├── serverless.yml │ │ │ │ ├── src │ │ │ │ │ └── index.ts │ │ │ │ └── tsconfig.json │ │ │ ├── ice-faas-ts-pkg-options │ │ │ │ ├── build.json │ │ │ │ ├── f.yml │ │ │ │ ├── package.json │ │ │ │ ├── src │ │ │ │ │ ├── apis │ │ │ │ │ │ └── index.ts │ │ │ │ │ ├── components │ │ │ │ │ │ ├── Greeting │ │ │ │ │ │ │ └── index.tsx │ │ │ │ │ │ └── Guide │ │ │ │ │ │ │ └── index.tsx │ │ │ │ │ ├── index.tsx │ │ │ │ │ ├── layouts │ │ │ │ │ │ └── BasicLayout │ │ │ │ │ │ │ ├── MainRoutes.tsx │ │ │ │ │ │ │ └── index.tsx │ │ │ │ │ ├── menuConfig.ts │ │ │ │ │ ├── pages │ │ │ │ │ │ └── Dashboard │ │ │ │ │ │ │ └── index.tsx │ │ │ │ │ ├── router.tsx │ │ │ │ │ └── routerConfig.ts │ │ │ │ ├── test │ │ │ │ │ └── index.js │ │ │ │ └── tsconfig.json │ │ │ ├── ice-faas-ts-standard │ │ │ │ ├── build.json │ │ │ │ ├── f.yml │ │ │ │ ├── package.json │ │ │ │ ├── src │ │ │ │ │ ├── apis │ │ │ │ │ │ └── index.ts │ │ │ │ │ ├── components │ │ │ │ │ │ ├── Greeting │ │ │ │ │ │ │ └── index.tsx │ │ │ │ │ │ └── Guide │ │ │ │ │ │ │ └── index.tsx │ │ │ │ │ ├── index.tsx │ │ │ │ │ ├── layouts │ │ │ │ │ │ └── BasicLayout │ │ │ │ │ │ │ ├── MainRoutes.tsx │ │ │ │ │ │ │ └── index.tsx │ │ │ │ │ ├── menuConfig.ts │ │ │ │ │ ├── pages │ │ │ │ │ │ └── Dashboard │ │ │ │ │ │ │ └── index.tsx │ │ │ │ │ ├── router.tsx │ │ │ │ │ └── routerConfig.ts │ │ │ │ ├── test │ │ │ │ │ └── index.js │ │ │ │ └── tsconfig.json │ │ │ └── multiApp │ │ │ │ ├── package.json │ │ │ │ ├── serverless.yml │ │ │ │ ├── src │ │ │ │ └── index.ts │ │ │ │ └── tsconfig.json │ │ ├── index.test.ts │ │ ├── invoke.js │ │ ├── main.test.ts │ │ └── multi.test.ts │ └── tsconfig.json ├── serverless-meta-json │ ├── CHANGELOG.md │ ├── README.md │ ├── package.json │ ├── src │ │ ├── index.ts │ │ └── inter.ts │ ├── test │ │ ├── archives-gateway │ │ │ ├── a.zip │ │ │ ├── b.zip │ │ │ ├── f.yml │ │ │ └── test_mapping.json │ │ ├── archives │ │ │ ├── a.zip │ │ │ └── b.zip │ │ └── index.test.ts │ └── tsconfig.json ├── serverless-scf-starter │ ├── CHANGELOG.md │ ├── README.md │ ├── package.json │ ├── resource │ │ └── event.json │ ├── src │ │ ├── index.ts │ │ └── runtime.ts │ ├── test │ │ └── index.test.ts │ └── tsconfig.json ├── serverless-scf-trigger │ ├── CHANGELOG.md │ ├── package.json │ ├── src │ │ ├── apiGateway.ts │ │ ├── base.ts │ │ ├── ckafka.ts │ │ ├── cmq.ts │ │ ├── cos.ts │ │ ├── index.ts │ │ └── timer.ts │ ├── test │ │ ├── fixtures │ │ │ ├── apiGateway │ │ │ │ └── index.ts │ │ │ ├── ckafka │ │ │ │ └── index.ts │ │ │ ├── cmq │ │ │ │ └── index.ts │ │ │ ├── cos │ │ │ │ └── index.ts │ │ │ └── timer │ │ │ │ └── index.ts │ │ └── index.test.ts │ └── tsconfig.json ├── serverless-spec-builder │ ├── CHANGELOG.md │ ├── README.md │ ├── fc │ │ ├── index.d.ts │ │ └── index.js │ ├── package.json │ ├── resource │ │ ├── serverless │ │ │ ├── serverless.json │ │ │ └── serverless.yml │ │ └── template │ │ │ ├── multi_function_template.yml │ │ │ ├── template.json │ │ │ └── template.yml │ ├── scf │ │ ├── index.d.ts │ │ └── index.js │ ├── src │ │ ├── builder.ts │ │ ├── fc │ │ │ ├── builder.ts │ │ │ ├── index.ts │ │ │ └── interface.ts │ │ ├── index.ts │ │ ├── interface.ts │ │ ├── parse.ts │ │ ├── scf │ │ │ ├── builder.ts │ │ │ ├── index.ts │ │ │ └── interface.ts │ │ ├── utils.ts │ │ └── wrapper.ts │ ├── test │ │ ├── fc.test.ts │ │ ├── fixtures │ │ │ ├── fc │ │ │ │ ├── f-base.yml │ │ │ │ ├── f-environment.yml │ │ │ │ ├── f-event-apigw.yml │ │ │ │ ├── f-event-http-no-method.yml │ │ │ │ ├── f-event-http.yml │ │ │ │ ├── f-event-mq.yml │ │ │ │ ├── f-event-oss.yml │ │ │ │ ├── f-event-timer.yml │ │ │ │ └── f-service-properties.yml │ │ │ ├── fun-var.yml │ │ │ ├── fun.yaml │ │ │ ├── fun.yml │ │ │ ├── scf │ │ │ │ ├── f-base.yml │ │ │ │ ├── f-event-apigw.yml │ │ │ │ ├── f-event-cmq.yml │ │ │ │ ├── f-event-cos.yml │ │ │ │ ├── f-event-timer.yml │ │ │ │ └── serverless.yml │ │ │ └── wrapper │ │ │ │ ├── aggre.js │ │ │ │ ├── index.js │ │ │ │ └── render.js │ │ ├── index.test.ts │ │ ├── scf.test.ts │ │ ├── utils.test.ts │ │ └── wrapper.test.ts │ └── tsconfig.json └── simple-lock │ ├── CHANGELOG.md │ ├── README.md │ ├── package.json │ ├── src │ └── index.ts │ ├── test │ └── index.test.ts │ └── tsconfig.json ├── scripts ├── build.sh ├── deploy.sh ├── deploy_doc.js ├── deploy_key.enc ├── ownerAdd.sh ├── publish.sh ├── resyncPublish.sh ├── sync.sh └── tag.sh └── tsconfig.json /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./node_modules/mwts/", 3 | "ignorePatterns": ["node_modules", "dist", "fixtures"], 4 | "env": { 5 | "mocha": true 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /.github/workflows/gh-pages.yml: -------------------------------------------------------------------------------- 1 | name: GitHub Pages 2 | 3 | on: 4 | schedule: 5 | # * is a special character in YAML so you have to quote this string 6 | - cron: '*/15 * * * *' 7 | 8 | jobs: 9 | deploy: 10 | runs-on: ubuntu-latest 11 | 12 | strategy: 13 | matrix: 14 | node-version: [12.x] 15 | 16 | steps: 17 | - uses: actions/checkout@v2 18 | - name: Use Node.js ${{ matrix.node-version }} 19 | uses: actions/setup-node@v1 20 | with: 21 | node-version: ${{ matrix.node-version }} 22 | - run: npm -v 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | *.log 3 | *.log.* 4 | logs 5 | .vscode 6 | dest 7 | dist 8 | coverage 9 | .idea 10 | package-lock.json 11 | .DS_* 12 | .nyc* 13 | !**/fixtures/app/node_modules/hello/* 14 | run/ 15 | package-lock.json 16 | .nodejs-cache 17 | AUTHORS 18 | .serverless 19 | .midway 20 | .ncc_entry 21 | .zip 22 | .aliyun_credentials 23 | .faas_debug_tmp 24 | .env_temp 25 | serverless.zip 26 | /packages/serverless-invoke/test/fixtures/*/build 27 | /packages/serverless-invoke/test/fixtures/**/*faas_debug_tmp/ 28 | /packages/faas-util-ts-compile/test/fixtures/files/tmp/* 29 | !/packages/faas-util-ts-compile/test/fixtures/files/tmp/.gitkeep 30 | 31 | -------------------------------------------------------------------------------- /.prettierrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | ...require('mwts/.prettierrc.json') 3 | } 4 | -------------------------------------------------------------------------------- /benchmark/bc.test.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/midwayjs/midway-faas/d3f3b8e01514c468070abb14340776724a382a29/benchmark/bc.test.ts -------------------------------------------------------------------------------- /lerna.json: -------------------------------------------------------------------------------- 1 | { 2 | "packages": [ 3 | "packages/*" 4 | ], 5 | "command": { 6 | "bootstrap": { 7 | "hoist": true, 8 | "noCi": true, 9 | "npmClientArgs": [ 10 | "--no-package-lock" 11 | ], 12 | "nohoist": [ 13 | "egg" 14 | ] 15 | }, 16 | "publish": { 17 | "ignoreChanges": [ 18 | "*.md" 19 | ] 20 | }, 21 | "version": { 22 | "conventionalCommits": true, 23 | "createRelease": "github" 24 | } 25 | }, 26 | "npmClient": "npm", 27 | "version": "0.3.7" 28 | } 29 | -------------------------------------------------------------------------------- /packages/egg-layer/framework/app/extend/context.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | get fctx() { 5 | if (!this.request.fctx) { 6 | return this.app; 7 | } 8 | return this.request.fctx; 9 | }, 10 | }; 11 | -------------------------------------------------------------------------------- /packages/egg-layer/framework/config/config.default.js: -------------------------------------------------------------------------------- 1 | const os = require('os'); 2 | exports.logger = { 3 | dir: os.tmpdir(), 4 | }; 5 | 6 | exports.rundir = os.tmpdir(); 7 | 8 | exports.static = { 9 | dir: os.tmpdir(), 10 | }; 11 | -------------------------------------------------------------------------------- /packages/egg-layer/framework/index.js: -------------------------------------------------------------------------------- 1 | const egg = require('egg'); 2 | 3 | const EGG_PATH = Symbol.for('egg#eggPath'); 4 | exports.getFramework = framework => { 5 | const customerEgg = framework ? require(framework) : egg; 6 | function extendsBase(BaseClass) { 7 | return class LayerWrapper extends BaseClass { 8 | get [EGG_PATH]() { 9 | return __dirname; 10 | } 11 | createAnonymousContext(req) { 12 | const ctx = super.createAnonymousContext(req); 13 | if (req && req.fctx) { 14 | ctx.request.fctx = req.fctx; 15 | } 16 | return ctx; 17 | } 18 | }; 19 | } 20 | exports.Agent = extendsBase(customerEgg.Agent); 21 | exports.Application = extendsBase(customerEgg.Application); 22 | }; 23 | -------------------------------------------------------------------------------- /packages/egg-layer/test/fixtures/eaas/README.md: -------------------------------------------------------------------------------- 1 | # test-eaas 2 | 3 | test-eaas 4 | 5 | ## QuickStart 6 | 7 | 8 | 9 | see [egg docs][egg] for more detail. 10 | 11 | ### Development 12 | 13 | ```bash 14 | $ npm i 15 | $ npm run dev 16 | $ open http://localhost:7001/ 17 | ``` 18 | 19 | ### Deploy 20 | 21 | ```bash 22 | $ npm start 23 | $ npm stop 24 | ``` 25 | 26 | ### npm scripts 27 | 28 | - Use `npm run lint` to check code style. 29 | - Use `npm test` to run unit test. 30 | - Use `npm run autod` to auto detect dependencies upgrade, see [autod](https://www.npmjs.com/package/autod) for more detail. 31 | 32 | 33 | [egg]: https://eggjs.org -------------------------------------------------------------------------------- /packages/egg-layer/test/fixtures/eaas/agent.js: -------------------------------------------------------------------------------- 1 | // agent.js 2 | module.exports = agent => { 3 | // 在这里写你的初始化逻辑 4 | 5 | // 也可以通过 messenger 对象发送消息给 App Worker 6 | // 但需要等待 App Worker 启动成功后才能发送,不然很可能丢失 7 | agent.messenger.on('egg-ready', () => { 8 | const data = { value: 'agent messenger works' }; 9 | agent.messenger.sendToApp('xxx_action', data); 10 | }); 11 | }; -------------------------------------------------------------------------------- /packages/egg-layer/test/fixtures/eaas/app.js: -------------------------------------------------------------------------------- 1 | // app.js 2 | module.exports = app => { 3 | app.messenger.on('xxx_action', data => { 4 | console.log(data); 5 | // ... 6 | }); 7 | }; -------------------------------------------------------------------------------- /packages/egg-layer/test/fixtures/eaas/app/controller/home.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const Controller = require('egg').Controller; 4 | 5 | class HomeController extends Controller { 6 | async index() { 7 | const { ctx } = this; 8 | ctx.body = 'hi, egg'; 9 | } 10 | async buffer() { 11 | const { ctx } = this; 12 | ctx.setHeader('x-res', 'buffer'); 13 | // assert 14 | ctx.body = Buffer.from('hi, egg'); 15 | } 16 | } 17 | 18 | module.exports = HomeController; 19 | -------------------------------------------------------------------------------- /packages/egg-layer/test/fixtures/eaas/app/router.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * @param {Egg.Application} app - egg application 5 | */ 6 | module.exports = app => { 7 | const { router, controller } = app; 8 | router.get('/', controller.home.index); 9 | router.get('/buffer', controller.home.buffer); 10 | }; 11 | -------------------------------------------------------------------------------- /packages/egg-layer/test/fixtures/eaas/config/config.default.js: -------------------------------------------------------------------------------- 1 | /* eslint valid-jsdoc: "off" */ 2 | 3 | 'use strict'; 4 | 5 | /** 6 | * @param {Egg.EggAppInfo} appInfo app info 7 | */ 8 | module.exports = appInfo => { 9 | /** 10 | * built-in config 11 | * @type {Egg.EggAppConfig} 12 | **/ 13 | const config = exports = {}; 14 | 15 | // use for cookie sign key, should change to your own and keep security 16 | config.keys = appInfo.name + '_1574154057813_8098'; 17 | 18 | // add your middleware config here 19 | config.middleware = []; 20 | 21 | // add your user config here 22 | const userConfig = { 23 | // myAppName: 'egg', 24 | }; 25 | 26 | return { 27 | ...config, 28 | ...userConfig, 29 | }; 30 | }; 31 | -------------------------------------------------------------------------------- /packages/egg-layer/test/fixtures/eaas/config/plugin.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** @type Egg.EggPlugin */ 4 | module.exports = { 5 | // had enabled by egg 6 | // static: { 7 | // enable: true, 8 | // } 9 | }; 10 | -------------------------------------------------------------------------------- /packages/egg-layer/test/fixtures/eaas/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/midwayjs/midway-faas/d3f3b8e01514c468070abb14340776724a382a29/packages/egg-layer/test/fixtures/eaas/index.js -------------------------------------------------------------------------------- /packages/egg-layer/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compileOnSave": true, 4 | "compilerOptions": { 5 | "rootDir": "src", 6 | "outDir": "dist" 7 | }, 8 | "include": [ 9 | "./src/**/*.ts" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /packages/faas-cli-command-core/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './interface/plugin'; 2 | export * from './interface/provider'; 3 | export * from './core'; 4 | export * from './plugin'; 5 | export * from './pluginManager'; 6 | export * from './interface/commandHookCore'; 7 | export * from './npm'; 8 | export * from './utils/loadSpec'; 9 | export * from './utils/commandLineUsage'; 10 | export * from './cli'; 11 | -------------------------------------------------------------------------------- /packages/faas-cli-command-core/src/interface/plugin.ts: -------------------------------------------------------------------------------- 1 | export interface IPluginInstance { 2 | commands?: IPluginCommands; 3 | hooks?: IPluginHooks; 4 | asyncInit?: () => Promise; 5 | } 6 | 7 | export interface ICommandInstance { 8 | type?: 'entrypoint'; 9 | lifecycleEvents?: string[]; 10 | usage?: string; 11 | rank?: number; 12 | options?: { 13 | [option: string]: { 14 | usage: string; 15 | shortcut?: string; 16 | }; 17 | }; 18 | commands?: { 19 | [command: string]: ICommandInstance; 20 | }; 21 | } 22 | 23 | export interface IPluginCommands { 24 | [command: string]: ICommandInstance; 25 | } 26 | 27 | export interface IPluginHooks { 28 | [hook: string]: () => void | Promise; 29 | } 30 | -------------------------------------------------------------------------------- /packages/faas-cli-command-core/src/interface/provider.ts: -------------------------------------------------------------------------------- 1 | // eslint-disable-next-line @typescript-eslint/no-empty-interface 2 | export interface IProviderInstance {} 3 | -------------------------------------------------------------------------------- /packages/faas-cli-command-core/test/cli.test.ts: -------------------------------------------------------------------------------- 1 | import { BaseCLI } from '../src/'; 2 | import * as assert from 'assert'; 3 | describe('/test/cli.test.ts', () => { 4 | it('help', async () => { 5 | const cli = new BaseCLI(['', '', '-h']); 6 | cli.loadRelativePlugin('./', './plugins/empty'); 7 | await cli.start(); 8 | assert(true); 9 | }); 10 | it('test', async () => { 11 | const cli = new BaseCLI(['', '', 'test', '-h']); 12 | cli.cwd = __dirname; 13 | cli.loadRelativePlugin('./', './plugins/empty'); 14 | await cli.start(); 15 | assert(true); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /packages/faas-cli-command-core/test/f.yml: -------------------------------------------------------------------------------- 1 | service: 2 | name: ginkgo-test 3 | provider: 4 | name: ginkgo 5 | runtime: node10tb 6 | functions: 7 | index: 8 | handler: index.handler 9 | events: 10 | - hsf: true 11 | -------------------------------------------------------------------------------- /packages/faas-cli-command-core/test/fixtures/userLifecycle/index.js: -------------------------------------------------------------------------------- 1 | const { unlinkSync, existsSync, writeFileSync } = require('fs'); 2 | const { join } = require('path'); 3 | ;(async () => { 4 | await new Promise(resolve => { 5 | setTimeout(resolve, 500); 6 | }); 7 | const file = join(__dirname, 'test.txt'); 8 | if (existsSync(file)) { 9 | unlinkSync(file); 10 | } 11 | writeFileSync(file, process.env.TEST_MIDWAY_CLI_CORE_TMPDATA || ''); 12 | })(); -------------------------------------------------------------------------------- /packages/faas-cli-command-core/test/fixtures/userLifecycle/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "midway-integration": { 3 | "lifecycle": { 4 | "before:invoke:one": "node ./index.js" 5 | } 6 | } 7 | } -------------------------------------------------------------------------------- /packages/faas-cli-command-core/test/fixtures/userLifecycle/test.txt: -------------------------------------------------------------------------------- 1 | 1592903346191 -------------------------------------------------------------------------------- /packages/faas-cli-command-core/test/plugins/empty.ts: -------------------------------------------------------------------------------- 1 | import { BasePlugin } from '../../src'; 2 | 3 | class Empty extends BasePlugin { 4 | commands = { 5 | test: {}, 6 | }; 7 | hooks = {}; 8 | } 9 | 10 | export = Empty; 11 | -------------------------------------------------------------------------------- /packages/faas-cli-command-core/test/plugins/one.common.ts: -------------------------------------------------------------------------------- 1 | import { BasePlugin } from '../../src'; 2 | 3 | class OnePlugin extends BasePlugin { 4 | provider = 'one'; 5 | commands = { 6 | common: { 7 | usage: 'common command', 8 | lifecycleEvents: ['main'], 9 | }, 10 | }; 11 | hooks = { 12 | 'common:main': async () => {}, 13 | }; 14 | } 15 | 16 | export default OnePlugin; 17 | -------------------------------------------------------------------------------- /packages/faas-cli-command-core/test/plugins/store.get.ts: -------------------------------------------------------------------------------- 1 | import { BasePlugin } from '../../src'; 2 | 3 | class StoreGet extends BasePlugin { 4 | commands = { 5 | store: { 6 | lifecycleEvents: ['main'], 7 | }, 8 | }; 9 | hooks = { 10 | 'after:store:main': async () => { 11 | this.setStore('get', this.getStore('set', 'StoreSet')); 12 | }, 13 | }; 14 | } 15 | 16 | export default StoreGet; 17 | -------------------------------------------------------------------------------- /packages/faas-cli-command-core/test/plugins/store.set.ts: -------------------------------------------------------------------------------- 1 | import { BasePlugin } from '../../src'; 2 | 3 | class StoreSet extends BasePlugin { 4 | commands = { 5 | store: { 6 | lifecycleEvents: ['main'], 7 | }, 8 | }; 9 | hooks = { 10 | 'store:main': async () => { 11 | this.setStore('set', 123456); 12 | }, 13 | }; 14 | } 15 | 16 | export default StoreSet; 17 | -------------------------------------------------------------------------------- /packages/faas-cli-command-core/test/plugins/test.lg.ts: -------------------------------------------------------------------------------- 1 | import { BasePlugin } from '../../src'; 2 | 3 | class LogPlugin extends BasePlugin { 4 | provider = 'test'; 5 | commands = { 6 | log: { 7 | usage: 'log command', 8 | lifecycleEvents: ['main'], 9 | }, 10 | }; 11 | hooks = { 12 | 'log:main': async () => { 13 | await this.core.invoke(['invoke']); 14 | }, 15 | }; 16 | } 17 | 18 | export default LogPlugin; 19 | -------------------------------------------------------------------------------- /packages/faas-cli-command-core/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compileOnSave": true, 4 | "compilerOptions": { 5 | "rootDir": "src", 6 | "outDir": "dist" 7 | }, 8 | "include": [ 9 | "./src/**/*.ts" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-create/README.md: -------------------------------------------------------------------------------- 1 | # faas-cli create 2 | 3 | `f create` command 4 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-create/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compileOnSave": true, 4 | "compilerOptions": { 5 | "rootDir": "src", 6 | "outDir": "dist" 7 | }, 8 | "include": [ 9 | "./src/**/*.ts" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-deploy/src/index.ts: -------------------------------------------------------------------------------- 1 | import { BasePlugin, ICoreInstance } from '@midwayjs/fcli-command-core'; 2 | export class DeployPlugin extends BasePlugin { 3 | core: ICoreInstance; 4 | options: any; 5 | commands = { 6 | deploy: { 7 | usage: 'Deploy to online', 8 | lifecycleEvents: ['deploy'], 9 | options: {}, 10 | }, 11 | }; 12 | } 13 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-deploy/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compileOnSave": true, 4 | "compilerOptions": { 5 | "rootDir": "src", 6 | "outDir": "dist" 7 | }, 8 | "include": [ 9 | "./src/**/*.ts" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-dev-pack/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compileOnSave": true, 4 | "compilerOptions": { 5 | "rootDir": "src", 6 | "outDir": "dist" 7 | }, 8 | "include": [ 9 | "./src/**/*.ts" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-fc/src/utils.ts: -------------------------------------------------------------------------------- 1 | export interface Ilayer { 2 | [extName: string]: { 3 | path: string; 4 | }; 5 | } 6 | 7 | export function formatLayers(...multiLayers: Ilayer[]) { 8 | const layerTypeList = { npm: {} }; 9 | multiLayers.forEach((layer: Ilayer) => { 10 | Object.keys(layer || {}).forEach(layerName => { 11 | const [type, path] = layer[layerName].path.split(':'); 12 | if (!layerTypeList[type]) { 13 | return; 14 | } 15 | layerTypeList[type][layerName] = path; 16 | }); 17 | }); 18 | return layerTypeList; 19 | } 20 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-fc/test/fixtures/base-fc/f.yml: -------------------------------------------------------------------------------- 1 | service: serverless-midway-test 2 | 3 | provider: 4 | name: aliyun 5 | 6 | functions: 7 | index: 8 | handler: index.handler 9 | events: 10 | - http: 11 | method: get 12 | index2: 13 | handler: index.handler2 14 | events: 15 | - http: 16 | method: get 17 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-fc/test/fixtures/base-fc/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "@midwayjs/runtime-engine": "*", 4 | "@midwayjs/faas": "*" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-fc/test/fixtures/base-fc/src/index.ts: -------------------------------------------------------------------------------- 1 | import { FaaSContext, func, inject, provide } from '@midwayjs/faas'; 2 | 3 | @provide() 4 | @func('index.handler') 5 | export class HelloService { 6 | 7 | @inject() 8 | ctx: FaaSContext; // context 9 | 10 | async handler(event, obj = {}) { 11 | return 'hello world'; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-fc/test/fixtures/base-fc/test/deploy.test.ts: -------------------------------------------------------------------------------- 1 | import * as assert from 'assert'; 2 | 3 | describe('/test/deploy/test/deploy.test.ts', () => { 4 | it('deploy result', async () => { 5 | assert(true); 6 | }); 7 | }); 8 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-fc/test/fixtures/base-fc/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": true, 3 | "compilerOptions": { 4 | "target": "ES2018", 5 | "module": "commonjs", 6 | "moduleResolution": "node", 7 | "experimentalDecorators": true, 8 | "emitDecoratorMetadata": true, 9 | "inlineSourceMap":true, 10 | "noImplicitThis": true, 11 | "noUnusedLocals": true, 12 | "stripInternal": true, 13 | "pretty": true, 14 | "declaration": true, 15 | "outDir": "dist" 16 | }, 17 | "exclude": [ 18 | "dist", 19 | "node_modules", 20 | "test" 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-fc/test/fixtures/eaas/.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | node_js: 4 | - '10' 5 | before_install: 6 | - npm i npminstall -g 7 | install: 8 | - npminstall 9 | script: 10 | - npm run ci 11 | after_script: 12 | - npminstall codecov && codecov 13 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-fc/test/fixtures/eaas/README.md: -------------------------------------------------------------------------------- 1 | # test-eaas 2 | 3 | test-eaas 4 | 5 | ## QuickStart 6 | 7 | 8 | 9 | see [egg docs][egg] for more detail. 10 | 11 | ### Development 12 | 13 | ```bash 14 | $ npm i 15 | $ npm run dev 16 | $ open http://localhost:7001/ 17 | ``` 18 | 19 | ### Deploy 20 | 21 | ```bash 22 | $ npm start 23 | $ npm stop 24 | ``` 25 | 26 | ### npm scripts 27 | 28 | - Use `npm run lint` to check code style. 29 | - Use `npm test` to run unit test. 30 | - Use `npm run autod` to auto detect dependencies upgrade, see [autod](https://www.npmjs.com/package/autod) for more detail. 31 | 32 | 33 | [egg]: https://eggjs.org -------------------------------------------------------------------------------- /packages/faas-cli-plugin-fc/test/fixtures/eaas/agent.js: -------------------------------------------------------------------------------- 1 | // agent.js 2 | module.exports = agent => { 3 | // 在这里写你的初始化逻辑 4 | 5 | // 也可以通过 messenger 对象发送消息给 App Worker 6 | // 但需要等待 App Worker 启动成功后才能发送,不然很可能丢失 7 | agent.messenger.on('egg-ready', () => { 8 | const data = { value: 'agent messenger works' }; 9 | agent.messenger.sendToApp('xxx_action', data); 10 | }); 11 | }; -------------------------------------------------------------------------------- /packages/faas-cli-plugin-fc/test/fixtures/eaas/app.js: -------------------------------------------------------------------------------- 1 | // app.js 2 | module.exports = app => { 3 | app.messenger.on('xxx_action', data => { 4 | console.log(data); 5 | // ... 6 | }); 7 | }; -------------------------------------------------------------------------------- /packages/faas-cli-plugin-fc/test/fixtures/eaas/app/controller/home.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const Controller = require('egg').Controller; 4 | 5 | class HomeController extends Controller { 6 | async index() { 7 | const { ctx } = this; 8 | ctx.body = 'hi, egg'; 9 | } 10 | async buffer() { 11 | const { ctx } = this; 12 | ctx.setHeader('x-res', 'buffer'); 13 | // assert 14 | ctx.body = Buffer.from('hi, egg'); 15 | } 16 | } 17 | 18 | module.exports = HomeController; 19 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-fc/test/fixtures/eaas/app/router.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * @param {Egg.Application} app - egg application 5 | */ 6 | module.exports = app => { 7 | const { router, controller } = app; 8 | router.get('/', controller.home.index); 9 | router.get('/buffer', controller.home.buffer); 10 | }; 11 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-fc/test/fixtures/eaas/appveyor.yml: -------------------------------------------------------------------------------- 1 | environment: 2 | matrix: 3 | - nodejs_version: '10' 4 | 5 | install: 6 | - ps: Install-Product node $env:nodejs_version 7 | - npm i npminstall && node_modules\.bin\npminstall 8 | 9 | test_script: 10 | - node --version 11 | - npm --version 12 | - npm run test 13 | 14 | build: off 15 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-fc/test/fixtures/eaas/config/config.default.js: -------------------------------------------------------------------------------- 1 | /* eslint valid-jsdoc: "off" */ 2 | 3 | 'use strict'; 4 | 5 | /** 6 | * @param {Egg.EggAppInfo} appInfo app info 7 | */ 8 | module.exports = appInfo => { 9 | /** 10 | * built-in config 11 | * @type {Egg.EggAppConfig} 12 | **/ 13 | const config = exports = {}; 14 | 15 | // use for cookie sign key, should change to your own and keep security 16 | config.keys = appInfo.name + '_1574154057813_8098'; 17 | 18 | // add your middleware config here 19 | config.middleware = []; 20 | 21 | // add your user config here 22 | const userConfig = { 23 | // myAppName: 'egg', 24 | }; 25 | 26 | return { 27 | ...config, 28 | ...userConfig, 29 | }; 30 | }; 31 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-fc/test/fixtures/eaas/config/plugin.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** @type Egg.EggPlugin */ 4 | module.exports = { 5 | // had enabled by egg 6 | // static: { 7 | // enable: true, 8 | // } 9 | }; 10 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-fc/test/fixtures/eaas/f.yml: -------------------------------------------------------------------------------- 1 | service: serverless-midway-test 2 | 3 | provider: 4 | name: aliyun 5 | 6 | functions: 7 | index: 8 | handler: index.handler 9 | events: 10 | - http: 11 | method: get 12 | 13 | layers: 14 | eggLayer: 15 | path: npm:@midwayjs/egg-layer 16 | 17 | package: 18 | include: 19 | - '*.js' 20 | - app 21 | - config 22 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-fc/test/fixtures/eaas/index.js: -------------------------------------------------------------------------------- 1 | const { asyncWrapper, start } = require('@midwayjs/serverless-fc-starter'); 2 | const eggLayer = require('@midwayjs/egg-layer'); 3 | 4 | let runtime; 5 | let inited = false; 6 | 7 | const initializeMethod = async (config = {}) => { 8 | runtime = await start({ 9 | layers: [eggLayer], 10 | }); 11 | inited = true; 12 | }; 13 | 14 | exports.initializer = asyncWrapper(async ({ config } = {}) => { 15 | await initializeMethod(config); 16 | }); 17 | 18 | exports.handler = asyncWrapper(async (...args) => { 19 | if (!inited) { 20 | await initializeMethod(); 21 | } 22 | 23 | return runtime.asyncEvent()(...args); 24 | }); 25 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-fc/test/fixtures/eaas/node_modules/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/midwayjs/midway-faas/d3f3b8e01514c468070abb14340776724a382a29/packages/faas-cli-plugin-fc/test/fixtures/eaas/node_modules/.keep -------------------------------------------------------------------------------- /packages/faas-cli-plugin-fc/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compileOnSave": true, 4 | "compilerOptions": { 5 | "rootDir": "src", 6 | "outDir": "dist" 7 | }, 8 | "include": [ 9 | "./src/**/*.ts" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/src/utils.ts: -------------------------------------------------------------------------------- 1 | import { existsSync, remove } from 'fs-extra'; 2 | import { join } from 'path'; 3 | export const exportMidwayFaaS = (() => { 4 | const midwayModuleName = process.env.MidwayModuleName || '@midwayjs/faas'; 5 | const faasPath = join(process.cwd(), './node_modules/', midwayModuleName); 6 | if (existsSync(faasPath)) { 7 | return require(faasPath); 8 | } else { 9 | try { 10 | return require(midwayModuleName); 11 | } catch (e) { 12 | return { FaaSStarter: class DefaulltMidwayFaasStarter {} }; 13 | } 14 | } 15 | })(); 16 | 17 | export const FaaSStarterClass = exportMidwayFaaS.FaaSStarter; 18 | 19 | export const cleanTarget = async (p: string) => { 20 | if (existsSync(p)) { 21 | await remove(p); 22 | } 23 | }; 24 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/baseApp/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "@midwayjs/faas": "*" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/baseApp/serverless.yml: -------------------------------------------------------------------------------- 1 | service: serverless-midway-test 2 | 3 | provider: 4 | name: aliyun 5 | runtime: nodejs8 6 | credentials: ./.aliyun_credentials # path must be absolute 7 | 8 | functions: 9 | http: 10 | handler: http.handler 11 | events: 12 | - http: 13 | method: get 14 | 15 | layers: 16 | 17 | 18 | package: 19 | include: 20 | exclude: 21 | - src/** 22 | - tsconfig.json 23 | - test/** 24 | excludeDevDependencies: false 25 | artifact: path/to/my-artifact.zip # Own package that should be used. You must provide this file. 26 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/baseApp/src/index.ts: -------------------------------------------------------------------------------- 1 | import { FaaSContext, func, inject, provide } from '@midwayjs/faas'; 2 | 3 | @provide() 4 | @func('http.handler') 5 | export class HelloHttpService { 6 | 7 | @inject() 8 | ctx: FaaSContext; // context 9 | 10 | handler() { 11 | return 'hello http world'; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/baseApp/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": true, 3 | "compilerOptions": { 4 | "target": "ES2018", 5 | "module": "commonjs", 6 | "moduleResolution": "node", 7 | "experimentalDecorators": true, 8 | "emitDecoratorMetadata": true, 9 | "inlineSourceMap": true, 10 | "noImplicitThis": true, 11 | "noUnusedLocals": true, 12 | "stripInternal": true, 13 | "pretty": true, 14 | "declaration": true, 15 | "outDir": "dist", 16 | "sourceRoot": "" 17 | }, 18 | "exclude": [ 19 | "dist", 20 | "node_modules", 21 | "test" 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/http-scf/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "@midwayjs/faas": "*" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/http-scf/serverless.yml: -------------------------------------------------------------------------------- 1 | service: serverless-midway-test 2 | 3 | provider: 4 | name: tencent 5 | runtime: nodejs8 6 | 7 | functions: 8 | http: 9 | handler: http.handler 10 | events: 11 | - apigw: 12 | method: get -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/http-scf/src/index.ts: -------------------------------------------------------------------------------- 1 | import { func, inject, provide } from '@midwayjs/faas'; 2 | 3 | @provide() 4 | @func('http.handler') 5 | export class HelloHttpService { 6 | 7 | @inject() 8 | ctx; // context 9 | 10 | async handler() { 11 | 12 | this.ctx.body = { 13 | headers: this.ctx.headers, 14 | method: this.ctx.method, 15 | path: this.ctx.path, 16 | body: this.ctx.request.body, 17 | params: this.ctx.params 18 | }; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/http-scf/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": true, 3 | "compilerOptions": { 4 | "target": "ES2018", 5 | "module": "commonjs", 6 | "moduleResolution": "node", 7 | "experimentalDecorators": true, 8 | "emitDecoratorMetadata": true, 9 | "inlineSourceMap": true, 10 | "noImplicitThis": true, 11 | "noUnusedLocals": true, 12 | "stripInternal": true, 13 | "pretty": true, 14 | "declaration": true, 15 | "outDir": "dist", 16 | "sourceRoot": "" 17 | }, 18 | "exclude": [ 19 | "dist", 20 | "node_modules", 21 | "test" 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/http/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "@midwayjs/faas": "*" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/http/serverless.yml: -------------------------------------------------------------------------------- 1 | service: serverless-midway-test 2 | 3 | provider: 4 | name: aliyun 5 | runtime: nodejs8 6 | 7 | functions: 8 | http: 9 | handler: http.handler 10 | events: 11 | - http: 12 | method: post -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/http/src/index.ts: -------------------------------------------------------------------------------- 1 | import { func, inject, provide } from '@midwayjs/faas'; 2 | 3 | @provide() 4 | @func('http.handler') 5 | export class HelloHttpService { 6 | 7 | @inject() 8 | ctx; // context 9 | 10 | async handler() { 11 | return { 12 | headers: this.ctx.headers, 13 | method: this.ctx.method, 14 | path: this.ctx.path, 15 | query: this.ctx.query, 16 | body: this.ctx.request.body, 17 | params: this.ctx.params 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/http/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": true, 3 | "compilerOptions": { 4 | "target": "ES2018", 5 | "module": "commonjs", 6 | "moduleResolution": "node", 7 | "experimentalDecorators": true, 8 | "emitDecoratorMetadata": true, 9 | "inlineSourceMap": true, 10 | "noImplicitThis": true, 11 | "noUnusedLocals": true, 12 | "stripInternal": true, 13 | "pretty": true, 14 | "declaration": true, 15 | "outDir": "dist", 16 | "sourceRoot": "" 17 | }, 18 | "exclude": [ 19 | "dist", 20 | "node_modules", 21 | "test" 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/ice-faas-ts-pkg-options/build.json: -------------------------------------------------------------------------------- 1 | { 2 | "entry": "src/index.tsx", 3 | "plugins": [ 4 | "build-plugin-ice-app", 5 | ["build-plugin-fusion", { 6 | "themePackage": "@icedesign/theme" 7 | }], 8 | "./build.plugin.js" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/ice-faas-ts-pkg-options/f.yml: -------------------------------------------------------------------------------- 1 | service: fc-test 2 | 3 | provider: 4 | name: fc 5 | runtime: nodejs10 6 | 7 | functions: 8 | test1: 9 | handler: index.handler 10 | events: 11 | - http: true 12 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/ice-faas-ts-pkg-options/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@icedesign/ts-scaffold9ade4c90-5de3-11e9-aef1-79dc0073b61f", 3 | "version": "1.0.3", 4 | "description": "该模板基于 TypeScript 适用于从 0 到 1 开始搭建项目,内置基础的页面,路由和菜单展示", 5 | "dependencies": { 6 | "@midwayjs/faas": "*", 7 | "react-router-dom": "*", 8 | "tslib": "*" 9 | }, 10 | "scripts": { 11 | "start": "build-scripts start", 12 | "build": "build-scripts build", 13 | "lint": "eslint . --ext '.js,.jsx' --fix" 14 | }, 15 | "engines": { 16 | "node": ">=8.0.0" 17 | }, 18 | "midway-integration": { 19 | "tsCodeRoot": "src/apis" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/ice-faas-ts-pkg-options/src/apis/index.ts: -------------------------------------------------------------------------------- 1 | import { 2 | provide, 3 | func, 4 | FunctionHandler, 5 | inject, 6 | FaaSContext, 7 | } from '@midwayjs/faas'; 8 | 9 | @provide() 10 | @func('index.handler') 11 | export class IndexHandler implements FunctionHandler { 12 | @inject() 13 | ctx: FaaSContext; 14 | /** 15 | * 发布为 hsf 时 16 | * 这个参数是 ginkgo 固定的,入参出参都为字符串 17 | * @param event 18 | */ 19 | async handler(event: string) { 20 | return 'hello http world'; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/ice-faas-ts-pkg-options/src/components/Greeting/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | export interface Props { 4 | name: string; 5 | } 6 | 7 | const Greeting = ({ name }: Props) => { 8 | return ( 9 |
10 | Hello, {name} 11 |
12 | ); 13 | }; 14 | 15 | export default Greeting; 16 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/ice-faas-ts-pkg-options/src/index.tsx: -------------------------------------------------------------------------------- 1 | import ReactDOM from 'react-dom'; 2 | 3 | // 载入默认全局样式 normalize 4 | import '@alifd/next/reset.scss'; 5 | 6 | import router from './router'; 7 | 8 | const ICE_CONTAINER = document.getElementById('ice-container'); 9 | 10 | if (!ICE_CONTAINER) { 11 | throw new Error('当前页面不存在
节点.'); 12 | } 13 | 14 | ReactDOM.render(router(), ICE_CONTAINER); 15 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/ice-faas-ts-pkg-options/src/layouts/BasicLayout/index.tsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import MainRoutes from './MainRoutes'; 3 | 4 | export default class BasicLayout extends Component { 5 | render() { 6 | return ( 7 |
8 | 9 |
10 | ); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/ice-faas-ts-pkg-options/src/menuConfig.ts: -------------------------------------------------------------------------------- 1 | // 菜单配置 2 | 3 | const asideMenuConfig = []; 4 | 5 | export { asideMenuConfig }; 6 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/ice-faas-ts-pkg-options/src/pages/Dashboard/index.tsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import Guide from '../../components/Guide'; 3 | import Greeting from '../../components/Greeting'; 4 | 5 | export default class Dashboard extends Component { 6 | render() { 7 | return ( 8 |
9 | 10 | 11 |
12 | ); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/ice-faas-ts-pkg-options/src/router.tsx: -------------------------------------------------------------------------------- 1 | /** 2 | * 定义应用路由 3 | */ 4 | import { HashRouter, Switch, Route } from 'react-router-dom'; 5 | import React from 'react'; 6 | import BasicLayout from './layouts/BasicLayout'; 7 | 8 | const router = () => { 9 | return ( 10 | 11 | 12 | 13 | 14 | 15 | ); 16 | }; 17 | 18 | export default router; 19 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/ice-faas-ts-pkg-options/src/routerConfig.ts: -------------------------------------------------------------------------------- 1 | // 以下文件格式为描述路由的协议格式 2 | // 你可以调整 routerConfig 里的内容 3 | // 变量名 routerConfig 为 iceworks 检测关键字,请不要修改名称 4 | import Dashboard from './pages/Dashboard'; 5 | 6 | const routerConfig = [ 7 | { 8 | path: '/dashboard', 9 | component: Dashboard, 10 | }, 11 | ]; 12 | 13 | export default routerConfig; 14 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/ice-faas-ts-pkg-options/test/index.js: -------------------------------------------------------------------------------- 1 | // test file 2 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/ice-faas-ts-standard/build.json: -------------------------------------------------------------------------------- 1 | { 2 | "entry": "src/index.tsx", 3 | "plugins": [ 4 | "build-plugin-ice-app", 5 | ["build-plugin-fusion", { 6 | "themePackage": "@icedesign/theme" 7 | }], 8 | "./build.plugin.js" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/ice-faas-ts-standard/f.yml: -------------------------------------------------------------------------------- 1 | service: fc-test 2 | 3 | provider: 4 | name: fc 5 | runtime: nodejs10 6 | 7 | functions: 8 | test1: 9 | handler: index.handler 10 | events: 11 | - http: true 12 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/ice-faas-ts-standard/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@icedesign/ts-scaffold9ade4c90-5de3-11e9-aef1-79dc0073b61f", 3 | "version": "1.0.3", 4 | "description": "该模板基于 TypeScript 适用于从 0 到 1 开始搭建项目,内置基础的页面,路由和菜单展示", 5 | "dependencies": { 6 | "@midwayjs/faas": "*", 7 | "react-router-dom": "*", 8 | "tslib": "*" 9 | }, 10 | "scripts": { 11 | "start": "build-scripts start", 12 | "build": "build-scripts build", 13 | "lint": "eslint . --ext '.js,.jsx' --fix" 14 | }, 15 | "engines": { 16 | "node": ">=8.0.0" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/ice-faas-ts-standard/src/apis/index.ts: -------------------------------------------------------------------------------- 1 | import { 2 | provide, 3 | func, 4 | FunctionHandler, 5 | inject, 6 | FaaSContext, 7 | } from '@midwayjs/faas'; 8 | 9 | @provide() 10 | @func('index.handler') 11 | export class IndexHandler implements FunctionHandler { 12 | @inject() 13 | ctx: FaaSContext; 14 | /** 15 | * 发布为 hsf 时 16 | * 这个参数是 ginkgo 固定的,入参出参都为字符串 17 | * @param event 18 | */ 19 | async handler(event: string) { 20 | return 'hello http world'; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/ice-faas-ts-standard/src/components/Greeting/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | export interface Props { 4 | name: string; 5 | } 6 | 7 | const Greeting = ({ name }: Props) => { 8 | return ( 9 |
10 | Hello, {name} 11 |
12 | ); 13 | }; 14 | 15 | export default Greeting; 16 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/ice-faas-ts-standard/src/index.tsx: -------------------------------------------------------------------------------- 1 | import ReactDOM from 'react-dom'; 2 | 3 | // 载入默认全局样式 normalize 4 | import '@alifd/next/reset.scss'; 5 | 6 | import router from './router'; 7 | 8 | const ICE_CONTAINER = document.getElementById('ice-container'); 9 | 10 | if (!ICE_CONTAINER) { 11 | throw new Error('当前页面不存在
节点.'); 12 | } 13 | 14 | ReactDOM.render(router(), ICE_CONTAINER); 15 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/ice-faas-ts-standard/src/layouts/BasicLayout/index.tsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import MainRoutes from './MainRoutes'; 3 | 4 | export default class BasicLayout extends Component { 5 | render() { 6 | return ( 7 |
8 | 9 |
10 | ); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/ice-faas-ts-standard/src/menuConfig.ts: -------------------------------------------------------------------------------- 1 | // 菜单配置 2 | 3 | const asideMenuConfig = []; 4 | 5 | export { asideMenuConfig }; 6 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/ice-faas-ts-standard/src/pages/Dashboard/index.tsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import Guide from '../../components/Guide'; 3 | import Greeting from '../../components/Greeting'; 4 | 5 | export default class Dashboard extends Component { 6 | render() { 7 | return ( 8 |
9 | 10 | 11 |
12 | ); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/ice-faas-ts-standard/src/router.tsx: -------------------------------------------------------------------------------- 1 | /** 2 | * 定义应用路由 3 | */ 4 | import { HashRouter, Switch, Route } from 'react-router-dom'; 5 | import React from 'react'; 6 | import BasicLayout from './layouts/BasicLayout'; 7 | 8 | const router = () => { 9 | return ( 10 | 11 | 12 | 13 | 14 | 15 | ); 16 | }; 17 | 18 | export default router; 19 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/ice-faas-ts-standard/src/routerConfig.ts: -------------------------------------------------------------------------------- 1 | // 以下文件格式为描述路由的协议格式 2 | // 你可以调整 routerConfig 里的内容 3 | // 变量名 routerConfig 为 iceworks 检测关键字,请不要修改名称 4 | import Dashboard from './pages/Dashboard'; 5 | 6 | const routerConfig = [ 7 | { 8 | path: '/dashboard', 9 | component: Dashboard, 10 | }, 11 | ]; 12 | 13 | export default routerConfig; 14 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/ice-faas-ts-standard/test/index.js: -------------------------------------------------------------------------------- 1 | // test file 2 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/initializer/index.js: -------------------------------------------------------------------------------- 1 | exports.initializer = () => { 2 | console.log('initializer'); 3 | } 4 | 5 | 6 | exports.handler = () => { 7 | console.log('handler'); 8 | } 9 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/initializer/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "@midwayjs/faas": "*" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/initializer/serverless.yml: -------------------------------------------------------------------------------- 1 | service: serverless-midway-test 2 | 3 | provider: 4 | name: aliyun 5 | 6 | functions: 7 | index: 8 | handler: index.handler -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/initializer/src/index.ts: -------------------------------------------------------------------------------- 1 | import { FaaSContext, func, inject, provide } from '@midwayjs/faas'; 2 | 3 | @provide() 4 | @func('http.handler') 5 | export class HelloHttpService { 6 | 7 | @inject() 8 | ctx: FaaSContext; // context 9 | 10 | async handler() { 11 | return 'hello http world'; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/initializer/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": true, 3 | "compilerOptions": { 4 | "target": "ES2018", 5 | "module": "commonjs", 6 | "moduleResolution": "node", 7 | "experimentalDecorators": true, 8 | "emitDecoratorMetadata": true, 9 | "inlineSourceMap": true, 10 | "noImplicitThis": true, 11 | "noUnusedLocals": true, 12 | "stripInternal": true, 13 | "pretty": true, 14 | "declaration": true, 15 | "outDir": "dist", 16 | "sourceRoot": "" 17 | }, 18 | "exclude": [ 19 | "dist", 20 | "node_modules", 21 | "test" 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/multiApp/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "@midwayjs/faas": "*" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/multiApp/serverless.yml: -------------------------------------------------------------------------------- 1 | service: serverless-midway-test 2 | 3 | provider: 4 | name: fc 5 | runtime: nodejs8 6 | credentials: ./.aliyun_credentials # path must be absolute 7 | 8 | functions: 9 | http: 10 | handler: http.handler 11 | events: 12 | - http: 13 | method: get 14 | 15 | layers: 16 | 17 | 18 | package: 19 | include: 20 | exclude: 21 | - src/** 22 | - tsconfig.json 23 | - test/** 24 | excludeDevDependencies: false 25 | artifact: path/to/my-artifact.zip # Own package that should be used. You must provide this file. 26 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/multiApp/src/index.ts: -------------------------------------------------------------------------------- 1 | import { FaaSContext, func, inject, provide } from '@midwayjs/faas'; 2 | 3 | @provide() 4 | @func('http.handler') 5 | export class HelloHttpService { 6 | 7 | @inject() 8 | ctx: FaaSContext; // context 9 | 10 | async handler() { 11 | return { 12 | headers: this.ctx.request.headers, 13 | method: this.ctx.request.method, 14 | query: this.ctx.request.query, 15 | path: this.ctx.request.path, 16 | body: this.ctx.request.body 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/multiApp/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": true, 3 | "compilerOptions": { 4 | "target": "ES2018", 5 | "module": "commonjs", 6 | "moduleResolution": "node", 7 | "experimentalDecorators": true, 8 | "emitDecoratorMetadata": true, 9 | "inlineSourceMap": true, 10 | "noImplicitThis": true, 11 | "noUnusedLocals": true, 12 | "stripInternal": true, 13 | "pretty": true, 14 | "declaration": true, 15 | "outDir": "dist", 16 | "sourceRoot": "" 17 | }, 18 | "exclude": [ 19 | "dist", 20 | "node_modules", 21 | "test" 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/noYaml/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "@midwayjs/faas": "*" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/noYaml/serverless.yml: -------------------------------------------------------------------------------- 1 | service: serverless-midway-test 2 | 3 | provider: 4 | name: aliyun 5 | runtime: nodejs8 6 | credentials: ./.aliyun_credentials # path must be absolute -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/noYaml/src/index.ts: -------------------------------------------------------------------------------- 1 | import { Func, Inject, Provide } from '@midwayjs/decorator'; 2 | import { FaaSContext } from '@midwayjs/faas'; 3 | 4 | @Provide() 5 | @Func('service.handler') 6 | export class Service { 7 | 8 | @Inject() 9 | ctx: FaaSContext; // context 10 | 11 | async handler() { 12 | return 'hello world'; 13 | } 14 | } 15 | 16 | @Provide() 17 | export class Service2 { 18 | @Inject() 19 | ctx: FaaSContext; 20 | 21 | @Func({ event: 'HTTP', method: 'POST', path: '/api/test2' }) 22 | async index() { 23 | return 'hello world' 24 | } 25 | } -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/noYaml/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": true, 3 | "compilerOptions": { 4 | "target": "ES2018", 5 | "module": "commonjs", 6 | "moduleResolution": "node", 7 | "experimentalDecorators": true, 8 | "emitDecoratorMetadata": true, 9 | "inlineSourceMap": true, 10 | "noImplicitThis": true, 11 | "noUnusedLocals": true, 12 | "stripInternal": true, 13 | "pretty": true, 14 | "declaration": true, 15 | "outDir": "dist", 16 | "sourceRoot": "" 17 | }, 18 | "exclude": [ 19 | "dist", 20 | "node_modules", 21 | "test" 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/same-handler-addon/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "@midwayjs/faas": "*" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/same-handler-addon/serverless.yml: -------------------------------------------------------------------------------- 1 | service: serverless-midway-test 2 | 3 | provider: 4 | name: aliyun 5 | runtime: nodejs8 6 | 7 | functions: 8 | http: 9 | handler: http.handler 10 | events: 11 | - http: 12 | method: post 13 | xxx: 14 | handler: http.xxx 15 | events: 16 | - http: 17 | method: post -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/same-handler-addon/src/index.ts: -------------------------------------------------------------------------------- 1 | import { func, inject, provide } from '@midwayjs/faas'; 2 | 3 | @provide() 4 | @func('http.handler') 5 | export class HelloHttpService { 6 | 7 | @inject() 8 | ctx; // context 9 | 10 | async handler() { 11 | return 'http' 12 | } 13 | } 14 | 15 | @provide() 16 | @func('http.xxx') 17 | export class HelloXXXHttpService { 18 | 19 | @inject() 20 | ctx; // context 21 | 22 | async handler() { 23 | return 'xxx' 24 | } 25 | } -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/fixtures/same-handler-addon/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": true, 3 | "compilerOptions": { 4 | "target": "ES2018", 5 | "module": "commonjs", 6 | "moduleResolution": "node", 7 | "experimentalDecorators": true, 8 | "emitDecoratorMetadata": true, 9 | "inlineSourceMap": true, 10 | "noImplicitThis": true, 11 | "noUnusedLocals": true, 12 | "stripInternal": true, 13 | "pretty": true, 14 | "declaration": true, 15 | "outDir": "dist", 16 | "sourceRoot": "" 17 | }, 18 | "exclude": [ 19 | "dist", 20 | "node_modules", 21 | "test" 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/initialize.test.ts: -------------------------------------------------------------------------------- 1 | import { invoke } from '../src/index'; 2 | import { join } from 'path'; 3 | import * as assert from 'assert'; 4 | import { remove } from 'fs-extra'; 5 | describe('/test/http.test.ts', () => { 6 | it('invoke', async () => { 7 | const baseDir = join(__dirname, 'fixtures/initializer'); 8 | await remove(join(baseDir, './.faas_debug_tmp')); 9 | const result: any = await invoke({ 10 | functionDir: baseDir, 11 | functionName: 'index', 12 | clean: false, 13 | }); 14 | console.log('result', result); 15 | assert(true); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/invoke.js: -------------------------------------------------------------------------------- 1 | const { invoke } = require('../'); 2 | const { join } = require('path'); 3 | invoke({ 4 | functionDir: join(__dirname, 'fixtures/baseApp'), 5 | functionName: 'http', 6 | data: [{ name: 'params' }], 7 | }).then(result => { 8 | console.log('result', result); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/test/main.test.ts: -------------------------------------------------------------------------------- 1 | import { invoke } from '../src/index'; 2 | import { join } from 'path'; 3 | import * as assert from 'assert'; 4 | describe('/test/main.test.ts', () => { 5 | it('invoke', async () => { 6 | const result: any = await (invoke as any)({ 7 | functionDir: join(__dirname, 'fixtures/baseApp'), 8 | functionName: 'http', 9 | clean: false, 10 | }); 11 | assert(result.body === 'hello http world'); 12 | }); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-invoke/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compileOnSave": true, 4 | "compilerOptions": { 5 | "rootDir": "src", 6 | "outDir": "dist" 7 | }, 8 | "include": [ 9 | "./src/**/*.ts" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/commonPrefix.test.ts: -------------------------------------------------------------------------------- 1 | import { commonPrefix } from '../src/utils'; 2 | import * as assert from 'assert'; 3 | describe('/test/commonPrefix.test.ts', () => { 4 | describe('commonPrefix', () => { 5 | it('/', async () => { 6 | const prefix = commonPrefix(['/api/index', '/api/api2', '/']); 7 | assert(prefix === ''); 8 | }); 9 | it('/*', async () => { 10 | const prefix = commonPrefix(['/api/index', '/api/api2', '//*']); 11 | assert(prefix === ''); 12 | }); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/aggregation/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "@midwayjs/faas": "*" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/aggregation/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": true, 3 | "compilerOptions": { 4 | "target": "ES2018", 5 | "module": "commonjs", 6 | "moduleResolution": "node", 7 | "experimentalDecorators": true, 8 | "emitDecoratorMetadata": true, 9 | "inlineSourceMap":true, 10 | "noImplicitThis": true, 11 | "noUnusedLocals": true, 12 | "stripInternal": true, 13 | "pretty": true, 14 | "declaration": true, 15 | "outDir": "dist" 16 | }, 17 | "exclude": [ 18 | "dist", 19 | "node_modules", 20 | "test" 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/base-app-pkg-config/a.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/base-app-pkg-config/app/test.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/midwayjs/midway-faas/d3f3b8e01514c468070abb14340776724a382a29/packages/faas-cli-plugin-package/test/fixtures/base-app-pkg-config/app/test.js -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/base-app-pkg-config/b.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/base-app-pkg-config/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "@midwayjs/runtime-engine": "*", 4 | "@midwayjs/faas": "*" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/base-app-pkg-config/serverless.yml: -------------------------------------------------------------------------------- 1 | service: serverless-midway-test 2 | 3 | provider: 4 | name: aliyun 5 | 6 | functions: 7 | index: 8 | handler: index.handler 9 | events: 10 | - http: 11 | method: get 12 | 13 | package: 14 | include: 15 | - '*.json' 16 | exclude: 17 | - b.json 18 | artifact: path/to/my-artifact.zip 19 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/base-app-pkg-config/src/index.ts: -------------------------------------------------------------------------------- 1 | import { FaaSContext, func, inject, provide } from '@midwayjs/faas'; 2 | 3 | @provide() 4 | @func('index.handler') 5 | export class HelloService { 6 | 7 | @inject() 8 | ctx: FaaSContext; // context 9 | 10 | async handler(event, obj = {}) { 11 | return 'hello world'; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/base-app-pkg-config/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": true, 3 | "compilerOptions": { 4 | "target": "ES2018", 5 | "module": "commonjs", 6 | "moduleResolution": "node", 7 | "experimentalDecorators": true, 8 | "emitDecoratorMetadata": true, 9 | "inlineSourceMap":true, 10 | "noImplicitThis": true, 11 | "noUnusedLocals": true, 12 | "stripInternal": true, 13 | "pretty": true, 14 | "declaration": true, 15 | "outDir": "dist" 16 | }, 17 | "exclude": [ 18 | "dist", 19 | "node_modules", 20 | "test" 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/base-app/copy.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/midwayjs/midway-faas/d3f3b8e01514c468070abb14340776724a382a29/packages/faas-cli-plugin-package/test/fixtures/base-app/copy.js -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/base-app/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "@midwayjs/runtime-engine": "*", 4 | "@midwayjs/faas": "*" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/base-app/serverless.yml: -------------------------------------------------------------------------------- 1 | service: serverless-midway-test 2 | 3 | provider: 4 | name: aliyun 5 | 6 | functions: 7 | index: 8 | handler: index.handler 9 | events: 10 | - http: 11 | method: get 12 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/base-app/src/index.ts: -------------------------------------------------------------------------------- 1 | import { FaaSContext, func, inject, provide } from '@midwayjs/faas'; 2 | 3 | @provide() 4 | @func('index.handler') 5 | export class HelloService { 6 | 7 | @inject() 8 | ctx: FaaSContext; // context 9 | 10 | async handler(event, obj = {}) { 11 | return 'hello world'; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/base-app/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": true, 3 | "compilerOptions": { 4 | "target": "ES2018", 5 | "module": "commonjs", 6 | "moduleResolution": "node", 7 | "experimentalDecorators": true, 8 | "emitDecoratorMetadata": true, 9 | "inlineSourceMap":true, 10 | "noImplicitThis": true, 11 | "noUnusedLocals": true, 12 | "stripInternal": true, 13 | "pretty": true, 14 | "declaration": true, 15 | "outDir": "dist" 16 | }, 17 | "exclude": [ 18 | "dist", 19 | "node_modules", 20 | "test" 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/eaas/.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | node_js: 4 | - '10' 5 | before_install: 6 | - npm i npminstall -g 7 | install: 8 | - npminstall 9 | script: 10 | - npm run ci 11 | after_script: 12 | - npminstall codecov && codecov 13 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/eaas/README.md: -------------------------------------------------------------------------------- 1 | # test-eaas 2 | 3 | test-eaas 4 | 5 | ## QuickStart 6 | 7 | 8 | 9 | see [egg docs][egg] for more detail. 10 | 11 | ### Development 12 | 13 | ```bash 14 | $ npm i 15 | $ npm run dev 16 | $ open http://localhost:7001/ 17 | ``` 18 | 19 | ### Deploy 20 | 21 | ```bash 22 | $ npm start 23 | $ npm stop 24 | ``` 25 | 26 | ### npm scripts 27 | 28 | - Use `npm run lint` to check code style. 29 | - Use `npm test` to run unit test. 30 | - Use `npm run autod` to auto detect dependencies upgrade, see [autod](https://www.npmjs.com/package/autod) for more detail. 31 | 32 | 33 | [egg]: https://eggjs.org -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/eaas/agent.js: -------------------------------------------------------------------------------- 1 | // agent.js 2 | module.exports = agent => { 3 | // 在这里写你的初始化逻辑 4 | 5 | // 也可以通过 messenger 对象发送消息给 App Worker 6 | // 但需要等待 App Worker 启动成功后才能发送,不然很可能丢失 7 | agent.messenger.on('egg-ready', () => { 8 | const data = { value: 'agent messenger works' }; 9 | agent.messenger.sendToApp('xxx_action', data); 10 | }); 11 | }; -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/eaas/app.js: -------------------------------------------------------------------------------- 1 | // app.js 2 | module.exports = app => { 3 | app.messenger.on('xxx_action', data => { 4 | console.log(data); 5 | // ... 6 | }); 7 | }; -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/eaas/app/controller/home.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const Controller = require('egg').Controller; 4 | 5 | class HomeController extends Controller { 6 | async index() { 7 | const { ctx } = this; 8 | ctx.body = 'hi, egg'; 9 | } 10 | async buffer() { 11 | const { ctx } = this; 12 | ctx.setHeader('x-res', 'buffer'); 13 | // assert 14 | ctx.body = Buffer.from('hi, egg'); 15 | } 16 | } 17 | 18 | module.exports = HomeController; 19 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/eaas/app/router.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * @param {Egg.Application} app - egg application 5 | */ 6 | module.exports = app => { 7 | const { router, controller } = app; 8 | router.get('/', controller.home.index); 9 | router.get('/buffer', controller.home.buffer); 10 | }; 11 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/eaas/appveyor.yml: -------------------------------------------------------------------------------- 1 | environment: 2 | matrix: 3 | - nodejs_version: '10' 4 | 5 | install: 6 | - ps: Install-Product node $env:nodejs_version 7 | - npm i npminstall && node_modules\.bin\npminstall 8 | 9 | test_script: 10 | - node --version 11 | - npm --version 12 | - npm run test 13 | 14 | build: off 15 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/eaas/config/config.default.js: -------------------------------------------------------------------------------- 1 | /* eslint valid-jsdoc: "off" */ 2 | 3 | 'use strict'; 4 | 5 | /** 6 | * @param {Egg.EggAppInfo} appInfo app info 7 | */ 8 | module.exports = appInfo => { 9 | /** 10 | * built-in config 11 | * @type {Egg.EggAppConfig} 12 | **/ 13 | const config = exports = {}; 14 | 15 | // use for cookie sign key, should change to your own and keep security 16 | config.keys = appInfo.name + '_1574154057813_8098'; 17 | 18 | // add your middleware config here 19 | config.middleware = []; 20 | 21 | // add your user config here 22 | const userConfig = { 23 | // myAppName: 'egg', 24 | }; 25 | 26 | return { 27 | ...config, 28 | ...userConfig, 29 | }; 30 | }; 31 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/eaas/config/plugin.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** @type Egg.EggPlugin */ 4 | module.exports = { 5 | // had enabled by egg 6 | // static: { 7 | // enable: true, 8 | // } 9 | }; 10 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/eaas/f.yml: -------------------------------------------------------------------------------- 1 | service: serverless-midway-test 2 | 3 | provider: 4 | name: aliyun 5 | 6 | functions: 7 | index: 8 | handler: index.handler 9 | events: 10 | - http: 11 | method: get 12 | 13 | layers: 14 | egg-layer: 15 | path: npm:@midwayjs/egg-layer 16 | 17 | package: 18 | include: 19 | - '*.js' 20 | - app 21 | - config 22 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/eaas/index.js: -------------------------------------------------------------------------------- 1 | const { asyncWrapper, start } = require('@midwayjs/serverless-fc-starter'); 2 | const eggLayer = require('@midwayjs/egg-layer'); 3 | 4 | let runtime; 5 | let inited = false; 6 | 7 | const initializeMethod = async (config = {}) => { 8 | runtime = await start({ 9 | layers: [eggLayer], 10 | }); 11 | inited = true; 12 | }; 13 | 14 | exports.initializer = asyncWrapper(async ({ config } = {}) => { 15 | await initializeMethod(config); 16 | }); 17 | 18 | exports.handler = asyncWrapper(async (...args) => { 19 | if (!inited) { 20 | await initializeMethod(); 21 | } 22 | 23 | return runtime.asyncEvent()(...args); 24 | }); 25 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/eaas/node_modules/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/midwayjs/midway-faas/d3f3b8e01514c468070abb14340776724a382a29/packages/faas-cli-plugin-package/test/fixtures/eaas/node_modules/.keep -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/ice-faas-ts/build.json: -------------------------------------------------------------------------------- 1 | { 2 | "entry": "src/index.tsx", 3 | "plugins": [ 4 | "build-plugin-ice-app", 5 | ["build-plugin-fusion", { 6 | "themePackage": "@icedesign/theme" 7 | }], 8 | "./build.plugin.js" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/ice-faas-ts/f.yml: -------------------------------------------------------------------------------- 1 | service: fc-test 2 | 3 | provider: 4 | name: fc 5 | runtime: nodejs10 6 | 7 | functions: 8 | test1: 9 | handler: index.handler 10 | events: 11 | - http: true 12 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/ice-faas-ts/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@icedesign/ts-scaffold9ade4c90-5de3-11e9-aef1-79dc0073b61f", 3 | "version": "1.0.3", 4 | "description": "该模板基于 TypeScript 适用于从 0 到 1 开始搭建项目,内置基础的页面,路由和菜单展示", 5 | "dependencies": { 6 | "@midwayjs/faas": "*", 7 | "react-router-dom": "*", 8 | "tslib": "*" 9 | }, 10 | "scripts": { 11 | "start": "build-scripts start", 12 | "build": "build-scripts build", 13 | "lint": "eslint . --ext '.js,.jsx' --fix" 14 | }, 15 | "engines": { 16 | "node": ">=8.0.0" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/ice-faas-ts/share/common/a.js: -------------------------------------------------------------------------------- 1 | alert('a'); 2 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/ice-faas-ts/share/render.html: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/ice-faas-ts/src/apis/index.ts: -------------------------------------------------------------------------------- 1 | import { 2 | provide, 3 | func, 4 | FunctionHandler, 5 | inject, 6 | FaaSContext, 7 | } from '@midwayjs/faas'; 8 | import foo from '../util' 9 | 10 | @provide() 11 | @func('index.handler') 12 | export class IndexHandler implements FunctionHandler { 13 | @inject() 14 | ctx: FaaSContext; 15 | /** 16 | * 发布为 hsf 时 17 | * 这个参数是 ginkgo 固定的,入参出参都为字符串 18 | * @param event 19 | */ 20 | async handler(event: string) { 21 | return 'hello' + foo(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/ice-faas-ts/src/components/Greeting/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | export interface Props { 4 | name: string; 5 | } 6 | 7 | const Greeting = ({ name }: Props) => { 8 | return ( 9 |
10 | Hello, {name} 11 |
12 | ); 13 | }; 14 | 15 | export default Greeting; 16 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/ice-faas-ts/src/index.tsx: -------------------------------------------------------------------------------- 1 | import ReactDOM from 'react-dom'; 2 | 3 | // 载入默认全局样式 normalize 4 | import '@alifd/next/reset.scss'; 5 | 6 | import router from './router'; 7 | 8 | const ICE_CONTAINER = document.getElementById('ice-container'); 9 | 10 | if (!ICE_CONTAINER) { 11 | throw new Error('当前页面不存在
节点.'); 12 | } 13 | 14 | ReactDOM.render(router(), ICE_CONTAINER); 15 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/ice-faas-ts/src/layouts/BasicLayout/index.tsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import MainRoutes from './MainRoutes'; 3 | 4 | export default class BasicLayout extends Component { 5 | render() { 6 | return ( 7 |
8 | 9 |
10 | ); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/ice-faas-ts/src/menuConfig.ts: -------------------------------------------------------------------------------- 1 | // 菜单配置 2 | 3 | const asideMenuConfig = []; 4 | 5 | export { asideMenuConfig }; 6 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/ice-faas-ts/src/pages/Dashboard/index.tsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import Guide from '../../components/Guide'; 3 | import Greeting from '../../components/Greeting'; 4 | 5 | export default class Dashboard extends Component { 6 | render() { 7 | return ( 8 |
9 | 10 | 11 |
12 | ); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/ice-faas-ts/src/router.tsx: -------------------------------------------------------------------------------- 1 | /** 2 | * 定义应用路由 3 | */ 4 | import { HashRouter, Switch, Route } from 'react-router-dom'; 5 | import React from 'react'; 6 | import BasicLayout from './layouts/BasicLayout'; 7 | 8 | const router = () => { 9 | return ( 10 | 11 | 12 | 13 | 14 | 15 | ); 16 | }; 17 | 18 | export default router; 19 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/ice-faas-ts/src/routerConfig.ts: -------------------------------------------------------------------------------- 1 | // 以下文件格式为描述路由的协议格式 2 | // 你可以调整 routerConfig 里的内容 3 | // 变量名 routerConfig 为 iceworks 检测关键字,请不要修改名称 4 | import Dashboard from './pages/Dashboard'; 5 | 6 | const routerConfig = [ 7 | { 8 | path: '/dashboard', 9 | component: Dashboard, 10 | }, 11 | ]; 12 | 13 | export default routerConfig; 14 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/ice-faas-ts/src/util.ts: -------------------------------------------------------------------------------- 1 | export default function foo () { 2 | return 'bar' 3 | } 4 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/ice-faas-ts/tests/index.js: -------------------------------------------------------------------------------- 1 | // test file 2 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/midway-faas-one/client/ice.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const fs = require('fs'); 3 | 4 | module.exports = { 5 | entry: 'src/index', 6 | publicPath: './', 7 | alias: { 8 | '@': path.resolve(__dirname, './src'), 9 | }, 10 | plugins: [ 11 | [ 12 | 'ice-plugin-fusion', 13 | { 14 | themePackage: '@alifd/theme-element', 15 | }, 16 | ], 17 | [ 18 | 'ice-plugin-moment-locales', 19 | { 20 | locales: ['zh-cn'], 21 | }, 22 | ] 23 | ], 24 | }; 25 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/midway-faas-one/client/src/index.tsx: -------------------------------------------------------------------------------- 1 | import ReactDOM from 'react-dom'; 2 | import { getMountNode, registerAppLeave } from '@ice/stark-app'; 3 | import './global.scss'; 4 | import router from './router'; 5 | 6 | const mountNode = getMountNode(); 7 | registerAppLeave(() => { 8 | ReactDOM.unmountComponentAtNode(mountNode); 9 | }); 10 | 11 | ReactDOM.render(router(), mountNode); 12 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/midway-faas-one/cloud/f.yml: -------------------------------------------------------------------------------- 1 | service: 2 | name: eleme/template 3 | gateway: gw-eleme 4 | 5 | provider: 6 | name: ginkgo 7 | runtime: nodejs10 8 | 9 | functions: 10 | ping: 11 | handler: ping.handler 12 | events: 13 | - hsf: true 14 | layers: 15 | - remote-debug 16 | post: 17 | handler: post.handler 18 | events: 19 | - hsf: true 20 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/midway-faas-one/cloud/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "taste-channel-faas-cloud", 3 | "version": "1.0.0", 4 | "main": "src/index.ts", 5 | "dependencies": { 6 | "@midwayjs/faas": "*", 7 | "request": "^2.88.0", 8 | "request-promise": "^4.2.5" 9 | }, 10 | "scripts": { 11 | "sync": "f sync", 12 | "fdev": "f dev" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/midway-faas-one/cloud/src/ping.ts: -------------------------------------------------------------------------------- 1 | import { 2 | provide, 3 | FunctionHandler, 4 | func, 5 | inject, 6 | FaaSContext, 7 | } from '@midwayjs/faas'; 8 | 9 | @provide() 10 | @func('ping.handler') 11 | export class ChannelPingHandler implements FunctionHandler { 12 | async handler() {} 13 | } 14 | 15 | @provide() 16 | @func('post.handler') 17 | export class PostPingHandler implements FunctionHandler { 18 | @inject() 19 | ctx: FaaSContext; 20 | 21 | async handler() {} 22 | } 23 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/midway-faas-one/cloud/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": true, 3 | "compilerOptions": { 4 | "target": "ES2017", 5 | "module": "commonjs", 6 | "moduleResolution": "node", 7 | "experimentalDecorators": true, 8 | "emitDecoratorMetadata": true, 9 | "esModuleInterop": true, 10 | "inlineSourceMap": true, 11 | "inlineSources": true, 12 | "noImplicitThis": true, 13 | "noUnusedLocals": true, 14 | "stripInternal": true, 15 | "pretty": true, 16 | "declaration": true, 17 | "outDir": "dist", 18 | "lib": ["es2017", "dom"] 19 | }, 20 | "exclude": ["dist", "node_modules", "test"] 21 | } 22 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/midway-faas-one/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "taste-channel-faas", 3 | "version": "1.0.0", 4 | "main": "client/src/index.js", 5 | "scripts": { 6 | "postinstall": "cd client && tnpm i && cd ../cloud && tnpm i", 7 | "dev": "cd client && node_modules/.bin/ice-scripts dev --config ./ice.config.js", 8 | "build": "cd client && node_modules/.bin/ice-scripts build --config ./ice.config.js", 9 | "clean": "rm -rf node_modules client/node_modules cloud/node_modules", 10 | "publish-def": "npm run build" 11 | }, 12 | "license": "ISC" 13 | } 14 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/noYaml/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "@midwayjs/faas": "*" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/noYaml/serverless.yml: -------------------------------------------------------------------------------- 1 | service: serverless-midway-test 2 | 3 | provider: 4 | name: aliyun 5 | runtime: nodejs8 6 | credentials: ./.aliyun_credentials # path must be absolute -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/noYaml/src/index.ts: -------------------------------------------------------------------------------- 1 | import { Func, Inject, Provide } from '@midwayjs/decorator'; 2 | import { FaaSContext } from '@midwayjs/faas'; 3 | 4 | @Provide() 5 | @Func('service.handler') 6 | export class Service { 7 | 8 | @Inject() 9 | ctx: FaaSContext; // context 10 | 11 | async handler() { 12 | return 'hello world'; 13 | } 14 | } -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/noYaml/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": true, 3 | "compilerOptions": { 4 | "target": "ES2018", 5 | "module": "commonjs", 6 | "moduleResolution": "node", 7 | "experimentalDecorators": true, 8 | "emitDecoratorMetadata": true, 9 | "inlineSourceMap": true, 10 | "noImplicitThis": true, 11 | "noUnusedLocals": true, 12 | "stripInternal": true, 13 | "pretty": true, 14 | "declaration": true, 15 | "outDir": "dist", 16 | "sourceRoot": "" 17 | }, 18 | "exclude": [ 19 | "dist", 20 | "node_modules", 21 | "test" 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/plugins/faas_tmp_out.ts: -------------------------------------------------------------------------------- 1 | import {BasePlugin} from '@midwayjs/fcli-command-core'; 2 | import { resolve } from 'path'; 3 | import { copy } from 'fs-extra'; 4 | export class FaaSTmpOutPlugin extends BasePlugin { 5 | hooks = { 6 | 'after:package:cleanup': async () => { 7 | const tmpDir = this.getStore('defaultTmpFaaSOut', 'PackagePlugin'); 8 | console.log('tmpDIr', tmpDir); 9 | await copy(resolve(__dirname, 'test.ts'), resolve(tmpDir, 'src/test.ts')); 10 | await copy(resolve(__dirname, 'test.js'), resolve(tmpDir, 'test.js')); 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/plugins/test.js: -------------------------------------------------------------------------------- 1 | console.log('test.js'); -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/plugins/test.ts: -------------------------------------------------------------------------------- 1 | import { Func, Provide } from '@midwayjs/decorator'; 2 | 3 | @Provide() 4 | export class Test { 5 | 6 | @Func('test.hand') 7 | async handler() { 8 | return 'hello world'; 9 | } 10 | } -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/ts-dir/build.json: -------------------------------------------------------------------------------- 1 | { 2 | "entry": "src/index.tsx", 3 | "plugins": [ 4 | "build-plugin-ice-app", 5 | ["build-plugin-fusion", { 6 | "themePackage": "@icedesign/theme" 7 | }], 8 | "./build.plugin.js" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/ts-dir/f.yml: -------------------------------------------------------------------------------- 1 | service: fc-test 2 | 3 | provider: 4 | name: fc 5 | runtime: nodejs10 6 | 7 | functions: 8 | test1: 9 | handler: index.handler 10 | events: 11 | - http: true 12 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/ts-dir/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@icedesign/ts-scaffold9ade4c90-5de3-11e9-aef1-79dc0073b61f", 3 | "version": "1.0.3", 4 | "description": "该模板基于 TypeScript 适用于从 0 到 1 开始搭建项目,内置基础的页面,路由和菜单展示", 5 | "dependencies": { 6 | "@midwayjs/faas": "*", 7 | "react-router-dom": "*", 8 | "tslib": "*" 9 | }, 10 | "scripts": { 11 | "start": "build-scripts start", 12 | "build": "build-scripts build", 13 | "lint": "eslint . --ext '.js,.jsx' --fix" 14 | }, 15 | "engines": { 16 | "node": ">=8.0.0" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/ts-dir/src/apis/index.ts: -------------------------------------------------------------------------------- 1 | import { 2 | provide, 3 | func, 4 | FunctionHandler, 5 | inject, 6 | FaaSContext, 7 | } from '@midwayjs/faas'; 8 | 9 | @provide() 10 | @func('index.handler') 11 | export class IndexHandler implements FunctionHandler { 12 | @inject() 13 | ctx: FaaSContext; 14 | /** 15 | * 发布为 hsf 时 16 | * 这个参数是 ginkgo 固定的,入参出参都为字符串 17 | * @param event 18 | */ 19 | async handler(event: string) { 20 | return 'hello'; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/ts-dir/src/components/Greeting/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | export interface Props { 4 | name: string; 5 | } 6 | 7 | const Greeting = ({ name }: Props) => { 8 | return ( 9 |
10 | Hello, {name} 11 |
12 | ); 13 | }; 14 | 15 | export default Greeting; 16 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/ts-dir/src/index.tsx: -------------------------------------------------------------------------------- 1 | import ReactDOM from 'react-dom'; 2 | 3 | // 载入默认全局样式 normalize 4 | import '@alifd/next/reset.scss'; 5 | 6 | import router from './router'; 7 | 8 | const ICE_CONTAINER = document.getElementById('ice-container'); 9 | 10 | if (!ICE_CONTAINER) { 11 | throw new Error('当前页面不存在
节点.'); 12 | } 13 | 14 | ReactDOM.render(router(), ICE_CONTAINER); 15 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/ts-dir/src/layouts/BasicLayout/index.tsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import MainRoutes from './MainRoutes'; 3 | 4 | export default class BasicLayout extends Component { 5 | render() { 6 | return ( 7 |
8 | 9 |
10 | ); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/ts-dir/src/menuConfig.ts: -------------------------------------------------------------------------------- 1 | // 菜单配置 2 | 3 | const asideMenuConfig = []; 4 | 5 | export { asideMenuConfig }; 6 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/ts-dir/src/pages/Dashboard/index.tsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import Guide from '../../components/Guide'; 3 | import Greeting from '../../components/Greeting'; 4 | 5 | export default class Dashboard extends Component { 6 | render() { 7 | return ( 8 |
9 | 10 | 11 |
12 | ); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/ts-dir/src/router.tsx: -------------------------------------------------------------------------------- 1 | /** 2 | * 定义应用路由 3 | */ 4 | import { HashRouter, Switch, Route } from 'react-router-dom'; 5 | import React from 'react'; 6 | import BasicLayout from './layouts/BasicLayout'; 7 | 8 | const router = () => { 9 | return ( 10 | 11 | 12 | 13 | 14 | 15 | ); 16 | }; 17 | 18 | export default router; 19 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/ts-dir/src/routerConfig.ts: -------------------------------------------------------------------------------- 1 | // 以下文件格式为描述路由的协议格式 2 | // 你可以调整 routerConfig 里的内容 3 | // 变量名 routerConfig 为 iceworks 检测关键字,请不要修改名称 4 | import Dashboard from './pages/Dashboard'; 5 | 6 | const routerConfig = [ 7 | { 8 | path: '/dashboard', 9 | component: Dashboard, 10 | }, 11 | ]; 12 | 13 | export default routerConfig; 14 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/test/fixtures/ts-dir/src/util.ts: -------------------------------------------------------------------------------- 1 | export default function foo () { 2 | return 'bar' 3 | } 4 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-package/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compileOnSave": true, 4 | "compilerOptions": { 5 | "rootDir": "src", 6 | "outDir": "dist" 7 | }, 8 | "include": [ 9 | "./src/**/*.ts" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-scf/test/fixtures/base/f.yml: -------------------------------------------------------------------------------- 1 | service: midway-test 2 | 3 | provider: 4 | name: tencent 5 | 6 | functions: 7 | index: 8 | handler: index.handler 9 | events: 10 | - http: 11 | method: get 12 | path: /http 13 | index2: 14 | handler: index.handler2 15 | events: 16 | - apigw: 17 | method: get 18 | path: /apigw 19 | 20 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-scf/test/fixtures/base/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "@midwayjs/runtime-engine": "*", 4 | "@midwayjs/faas": "*" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-scf/test/fixtures/base/src/index.ts: -------------------------------------------------------------------------------- 1 | import { FaaSContext, func, inject, provide } from '@midwayjs/faas'; 2 | 3 | @provide() 4 | @func('index.handler') 5 | export class HelloService { 6 | 7 | @inject() 8 | ctx: FaaSContext; // context 9 | 10 | async handler(event, obj = {}) { 11 | return 'hello world'; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-scf/test/fixtures/base/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": true, 3 | "compilerOptions": { 4 | "target": "ES2018", 5 | "module": "commonjs", 6 | "moduleResolution": "node", 7 | "experimentalDecorators": true, 8 | "emitDecoratorMetadata": true, 9 | "inlineSourceMap":true, 10 | "noImplicitThis": true, 11 | "noUnusedLocals": true, 12 | "stripInternal": true, 13 | "pretty": true, 14 | "declaration": true, 15 | "outDir": "dist" 16 | }, 17 | "exclude": [ 18 | "dist", 19 | "node_modules", 20 | "test" 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-scf/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compileOnSave": true, 4 | "compilerOptions": { 5 | "rootDir": "src", 6 | "outDir": "dist" 7 | }, 8 | "include": [ 9 | "./src/**/*.ts" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-test/test/a.test.ts: -------------------------------------------------------------------------------- 1 | import * as assert from 'assert'; 2 | describe('/test/a.test.ts', () => { 3 | it('testA', async () => { 4 | assert(true); 5 | }); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-test/test/b.test.ts: -------------------------------------------------------------------------------- 1 | import * as assert from 'assert'; 2 | describe('/test/b.test.ts', () => { 3 | it('testB', async () => { 4 | assert(true); 5 | }); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/faas-cli-plugin-test/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compileOnSave": true, 4 | "compilerOptions": { 5 | "rootDir": "src", 6 | "outDir": "dist" 7 | }, 8 | "include": [ 9 | "./src/**/*.ts" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /packages/faas-cli/bin/cli.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const { debugWrapper } = require('@midwayjs/debugger'); 3 | const cliFun = async argv => { 4 | require('source-map-support/register'); 5 | const { CLI } = require('../dist'); 6 | const cli = new CLI(argv); 7 | cli 8 | .start() 9 | .then(() => { 10 | process.exit(); 11 | }) 12 | .catch(e => { 13 | process.exit(); 14 | }); 15 | }; 16 | 17 | const cli = argv => { 18 | const isDebug = argv.debug; 19 | delete argv.debug; 20 | debugWrapper({ 21 | file: __filename, // 要包裹的方法所在文件 22 | export: 'cliFun', // 要包裹的方法的方法名 23 | debug: isDebug, 24 | })(argv); 25 | }; 26 | 27 | module.exports = { 28 | cliFun, 29 | cli, 30 | }; 31 | -------------------------------------------------------------------------------- /packages/faas-cli/bin/fun.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 'use strict'; 3 | const { cli } = require('./cli'); 4 | const minimist = require('minimist'); 5 | const argv = minimist(process.argv.slice(2)); 6 | cli(argv); 7 | -------------------------------------------------------------------------------- /packages/faas-cli/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compileOnSave": true, 4 | "compilerOptions": { 5 | "rootDir": "src", 6 | "outDir": "dist" 7 | }, 8 | "include": [ 9 | "./src/**/*.ts" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /packages/faas-dev-pack/README.md: -------------------------------------------------------------------------------- 1 | # Midway FaaS Dev 2 | 3 | 本模块用于 faas 代码的本地调试,用于接入现有的前端 DevServer,提供一个统一的中间件调用。 4 | 5 | 6 | ## Usage 7 | 8 | ```ts 9 | import { useExpressDevPack } from '@midwayjs/faas-dev-pack'; 10 | 11 | // dev server 代码 12 | app = express(); 13 | 14 | // 加载中间件 15 | app.use( 16 | useExpressDevPack({ 17 | functionDir: join(__dirname, './fixtures/ice-demo-repo'), 18 | sourceDir: 'src/apis', 19 | }) 20 | ); 21 | ``` 22 | 23 | ## API 24 | 25 | 暴露出两个中间件方法,用于上层集成。 26 | 27 | - `useExpressDevPack(options: DevOptions)` 28 | - `useKoaDevPack(options: DevOptions)` 29 | 30 | DevOptions 31 | 32 | ```ts 33 | export interface DevOptions { 34 | functionDir: string; // 本地目录,默认 process.cwd() 35 | sourceDir?: string; // 一体化调用时,需要知道当前的函数目录结构 36 | } 37 | ``` 38 | 39 | -------------------------------------------------------------------------------- /packages/faas-dev-pack/gateway.json: -------------------------------------------------------------------------------- 1 | { 2 | "http": "@midwayjs/gateway-common-http" 3 | } 4 | -------------------------------------------------------------------------------- /packages/faas-dev-pack/src/common.ts: -------------------------------------------------------------------------------- 1 | import { invoke } from '@midwayjs/serverless-invoke'; 2 | 3 | export function resolveModule(gatewayName: string) { 4 | const gatewayJSON = require('../gateway.json'); 5 | if (gatewayJSON[gatewayName]) { 6 | return require(gatewayJSON[gatewayName]); 7 | } else { 8 | throw new Error(`unsupport gateway type ${gatewayName}`); 9 | } 10 | } 11 | 12 | export async function invokeFunction(options) { 13 | return invoke(options); 14 | } 15 | -------------------------------------------------------------------------------- /packages/faas-dev-pack/src/interface.ts: -------------------------------------------------------------------------------- 1 | export interface InvokeParams { 2 | functionName: string; 3 | data?: any; 4 | contextData?: string; 5 | eventType?: string; 6 | verbose?: boolean; 7 | } 8 | -------------------------------------------------------------------------------- /packages/faas-dev-pack/test/fixtures/base-fn-apigw/f.yml: -------------------------------------------------------------------------------- 1 | service: 2 | name: serverless-hello-world 3 | 4 | provider: 5 | name: aliyun 6 | 7 | functions: 8 | index: 9 | handler: index.handler 10 | events: 11 | - apigw: 12 | path: /* 13 | method: get 14 | 15 | package: 16 | include: 17 | - public/* 18 | artifact: code.zip 19 | -------------------------------------------------------------------------------- /packages/faas-dev-pack/test/fixtures/base-fn-apigw/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "faas-demo", 3 | "dependencies": { 4 | "@midwayjs/faas": "*" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /packages/faas-dev-pack/test/fixtures/base-fn-apigw/src/index.ts: -------------------------------------------------------------------------------- 1 | import { Func, Inject, Provide } from '@midwayjs/decorator'; 2 | import { FaaSContext, FunctionHandler } from '@midwayjs/faas'; 3 | 4 | @Provide() 5 | export class IndexService implements FunctionHandler { 6 | @Inject() 7 | ctx: FaaSContext; // context 8 | 9 | @Func('index.handler') 10 | async handler() { 11 | this.ctx.type = 'text'; 12 | return new Buffer('hello world', 'utf-8'); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /packages/faas-dev-pack/test/fixtures/base-fn-apigw/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": true, 3 | "compilerOptions": { 4 | "target": "ES2018", 5 | "module": "commonjs", 6 | "moduleResolution": "node", 7 | "experimentalDecorators": true, 8 | "emitDecoratorMetadata": true, 9 | "inlineSourceMap":true, 10 | "noImplicitThis": true, 11 | "noUnusedLocals": false, 12 | "stripInternal": true, 13 | "pretty": true, 14 | "declaration": true, 15 | "outDir": "dist", 16 | "resolveJsonModule": true, 17 | "incremental": true 18 | }, 19 | "exclude": [ 20 | "dist", 21 | "node_modules", 22 | "test" 23 | ] 24 | } 25 | 26 | -------------------------------------------------------------------------------- /packages/faas-dev-pack/test/fixtures/base-fn-http/f.yml: -------------------------------------------------------------------------------- 1 | service: 2 | name: serverless-hello-world 3 | 4 | provider: 5 | name: aliyun 6 | 7 | functions: 8 | index: 9 | handler: index.handler 10 | events: 11 | - http: 12 | path: /* 13 | method: get 14 | 15 | package: 16 | include: 17 | - public/* 18 | artifact: code.zip 19 | -------------------------------------------------------------------------------- /packages/faas-dev-pack/test/fixtures/base-fn-http/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "faas-demo", 3 | "dependencies": { 4 | "@midwayjs/faas": "*" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /packages/faas-dev-pack/test/fixtures/base-fn-http/src/index.ts: -------------------------------------------------------------------------------- 1 | import { Func, Inject, Provide } from '@midwayjs/decorator'; 2 | import { FaaSContext, FunctionHandler } from '@midwayjs/faas'; 3 | 4 | @Provide() 5 | export class IndexService implements FunctionHandler { 6 | @Inject() 7 | ctx: FaaSContext; // context 8 | 9 | @Func('index.handler') 10 | async handler() { 11 | this.ctx.type = 'text'; 12 | return new Buffer('hello world', 'utf-8'); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /packages/faas-dev-pack/test/fixtures/base-fn-http/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": true, 3 | "compilerOptions": { 4 | "target": "ES2018", 5 | "module": "commonjs", 6 | "moduleResolution": "node", 7 | "experimentalDecorators": true, 8 | "emitDecoratorMetadata": true, 9 | "inlineSourceMap":true, 10 | "noImplicitThis": true, 11 | "noUnusedLocals": false, 12 | "stripInternal": true, 13 | "pretty": true, 14 | "declaration": true, 15 | "outDir": "dist", 16 | "resolveJsonModule": true, 17 | "incremental": true 18 | }, 19 | "exclude": [ 20 | "dist", 21 | "node_modules", 22 | "test" 23 | ] 24 | } 25 | 26 | -------------------------------------------------------------------------------- /packages/faas-dev-pack/test/fixtures/ice-demo-repo/README.md: -------------------------------------------------------------------------------- 1 | # ice-typescript-starter 2 | 3 | ## 使用 4 | 5 | - 启动调试服务: `npm start` 6 | - 构建 dist: `npm run build` 7 | 8 | ## 目录结构 9 | 10 | - react-router @4.x 默认采用 hashHistory 的单页应用 11 | - 入口文件: `src/index.js` 12 | - 导航配置: `src/menuConfig.js` 13 | - 路由配置: `src/routerConfig.js` 14 | - 路由入口: `src/router.jsx` 15 | - 布局文件: `src/layouts` 16 | - 通用组件: `src/components` 17 | - 页面文件: `src/pages` 18 | 19 | ## 效果图 20 | 21 | ![screenshot](https://img.alicdn.com/tfs/TB13AFlH6TpK1RjSZKPXXa3UpXa-2860-1580.png) 22 | -------------------------------------------------------------------------------- /packages/faas-dev-pack/test/fixtures/ice-demo-repo/f.yml: -------------------------------------------------------------------------------- 1 | service: fc-test 2 | 3 | provider: 4 | name: aliyun 5 | runtime: nodejs10 6 | 7 | functions: 8 | test1: 9 | handler: index.handler 10 | events: 11 | - http: 12 | path: /server/user/info 13 | test2: 14 | handler: test2.handler 15 | events: 16 | - http: 17 | path: /* 18 | -------------------------------------------------------------------------------- /packages/faas-dev-pack/test/fixtures/ice-demo-repo/ice.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | entry: 'src/index.tsx', 3 | plugins: [ 4 | ['ice-plugin-fusion', { 5 | themePackage: '@icedesign/theme', 6 | }], 7 | ['ice-plugin-moment-locales', { 8 | locales: ['zh-cn'], 9 | }], 10 | ], 11 | }; 12 | -------------------------------------------------------------------------------- /packages/faas-dev-pack/test/fixtures/ice-demo-repo/public/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/midwayjs/midway-faas/d3f3b8e01514c468070abb14340776724a382a29/packages/faas-dev-pack/test/fixtures/ice-demo-repo/public/favicon.png -------------------------------------------------------------------------------- /packages/faas-dev-pack/test/fixtures/ice-demo-repo/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | ICE TypeScript Starter 8 | 9 | 10 | 11 |
12 | 13 | 14 | -------------------------------------------------------------------------------- /packages/faas-dev-pack/test/fixtures/ice-demo-repo/src/apis/index.ts: -------------------------------------------------------------------------------- 1 | import { 2 | provide, 3 | func, 4 | FunctionHandler, 5 | inject, 6 | FaaSContext, 7 | } from '@midwayjs/faas'; 8 | 9 | @provide() 10 | @func('index.handler') 11 | export class IndexHandler implements FunctionHandler { 12 | @inject() 13 | ctx: FaaSContext; 14 | 15 | async handler() { 16 | console.log('this.ctx.req.body', this.ctx.request.body, this.ctx.query); 17 | const name = this.ctx.request.body['name']; 18 | const action = this.ctx.query['action']; 19 | this.ctx.type = 'text/html; charset=utf-8'; 20 | this.ctx.set('x-schema', 'bbb'); 21 | this.ctx.body = `${name},hello http world,${action}`; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /packages/faas-dev-pack/test/fixtures/ice-demo-repo/src/apis/test2.ts: -------------------------------------------------------------------------------- 1 | import { 2 | provide, 3 | func, 4 | FunctionHandler, 5 | inject, 6 | FaaSContext, 7 | } from '@midwayjs/faas'; 8 | 9 | @provide() 10 | @func('test2.handler') 11 | export class Test2Handler implements FunctionHandler { 12 | @inject() 13 | ctx: FaaSContext; 14 | 15 | async handler() { 16 | this.ctx.body = { data: 'test2' }; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /packages/faas-dev-pack/test/fixtures/ice-demo-repo/src/components/Greeting/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | export interface Props { 4 | name: string; 5 | } 6 | 7 | const Greeting = ({ name }: Props) => { 8 | return ( 9 |
10 | Hello, {name} 11 |
12 | ); 13 | }; 14 | 15 | export default Greeting; 16 | -------------------------------------------------------------------------------- /packages/faas-dev-pack/test/fixtures/ice-demo-repo/src/index.tsx: -------------------------------------------------------------------------------- 1 | import ReactDOM from 'react-dom'; 2 | 3 | // 载入默认全局样式 normalize 4 | import '@alifd/next/reset.scss'; 5 | 6 | import router from './router'; 7 | 8 | const ICE_CONTAINER = document.getElementById('ice-container'); 9 | 10 | if (!ICE_CONTAINER) { 11 | throw new Error('当前页面不存在
节点.'); 12 | } 13 | 14 | ReactDOM.render(router(), ICE_CONTAINER); 15 | -------------------------------------------------------------------------------- /packages/faas-dev-pack/test/fixtures/ice-demo-repo/src/layouts/BasicLayout/index.tsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import MainRoutes from './MainRoutes'; 3 | 4 | export default class BasicLayout extends Component { 5 | render() { 6 | return ( 7 |
8 | 9 |
10 | ); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /packages/faas-dev-pack/test/fixtures/ice-demo-repo/src/menuConfig.ts: -------------------------------------------------------------------------------- 1 | // 菜单配置 2 | 3 | const asideMenuConfig = []; 4 | 5 | export { asideMenuConfig }; 6 | -------------------------------------------------------------------------------- /packages/faas-dev-pack/test/fixtures/ice-demo-repo/src/pages/Dashboard/index.tsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import Guide from '../../components/Guide'; 3 | import Greeting from '../../components/Greeting'; 4 | 5 | export default class Dashboard extends Component { 6 | render() { 7 | return ( 8 |
9 | 10 | 11 |
12 | ); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /packages/faas-dev-pack/test/fixtures/ice-demo-repo/src/router.tsx: -------------------------------------------------------------------------------- 1 | /** 2 | * 定义应用路由 3 | */ 4 | import { HashRouter, Switch, Route } from 'react-router-dom'; 5 | import React from 'react'; 6 | import BasicLayout from './layouts/BasicLayout'; 7 | 8 | const router = () => { 9 | return ( 10 | 11 | 12 | 13 | 14 | 15 | ); 16 | }; 17 | 18 | export default router; 19 | -------------------------------------------------------------------------------- /packages/faas-dev-pack/test/fixtures/ice-demo-repo/src/routerConfig.ts: -------------------------------------------------------------------------------- 1 | // 以下文件格式为描述路由的协议格式 2 | // 你可以调整 routerConfig 里的内容 3 | // 变量名 routerConfig 为 iceworks 检测关键字,请不要修改名称 4 | import Dashboard from './pages/Dashboard'; 5 | 6 | const routerConfig = [ 7 | { 8 | path: '/dashboard', 9 | component: Dashboard, 10 | }, 11 | ]; 12 | 13 | export default routerConfig; 14 | -------------------------------------------------------------------------------- /packages/faas-dev-pack/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compileOnSave": true, 4 | "compilerOptions": { 5 | "rootDir": "src", 6 | "outDir": "dist" 7 | }, 8 | "include": [ 9 | "./src/**/*.ts" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /packages/faas-typings/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './typings/common'; 2 | export * from './typings/fc'; 3 | export * from './typings/scf'; 4 | -------------------------------------------------------------------------------- /packages/faas-typings/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@midwayjs/faas-typings", 3 | "version": "0.3.0", 4 | "typings": "index.d.ts", 5 | "engines": { 6 | "node": ">= 10" 7 | }, 8 | "keywords": [ 9 | "midway", 10 | "faas", 11 | "typings", 12 | "cloud", 13 | "definition" 14 | ], 15 | "repository": { 16 | "type": "git", 17 | "url": "git@github.com:midwayjs/midway-faas.git" 18 | }, 19 | "license": "MIT", 20 | "gitHead": "5a6539a27cf1376a8ea9c9a8553fdfb2f78d55bd" 21 | } 22 | -------------------------------------------------------------------------------- /packages/faas-util-ts-compile/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './utils'; 2 | export * from './codeAnalysis'; 3 | -------------------------------------------------------------------------------- /packages/faas-util-ts-compile/test/fixtures/baseApp/src/class.ts: -------------------------------------------------------------------------------- 1 | import { Inject, Func, Provide } from '@midwayjs/decorator'; 2 | import { FaaSContext } from '@midwayjs/faas'; 3 | 4 | const FaaSTrigger = { 5 | HTTP: 'HTTP', 6 | }; 7 | 8 | @Provide() 9 | @Func({ event: FaaSTrigger.HTTP }) 10 | export class NoHandlerAndPath { 11 | @Inject() 12 | ctx: FaaSContext; 13 | 14 | async handler() { 15 | return 'hello world'; 16 | } 17 | } 18 | 19 | @Provide() 20 | @Func('test.handler') 21 | export class NoEvents { 22 | @Inject() 23 | ctx: FaaSContext; 24 | 25 | async handler() { 26 | return 'hello world'; 27 | } 28 | } 29 | 30 | @Provide() 31 | @Func('test2.handler') 32 | export class Test2Events { 33 | @Inject() 34 | ctx: FaaSContext; 35 | 36 | async handler() { 37 | return 'hello world'; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /packages/faas-util-ts-compile/test/fixtures/files/from/1.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/midwayjs/midway-faas/d3f3b8e01514c468070abb14340776724a382a29/packages/faas-util-ts-compile/test/fixtures/files/from/1.js -------------------------------------------------------------------------------- /packages/faas-util-ts-compile/test/fixtures/files/from/1.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/midwayjs/midway-faas/d3f3b8e01514c468070abb14340776724a382a29/packages/faas-util-ts-compile/test/fixtures/files/from/1.json -------------------------------------------------------------------------------- /packages/faas-util-ts-compile/test/fixtures/files/from/1.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/midwayjs/midway-faas/d3f3b8e01514c468070abb14340776724a382a29/packages/faas-util-ts-compile/test/fixtures/files/from/1.txt -------------------------------------------------------------------------------- /packages/faas-util-ts-compile/test/fixtures/files/from/files/a.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/midwayjs/midway-faas/d3f3b8e01514c468070abb14340776724a382a29/packages/faas-util-ts-compile/test/fixtures/files/from/files/a.ts -------------------------------------------------------------------------------- /packages/faas-util-ts-compile/test/fixtures/files/from/files/b.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/midwayjs/midway-faas/d3f3b8e01514c468070abb14340776724a382a29/packages/faas-util-ts-compile/test/fixtures/files/from/files/b.ts -------------------------------------------------------------------------------- /packages/faas-util-ts-compile/test/fixtures/files/tmp/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/midwayjs/midway-faas/d3f3b8e01514c468070abb14340776724a382a29/packages/faas-util-ts-compile/test/fixtures/files/tmp/.gitkeep -------------------------------------------------------------------------------- /packages/faas-util-ts-compile/test/fixtures/files/to/1.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/midwayjs/midway-faas/d3f3b8e01514c468070abb14340776724a382a29/packages/faas-util-ts-compile/test/fixtures/files/to/1.js -------------------------------------------------------------------------------- /packages/faas-util-ts-compile/test/fixtures/files/to/1.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/midwayjs/midway-faas/d3f3b8e01514c468070abb14340776724a382a29/packages/faas-util-ts-compile/test/fixtures/files/to/1.txt -------------------------------------------------------------------------------- /packages/faas-util-ts-compile/test/fixtures/files/to/files/b.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/midwayjs/midway-faas/d3f3b8e01514c468070abb14340776724a382a29/packages/faas-util-ts-compile/test/fixtures/files/to/files/b.ts -------------------------------------------------------------------------------- /packages/faas-util-ts-compile/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compileOnSave": true, 4 | "compilerOptions": { 5 | "rootDir": "src", 6 | "outDir": "dist" 7 | }, 8 | "include": [ 9 | "./src/**/*.ts" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /packages/faas/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from '@midwayjs/faas-typings'; 2 | export * from './dist/index'; 3 | -------------------------------------------------------------------------------- /packages/faas/src/config.default.ts: -------------------------------------------------------------------------------- 1 | export const middleware = []; 2 | -------------------------------------------------------------------------------- /packages/faas/src/configuration.ts: -------------------------------------------------------------------------------- 1 | import { Configuration, App, Config } from '@midwayjs/decorator'; 2 | import { ILifeCycle } from '@midwayjs/core'; 3 | import { IFaaSApplication } from './interface'; 4 | 5 | @Configuration({ 6 | importConfigs: ['./config.default'], 7 | }) 8 | export class FaaSContainerConfiguration implements ILifeCycle { 9 | @App() 10 | app: IFaaSApplication; 11 | 12 | @Config('middleware') 13 | middleware: string[]; 14 | 15 | async onReady() { 16 | // add middleware from user config 17 | if (this.app?.use && this.middleware?.length) { 18 | await this.app.useMiddleware(this.middleware); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /packages/faas/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './interface'; 2 | export * from './starter'; 3 | export * from '@midwayjs/core'; 4 | export { 5 | Func as func, 6 | Provide as provide, 7 | Inject as inject, 8 | Config as config, 9 | Plugin as plugin, 10 | Logger as logger, 11 | Init as init, 12 | } from '@midwayjs/decorator'; 13 | -------------------------------------------------------------------------------- /packages/faas/test/configuration.ts: -------------------------------------------------------------------------------- 1 | import { Configuration } from '@midwayjs/decorator'; 2 | import { join } from 'path'; 3 | 4 | @Configuration({ 5 | imports: [join(__dirname, './fixtures/midway-plugin-mod')], 6 | }) 7 | export class ContainerLifeCycle {} 8 | -------------------------------------------------------------------------------- /packages/faas/test/fixtures/base-app-configuration/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "base-app-configuration", 3 | "version": "1.0" 4 | } 5 | -------------------------------------------------------------------------------- /packages/faas/test/fixtures/base-app-configuration/src/config.default.ts: -------------------------------------------------------------------------------- 1 | export = { 2 | case: '1235' 3 | }; 4 | -------------------------------------------------------------------------------- /packages/faas/test/fixtures/base-app-configuration/src/config/config.prod.ts: -------------------------------------------------------------------------------- 1 | export = { 2 | case: '5321', 3 | }; 4 | -------------------------------------------------------------------------------- /packages/faas/test/fixtures/base-app-configuration/src/configuration.ts: -------------------------------------------------------------------------------- 1 | import { Configuration } from '@midwayjs/decorator'; 2 | 3 | @Configuration({ 4 | imports: [], 5 | importConfigs: ['./config.default', './config/config.prod'], 6 | }) 7 | export class AutoConfiguraion {} 8 | -------------------------------------------------------------------------------- /packages/faas/test/fixtures/base-app-configuration/src/lib/userManager.ts: -------------------------------------------------------------------------------- 1 | import { Provide } from '@midwayjs/decorator'; 2 | 3 | @Provide() 4 | export class UserManager { 5 | async getUser() { 6 | return 'harry'; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /packages/faas/test/fixtures/base-app-handler/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "demo-app" 3 | } -------------------------------------------------------------------------------- /packages/faas/test/fixtures/base-app-handler/src/index.ts: -------------------------------------------------------------------------------- 1 | import { Inject, Provide, Func } from '@midwayjs/decorator'; 2 | import { FunctionHandler } from '../../../../src'; 3 | 4 | @Provide() 5 | export class IndexService implements FunctionHandler { 6 | @Inject() 7 | ctx; // context 8 | 9 | @Func('index.entry') 10 | handler(event) { 11 | return event.text + this.ctx.text; 12 | } 13 | 14 | @Func('index.list', { event: 'HTTP', path: '/list' }) 15 | getList(event) { 16 | return event.text + this.ctx.text; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /packages/faas/test/fixtures/base-app-handler2/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "demo-app" 3 | } -------------------------------------------------------------------------------- /packages/faas/test/fixtures/base-app-handler2/src/index.ts: -------------------------------------------------------------------------------- 1 | import { Inject, Provide, Func } from '@midwayjs/decorator'; 2 | import { FunctionHandler } from '../../../../src'; 3 | 4 | @Provide() 5 | @Func('index.handler') 6 | export class IndexService implements FunctionHandler { 7 | @Inject() 8 | ctx; // context 9 | 10 | // index.handler default method 11 | handler(event) { 12 | return 'default' + event.text + this.ctx.text; 13 | } 14 | 15 | @Func('index.list', {}) 16 | getList(event) { 17 | return event.text + this.ctx.text; 18 | } 19 | 20 | @Func({ path: '/' }) 21 | get(event) { 22 | return 'hello'; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /packages/faas/test/fixtures/base-app-inject/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "demo-app" 3 | } -------------------------------------------------------------------------------- /packages/faas/test/fixtures/base-app-inject/src/index.ts: -------------------------------------------------------------------------------- 1 | import { inject, provide, func, FunctionHandler } from '../../../../src'; 2 | import { Plugin, App } from '@midwayjs/decorator'; 3 | import * as assert from 'assert'; 4 | 5 | @provide() 6 | @func('index.handler') 7 | export class HelloService implements FunctionHandler { 8 | @inject() 9 | ctx; // context 10 | 11 | @App() 12 | app; 13 | 14 | @Plugin() 15 | mysql; 16 | 17 | handler(event) { 18 | assert(this.app); 19 | return this.ctx.originContext['text'] + event.text + this.mysql.model; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /packages/faas/test/fixtures/base-app-ioc/ioc.js: -------------------------------------------------------------------------------- 1 | const { join } = require('path'); 2 | module.exports = options => { 3 | return { 4 | loadDir: [ 5 | options.baseDir, 6 | join(options.appDir, 'proxy') 7 | ], 8 | }; 9 | }; 10 | -------------------------------------------------------------------------------- /packages/faas/test/fixtures/base-app-ioc/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "demo-app", 3 | "version": "1.0" 4 | } 5 | -------------------------------------------------------------------------------- /packages/faas/test/fixtures/base-app-ioc/proxy/test.ts: -------------------------------------------------------------------------------- 1 | import { Provide } from '@midwayjs/decorator'; 2 | 3 | @Provide() 4 | export class TestService { 5 | invoke() { 6 | return 'test'; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /packages/faas/test/fixtures/base-app-ioc/src/index.ts: -------------------------------------------------------------------------------- 1 | import { inject, provide, func, FunctionHandler } from '../../../../src'; 2 | 3 | @provide() 4 | @func('index.handler') 5 | export class HelloService implements FunctionHandler { 6 | @inject() 7 | ctx; // context 8 | 9 | @inject() 10 | testService; 11 | 12 | handler(event) { 13 | return event.text + this.ctx.text + this.testService.invoke(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /packages/faas/test/fixtures/base-app-middleware/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "demo-app" 3 | } -------------------------------------------------------------------------------- /packages/faas/test/fixtures/base-app-middleware/src/config.default.ts: -------------------------------------------------------------------------------- 1 | export const middleware = ['testMiddleware']; 2 | -------------------------------------------------------------------------------- /packages/faas/test/fixtures/base-app-middleware/src/configuration.ts: -------------------------------------------------------------------------------- 1 | import { Configuration } from '@midwayjs/decorator'; 2 | 3 | @Configuration({ 4 | importConfigs: ['./config.default'], 5 | }) 6 | export class AutoConfiguraion {} 7 | -------------------------------------------------------------------------------- /packages/faas/test/fixtures/base-app-middleware/src/index.ts: -------------------------------------------------------------------------------- 1 | import { inject, provide, func, FunctionHandler } from '../../../../src'; 2 | 3 | @provide() 4 | @func('index.handler') 5 | export class HelloService implements FunctionHandler { 6 | @inject() 7 | ctx; // context 8 | 9 | handler(event) { 10 | return this.ctx.originContext['text'] + event.text + this.ctx.requestId; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /packages/faas/test/fixtures/base-app-middleware/src/mw/test.ts: -------------------------------------------------------------------------------- 1 | import { Provide } from '@midwayjs/decorator'; 2 | import * as assert from 'assert'; 3 | 4 | @Provide() 5 | export class TestMiddleware { 6 | resolve() { 7 | return async (ctx, next) => { 8 | assert(ctx.logger); 9 | ctx.requestId = 555; 10 | await next(); 11 | }; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /packages/faas/test/fixtures/base-app-new/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "demo-app" 3 | } -------------------------------------------------------------------------------- /packages/faas/test/fixtures/base-app-new/src/index.ts: -------------------------------------------------------------------------------- 1 | import { Inject, Provide, Func } from '@midwayjs/decorator'; 2 | import { FunctionHandler } from '../../../../src'; 3 | 4 | @Provide() 5 | @Func('index.handler', { 6 | middleware: ['auth'], 7 | }) 8 | export class HelloService implements FunctionHandler { 9 | @Inject() 10 | ctx; // context 11 | 12 | async handler(event) { 13 | return event.text + this.ctx.text; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /packages/faas/test/fixtures/base-app-new/src/middleware/auth.ts: -------------------------------------------------------------------------------- 1 | import { Provide } from '@midwayjs/decorator'; 2 | import { FaaSContext, IMiddleware } from '../../../../../src'; 3 | 4 | @Provide('auth') 5 | export class AuthMiddleware implements IMiddleware { 6 | resolve() { 7 | return async (ctx, next) => { 8 | ctx.text = 'hello'; 9 | await next(); 10 | }; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /packages/faas/test/fixtures/base-app-route/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "demo-app" 3 | } -------------------------------------------------------------------------------- /packages/faas/test/fixtures/base-app-route/src/index.ts: -------------------------------------------------------------------------------- 1 | import { inject, provide, func, FunctionHandler } from '../../../../src'; 2 | 3 | @provide() 4 | @func('deploy.handler9') 5 | export class HelloService implements FunctionHandler { 6 | 7 | @inject() 8 | ctx; // context 9 | 10 | handler(event) { 11 | return event.text + this.ctx.text; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /packages/faas/test/fixtures/base-app/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "demo-app" 3 | } -------------------------------------------------------------------------------- /packages/faas/test/fixtures/base-app/src/index.ts: -------------------------------------------------------------------------------- 1 | import { inject, provide, func, FunctionHandler } from '../../../../src'; 2 | 3 | @provide() 4 | @func('index.handler') 5 | export class HelloService implements FunctionHandler { 6 | 7 | @inject() 8 | ctx; // context 9 | 10 | handler(event) { 11 | return event.text + this.ctx.text; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /packages/faas/test/fixtures/midway-plugin-mod/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "midway-plugin-mod", 3 | "main": "src/index" 4 | } 5 | -------------------------------------------------------------------------------- /packages/faas/test/fixtures/midway-plugin-mod/src/articleManager.ts: -------------------------------------------------------------------------------- 1 | import { Provide, Inject } from '@midwayjs/decorator'; 2 | import { ReplaceManager } from './replaceManager'; 3 | 4 | @Provide() 5 | export class ArticleManager { 6 | @Inject() 7 | replaceManager: ReplaceManager; 8 | 9 | async getOne() { 10 | return 'one article' + (await this.replaceManager.getOne()); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /packages/faas/test/fixtures/midway-plugin-mod/src/configuration.ts: -------------------------------------------------------------------------------- 1 | import { Configuration } from '@midwayjs/decorator'; 2 | 3 | @Configuration({ 4 | imports: [], 5 | namespace: 'midway-plugin-mod', 6 | }) 7 | export class AutoConfiguraion {} 8 | -------------------------------------------------------------------------------- /packages/faas/test/fixtures/midway-plugin-mod/src/replaceManager.ts: -------------------------------------------------------------------------------- 1 | import { Provide } from '@midwayjs/decorator'; 2 | 3 | @Provide() 4 | export class ReplaceManager { 5 | async getOne() { 6 | return 'replace manager'; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /packages/faas/test/fixtures/midway-plugin-mod/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2018", 4 | "module": "commonjs", 5 | "moduleResolution": "node", 6 | "experimentalDecorators": true, 7 | "noImplicitThis": true, 8 | "noUnusedLocals": true, 9 | "stripInternal": true, 10 | "pretty": true, 11 | "declaration": true, 12 | "outDir": "dist", 13 | "sourceMap": true 14 | }, 15 | "exclude": [ 16 | "dist", 17 | "node_modules", 18 | "test" 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /packages/faas/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compileOnSave": true, 4 | "compilerOptions": { 5 | "rootDir": "src", 6 | "outDir": "dist" 7 | }, 8 | "include": [ 9 | "./src/**/*.ts" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /packages/gateway-common-core/README.md: -------------------------------------------------------------------------------- 1 | # @midwayjs/gateway-common-core 2 | 3 | 网关通用类库或依赖 4 | -------------------------------------------------------------------------------- /packages/gateway-common-core/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './interface'; 2 | export * from './gatewaySuit'; 3 | export { Context, Request as KoaRequest, Response as KoaResponse } from 'koa'; 4 | export { NextFunction, Request, Response } from 'express'; 5 | -------------------------------------------------------------------------------- /packages/gateway-common-core/test/suit.test.ts: -------------------------------------------------------------------------------- 1 | import { createExpressSuit, createKoaSuit } from '../src'; 2 | 3 | describe('/test.suit.test.ts', () => { 4 | it('test express', done => { 5 | createExpressSuit({ 6 | gatewayDir: __dirname, 7 | }) 8 | .get('/test') 9 | .expect(/321/) 10 | .expect(200, done); 11 | }); 12 | 13 | it('test koa', done => { 14 | createKoaSuit({ 15 | gatewayDir: __dirname, 16 | }) 17 | .get('/test') 18 | .expect(/123/) 19 | .expect(200, done); 20 | }); 21 | }); 22 | -------------------------------------------------------------------------------- /packages/gateway-common-core/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compileOnSave": true, 4 | "compilerOptions": { 5 | "rootDir": "src", 6 | "outDir": "dist" 7 | }, 8 | "include": [ 9 | "./src/**/*.ts" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /packages/gateway-common-http/README.md: -------------------------------------------------------------------------------- 1 | # @midwayjs/gateway-common-http 2 | 3 | http 网关模拟 4 | -------------------------------------------------------------------------------- /packages/gateway-common-http/src/utils.ts: -------------------------------------------------------------------------------- 1 | export function getHeaderValue(headers, key) { 2 | return Array.isArray(headers[key]) && headers[key].length === 1 3 | ? headers[key][0] 4 | : headers[key]; 5 | } 6 | -------------------------------------------------------------------------------- /packages/gateway-common-http/test/fixtures/ice-demo-repo/README.md: -------------------------------------------------------------------------------- 1 | # ice-typescript-starter 2 | 3 | ## 使用 4 | 5 | - 启动调试服务: `npm start` 6 | - 构建 dist: `npm run build` 7 | 8 | ## 目录结构 9 | 10 | - react-router @4.x 默认采用 hashHistory 的单页应用 11 | - 入口文件: `src/index.js` 12 | - 导航配置: `src/menuConfig.js` 13 | - 路由配置: `src/routerConfig.js` 14 | - 路由入口: `src/router.jsx` 15 | - 布局文件: `src/layouts` 16 | - 通用组件: `src/components` 17 | - 页面文件: `src/pages` 18 | -------------------------------------------------------------------------------- /packages/gateway-common-http/test/fixtures/ice-demo-repo/f.yml: -------------------------------------------------------------------------------- 1 | service: fc-test 2 | 3 | provider: 4 | name: tencent 5 | runtime: nodejs10 6 | 7 | functions: 8 | test1: 9 | handler: index.handler 10 | events: 11 | - http: 12 | path: /server/user/info 13 | - http: 14 | path: /server/user/info2 15 | test2: 16 | handler: test2.handler 17 | events: 18 | - http: true 19 | test3: 20 | handler: test3.handler 21 | events: 22 | - apigw: 23 | path: /api/* 24 | test4: 25 | handler: test4.handler 26 | events: 27 | - http: 28 | path: /api/a/b/c 29 | test5: 30 | handler: test4.handler 31 | events: 32 | - http: 33 | path: /ignore.do 34 | test6: 35 | handler: test6.handler 36 | events: 37 | - apigw: 38 | path: /api/ 39 | -------------------------------------------------------------------------------- /packages/gateway-common-http/test/fixtures/ice-demo-repo/ice.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | entry: 'src/index.tsx', 3 | plugins: [ 4 | ['ice-plugin-fusion', { 5 | themePackage: '@icedesign/theme', 6 | }], 7 | ['ice-plugin-moment-locales', { 8 | locales: ['zh-cn'], 9 | }], 10 | ], 11 | }; 12 | -------------------------------------------------------------------------------- /packages/gateway-common-http/test/fixtures/ice-demo-repo/public/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/midwayjs/midway-faas/d3f3b8e01514c468070abb14340776724a382a29/packages/gateway-common-http/test/fixtures/ice-demo-repo/public/favicon.png -------------------------------------------------------------------------------- /packages/gateway-common-http/test/fixtures/ice-demo-repo/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | ICE TypeScript Starter 8 | 9 | 10 | 11 |
12 | 13 | 14 | -------------------------------------------------------------------------------- /packages/gateway-common-http/test/fixtures/ice-demo-repo/src/apis/index.ts: -------------------------------------------------------------------------------- 1 | import { 2 | provide, 3 | func, 4 | FunctionHandler, 5 | inject, 6 | FaaSContext, 7 | } from '@midwayjs/faas'; 8 | 9 | @provide() 10 | @func('index.handler') 11 | export class IndexHandler implements FunctionHandler { 12 | @inject() 13 | ctx: FaaSContext; 14 | 15 | async handler() { 16 | const name = this.ctx.req.body['name']; 17 | const action = this.ctx.query['action']; 18 | this.ctx.type = 'text/html; charset=utf-8'; 19 | this.ctx.set('x-schema', 'bbb'); 20 | this.ctx.body = `${name},hello http world,${action}`; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /packages/gateway-common-http/test/fixtures/ice-demo-repo/src/apis/test2.ts: -------------------------------------------------------------------------------- 1 | import { 2 | provide, 3 | func, 4 | FunctionHandler, 5 | inject, 6 | FaaSContext, 7 | } from '@midwayjs/faas'; 8 | 9 | @provide() 10 | @func('test2.handler') 11 | export class Test2Handler implements FunctionHandler { 12 | @inject() 13 | ctx: FaaSContext; 14 | 15 | async handler() { 16 | this.ctx.body = {data: 'test2'}; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /packages/gateway-common-http/test/fixtures/ice-demo-repo/src/apis/test3.ts: -------------------------------------------------------------------------------- 1 | import { 2 | provide, 3 | func, 4 | FunctionHandler, 5 | inject, 6 | FaaSContext, 7 | } from '@midwayjs/faas'; 8 | 9 | @provide() 10 | @func('test3.handler') 11 | export class Test3Handler implements FunctionHandler { 12 | @inject() 13 | ctx: FaaSContext; 14 | 15 | async handler() { 16 | this.ctx.body = {data: 'test3'}; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /packages/gateway-common-http/test/fixtures/ice-demo-repo/src/apis/test4.ts: -------------------------------------------------------------------------------- 1 | import { 2 | provide, 3 | func, 4 | FunctionHandler, 5 | inject, 6 | FaaSContext, 7 | } from '@midwayjs/faas'; 8 | 9 | @provide() 10 | @func('test4.handler') 11 | export class Test4Handler implements FunctionHandler { 12 | @inject() 13 | ctx: FaaSContext; 14 | 15 | async handler() { 16 | this.ctx.body = {data: 'test4'}; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /packages/gateway-common-http/test/fixtures/ice-demo-repo/src/apis/test6.ts: -------------------------------------------------------------------------------- 1 | import { 2 | provide, 3 | func, 4 | FunctionHandler, 5 | inject, 6 | FaaSContext, 7 | } from '@midwayjs/faas'; 8 | 9 | @provide() 10 | @func('test6.handler') 11 | export class Test6Handler implements FunctionHandler { 12 | @inject() 13 | ctx: FaaSContext; 14 | 15 | async handler() { 16 | this.ctx.body = {data: 'test6'}; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /packages/gateway-common-http/test/fixtures/ice-demo-repo/src/components/Greeting/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | export interface Props { 4 | name: string; 5 | } 6 | 7 | const Greeting = ({ name }: Props) => { 8 | return ( 9 |
10 | Hello, {name} 11 |
12 | ); 13 | }; 14 | 15 | export default Greeting; 16 | -------------------------------------------------------------------------------- /packages/gateway-common-http/test/fixtures/ice-demo-repo/src/index.tsx: -------------------------------------------------------------------------------- 1 | import ReactDOM from 'react-dom'; 2 | 3 | // 载入默认全局样式 normalize 4 | import '@alifd/next/reset.scss'; 5 | 6 | import router from './router'; 7 | 8 | const ICE_CONTAINER = document.getElementById('ice-container'); 9 | 10 | if (!ICE_CONTAINER) { 11 | throw new Error('当前页面不存在
节点.'); 12 | } 13 | 14 | ReactDOM.render(router(), ICE_CONTAINER); 15 | -------------------------------------------------------------------------------- /packages/gateway-common-http/test/fixtures/ice-demo-repo/src/layouts/BasicLayout/index.tsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import MainRoutes from './MainRoutes'; 3 | 4 | export default class BasicLayout extends Component { 5 | render() { 6 | return ( 7 |
8 | 9 |
10 | ); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /packages/gateway-common-http/test/fixtures/ice-demo-repo/src/menuConfig.ts: -------------------------------------------------------------------------------- 1 | // 菜单配置 2 | 3 | const asideMenuConfig = []; 4 | 5 | export { asideMenuConfig }; 6 | -------------------------------------------------------------------------------- /packages/gateway-common-http/test/fixtures/ice-demo-repo/src/pages/Dashboard/index.tsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import Guide from '../../components/Guide'; 3 | import Greeting from '../../components/Greeting'; 4 | 5 | export default class Dashboard extends Component { 6 | render() { 7 | return ( 8 |
9 | 10 | 11 |
12 | ); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /packages/gateway-common-http/test/fixtures/ice-demo-repo/src/router.tsx: -------------------------------------------------------------------------------- 1 | /** 2 | * 定义应用路由 3 | */ 4 | import { HashRouter, Switch, Route } from 'react-router-dom'; 5 | import React from 'react'; 6 | import BasicLayout from './layouts/BasicLayout'; 7 | 8 | const router = () => { 9 | return ( 10 | 11 | 12 | 13 | 14 | 15 | ); 16 | }; 17 | 18 | export default router; 19 | -------------------------------------------------------------------------------- /packages/gateway-common-http/test/fixtures/ice-demo-repo/src/routerConfig.ts: -------------------------------------------------------------------------------- 1 | // 以下文件格式为描述路由的协议格式 2 | // 你可以调整 routerConfig 里的内容 3 | // 变量名 routerConfig 为 iceworks 检测关键字,请不要修改名称 4 | import Dashboard from './pages/Dashboard'; 5 | 6 | const routerConfig = [ 7 | { 8 | path: '/dashboard', 9 | component: Dashboard, 10 | }, 11 | ]; 12 | 13 | export default routerConfig; 14 | -------------------------------------------------------------------------------- /packages/gateway-common-http/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compileOnSave": true, 4 | "compilerOptions": { 5 | "rootDir": "src", 6 | "outDir": "dist" 7 | }, 8 | "include": [ 9 | "./src/**/*.ts" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /packages/runtime-engine/src/error.ts: -------------------------------------------------------------------------------- 1 | export class RuntimeError extends Error { 2 | name = 'RuntimeError'; 3 | code = 1; 4 | 5 | constructor(message: string, errName?: string, code?: number) { 6 | super(message); 7 | this.name = errName || this.constructor.name; 8 | this.code = code || 1; 9 | } 10 | 11 | static create(errorObject: { name?: string; code: number; message: string }) { 12 | let errName = errorObject.name || 'RuntimeError'; 13 | if (!/Error$/.test(errName)) { 14 | errName += 'Error'; 15 | } 16 | return new RuntimeError(errorObject.message, errName, errorObject.code); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /packages/runtime-engine/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './interface'; 2 | export * from './runtime'; 3 | export * from './engine'; 4 | export * from './lib/parser'; 5 | export * from './lib/debug'; 6 | export * from './lightRuntime'; 7 | export * from './lib/loggerFactory'; 8 | export * from './lib/logger'; 9 | export * from './error'; 10 | export * from './bootstrap'; 11 | export * from './util'; 12 | -------------------------------------------------------------------------------- /packages/runtime-engine/src/lib/debug.ts: -------------------------------------------------------------------------------- 1 | /* istanbul ignore file */ 2 | import { isDebug } from '../util'; 3 | 4 | export class DebugLogger { 5 | prefix; 6 | isDebugEnv; 7 | 8 | constructor(prefix?) { 9 | this.prefix = prefix || ''; 10 | this.isDebugEnv = isDebug(); 11 | } 12 | 13 | log(...args) { 14 | if (this.isDebugEnv) { 15 | if (this.prefix) { 16 | console.log(`[faas_debug:${this.prefix}]`, args); 17 | } else { 18 | console.log('[faas_debug]', args); 19 | } 20 | } 21 | } 22 | 23 | write(...args) { 24 | this.log(...args); 25 | } 26 | 27 | warn(...args) { 28 | this.log(...args); 29 | } 30 | 31 | info(...args) { 32 | this.log(...args); 33 | } 34 | 35 | error(...args) { 36 | this.log(...args); 37 | } 38 | 39 | debug(...args) { 40 | this.log(...args); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /packages/runtime-engine/test/fixtures/common/index.ts: -------------------------------------------------------------------------------- 1 | export const initialize = () => {}; 2 | 3 | export const handler = async () => { 4 | return 'Hello, world!'; 5 | }; 6 | -------------------------------------------------------------------------------- /packages/runtime-engine/test/fixtures/crash/index.ts: -------------------------------------------------------------------------------- 1 | throw new Error('empty'); 2 | -------------------------------------------------------------------------------- /packages/runtime-engine/test/fixtures/error/index.ts: -------------------------------------------------------------------------------- 1 | export const initialize = () => { 2 | // throw new Error('initialize error...'); 3 | }; 4 | 5 | export const handler = async ctx => { 6 | throw new Error('Ops'); 7 | }; 8 | -------------------------------------------------------------------------------- /packages/runtime-engine/test/fixtures/extension/httpEvent.ts: -------------------------------------------------------------------------------- 1 | import { FunctionEvent } from '../../../src'; 2 | 3 | export class HttpEvent implements FunctionEvent { 4 | type: string; 5 | meta: object; 6 | logger; 7 | 8 | constructor(options) { 9 | this.type = 'HTTP'; 10 | this.meta = { domainName: 'http.test.com' }; 11 | this.logger = options.logger; 12 | } 13 | 14 | match() { 15 | return true; 16 | } 17 | 18 | transformInvokeArgs(...args): any[] { 19 | return args; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /packages/runtime-engine/test/fixtures/extension/index.ts: -------------------------------------------------------------------------------- 1 | import { ServerlessBaseRuntime} from '../../../src'; 2 | import assert = require('assert'); 3 | 4 | export const initialize = (runtime) => { 5 | assert(runtime instanceof ServerlessBaseRuntime) 6 | }; 7 | 8 | export const handler = async ctx => { 9 | return ctx.myValue + 'Hello, world!'; 10 | }; 11 | -------------------------------------------------------------------------------- /packages/runtime-engine/test/fixtures/js/index.ts: -------------------------------------------------------------------------------- 1 | export const initialize = (runtime) => { 2 | console.log('this is runtime', runtime) 3 | }; 4 | 5 | export const handler = async () => { 6 | return 'Hello, world!'; 7 | }; 8 | -------------------------------------------------------------------------------- /packages/runtime-engine/test/layer.test.ts: -------------------------------------------------------------------------------- 1 | describe('/test/layer.test.ts', () => {}); 2 | -------------------------------------------------------------------------------- /packages/runtime-engine/test/runtime-error.test.ts: -------------------------------------------------------------------------------- 1 | import { RuntimeError } from '..'; 2 | import * as assert from 'assert'; 3 | 4 | describe('runtime-error', () => { 5 | it('create new error', () => { 6 | try { 7 | throw new RuntimeError('init fail'); 8 | } catch (e) { 9 | assert.equal(e.name, 'RuntimeError'); 10 | assert.equal(e.message, 'init fail'); 11 | } 12 | }); 13 | 14 | it('create default error with code', () => { 15 | const err = RuntimeError.create({ 16 | code: -1, 17 | message: 'hello world', 18 | name: 'custom', 19 | }); 20 | assert(err.name === 'customError'); 21 | assert(err.code === -1); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /packages/runtime-engine/test/util.test.ts: -------------------------------------------------------------------------------- 1 | import { completeAssign } from '../src/util'; 2 | import * as assert from 'assert'; 3 | 4 | describe('/test/util.test.ts', () => { 5 | it('test assign', () => { 6 | let a = 2; 7 | 8 | const data = completeAssign( 9 | {}, 10 | { 11 | afterTest() { 12 | a = 1; 13 | }, 14 | a: 1, 15 | beforeGo: 1, 16 | }, 17 | { 18 | afterTest() { 19 | a = 3; 20 | }, 21 | beforeHello() {}, 22 | } 23 | ); 24 | 25 | const afterTestHandlers = data['handlerStore'].get('afterTestHandler'); 26 | assert(afterTestHandlers.length === 2); 27 | for (const handler of afterTestHandlers) { 28 | handler(); 29 | } 30 | assert(a === 3); 31 | assert(data.a === 1); 32 | assert(data.beforeGo === 1); 33 | }); 34 | }); 35 | -------------------------------------------------------------------------------- /packages/runtime-engine/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compileOnSave": true, 4 | "compilerOptions": { 5 | "rootDir": "src", 6 | "outDir": "dist" 7 | }, 8 | "include": [ 9 | "./src/**/*.ts" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /packages/runtime-mock/src/event.ts: -------------------------------------------------------------------------------- 1 | import { FunctionEvent } from '@midwayjs/runtime-engine'; 2 | 3 | export class HTTPEvent implements FunctionEvent { 4 | type; 5 | meta; 6 | 7 | constructor() { 8 | this.type = 'HTTP'; 9 | this.meta = {}; 10 | } 11 | 12 | match() { 13 | return true; 14 | } 15 | 16 | transformInvokeArgs(context): any[] { 17 | if (Array.isArray(context)) { 18 | context = context.shift(); 19 | } 20 | return [context, {}]; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /packages/runtime-mock/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './runtime'; 2 | export * from './trigger'; 3 | export * from './event'; 4 | -------------------------------------------------------------------------------- /packages/runtime-mock/src/trigger.ts: -------------------------------------------------------------------------------- 1 | export interface Trigger { 2 | useCallback: boolean; 3 | toArgs(): any; 4 | delegate(invokeWrapper: (invokeArgs: any[]) => any): any; 5 | close(); 6 | createCallback(cb); 7 | } 8 | 9 | export class BaseTrigger implements Trigger { 10 | triggerOptions: any; 11 | useCallback = false; 12 | 13 | constructor(triggerOptions?: any) { 14 | this.triggerOptions = triggerOptions || {}; 15 | } 16 | 17 | async toArgs(): Promise { 18 | return Promise.resolve([]); 19 | } 20 | 21 | async close() {} 22 | 23 | createCallback(handler) { 24 | return (err, result) => { 25 | handler(err, result); 26 | }; 27 | } 28 | 29 | async delegate(invokeWrapper: (invokeArgs: any[]) => any): Promise {} 30 | } 31 | -------------------------------------------------------------------------------- /packages/runtime-mock/test/code/index.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | exports.handler = (ctx, event) => { 4 | return 'hello ' + event.query.name; 5 | }; 6 | -------------------------------------------------------------------------------- /packages/runtime-mock/test/code/spec.yml: -------------------------------------------------------------------------------- 1 | group: market-fn 2 | name: empty-hsf-1 3 | 4 | runtime: nodejs10 5 | handler: index.handler 6 | 7 | timeout: 50000 8 | 9 | memory: 2048MB 10 | cpu: 0.5 11 | 12 | trigger-hsf: true # enable HSF trigger 13 | 14 | #trigger-http: # enable HTTP trigger 15 | #vip-server: true # whether register a VipServer domain for the function 16 | 17 | #trigger-queue: # enable metaq trigger 18 | #metaq: 19 | #consumer-group: ginkgoMidway # consumer group name 20 | #topic: greeting # topic name 21 | #tags: a||b # message tag names. optional, default value is '*' 22 | -------------------------------------------------------------------------------- /packages/runtime-mock/test/index.test.ts: -------------------------------------------------------------------------------- 1 | import { createRuntime, HTTPEvent } from '../src'; 2 | import { join } from 'path'; 3 | 4 | const assert = require('assert'); 5 | 6 | describe('/test/index.test.ts', () => { 7 | it('should create runtime', async () => { 8 | const runtime = createRuntime({ 9 | functionDir: join(__dirname, './code'), 10 | events: [new HTTPEvent()], 11 | }); 12 | await runtime.start(); 13 | const result = await runtime.invoke({ 14 | path: '/', 15 | query: { 16 | name: 'Alan', 17 | }, 18 | }); 19 | assert.equal(result, 'hello Alan'); 20 | await runtime.close(); 21 | }); 22 | }); 23 | -------------------------------------------------------------------------------- /packages/runtime-mock/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compileOnSave": true, 4 | "compilerOptions": { 5 | "rootDir": "src", 6 | "outDir": "dist" 7 | }, 8 | "include": [ 9 | "./src/**/*.ts" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /packages/serverless-aws-starter/README.md: -------------------------------------------------------------------------------- 1 | # serverless fc starter 2 | 3 | 本模块用于包裹无法定制运行时的 FaaS 平台,比如阿里云 FC。 4 | 5 | ## 阿里云 FC 6 | 7 | ```ts 8 | import { asyncWrapper, createRuntime } from '@midwayjs/serverless-fc-starter'; 9 | 10 | let runtime; 11 | export.init = asyncWrapper(async () => { 12 | runtime = await createRuntime(); 13 | }); 14 | 15 | // for web request 16 | export.handler = asyncWrapper(async (...args) => { 17 | return runtime.asyncEvent(async function(ctx) { 18 | return 'hello world'; // ctx.body = 'hello world'; 19 | })(...args); 20 | }); 21 | 22 | // for event 23 | export.handler = asyncWrapper(async (...args) => { 24 | return runtime.asyncEvent(async function(ctx, event) { 25 | return {data: 1}; 26 | })(...args); 27 | }); 28 | 29 | ``` 30 | -------------------------------------------------------------------------------- /packages/serverless-aws-starter/src/index.ts: -------------------------------------------------------------------------------- 1 | import { BaseRuntimeEngine, LightRuntime } from '@midwayjs/runtime-engine'; 2 | import { AWSRuntime } from './runtime'; 3 | 4 | export { asyncWrapper } from '@midwayjs/runtime-engine'; 5 | 6 | export const createRuntime = async () => { 7 | const runtimeEngine = new BaseRuntimeEngine(); 8 | runtimeEngine.add(engine => { 9 | engine.addBaseRuntime(new AWSRuntime()); 10 | }); 11 | 12 | await runtimeEngine.ready(); 13 | return runtimeEngine.getCurrentRuntime() as LightRuntime; 14 | }; 15 | -------------------------------------------------------------------------------- /packages/serverless-aws-starter/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compileOnSave": true, 4 | "compilerOptions": { 5 | "rootDir": "src", 6 | "outDir": "dist" 7 | }, 8 | "include": [ 9 | "./src/**/*.ts" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /packages/serverless-fc-starter/README.md: -------------------------------------------------------------------------------- 1 | # serverless fc starter 2 | 3 | 本模块用于包裹无法定制运行时的 FaaS 平台,比如阿里云 FC。 4 | 5 | ## 阿里云 FC 6 | 7 | ```ts 8 | import { asyncWrapper, start } from '@midwayjs/serverless-fc-starter'; 9 | 10 | let runtime; 11 | exports.init = asyncWrapper(async () => { 12 | runtime = await start(); 13 | }); 14 | 15 | // for web request 16 | exports.handler = asyncWrapper(async (...args) => { 17 | return runtime.asyncEvent(async function(ctx) { 18 | return 'hello world'; // ctx.body = 'hello world'; 19 | })(...args); 20 | }); 21 | 22 | // for event 23 | exports.handler = asyncWrapper(async (...args) => { 24 | return runtime.asyncEvent(async function(ctx, event) { 25 | return {data: 1}; 26 | })(...args); 27 | }); 28 | 29 | ``` 30 | -------------------------------------------------------------------------------- /packages/serverless-fc-starter/resource/event_req.json: -------------------------------------------------------------------------------- 1 | { 2 | "domain": null, 3 | "_events": {}, 4 | "_eventsCount": 0, 5 | "method": "GET", 6 | "clientIP": "127.0.0.1", 7 | "url": "/daily/?a=1", 8 | "path": "/daily/", 9 | "queries": { 10 | "a": "1" 11 | }, 12 | "headers": { 13 | "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3", 14 | "accept-language": "en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7", 15 | "cache-control": "max-age=0", 16 | "cookie": "****", 17 | "upgrade-insecure-requests": "1", 18 | "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /packages/serverless-fc-starter/src/index.ts: -------------------------------------------------------------------------------- 1 | import { BaseBootstrap } from '@midwayjs/runtime-engine'; 2 | import { FCRuntime } from './runtime'; 3 | 4 | export { asyncWrapper } from '@midwayjs/runtime-engine'; 5 | export * from './runtime'; 6 | 7 | let bootstrap; 8 | 9 | export const start = async (options: any = {}) => { 10 | bootstrap = new BaseBootstrap( 11 | Object.assign( 12 | { 13 | runtime: new FCRuntime(), 14 | }, 15 | options 16 | ) 17 | ); 18 | await bootstrap.start(); 19 | return bootstrap.getRuntime(); 20 | }; 21 | 22 | export const close = async () => { 23 | return bootstrap.close(); 24 | }; 25 | -------------------------------------------------------------------------------- /packages/serverless-fc-starter/test/fixtures/event/index.ts: -------------------------------------------------------------------------------- 1 | import { asyncWrapper, start } from '../../../src'; 2 | 3 | let runtime; 4 | exports.init = asyncWrapper(async () => { 5 | runtime = await start(); 6 | }); 7 | 8 | exports.handler = asyncWrapper(async (...args) => { 9 | return runtime.asyncEvent(async function (ctx, event) { 10 | return 'hello world'; 11 | })(...args); 12 | }); 13 | -------------------------------------------------------------------------------- /packages/serverless-fc-starter/test/fixtures/http-json/index.ts: -------------------------------------------------------------------------------- 1 | import { asyncWrapper, start } from '../../../src'; 2 | 3 | let runtime; 4 | let inited; 5 | 6 | exports.handler = asyncWrapper(async (...args) => { 7 | if (!inited) { 8 | inited = true; 9 | runtime = await start(); 10 | } 11 | return runtime.asyncEvent(async function (ctx) { 12 | ctx.body = { 13 | name: 'Alan', 14 | }; 15 | })(...args); 16 | }); 17 | -------------------------------------------------------------------------------- /packages/serverless-fc-starter/test/fixtures/http/index.ts: -------------------------------------------------------------------------------- 1 | import { asyncWrapper, start } from '../../../src'; 2 | 3 | let runtime; 4 | let inited; 5 | 6 | exports.handler = asyncWrapper(async (...args) => { 7 | if (!inited) { 8 | inited = true; 9 | runtime = await start(); 10 | } 11 | return runtime.asyncEvent(async function (ctx) { 12 | ctx.body = 'Alan'; 13 | })(...args); 14 | }); 15 | -------------------------------------------------------------------------------- /packages/serverless-fc-starter/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compileOnSave": true, 4 | "compilerOptions": { 5 | "rootDir": "src", 6 | "outDir": "dist" 7 | }, 8 | "include": [ 9 | "./src/**/*.ts" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /packages/serverless-fc-trigger/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './interface'; 2 | export * from './http'; 3 | export * from './apiGateway'; 4 | export * from './oss'; 5 | export * from './sls'; 6 | export * from './cdn'; 7 | export * from './timer'; 8 | export * from './base'; 9 | -------------------------------------------------------------------------------- /packages/serverless-fc-trigger/src/mns.ts: -------------------------------------------------------------------------------- 1 | import { FCBaseTrigger } from './base'; 2 | 3 | /** 4 | * https://help.aliyun.com/document_detail/100092.html 5 | */ 6 | export class MNSTrigger extends FCBaseTrigger { 7 | handler; 8 | 9 | async toArgs(): Promise { 10 | const event = { 11 | Context: 'user custom info', 12 | TopicOwner: '1186202104331798', 13 | Message: 'hello topic', 14 | Subscriber: '1186202104331798', 15 | PublishTime: 1550216302888, 16 | SubscriptionName: 'test-fc-subscibe', 17 | MessageMD5: 'BA4BA9B48AC81F0F9C66F6C909C39DBB', 18 | TopicName: 'test-topic', 19 | MessageId: '2F5B3C281B283D4EAC694B7425288675', 20 | }; 21 | 22 | return [event, this.createContext()]; 23 | } 24 | } 25 | 26 | export const mq = MNSTrigger; 27 | -------------------------------------------------------------------------------- /packages/serverless-fc-trigger/src/timer.ts: -------------------------------------------------------------------------------- 1 | import { FCBaseTrigger } from './base'; 2 | 3 | /** 4 | * https://help.aliyun.com/document_detail/62922.html 5 | */ 6 | export class TimerTrigger extends FCBaseTrigger { 7 | handler; 8 | 9 | async toArgs(): Promise { 10 | const event = { 11 | triggerTime: '2019-12-01T16:00:00Z', 12 | triggerName: 'timer', 13 | payload: '', 14 | }; 15 | return [event, this.createContext()]; 16 | } 17 | } 18 | export const timer = TimerTrigger; 19 | -------------------------------------------------------------------------------- /packages/serverless-fc-trigger/test/fixtures/apiGateway/index.ts: -------------------------------------------------------------------------------- 1 | import { asyncWrapper, start } from '@midwayjs/serverless-fc-starter'; 2 | 3 | exports.init = asyncWrapper(async () => { 4 | await start(); 5 | }); 6 | 7 | exports.handler = (event, context, callback) => { 8 | callback(null, { 9 | isBase64Encoded: false, 10 | statusCode: 200, 11 | headers: {}, 12 | body: 'hello Alan' 13 | }); 14 | }; 15 | -------------------------------------------------------------------------------- /packages/serverless-fc-trigger/test/fixtures/cdn/index.ts: -------------------------------------------------------------------------------- 1 | import { asyncWrapper, start } from '@midwayjs/serverless-fc-starter'; 2 | 3 | exports.init = asyncWrapper(async () => { 4 | await start(); 5 | }); 6 | 7 | exports.handler = (event, context, callback) => { 8 | callback(null, event); 9 | }; 10 | -------------------------------------------------------------------------------- /packages/serverless-fc-trigger/test/fixtures/event/index.ts: -------------------------------------------------------------------------------- 1 | import { asyncWrapper, start } from '@midwayjs/serverless-fc-starter'; 2 | 3 | exports.init = asyncWrapper(async () => { 4 | await start(); 5 | }); 6 | 7 | exports.handler = (event, context, callback) => { 8 | callback(null, event); 9 | }; 10 | -------------------------------------------------------------------------------- /packages/serverless-fc-trigger/test/fixtures/http/index.ts: -------------------------------------------------------------------------------- 1 | import { asyncWrapper, start } from '@midwayjs/serverless-fc-starter'; 2 | 3 | exports.init = asyncWrapper(async () => { 4 | await start(); 5 | }); 6 | 7 | exports.handler = (req, res, context) => { 8 | res.send('hello Alan'); 9 | }; 10 | -------------------------------------------------------------------------------- /packages/serverless-fc-trigger/test/fixtures/oss/index.ts: -------------------------------------------------------------------------------- 1 | import { asyncWrapper, start } from '@midwayjs/serverless-fc-starter'; 2 | 3 | exports.init = asyncWrapper(async () => { 4 | await start(); 5 | }); 6 | 7 | exports.handler = (event, context, callback) => { 8 | callback(null, event); 9 | }; 10 | -------------------------------------------------------------------------------- /packages/serverless-fc-trigger/test/fixtures/sls/index.ts: -------------------------------------------------------------------------------- 1 | import { asyncWrapper, start } from '@midwayjs/serverless-fc-starter'; 2 | 3 | exports.init = asyncWrapper(async () => { 4 | await start(); 5 | }); 6 | 7 | exports.handler = (event, context, callback) => { 8 | callback(null, event); 9 | }; 10 | -------------------------------------------------------------------------------- /packages/serverless-fc-trigger/test/fixtures/timer/index.ts: -------------------------------------------------------------------------------- 1 | import { asyncWrapper, start } from '@midwayjs/serverless-fc-starter'; 2 | 3 | exports.init = asyncWrapper(async () => { 4 | await start(); 5 | }); 6 | 7 | exports.handler = (event, context, callback) => { 8 | callback(null, event); 9 | }; 10 | -------------------------------------------------------------------------------- /packages/serverless-fc-trigger/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compileOnSave": true, 4 | "compilerOptions": { 5 | "rootDir": "src", 6 | "outDir": "dist" 7 | }, 8 | "include": [ 9 | "./src/**/*.ts" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /packages/serverless-http-parser/README.md: -------------------------------------------------------------------------------- 1 | # serverless http parser 2 | 3 | parse http/apigw trigger event to koa ctx. 4 | -------------------------------------------------------------------------------- /packages/serverless-http-parser/src/http/res.ts: -------------------------------------------------------------------------------- 1 | export class HTTPResponse { 2 | public statusCode = 200; 3 | public statusMessage; 4 | public headersSent = false; 5 | private _headers = {}; 6 | 7 | get headers() { 8 | return this._headers; 9 | } 10 | 11 | set headers(value) { 12 | this._headers = value; 13 | } 14 | 15 | getHeader(field) { 16 | return this.headers[field.toLowerCase()] || ''; 17 | } 18 | 19 | removeHeader(field) { 20 | delete this.headers[field.toLowerCase()]; 21 | } 22 | 23 | hasHeader(field) { 24 | return field.toLowerCase() in this.headers; 25 | } 26 | 27 | setHeader(name, value) { 28 | name = name.toLowerCase(); 29 | this.headers[name] = value; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /packages/serverless-http-parser/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './context'; 2 | export * from './request'; 3 | export * from './response'; 4 | export * from './interface'; 5 | export * from './application'; 6 | export * from './http/req'; 7 | export * from './http/res'; 8 | -------------------------------------------------------------------------------- /packages/serverless-http-parser/test/resource/fc_apigw.json: -------------------------------------------------------------------------------- 1 | { 2 | "path":"/api", 3 | "httpMethod":"GET", 4 | "headers":{ 5 | "Accept-Language": "en-US,en,cn", 6 | "Accept": "text/html,application/xml,application/json", 7 | "Host": "service-3ei3tii4-251000691.ap-guangzhou.apigateway.myqloud.com", 8 | "User-Agent": "User Agent String" 9 | }, 10 | "queryParameters":{ 11 | "name": "test" 12 | }, 13 | "pathParameters":{ 14 | "id": "12345" 15 | }, 16 | "body": "{\"test\":\"body\"}", 17 | "isBase64Encoded": "false" 18 | } 19 | -------------------------------------------------------------------------------- /packages/serverless-http-parser/test/resource/fc_apigw_post_form.json: -------------------------------------------------------------------------------- 1 | { 2 | "body": "{\"c\":\"b\"}", 3 | "headers": { 4 | "accept": "*/*", 5 | "cache-control": "no-cache", 6 | "user-agent": "PostmanRuntime/7.24.1", 7 | "postman-token": "feb51b11-9103-463a-92ff-73076d37b683", 8 | "accept-encoding": "gzip, deflate, br", 9 | "content-type": "application/x-www-form-urlencoded" 10 | }, 11 | "httpMethod": "POST", 12 | "isBase64Encoded": false, 13 | "path": "/api/321", 14 | "pathParameters": { 15 | "userId": "321" 16 | }, 17 | "queryParameters": {} 18 | } 19 | -------------------------------------------------------------------------------- /packages/serverless-http-parser/test/resource/fc_apigw_post_gw_filter.json: -------------------------------------------------------------------------------- 1 | { 2 | "body": "eyJjIjoiYiJ9", 3 | "headers": { 4 | "X-Ca-Dashboard-Action": "DEBUG", 5 | "X-Ca-Dashboard-Uid": "111111", 6 | "X-Ca-Dashboard-Role": "USER" 7 | }, 8 | "httpMethod": "POST", 9 | "isBase64Encoded": true, 10 | "path": "/api/321", 11 | "pathParameters": { 12 | "userId": "321" 13 | }, 14 | "queryParameters": {} 15 | } 16 | -------------------------------------------------------------------------------- /packages/serverless-http-parser/test/resource/fc_apigw_post_json.json: -------------------------------------------------------------------------------- 1 | { 2 | "body": "eyJjIjoiYiJ9", 3 | "headers": { 4 | "X-Ca-Dashboard-Action": "DEBUG", 5 | "X-Ca-Dashboard-Uid": "125087", 6 | "X-Ca-Stage": "RELEASE", 7 | "X-Ca-Dashboard-Role": "USER", 8 | "User-Agent": "Apache-HttpClient/4.5.6 (Java/1.8.0_172)", 9 | "Accept-Encoding": "gzip,deflate", 10 | "Content-MD5": "Kry+hjKjc2lvIrwoJqdY9Q==", 11 | "Content-Type": "application/json; charset=utf-8" 12 | }, 13 | "httpMethod": "POST", 14 | "isBase64Encoded": true, 15 | "path": "/api/321", 16 | "pathParameters": { 17 | "userId": "321" 18 | }, 19 | "queryParameters": {} 20 | } 21 | -------------------------------------------------------------------------------- /packages/serverless-http-parser/test/resource/fc_apigw_post_text.json: -------------------------------------------------------------------------------- 1 | { 2 | "body": "eyJjIjoiYiJ9", 3 | "headers": { 4 | "x-ca-dashboard-action": "DEBUG", 5 | "x-ca-dashboard-uid": "125087", 6 | "x-ca-stage": "RELEASE", 7 | "x-ca-dashboard-role": "USER", 8 | "user-agent": "Apache-HttpClient/4.5.6 (Java/1.8.0_172)", 9 | "accept-encoding": "gzip,deflate", 10 | "content-md5": "Kry+hjKjc2lvIrwoJqdY9Q==", 11 | "content-type": "text/html; charset=utf-8" 12 | }, 13 | "httpMethod": "POST", 14 | "isBase64Encoded": true, 15 | "path": "/api/321", 16 | "pathParameters": { 17 | "userId": "321" 18 | }, 19 | "queryParameters": {} 20 | } 21 | -------------------------------------------------------------------------------- /packages/serverless-http-parser/test/resource/fc_ctx.json: -------------------------------------------------------------------------------- 1 | { 2 | "requestId": "b1c5100f-819d-c421-3a5e-7782a27d8a33", 3 | "credentials": { 4 | "accessKeyId": "STS.access_key_id", 5 | "accessKeySecret": "access_key_secret", 6 | "securityToken": "security_token" 7 | }, 8 | "function": { 9 | "name": "my-func", 10 | "handler": "index.handler", 11 | "memory": 128, 12 | "timeout": 10, 13 | "initializer": "index.initializer", 14 | "initializationTimeout": 10 15 | }, 16 | "service": { 17 | "name": "my-service", 18 | "logProject": "my-log-project", 19 | "logStore": "my-log-store", 20 | "qualifier": "qualifier", 21 | "versionId": "1" 22 | }, 23 | "region": "cn-shanghai", 24 | "accountId": "123456" 25 | } 26 | -------------------------------------------------------------------------------- /packages/serverless-http-parser/test/resource/fc_http.json: -------------------------------------------------------------------------------- 1 | { 2 | "domain": null, 3 | "_events": {}, 4 | "_eventsCount": 0, 5 | "method": "GET", 6 | "clientIP": "127.0.0.1", 7 | "url": "/daily/?a=1", 8 | "path": "/daily/", 9 | "queries": { 10 | "a": "1" 11 | }, 12 | "headers": { 13 | "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3", 14 | "accept-language": "en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7", 15 | "cache-control": "max-age=0", 16 | "cookie": "****", 17 | "upgrade-insecure-requests": "1", 18 | "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /packages/serverless-http-parser/test/resource/scf_ctx.json: -------------------------------------------------------------------------------- 1 | { 2 | "time_limit_in_ms": 3000, 3 | "request_id": "627466b4-8049-11e8-8758-5254005d5fdb", 4 | "memory_limit_in_mb": 512 5 | } 6 | -------------------------------------------------------------------------------- /packages/serverless-http-parser/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compileOnSave": true, 4 | "compilerOptions": { 5 | "rootDir": "src", 6 | "outDir": "dist" 7 | }, 8 | "include": [ 9 | "./src/**/*.ts" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /packages/serverless-invoke/README.md: -------------------------------------------------------------------------------- 1 | # serverless invoke 2 | 3 | 本模块用于在本地执行函数、本地debug调试函数 4 | 5 | ## Usage 6 | ``` 7 | import { invoke } from '@midwayjs/serverless-invoke'; 8 | 9 | (async () => { 10 | const result = await invoke({ 11 | functionName: string // 函数名,如 index 12 | data?: any[] // 函数入参,需要传入数组 13 | functionDir?: string // 函数(serverless.yml)所在目录,默认为 process.env.PWD 14 | debug?: string // debug端口号,不指定则不开启debug单步调试功能 15 | trigger?: string // 函数触发器,默认会从函数的serverless.yml配置中events数组中选择第一个,例如 http 16 | }); 17 | })(); 18 | ``` 19 | -------------------------------------------------------------------------------- /packages/serverless-invoke/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from '@midwayjs/fcli-plugin-invoke'; 2 | -------------------------------------------------------------------------------- /packages/serverless-invoke/test/fixtures/baseApp/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "@midwayjs/faas": "*" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /packages/serverless-invoke/test/fixtures/baseApp/serverless.yml: -------------------------------------------------------------------------------- 1 | service: serverless-midway-test 2 | 3 | provider: 4 | name: aliyun 5 | runtime: nodejs8 6 | credentials: ./.aliyun_credentials # path must be absolute 7 | 8 | functions: 9 | http: 10 | handler: http.handler 11 | events: 12 | - http: 13 | method: get 14 | 15 | layers: 16 | 17 | 18 | package: 19 | include: 20 | exclude: 21 | - src/** 22 | - tsconfig.json 23 | - test/** 24 | excludeDevDependencies: false 25 | artifact: path/to/my-artifact.zip # Own package that should be used. You must provide this file. 26 | -------------------------------------------------------------------------------- /packages/serverless-invoke/test/fixtures/baseApp/src/index.ts: -------------------------------------------------------------------------------- 1 | import { FaaSContext, func, inject, provide } from '@midwayjs/faas'; 2 | 3 | @provide() 4 | @func('http.handler') 5 | export class HelloHttpService { 6 | 7 | @inject() 8 | ctx: FaaSContext; // context 9 | 10 | async handler() { 11 | return 'hello http world'; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /packages/serverless-invoke/test/fixtures/baseApp/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": true, 3 | "compilerOptions": { 4 | "target": "ES2018", 5 | "module": "commonjs", 6 | "moduleResolution": "node", 7 | "experimentalDecorators": true, 8 | "emitDecoratorMetadata": true, 9 | "inlineSourceMap": true, 10 | "noImplicitThis": true, 11 | "noUnusedLocals": true, 12 | "stripInternal": true, 13 | "pretty": true, 14 | "declaration": true, 15 | "outDir": "dist", 16 | "sourceRoot": "" 17 | }, 18 | "exclude": [ 19 | "dist", 20 | "node_modules", 21 | "test" 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /packages/serverless-invoke/test/fixtures/ice-faas-ts-pkg-options/build.json: -------------------------------------------------------------------------------- 1 | { 2 | "entry": "src/index.tsx", 3 | "plugins": [ 4 | "build-plugin-ice-app", 5 | ["build-plugin-fusion", { 6 | "themePackage": "@icedesign/theme" 7 | }], 8 | "./build.plugin.js" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/serverless-invoke/test/fixtures/ice-faas-ts-pkg-options/f.yml: -------------------------------------------------------------------------------- 1 | service: fc-test 2 | 3 | provider: 4 | name: fc 5 | runtime: nodejs10 6 | 7 | functions: 8 | test1: 9 | handler: index.handler 10 | events: 11 | - http: true 12 | -------------------------------------------------------------------------------- /packages/serverless-invoke/test/fixtures/ice-faas-ts-pkg-options/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@icedesign/ts-scaffold9ade4c90-5de3-11e9-aef1-79dc0073b61f", 3 | "version": "1.0.3", 4 | "description": "该模板基于 TypeScript 适用于从 0 到 1 开始搭建项目,内置基础的页面,路由和菜单展示", 5 | "dependencies": { 6 | "@midwayjs/faas": "*", 7 | "react-router-dom": "*", 8 | "tslib": "*" 9 | }, 10 | "scripts": { 11 | "start": "build-scripts start", 12 | "build": "build-scripts build", 13 | "lint": "eslint . --ext '.js,.jsx' --fix" 14 | }, 15 | "engines": { 16 | "node": ">=8.0.0" 17 | }, 18 | "midway-integration": { 19 | "tsCodeRoot": "src/apis" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /packages/serverless-invoke/test/fixtures/ice-faas-ts-pkg-options/src/apis/index.ts: -------------------------------------------------------------------------------- 1 | import { 2 | provide, 3 | func, 4 | FunctionHandler, 5 | inject, 6 | FaaSContext, 7 | } from '@midwayjs/faas'; 8 | 9 | @provide() 10 | @func('index.handler') 11 | export class IndexHandler implements FunctionHandler { 12 | @inject() 13 | ctx: FaaSContext; 14 | /** 15 | * 发布为 hsf 时 16 | * 这个参数是 ginkgo 固定的,入参出参都为字符串 17 | * @param event 18 | */ 19 | async handler(event: string) { 20 | return 'hello http world'; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /packages/serverless-invoke/test/fixtures/ice-faas-ts-pkg-options/src/components/Greeting/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | export interface Props { 4 | name: string; 5 | } 6 | 7 | const Greeting = ({ name }: Props) => { 8 | return ( 9 |
10 | Hello, {name} 11 |
12 | ); 13 | }; 14 | 15 | export default Greeting; 16 | -------------------------------------------------------------------------------- /packages/serverless-invoke/test/fixtures/ice-faas-ts-pkg-options/src/index.tsx: -------------------------------------------------------------------------------- 1 | import ReactDOM from 'react-dom'; 2 | 3 | // 载入默认全局样式 normalize 4 | import '@alifd/next/reset.scss'; 5 | 6 | import router from './router'; 7 | 8 | const ICE_CONTAINER = document.getElementById('ice-container'); 9 | 10 | if (!ICE_CONTAINER) { 11 | throw new Error('当前页面不存在
节点.'); 12 | } 13 | 14 | ReactDOM.render(router(), ICE_CONTAINER); 15 | -------------------------------------------------------------------------------- /packages/serverless-invoke/test/fixtures/ice-faas-ts-pkg-options/src/layouts/BasicLayout/index.tsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import MainRoutes from './MainRoutes'; 3 | 4 | export default class BasicLayout extends Component { 5 | render() { 6 | return ( 7 |
8 | 9 |
10 | ); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /packages/serverless-invoke/test/fixtures/ice-faas-ts-pkg-options/src/menuConfig.ts: -------------------------------------------------------------------------------- 1 | // 菜单配置 2 | 3 | const asideMenuConfig = []; 4 | 5 | export { asideMenuConfig }; 6 | -------------------------------------------------------------------------------- /packages/serverless-invoke/test/fixtures/ice-faas-ts-pkg-options/src/pages/Dashboard/index.tsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import Guide from '../../components/Guide'; 3 | import Greeting from '../../components/Greeting'; 4 | 5 | export default class Dashboard extends Component { 6 | render() { 7 | return ( 8 |
9 | 10 | 11 |
12 | ); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /packages/serverless-invoke/test/fixtures/ice-faas-ts-pkg-options/src/router.tsx: -------------------------------------------------------------------------------- 1 | /** 2 | * 定义应用路由 3 | */ 4 | import { HashRouter, Switch, Route } from 'react-router-dom'; 5 | import React from 'react'; 6 | import BasicLayout from './layouts/BasicLayout'; 7 | 8 | const router = () => { 9 | return ( 10 | 11 | 12 | 13 | 14 | 15 | ); 16 | }; 17 | 18 | export default router; 19 | -------------------------------------------------------------------------------- /packages/serverless-invoke/test/fixtures/ice-faas-ts-pkg-options/src/routerConfig.ts: -------------------------------------------------------------------------------- 1 | // 以下文件格式为描述路由的协议格式 2 | // 你可以调整 routerConfig 里的内容 3 | // 变量名 routerConfig 为 iceworks 检测关键字,请不要修改名称 4 | import Dashboard from './pages/Dashboard'; 5 | 6 | const routerConfig = [ 7 | { 8 | path: '/dashboard', 9 | component: Dashboard, 10 | }, 11 | ]; 12 | 13 | export default routerConfig; 14 | -------------------------------------------------------------------------------- /packages/serverless-invoke/test/fixtures/ice-faas-ts-pkg-options/test/index.js: -------------------------------------------------------------------------------- 1 | // test file 2 | -------------------------------------------------------------------------------- /packages/serverless-invoke/test/fixtures/ice-faas-ts-standard/build.json: -------------------------------------------------------------------------------- 1 | { 2 | "entry": "src/index.tsx", 3 | "plugins": [ 4 | "build-plugin-ice-app", 5 | ["build-plugin-fusion", { 6 | "themePackage": "@icedesign/theme" 7 | }], 8 | "./build.plugin.js" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/serverless-invoke/test/fixtures/ice-faas-ts-standard/f.yml: -------------------------------------------------------------------------------- 1 | service: fc-test 2 | 3 | provider: 4 | name: fc 5 | runtime: nodejs10 6 | 7 | functions: 8 | test1: 9 | handler: index.handler 10 | events: 11 | - http: true 12 | -------------------------------------------------------------------------------- /packages/serverless-invoke/test/fixtures/ice-faas-ts-standard/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@icedesign/ts-scaffold9ade4c90-5de3-11e9-aef1-79dc0073b61f", 3 | "version": "1.0.3", 4 | "description": "该模板基于 TypeScript 适用于从 0 到 1 开始搭建项目,内置基础的页面,路由和菜单展示", 5 | "dependencies": { 6 | "@midwayjs/faas": "*", 7 | "react-router-dom": "*", 8 | "tslib": "*" 9 | }, 10 | "scripts": { 11 | "start": "build-scripts start", 12 | "build": "build-scripts build", 13 | "lint": "eslint . --ext '.js,.jsx' --fix" 14 | }, 15 | "engines": { 16 | "node": ">=8.0.0" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /packages/serverless-invoke/test/fixtures/ice-faas-ts-standard/src/apis/index.ts: -------------------------------------------------------------------------------- 1 | import { 2 | provide, 3 | func, 4 | FunctionHandler, 5 | inject, 6 | FaaSContext, 7 | } from '@midwayjs/faas'; 8 | 9 | @provide() 10 | @func('index.handler') 11 | export class IndexHandler implements FunctionHandler { 12 | @inject() 13 | ctx: FaaSContext; 14 | /** 15 | * 发布为 hsf 时 16 | * 这个参数是 ginkgo 固定的,入参出参都为字符串 17 | * @param event 18 | */ 19 | async handler(event: string) { 20 | return 'hello http world'; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /packages/serverless-invoke/test/fixtures/ice-faas-ts-standard/src/components/Greeting/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | export interface Props { 4 | name: string; 5 | } 6 | 7 | const Greeting = ({ name }: Props) => { 8 | return ( 9 |
10 | Hello, {name} 11 |
12 | ); 13 | }; 14 | 15 | export default Greeting; 16 | -------------------------------------------------------------------------------- /packages/serverless-invoke/test/fixtures/ice-faas-ts-standard/src/index.tsx: -------------------------------------------------------------------------------- 1 | import ReactDOM from 'react-dom'; 2 | 3 | // 载入默认全局样式 normalize 4 | import '@alifd/next/reset.scss'; 5 | 6 | import router from './router'; 7 | 8 | const ICE_CONTAINER = document.getElementById('ice-container'); 9 | 10 | if (!ICE_CONTAINER) { 11 | throw new Error('当前页面不存在
节点.'); 12 | } 13 | 14 | ReactDOM.render(router(), ICE_CONTAINER); 15 | -------------------------------------------------------------------------------- /packages/serverless-invoke/test/fixtures/ice-faas-ts-standard/src/layouts/BasicLayout/index.tsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import MainRoutes from './MainRoutes'; 3 | 4 | export default class BasicLayout extends Component { 5 | render() { 6 | return ( 7 |
8 | 9 |
10 | ); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /packages/serverless-invoke/test/fixtures/ice-faas-ts-standard/src/menuConfig.ts: -------------------------------------------------------------------------------- 1 | // 菜单配置 2 | 3 | const asideMenuConfig = []; 4 | 5 | export { asideMenuConfig }; 6 | -------------------------------------------------------------------------------- /packages/serverless-invoke/test/fixtures/ice-faas-ts-standard/src/pages/Dashboard/index.tsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import Guide from '../../components/Guide'; 3 | import Greeting from '../../components/Greeting'; 4 | 5 | export default class Dashboard extends Component { 6 | render() { 7 | return ( 8 |
9 | 10 | 11 |
12 | ); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /packages/serverless-invoke/test/fixtures/ice-faas-ts-standard/src/router.tsx: -------------------------------------------------------------------------------- 1 | /** 2 | * 定义应用路由 3 | */ 4 | import { HashRouter, Switch, Route } from 'react-router-dom'; 5 | import React from 'react'; 6 | import BasicLayout from './layouts/BasicLayout'; 7 | 8 | const router = () => { 9 | return ( 10 | 11 | 12 | 13 | 14 | 15 | ); 16 | }; 17 | 18 | export default router; 19 | -------------------------------------------------------------------------------- /packages/serverless-invoke/test/fixtures/ice-faas-ts-standard/src/routerConfig.ts: -------------------------------------------------------------------------------- 1 | // 以下文件格式为描述路由的协议格式 2 | // 你可以调整 routerConfig 里的内容 3 | // 变量名 routerConfig 为 iceworks 检测关键字,请不要修改名称 4 | import Dashboard from './pages/Dashboard'; 5 | 6 | const routerConfig = [ 7 | { 8 | path: '/dashboard', 9 | component: Dashboard, 10 | }, 11 | ]; 12 | 13 | export default routerConfig; 14 | -------------------------------------------------------------------------------- /packages/serverless-invoke/test/fixtures/ice-faas-ts-standard/test/index.js: -------------------------------------------------------------------------------- 1 | // test file 2 | -------------------------------------------------------------------------------- /packages/serverless-invoke/test/fixtures/multiApp/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "@midwayjs/faas": "*" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /packages/serverless-invoke/test/fixtures/multiApp/serverless.yml: -------------------------------------------------------------------------------- 1 | service: serverless-midway-test 2 | 3 | provider: 4 | name: fc 5 | runtime: nodejs8 6 | credentials: ./.aliyun_credentials # path must be absolute 7 | 8 | functions: 9 | http: 10 | handler: http.handler 11 | events: 12 | - http: 13 | method: get 14 | 15 | 16 | layers: 17 | 18 | 19 | package: 20 | include: 21 | exclude: 22 | - src/** 23 | - tsconfig.json 24 | - test/** 25 | excludeDevDependencies: false 26 | artifact: path/to/my-artifact.zip # Own package that should be used. You must provide this file. 27 | -------------------------------------------------------------------------------- /packages/serverless-invoke/test/fixtures/multiApp/src/index.ts: -------------------------------------------------------------------------------- 1 | import { FaaSContext, func, inject, provide } from '@midwayjs/faas'; 2 | 3 | @provide() 4 | @func('http.handler') 5 | export class HelloHttpService { 6 | 7 | @inject() 8 | ctx: FaaSContext; // context 9 | 10 | async handler() { 11 | return 'hello http world'; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /packages/serverless-invoke/test/fixtures/multiApp/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": true, 3 | "compilerOptions": { 4 | "target": "ES2018", 5 | "module": "commonjs", 6 | "moduleResolution": "node", 7 | "experimentalDecorators": true, 8 | "emitDecoratorMetadata": true, 9 | "inlineSourceMap": true, 10 | "noImplicitThis": true, 11 | "noUnusedLocals": true, 12 | "stripInternal": true, 13 | "pretty": true, 14 | "declaration": true, 15 | "outDir": "dist", 16 | "sourceRoot": "" 17 | }, 18 | "exclude": [ 19 | "dist", 20 | "node_modules", 21 | "test" 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /packages/serverless-invoke/test/invoke.js: -------------------------------------------------------------------------------- 1 | const { invoke } = require('../'); 2 | const { join } = require('path'); 3 | invoke({ 4 | functionDir: join(__dirname, 'fixtures/baseApp'), 5 | functionName: 'http', 6 | data: [{ name: 'params' }], 7 | debug: '9229', 8 | }).then(result => { 9 | console.log('result', result); 10 | }); 11 | -------------------------------------------------------------------------------- /packages/serverless-invoke/test/main.test.ts: -------------------------------------------------------------------------------- 1 | import { invoke } from '../src'; 2 | import { join } from 'path'; 3 | import * as assert from 'assert'; 4 | describe('/test/main.test.ts', () => { 5 | it('invoke', async () => { 6 | const result: any = await invoke({ 7 | functionDir: join(__dirname, 'fixtures/baseApp'), 8 | functionName: 'http', 9 | clean: false, 10 | }); 11 | assert(result.body === 'hello http world'); 12 | }); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/serverless-invoke/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compileOnSave": true, 4 | "compilerOptions": { 5 | "rootDir": "src", 6 | "outDir": "dist" 7 | }, 8 | "include": [ 9 | "./src/**/*.ts" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /packages/serverless-meta-json/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@midwayjs/serverless-meta-json", 3 | "version": "0.3.1", 4 | "main": "dist/index", 5 | "typings": "dist/index.d.ts", 6 | "devDependencies": { 7 | "@midwayjs/faas": "^0.3.1", 8 | "midway-bin": "^2.0.0" 9 | }, 10 | "files": [ 11 | "dist", 12 | "src" 13 | ], 14 | "scripts": { 15 | "build": "midway-bin build -c", 16 | "test": "midway-bin test --ts --full-trace", 17 | "debug": "midway-bin test --ts --full-trace --inspect-brk=9229", 18 | "cov": "midway-bin cov --ts", 19 | "clean": "midway-bin clean", 20 | "autod": "midway-bin autod" 21 | }, 22 | "repository": { 23 | "type": "git", 24 | "url": "git@github.com:midwayjs/midway-faas.git" 25 | }, 26 | "license": "MIT", 27 | "gitHead": "b67e2753cbdcc91813067ba2a1bb1ce7e85a3dff" 28 | } 29 | -------------------------------------------------------------------------------- /packages/serverless-meta-json/test/archives-gateway/a.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/midwayjs/midway-faas/d3f3b8e01514c468070abb14340776724a382a29/packages/serverless-meta-json/test/archives-gateway/a.zip -------------------------------------------------------------------------------- /packages/serverless-meta-json/test/archives-gateway/b.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/midwayjs/midway-faas/d3f3b8e01514c468070abb14340776724a382a29/packages/serverless-meta-json/test/archives-gateway/b.zip -------------------------------------------------------------------------------- /packages/serverless-meta-json/test/archives-gateway/f.yml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/midwayjs/midway-faas/d3f3b8e01514c468070abb14340776724a382a29/packages/serverless-meta-json/test/archives-gateway/f.yml -------------------------------------------------------------------------------- /packages/serverless-meta-json/test/archives-gateway/test_mapping.json: -------------------------------------------------------------------------------- 1 | { 2 | "testName": "123456" 3 | } -------------------------------------------------------------------------------- /packages/serverless-meta-json/test/archives/a.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/midwayjs/midway-faas/d3f3b8e01514c468070abb14340776724a382a29/packages/serverless-meta-json/test/archives/a.zip -------------------------------------------------------------------------------- /packages/serverless-meta-json/test/archives/b.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/midwayjs/midway-faas/d3f3b8e01514c468070abb14340776724a382a29/packages/serverless-meta-json/test/archives/b.zip -------------------------------------------------------------------------------- /packages/serverless-meta-json/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compileOnSave": true, 4 | "compilerOptions": { 5 | "rootDir": "src", 6 | "outDir": "dist" 7 | }, 8 | "include": [ 9 | "./src/**/*.ts" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /packages/serverless-scf-starter/README.md: -------------------------------------------------------------------------------- 1 | # Serverless SCF starter 2 | 3 | 本模块用于包裹无法定制运行时的 FaaS 平台,比如腾讯云 SCF。 4 | 5 | ## 腾讯云 SCF 6 | 7 | ```ts 8 | import { asyncWrapper, start } from '@midwayjs/serverless-scf-starter'; 9 | 10 | let runtime; 11 | export.init = asyncWrapper(async () => { 12 | runtime = await start(); 13 | }); 14 | 15 | // for web request 16 | export.handler = asyncWrapper(async (...args) => { 17 | return runtime.asyncEvent(async function(ctx) { 18 | return 'hello world'; // ctx.body = 'hello world'; 19 | })(...args); 20 | }); 21 | 22 | // for event 23 | export.handler = asyncWrapper(async (...args) => { 24 | return runtime.asyncEvent(async function(ctx, event) { 25 | return {data: 1}; 26 | })(...args); 27 | }); 28 | 29 | ``` 30 | -------------------------------------------------------------------------------- /packages/serverless-scf-starter/src/index.ts: -------------------------------------------------------------------------------- 1 | import { BaseBootstrap } from '@midwayjs/runtime-engine'; 2 | import { SCFRuntime } from './runtime'; 3 | 4 | export * from './runtime'; 5 | export { asyncWrapper } from '@midwayjs/runtime-engine'; 6 | 7 | let bootstrap; 8 | 9 | export const start = async (options: any = {}) => { 10 | bootstrap = new BaseBootstrap( 11 | Object.assign( 12 | { 13 | runtime: new SCFRuntime(), 14 | }, 15 | options 16 | ) 17 | ); 18 | await bootstrap.start(); 19 | return bootstrap.getRuntime(); 20 | }; 21 | 22 | export const close = async () => { 23 | return bootstrap.close(); 24 | }; 25 | -------------------------------------------------------------------------------- /packages/serverless-scf-starter/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compileOnSave": true, 4 | "compilerOptions": { 5 | "rootDir": "src", 6 | "outDir": "dist" 7 | }, 8 | "include": [ 9 | "./src/**/*.ts" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /packages/serverless-scf-trigger/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './apiGateway'; 2 | export * from './cos'; 3 | export * from './timer'; 4 | export * from './ckafka'; 5 | export * from './cmq'; 6 | -------------------------------------------------------------------------------- /packages/serverless-scf-trigger/src/timer.ts: -------------------------------------------------------------------------------- 1 | import { SCFBaseTrigger } from './base'; 2 | import { SCF } from '@midwayjs/faas-typings'; 3 | 4 | /** 5 | * https://cloud.tencent.com/document/product/583/9708 6 | */ 7 | export class TimerTrigger extends SCFBaseTrigger { 8 | handler; 9 | 10 | async toArgs() { 11 | const event: SCF.TimerEvent = { 12 | Message: '', 13 | Time: '2019-11-19T03:33:00Z', 14 | TriggerName: 'test', 15 | Type: 'Timer', 16 | }; 17 | return [event, this.createContext()]; 18 | } 19 | } 20 | 21 | export const timer = TimerTrigger; 22 | -------------------------------------------------------------------------------- /packages/serverless-scf-trigger/test/fixtures/apiGateway/index.ts: -------------------------------------------------------------------------------- 1 | exports.handler = (event, context, callback) => { 2 | callback(null, { 3 | isBase64Encoded: false, 4 | statusCode: 200, 5 | headers: {}, 6 | body: 'hello Alan' 7 | }); 8 | }; 9 | -------------------------------------------------------------------------------- /packages/serverless-scf-trigger/test/fixtures/ckafka/index.ts: -------------------------------------------------------------------------------- 1 | exports.handler = (event, context, callback) => { 2 | callback(null, event); 3 | }; 4 | -------------------------------------------------------------------------------- /packages/serverless-scf-trigger/test/fixtures/cmq/index.ts: -------------------------------------------------------------------------------- 1 | exports.handler = (event, context, callback) => { 2 | callback(null, event); 3 | }; 4 | -------------------------------------------------------------------------------- /packages/serverless-scf-trigger/test/fixtures/cos/index.ts: -------------------------------------------------------------------------------- 1 | exports.handler = (event, context, callback) => { 2 | callback(null, event); 3 | }; 4 | -------------------------------------------------------------------------------- /packages/serverless-scf-trigger/test/fixtures/timer/index.ts: -------------------------------------------------------------------------------- 1 | exports.handler = (event, context, callback) => { 2 | callback(null, event); 3 | }; 4 | -------------------------------------------------------------------------------- /packages/serverless-scf-trigger/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compileOnSave": true, 4 | "compilerOptions": { 5 | "rootDir": "src", 6 | "outDir": "dist" 7 | }, 8 | "include": [ 9 | "./src/**/*.ts" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /packages/serverless-spec-builder/README.md: -------------------------------------------------------------------------------- 1 | # serverless spec builder 2 | 3 | FaaS 标准 Spec 解析工具,以及用于其他平台 spec 转换的基础定义。 4 | 5 | ## API 6 | 7 | **transform** 8 | 9 | 根据传入的标准 spec 文件和一个生成器类,转换成标准的 JSON 格式。 10 | 11 | ```ts 12 | transform(sourcefilePath: string, builderCls?); 13 | ``` 14 | 15 | - sourcefilePath 原始 spec 文件地址 16 | - builderCls 转换的 class(非实例),默认为 SpecBuilder 类型,可以继承后传入 17 | 18 | **generate** 19 | 20 | ```ts 21 | generate(sourceFilePath: string, targetFilePath: string, builderCls?); 22 | ``` 23 | 24 | - sourcefilePath 原始 spec 文件地址 25 | - targetFilePath 转换后的 spec 文件地址 26 | - builderCls 转换的 class(非实例),默认为 SpecBuilder 类型,可以继承后传入 27 | 28 | **saveYaml** 29 | 30 | 保存 JSON 到 yml 文件 31 | 32 | ```ts 33 | saveYaml(filePath: string, target:object); 34 | ``` 35 | 36 | - filePath 需要保存到的 yml 文件路径 37 | - 保存到 yml 文件的 JSON 内容 38 | -------------------------------------------------------------------------------- /packages/serverless-spec-builder/fc/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from '../dist/fc'; 2 | -------------------------------------------------------------------------------- /packages/serverless-spec-builder/fc/index.js: -------------------------------------------------------------------------------- 1 | module.exports = require('../dist/fc'); 2 | -------------------------------------------------------------------------------- /packages/serverless-spec-builder/resource/template/template.yml: -------------------------------------------------------------------------------- 1 | Globals: 2 | Function: 3 | Runtime: Python2.7 4 | Timeout: 30 5 | Handler: index.handler 6 | Environment: 7 | Variables: 8 | DB_NAME: mydb 9 | 10 | Resources: 11 | default: 12 | Type: TencentCloud::Serverless::Namespace 13 | hello_world: 14 | Type: TencentCloud::Serverless::Function 15 | Properties: 16 | CodeUri: ./ 17 | Type: Event 18 | Description: This is a template function 19 | Handler: index.main_handler 20 | MemorySize: 128 21 | Runtime: Python3.6 22 | Timeout: 3 23 | Events: 24 | hello_world_apigw: # ${FunctionName} + '_apigw' 25 | Type: APIGW 26 | Properties: 27 | StageName: release 28 | ServiceId: 29 | HttpMethod: ANY 30 | -------------------------------------------------------------------------------- /packages/serverless-spec-builder/scf/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from '../dist/scf'; 2 | -------------------------------------------------------------------------------- /packages/serverless-spec-builder/scf/index.js: -------------------------------------------------------------------------------- 1 | module.exports = require('../dist/scf'); 2 | -------------------------------------------------------------------------------- /packages/serverless-spec-builder/src/fc/index.ts: -------------------------------------------------------------------------------- 1 | import { transform, generate } from '../index'; 2 | import { FCSpecBuilder } from './builder'; 3 | 4 | export const generateFunctionsSpec = filePath => { 5 | return transform(filePath, FCSpecBuilder); 6 | }; 7 | 8 | export const generateFunctionsSpecFile = ( 9 | filePath, 10 | targetFilePath = 'template.yml' 11 | ) => { 12 | generate(filePath, targetFilePath, FCSpecBuilder); 13 | }; 14 | -------------------------------------------------------------------------------- /packages/serverless-spec-builder/src/scf/index.ts: -------------------------------------------------------------------------------- 1 | import { SCFServerlessSpecBuilder } from './builder'; 2 | import { transform, generate } from '..'; 3 | 4 | export const generateFunctionsSpec = (filePath: any) => { 5 | return transform(filePath, SCFServerlessSpecBuilder); 6 | }; 7 | 8 | export const generateFunctionsSpecFile = ( 9 | sourceFilePathOrJson: any, 10 | targetFilePath = '.serverless/serverless.yml' 11 | ) => { 12 | generate(sourceFilePathOrJson, targetFilePath, SCFServerlessSpecBuilder); 13 | }; 14 | -------------------------------------------------------------------------------- /packages/serverless-spec-builder/test/fixtures/fc/f-base.yml: -------------------------------------------------------------------------------- 1 | service: 2 | name: serverless-hello-world 3 | 4 | provider: 5 | name: aliyun 6 | 7 | functions: 8 | index: 9 | handler: index.handler 10 | concurrency: 2 11 | 12 | package: 13 | artifact: code.zip 14 | -------------------------------------------------------------------------------- /packages/serverless-spec-builder/test/fixtures/fc/f-environment.yml: -------------------------------------------------------------------------------- 1 | service: 2 | name: serverless-hello-world 3 | 4 | provider: 5 | name: aliyun 6 | environment: 7 | GLOBAL_PASS: admin 8 | 9 | functions: 10 | index: 11 | handler: index.handler 12 | index2: 13 | handler: index2.handler 14 | environment: 15 | MYSQL_USER: root 16 | MYSQL_PASS: pass 17 | 18 | package: 19 | artifact: code.zip 20 | -------------------------------------------------------------------------------- /packages/serverless-spec-builder/test/fixtures/fc/f-event-apigw.yml: -------------------------------------------------------------------------------- 1 | service: 2 | name: serverless-hello-world 3 | 4 | provider: 5 | name: aliyun 6 | 7 | functions: 8 | index: 9 | handler: index.handler 10 | events: 11 | - apigw 12 | 13 | package: 14 | artifact: code.zip 15 | -------------------------------------------------------------------------------- /packages/serverless-spec-builder/test/fixtures/fc/f-event-http-no-method.yml: -------------------------------------------------------------------------------- 1 | service: 2 | name: serverless-hello-world 3 | 4 | provider: 5 | name: aliyun 6 | 7 | functions: 8 | index: 9 | handler: index.handler 10 | events: 11 | - http: 12 | path: / 13 | 14 | package: 15 | artifact: code.zip 16 | -------------------------------------------------------------------------------- /packages/serverless-spec-builder/test/fixtures/fc/f-event-http.yml: -------------------------------------------------------------------------------- 1 | service: 2 | name: serverless-hello-world 3 | 4 | provider: 5 | name: aliyun 6 | 7 | functions: 8 | index: 9 | handler: index.handler 10 | events: 11 | - http: 12 | method: get 13 | path: / 14 | 15 | index2: 16 | handler: index.handler 17 | events: 18 | - http: 19 | method: post 20 | path: /api 21 | role: 'acs:ram::1234567890:role/fc-invoke-test' 22 | version: LATEST 23 | 24 | package: 25 | artifact: code.zip 26 | -------------------------------------------------------------------------------- /packages/serverless-spec-builder/test/fixtures/fc/f-event-mq.yml: -------------------------------------------------------------------------------- 1 | service: 2 | name: serverless-hello-world 3 | 4 | provider: 5 | name: aliyun 6 | 7 | functions: 8 | index: 9 | handler: index.handler 10 | events: 11 | - mq: 12 | topic: test-topic 13 | region: cn-shanghai 14 | 15 | package: 16 | artifact: code.zip 17 | -------------------------------------------------------------------------------- /packages/serverless-spec-builder/test/fixtures/fc/f-event-oss.yml: -------------------------------------------------------------------------------- 1 | service: 2 | name: serverless-hello-world 3 | 4 | provider: 5 | name: aliyun 6 | 7 | functions: 8 | index: 9 | handler: index.handler 10 | events: 11 | - os: 12 | bucket: ossBucketName 13 | events: 14 | - oss:ObjectCreated:* 15 | - oss:ObjectRemoved:DeleteObject 16 | filter: 17 | prefix: filterdir/ 18 | suffix: .jpg 19 | role: acs:ram::1234567890:role/fc-invoke-test 20 | version: LATEST 21 | 22 | 23 | 24 | package: 25 | artifact: code.zip 26 | -------------------------------------------------------------------------------- /packages/serverless-spec-builder/test/fixtures/fc/f-event-timer.yml: -------------------------------------------------------------------------------- 1 | service: 2 | name: serverless-hello-world 3 | 4 | provider: 5 | name: aliyun 6 | 7 | functions: 8 | index: 9 | handler: index.handler 10 | events: 11 | - timer: 12 | type: every 13 | value: 1m 14 | payload: 'awesome-fc' 15 | enable: false 16 | version: LATEST 17 | 18 | package: 19 | artifact: code.zip 20 | -------------------------------------------------------------------------------- /packages/serverless-spec-builder/test/fixtures/fc/f-service-properties.yml: -------------------------------------------------------------------------------- 1 | service: 2 | name: serverless-hello-world 3 | 4 | provider: 5 | name: aliyun 6 | policies: 7 | - AliyunECSNetworkInterfaceManagementAccess 8 | vpcConfig: 9 | vpcId: 'vpc-j6cfu2g6tslzekh8grfmk' 10 | vSwitchIds: [ 'vsw-j6chkgsg9naj6gx49espd' ] 11 | securityGroupId: 'sg-j6ceitqs6ljyssm1apom' 12 | logConfig: 13 | project: localtestlog 14 | logstore: localteststore 15 | nasConfig: 16 | userId: 10003 17 | groupId: 10003 18 | mountPoints: 19 | - serverAddr: '012194b28f-xxxxx.cn-hangzhou.nas.aliyuncs.com:/' 20 | mountDir: '/mnt/test' 21 | 22 | functions: 23 | index: 24 | handler: index.handler 25 | 26 | package: 27 | artifact: code.zip 28 | -------------------------------------------------------------------------------- /packages/serverless-spec-builder/test/fixtures/fun-var.yml: -------------------------------------------------------------------------------- 1 | service: serverless-hello-world 2 | 3 | provider: 4 | name: ${ env.FAAS_PROVIDER } 5 | runtime: ${ env.NODEJS_VERSION } 6 | 7 | functions: 8 | hello: 9 | handler: ${env.FN_HANDLER} 10 | events: 11 | - http: 12 | path: ${ env.FN_HTTP_PATH} 13 | method: ${env.FN_HTTP_METHOD } 14 | 15 | package: 16 | exclude: 17 | - package-lock.json 18 | - .gitignore 19 | - .git/** 20 | 21 | layers: 22 | test: 23 | path: npm:@midwayjs/egg-layer@latest 24 | 25 | -------------------------------------------------------------------------------- /packages/serverless-spec-builder/test/fixtures/fun.yaml: -------------------------------------------------------------------------------- 1 | service: serverless-hello-world 2 | 3 | provider: 4 | name: fc 5 | runtime: nodejs8 6 | 7 | functions: 8 | hello: 9 | handler: index.handler 10 | events: 11 | - http: 12 | path: /foo 13 | method: get 14 | 15 | package: 16 | exclude: 17 | - package-lock.json 18 | - .gitignore 19 | - .git/** 20 | 21 | layers: 22 | test: 23 | path: npm:@midwayjs/egg-layer@latest 24 | 25 | -------------------------------------------------------------------------------- /packages/serverless-spec-builder/test/fixtures/fun.yml: -------------------------------------------------------------------------------- 1 | service: serverless-hello-world 2 | 3 | provider: 4 | name: fc 5 | runtime: nodejs8 6 | 7 | functions: 8 | hello: 9 | handler: index.handler 10 | events: 11 | - http: 12 | path: /foo 13 | method: get 14 | 15 | package: 16 | exclude: 17 | - package-lock.json 18 | - .gitignore 19 | - .git/** 20 | 21 | layers: 22 | test: 23 | path: npm:@midwayjs/egg-layer@latest 24 | 25 | -------------------------------------------------------------------------------- /packages/serverless-spec-builder/test/fixtures/scf/f-base.yml: -------------------------------------------------------------------------------- 1 | service: 2 | name: serverless-hello-world 3 | 4 | provider: 5 | name: tecent 6 | runtime: nodejs8 7 | stage: dev 8 | region: ap-shanghai 9 | credentials: ~/credentials 10 | timeout: 10 11 | memorySize: 256 12 | role: QCS_SCFExcuteRole 13 | environment: 14 | ENV_FIRST: env1 15 | ENV_SECOND: env2 16 | serviceId: service-bkabs 17 | 18 | functions: 19 | index: 20 | handler: index.handler 21 | 22 | package: 23 | artifact: code.zip 24 | -------------------------------------------------------------------------------- /packages/serverless-spec-builder/test/fixtures/scf/f-event-apigw.yml: -------------------------------------------------------------------------------- 1 | service: 2 | name: serverless-hello-world 3 | 4 | provider: 5 | name: tecent 6 | runtime: nodejs10 7 | 8 | functions: 9 | index: 10 | handler: index.handler 11 | events: 12 | - http: 13 | path: /foo 14 | method: 15 | - GET 16 | - POST 17 | 18 | package: 19 | artifact: code.zip 20 | -------------------------------------------------------------------------------- /packages/serverless-spec-builder/test/fixtures/scf/f-event-cmq.yml: -------------------------------------------------------------------------------- 1 | service: 2 | name: serverless-hello-world 3 | 4 | provider: 5 | name: tecent 6 | runtime: nodejs10 7 | 8 | functions: 9 | index: 10 | handler: index.handler 11 | events: 12 | - cmq: 13 | topic: test-topic-queue 14 | enable: false 15 | package: 16 | artifact: code.zip 17 | -------------------------------------------------------------------------------- /packages/serverless-spec-builder/test/fixtures/scf/f-event-cos.yml: -------------------------------------------------------------------------------- 1 | service: 2 | name: serverless-hello-world 3 | 4 | provider: 5 | name: tecent 6 | runtime: nodejs10 7 | 8 | functions: 9 | index: 10 | handler: index.handler 11 | events: 12 | - os: 13 | bucket: cli-appid.cos.ap-beijing.myqcloud.com 14 | filter: 15 | prefix: filterdir/ 16 | suffix: .jpg 17 | events: cos:ObjectCreated:* 18 | enable: false 19 | 20 | package: 21 | artifact: code.zip 22 | -------------------------------------------------------------------------------- /packages/serverless-spec-builder/test/fixtures/scf/f-event-timer.yml: -------------------------------------------------------------------------------- 1 | service: 2 | name: serverless-hello-world 3 | 4 | provider: 5 | name: tecent 6 | runtime: nodejs10 7 | 8 | functions: 9 | index: 10 | handler: index.handler 11 | events: 12 | - timer: 13 | type: 'cron' 14 | value: '*/5 * * * *' 15 | payload: 'test' 16 | package: 17 | artifact: code.zip 18 | -------------------------------------------------------------------------------- /packages/serverless-spec-builder/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compileOnSave": true, 4 | "compilerOptions": { 5 | "rootDir": "src", 6 | "outDir": "dist" 7 | }, 8 | "include": [ 9 | "./src/**/*.ts" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /packages/simple-lock/README.md: -------------------------------------------------------------------------------- 1 | # simple lock 2 | 3 | ## sureOnce 4 | 5 | * fn execute only once 6 | 7 | 8 | ## acquire 9 | 10 | * just lock, fn executed by array -------------------------------------------------------------------------------- /packages/simple-lock/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@midwayjs/simple-lock", 3 | "version": "0.3.0", 4 | "main": "dist/index", 5 | "typings": "dist/index.d.ts", 6 | "files": [ 7 | "dist" 8 | ], 9 | "devDependencies": { 10 | "midway-bin": "^2.0.0" 11 | }, 12 | "engines": { 13 | "node": ">= 10" 14 | }, 15 | "scripts": { 16 | "build": "midway-bin build -c", 17 | "test": "midway-bin test --ts --full-trace", 18 | "cov": "midway-bin cov --ts", 19 | "clean": "midway-bin clean", 20 | "autod": "midway-bin autod" 21 | }, 22 | "repository": { 23 | "type": "git", 24 | "url": "git@github.com:midwayjs/midway-faas.git" 25 | }, 26 | "license": "MIT" 27 | } 28 | -------------------------------------------------------------------------------- /packages/simple-lock/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compileOnSave": true, 4 | "compilerOptions": { 5 | "rootDir": "src", 6 | "outDir": "dist", 7 | // TODO: remove this flag 8 | "esModuleInterop": true, 9 | }, 10 | "include": [ 11 | "./src/**/*.ts" 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /scripts/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | lerna run build 5 | -------------------------------------------------------------------------------- /scripts/deploy_key.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/midwayjs/midway-faas/d3f3b8e01514c468070abb14340776724a382a29/scripts/deploy_key.enc -------------------------------------------------------------------------------- /scripts/ownerAdd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | user=$1 3 | pkgs=`find packages -maxdepth 1 -mindepth 1` 4 | cwd=`pwd` 5 | for pkg in $pkgs 6 | do 7 | cd $cwd 8 | if [ -e "${pkg}/package.json" ] 9 | then 10 | cd $pkg 11 | echo ">>>>>> Owner Adding" 12 | echo ">>>>>>" $pkg 13 | npm owner add $user 14 | fi 15 | done 16 | cd $cwd 17 | -------------------------------------------------------------------------------- /scripts/publish.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | source `dirname $0`/build.sh 4 | git add . 5 | lerna publish $* 6 | -------------------------------------------------------------------------------- /scripts/resyncPublish.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | pkgs=`find packages -maxdepth 1 -mindepth 1` 4 | cwd=`pwd` 5 | for pkg in $pkgs 6 | do 7 | cd $cwd 8 | if [ -e "${pkg}/package.json" ] 9 | then 10 | cd $pkg 11 | echo ">>>>>> Publishing" 12 | echo ">>>>>>" $pkg 13 | npm publish 14 | fi 15 | done 16 | cd $cwd 17 | -------------------------------------------------------------------------------- /scripts/sync.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | pkgs=`find packages -maxdepth 1 -mindepth 1` 3 | cwd=`pwd` 4 | 5 | for pkg in $pkgs 6 | do 7 | cd $cwd 8 | if [ -f "${pkg}/package.json" ]; then 9 | cd $pkg 10 | NAME=$(node -pe "require('./package.json').name") 11 | SHH="tnpm sync ${NAME}" 12 | echo $SHH 13 | $SHH 14 | fi 15 | done 16 | cd $cwd 17 | -------------------------------------------------------------------------------- /scripts/tag.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | pkgs=`find packages -maxdepth 1 -mindepth 1` 3 | cwd=`pwd` 4 | TAG=$1; 5 | 6 | if [ -z "$TAG" ]; then 7 | echo Please provide a valid tag name!; 8 | exit 1; 9 | fi 10 | 11 | for pkg in $pkgs 12 | do 13 | cd $cwd 14 | if [ -f "${pkg}/package.json" ]; then 15 | cd $pkg 16 | NAME=$(node -pe "require('./package.json').name") 17 | VERSION=$(node -pe "require('./package.json').version") 18 | SHH="npm dist-tag add ${NAME}@${VERSION} $TAG" 19 | echo $SHH 20 | $SHH 21 | fi 22 | done 23 | cd $cwd 24 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./node_modules/mwts/tsconfig-midway.json", 3 | "compileOnSave": true, 4 | "compilerOptions": { 5 | "moduleResolution": "node", 6 | "experimentalDecorators": true, 7 | "emitDecoratorMetadata": true, 8 | "noImplicitThis": true, 9 | "noUnusedLocals": true, 10 | "stripInternal": true, 11 | // TODO: enable strict checks 12 | "noImplicitReturns": false, 13 | "strict": false, 14 | // TODO: Emit test files to outDir 15 | "noEmitOnError": false, 16 | }, 17 | "exclude": [ 18 | "dist", 19 | "node_modules", 20 | "test" 21 | ] 22 | } 23 | --------------------------------------------------------------------------------