Skip to content

Commit

Permalink
Merge branch 'master' of github.com:aliyun/fun
Browse files Browse the repository at this point in the history
  • Loading branch information
vangie committed Dec 2, 2018
2 parents c5bec61 + 3ddfa9d commit 41e04a8
Show file tree
Hide file tree
Showing 51 changed files with 1,654 additions and 41 deletions.
Binary file added .DS_Store
Binary file not shown.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ examples/local/java8/target/*

output
.oss_cfg

*.pyc
*.iml
*.class
*.class
.DS_Store
10 changes: 8 additions & 2 deletions README-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@

## 开始使用

我们准备了一系列教程,助您更快上手:
Fun 作为一个命令行工具,内置了多个子命令,比如 config、local、deploy 等。

- [安装教程](https://github.com/aliyun/fun/blob/master/docs/usage/installation-zh.md):介绍了如何在 macOS、Linux 或者 Windows 上安装 Fun。
其中,config 子命令可以用来配置 fun,local 子命令可以用来本地运行调试函数,deploy 子命令可以将资源发布到线上。

为了让您尽快上手,我们准备了一系列教程:

- [安装教程](https://github.com/aliyun/fun/blob/master/docs/usage/installation-zh.md):介绍了如何在 Mac、Linux 或者 Windows 上安装 Fun。
- [使用](https://github.com/aliyun/fun/blob/master/docs/usage/getting_started-zh.md):通过一个简单的示例介绍了 Fun 的基本用法。
- **本地运行与调试**:关于如何本地运行、调试函数,以及介绍排查 bug 技巧的系列文章。
- [开发函数计算的正确姿势 —— 使用 Fun Local 本地运行与调试](https://yq.aliyun.com/articles/672623):介绍了 Fun Local 基本用法。
Expand All @@ -33,7 +37,9 @@
- [函数计算](https://www.aliyun.com/product/fc)
- [API Gateway](https://www.aliyun.com/product/apigateway)
- [Fun 发布 2.0 新版本啦](https://yq.aliyun.com/articles/604490)
- [函数计算工具链新成员 —— Fun Local 发布啦](https://yq.aliyun.com/articles/672656)
- [三十分钟快速搭建 serverless 网盘服务](https://yq.aliyun.com/articles/613780)
- [Fc Docker](https://github.com/aliyun/fc-docker)

## 开源许可

Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ If you want to use the old syntax, please refer to [README.md](https://github.co

## Get Started

As a command-line tool, Fun has built-in subcommands such as config, local, deploy, and so on.

The config subcommand can be used to configure fun, the local subcommand can be used to run the debugging function locally, and the deploy subcommand can publish your resources.

We have prepared a series of tutorials to help you use the Fun tool more easily:

- [installation.md](dhttps://github.com/aliyun/fun/blob/master/docs/usage/installation.md): Learn how to install Fun on macOS, Linux or Windows.
- [getting_started](https://github.com/aliyun/fun/blob/master/docs/usage/getting_started.md): The basic usage of Fun is introduced with a simple example.
- [Installation](https://github.com/aliyun/fun/blob/master/docs/usage/installation.md): Learn how to install Fun on Mac, Linux or Windows.
- [Getting Started](https://github.com/aliyun/fun/blob/master/docs/usage/getting_started.md): The basic usage of Fun is introduced with a simple example.
- **Running and debugging locally**: A series on how to run locally, debug functions, and tips on troubleshooting related issues.
- [开发函数计算的正确姿势 —— 使用 Fun Local 本地运行与调试](https://yq.aliyun.com/articles/672623): Introduced the basic usage of Fun Local.
- [开发函数计算的正确姿势 —— 爬虫](https://yq.aliyun.com/articles/672624): How to use the Fun tool to develop a Serverless application from scratch.
Expand All @@ -29,7 +33,9 @@ We have prepared a series of tutorials to help you use the Fun tool more easily:
- [函数计算](https://www.aliyun.com/product/fc)
- [API Gateway](https://www.aliyun.com/product/apigateway)
- [Fun 发布 2.0 新版本啦](https://yq.aliyun.com/articles/604490)
- [函数计算工具链新成员 —— Fun Local 发布啦](https://yq.aliyun.com/articles/672656)
- [三十分钟快速搭建 serverless 网盘服务](https://yq.aliyun.com/articles/613780)
- [Fc Docker](https://github.com/aliyun/fc-docker)

## License

Expand Down
68 changes: 68 additions & 0 deletions bin/fun-init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env node

/* eslint-disable quotes */

'use strict';

const program = require('commander');

