forked from Azure/azure-functions-pack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctionPublish.ts
61 lines (49 loc) · 1.66 KB
/
functionPublish.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// import * as debugLib from "debug";
import { AzureProvider } from './provider';
import { FileHelper } from "./utils";
import * as winston from "winston";
import { createLogger } from './utils/logger';
const logger = createLogger('azure.functions.webpack.funcitonDeploy');
export class FunctionDeploy {
azure: AzureProvider;
bundlePath: string;
constructor(options: any) {
this.bundlePath = options.bundlePath;
this.azure = new AzureProvider(options);
}
public async deploy() {
await this.login();
await this.cleanUpFunctions();
await this.createResourceGroup();
await this.createFunctionApp();
const zipFile = await this.createZipFile();
await this.zipDeploy(zipFile);
}
private async login() {
return this.azure.login();
}
private async cleanUpFunctions() {
const isExisting = await this.azure.isExistingFunctionApp();
if (isExisting) {
logger.debug(`Existing Function App found, trying to clean up...`);
const functions = await FileHelper.loadFunctionsFromDirectory(this.bundlePath);
if (functions && functions.size > 0) {
await this.azure.getDeployedFunctionsNames();
await this.azure.cleanUpFunctionsBeforeDeploy(Array.from(functions.keys()));
}
}
}
private async createResourceGroup() {
return this.azure.createResourceGroup();
}
private async createFunctionApp() {
return this.azure.createFunctionApp();
}
private async createZipFile() {
await FileHelper.mkDirP('./.bundle');
return FileHelper.zipFolder(this.bundlePath, './.bundle/app.zip');
}
private async zipDeploy(zipFile: string) {
return this.azure.uploadFunction(zipFile);
}
}