This repository was archived by the owner on Sep 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathbuild.js
61 lines (53 loc) · 1.73 KB
/
build.js
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
const fs = require("fs");
const { flags } = require("@oclif/command");
const Command = require("@netlify/cli-utils");
const { zipFunctions } = require("@netlify/zip-it-and-ship-it");
const {
NETLIFYDEV,
NETLIFYDEVLOG,
NETLIFYDEVWARN,
NETLIFYDEVERR
} = require("netlify-cli-logo");
class FunctionsBuildCommand extends Command {
async run() {
const { flags, args } = this.parse(FunctionsBuildCommand);
const { config } = this.netlify;
const src = flags.src || config.build.functionsSource;
const dst = flags.functions || config.build.functions;
if (src === dst) {
this.log(
`${NETLIFYDEVERR} Source and destination for function build can't be the same`
);
process.exit(1);
}
if (!src || !dst) {
if (!src)
this.log(
`${NETLIFYDEVERR} Error: You must specify a source folder with a --src flag or a functionsSource field in your config`
);
if (!dst)
this.log(
`${NETLIFYDEVERR} Error: You must specify a destination functions folder with a --functions flag or a functions field in your config`
);
process.exit(1);
}
fs.mkdirSync(dst, { recursive: true });
this.log(`${NETLIFYDEVLOG} Building functions`);
zipFunctions(src, dst, { skipGo: true });
this.log(`${NETLIFYDEVLOG} Functions built to `, dst);
}
}
FunctionsBuildCommand.description = `build functions locally
`;
FunctionsBuildCommand.aliases = ["function:build"];
FunctionsBuildCommand.flags = {
functions: flags.string({
char: "f",
description: "Specify a functions folder to build to"
}),
src: flags.string({
char: "s",
description: "Specify the source folder for the functions"
})
};
module.exports = FunctionsBuildCommand;