const examples =
`
Examples:
$ fun init
$ fun init helloworld-nodejs8
$ fun init foo/bar
$ fun init gh:foo/bar
$ fun init gl:foo/bar
$ fun init bb:foo/bar
$ fun init github:foo/bar
$ fun init gitlab:foo/bar
$ fun init bitbucket:foo/bar
$ fun init git+ssh://[email protected]/foo/bar.git
$ fun init hg+ssh://[email protected]/bar/foo
$ fun init [email protected]:foo/bar.git
$ fun init https://github.com/foo/bar.git
$ fun init /path/foo/bar
$ fun init -n fun-app -V foo=bar /path/foo/bar
`;

const parseVars = (val, vars) => {
/*
* Key-value pairs, separated by equal signs
* keys can only contain letters, numbers, and underscores
* values can be any character
*/
const group = val.match(/(^[a-zA-Z_][a-zA-Z\d_]*)=(.*)/);
vars = vars || {};
if (group) {
vars[group[1]] = group[2];
}
return vars;
};

program
.name('fun init')
.usage('[options] [location]')
.description('Initializes a new fun project.')
.option('-o, --output-dir [path]', 'where to output the initialized app into', '.')
.option('-n, --name [name]', 'name of your project to be generated as a folder', 'fun-app')
.option('--no-input [noInput]', 'disable prompting and accept default values defined template config')
.option('-V, --var [vars]', 'template variable', parseVars)
.on('--help', () => {
console.log(examples);
})
.parse(process.argv);

const context = {
name: program.name,
outputDir: program.outputDir,
input: program.input,
vars: program.var || {}
};

if (program.args.length > 0) {
context.location = program.args[0];
}

require('../lib/commands/init')(context).catch(require('../lib/exception-handler'));
3 changes: 2 additions & 1 deletion bin/fun.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ program
// The commander will try to search the executables in the directory of the entry script
// (like ./examples/pm) with the name program-command.
.command('config', 'configure the fun')
.command('init', 'initialize a new fun project')
.command('build', 'build the dependencies')
.command('local', 'run your serverless application locally')
.command('validate', 'validate a fun template')
Expand All @@ -38,4 +39,4 @@ program.on('command:*', (cmds) => {
}
});

program.parse(process.argv);
program.parse(process.argv);
25 changes: 25 additions & 0 deletions docs/usage/getting_started-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,28 @@ fun 配置方式的优先级按以下顺序依次递减:
- .env
- 环境变量
- ~/.fcli/config.yaml

### .funignore

在 template.yml 所在的目录放置一个 .funignore 文件,打包 zip 文件的时候可以排除掉 .funignore 内描述的文件或者文件夹。 例如:

```
# Logs
logs/
*.log

# Dependency directories
node_modules/
!bb/node_modules
```
打包时会忽略 logs/ 目录 、*.log 文件。所有层级的 node_modules/ 目录会被忽略,但是 bb/node_modules 会被保留。
.funignore 遵从 .gitignore 的语法。
## 更多示例
下面有更多的示例:
- https://github.com/aliyun/fun/tree/master/examples
- [十分钟上线-在函数计算上部署基于django开发的个人博客系统](https://yq.aliyun.com/articles/603249?spm=a2c4e.11153959.teamhomeleft.26.115948f26ECqbQ)
18 changes: 18 additions & 0 deletions docs/usage/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,24 @@ The priority of the fun configuration is decremented in the following order:
- environment variables
- ~/.fcli/config.yaml

### .funignore

Create a .funignore file in the same directory as template.yml. When packaging the zip file, you can exclude the files or folders described in .funignore. such as:

```
# Logs
logs/
*.log
# Dependency directories
node_modules/
!bb/node_modules
```

The logs/ directory and *.log files are ignored when packaging. The node_modules/ directory of all levels will be ignored, but bb/node_modules is preserved.

.funignore follows the syntax of .gitignore.

## More examples

You can find more complex examples here:
Expand Down
54 changes: 51 additions & 3 deletions docs/usage/installation-zh.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,40 @@
# Installation
# 安装

本地使用 Fun 时,如果需要在本地运行、调试函数,则需要使用 fun local 子命令.

fun 是一个 Node.js 编写的命令行工具,但它也能支持 Python,Java 等环境的部署操作。安装它的方式是通过 npm:
使用 fun local 子命令就需要预先安装 docker。如果不要求在本地运行、调试函数,则不需要安装 docker。

## Docker

### 安装 Docker

#### Mac 安装 docker

可以参考官方[教程](https://store.docker.com/editions/community/docker-ce-desktop-mac?tab=description)

如果遇到网络问题,可以下载阿里云提供的 [Docker For Mac](http://mirrors.aliyun.com/docker-toolbox/mac/docker-for-mac/stable/)

### Windows 安装 docker

可以参考官方[教程](https://store.docker.com/editions/community/docker-ce-desktop-windows)

如果遇到网络问题,可以下载阿里云提供的 [Docker For Windows](http://mirrors.aliyun.com/docker-toolbox/windows/docker-for-windows/stable/)

### Linux 安装 docker

可以参考官方[教程](https://docs.docker.com/install/linux/docker-ce/ubuntu/#install-using-the-repository)

如果遇到网络问题,可以通过阿里云 Docker CE 镜像源站[下载](https://yq.aliyun.com/articles/110806)

### 配置镜像加速器

安装好 docker 之后,就可以使用 docker 下载镜像了。如果遇到网络问题,推荐配置 aliyun [镜像加速器](https://yq.aliyun.com/articles/29941)

## 安装 Fun

### 通过 npm 安装 Fun

安装它的方式是通过 npm:

```shell
$ npm install @alicloud/fun -g
Expand All @@ -27,4 +60,19 @@ $ fun -h
validate [options] Validate a fun template
deploy Deploy a project to AliCloud
build Build the dependencies
```
```

### 直接下载 Fun 二进制运行程序

打开 [releases](https://github.com/aliyun/fun/releases) 页面,在最新的版本中选择一个对应平台的 release 压缩包链接,点击即可直接下载。

下载到本地后,解压,即可直接使用。

### 通过 homebrew 安装 Fun

对于 Mac 系统,还可以选择使用 homebrew 安装 Fun。

```
brew tap vangie/formula
brew install fun
```
51 changes: 50 additions & 1 deletion docs/usage/installation.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,40 @@
# Installation

Fun is a command line tool developed for Node.js, however it also support Python, Java or other runtime enviroments. It can be installed by [npm](https://www.npmjs.com/):
When using Fun, if you need to run and debug function locally, you need to use the fun local subcommand.

Fun local subcommand depend on docker.

If you don't want to run and debug function locally, docker is not required.

## Docker

### Install Docker

#### Install Docker On Mac

You can refer to the official [Tutorial](https://store.docker.com/editions/community/docker-ce-desktop-mac?tab=description).

If you encounter network problems, you can download [Docker For Mac](http://mirrors.aliyun.com/docker-toolbox/mac/docker-for-mac/stable/) provided by Alibaba Cloud.

#### Install Docker On Windows

You can refer to the official [Tutorial](https://store.docker.com/editions/community/docker-ce-desktop-windows).

If you encounter network problems, you can download [Docker For Windows](http://mirrors.aliyun.com/docker-toolbox/windows/docker-for-windows/stable/) provided by Alibaba Cloud.

#### Install Docker On Linux

You can refer to the official [Tutorial](https://docs.docker.com/install/linux/docker-ce/ubuntu).

If you encounter network problems, you can use Alibaba Cloud Docker CE mirror to download. please refer to this [tutorial](https://yq.aliyun.com/articles/110806).

### Configuring Docker Registry Mirror

Once docker is installed, you can use docker to download the image. If you encounter network problems, it is recommended to configure aliyun [Registry Mirror](https://yq.aliyun.com/articles/29941).

## Install Fun Using Npm

Fun could be installed by [npm](https://www.npmjs.com/):

```shell
$ npm install @alicloud/fun -g
Expand All @@ -27,3 +61,18 @@ $ fun
deploy Deploy a project to AliCloud
build Build the dependencies
```

## Install Fun by Downloading The Latest Binary

Open the [Releases](https://github.com/aliyun/fun/releases) page, click a link of the corresponding platform to download the Fun zip package.

After downloading, unzip it and use it directly.

## Install Fun Using Homebrew

For Mac, you can also install Fun using homebrew.

```
brew tap vangie/formula
brew install fun
```
Binary file added examples/.DS_Store
Binary file not shown.
4 changes: 3 additions & 1 deletion examples/package/funignore/.funignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ tmp/
usr/
.env
package-lock.json
template.yml
template.yml

.funignore
30 changes: 30 additions & 0 deletions lib/commands/init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict';

const { determineRepoDir, getOfficialTemplates } = require('../init/repository');
const { render } = require('../init/renderer');
const { sync } = require('rimraf');
const { buildContext } = require('../init/context');
const { promptForTemplate } = require('../init/prompt');
const debug = require('debug')('fun:init');

function cleanTemplate(repoDir) {
debug('Cleaning Template: %', repoDir);
sync(repoDir);
}

async function init(context) {
debug('location is: %s', context.location);
context.templates = getOfficialTemplates();
if (!context.location) {
context.location = await promptForTemplate(Object.keys(context.templates));
}
const {repoDir, clean} = await determineRepoDir(context);
await buildContext(repoDir, context);
render(context);
if (clean) {
cleanTemplate(repoDir);
}

}

module.exports = init;
Loading

0 comments on commit 41e04a8

Please sign in to comment.