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 pathlist.js
104 lines (95 loc) · 3.29 KB
/
list.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
const chalk = require("chalk");
const Command = require("@netlify/cli-utils");
const { flags } = require("@oclif/command");
const AsciiTable = require("ascii-table");
const { getFunctions } = require("../../utils/get-functions");
class FunctionsListCommand extends Command {
async run() {
let { flags } = this.parse(FunctionsListCommand);
const { api, site, config } = this.netlify;
// get deployed site details
// copied from `netlify status`
const siteId = site.id;
if (!siteId) {
this.warn("Did you run `netlify link` yet?");
this.error(`You don't appear to be in a folder that is linked to a site`);
}
let siteData;
try {
siteData = await api.getSite({ siteId });
} catch (e) {
if (e.status === 401 /* unauthorized*/) {
this.warn(
`Log in with a different account or re-link to a site you have permission for`
);
this.error(
`Not authorized to view the currently linked site (${siteId})`
);
}
if (e.status === 404 /* missing */) {
this.error(`The site this folder is linked to can't be found`);
}
this.error(e);
}
const deploy = siteData.published_deploy || {};
const deployed_functions = deploy.available_functions || [];
const functionsDir =
flags.functions ||
(config.dev && config.dev.functions) ||
(config.build && config.build.functions);
if (typeof functionsDir === "undefined") {
this.error(
"functions directory is undefined, did you forget to set it in netlify.toml?"
);
process.exit(1);
}
var table = new AsciiTable(
`Netlify Functions (based on local functions folder "${functionsDir}")`
);
const functions = getFunctions(functionsDir);
table.setHeading("Name", "Url", "moduleDir", "deployed");
Object.entries(functions).forEach(([functionName, { moduleDir }]) => {
const isDeployed = deployed_functions
.map(({ n }) => n)
.includes(functionName);
// this.log(`${chalk.yellow("function name")}: ${functionName}`);
// this.log(
// ` ${chalk.yellow(
// "url"
// )}: ${`/.netlify/functions/${functionName}`}`
// );
// this.log(` ${chalk.yellow("moduleDir")}: ${moduleDir}`);
// this.log(
// ` ${chalk.yellow("deployed")}: ${
// isDeployed ? chalk.green("yes") : chalk.yellow("no")
// }`
// );
// this.log("----------");
table.addRow(
functionName,
`/.netlify/functions/${functionName}`,
moduleDir,
isDeployed ? "yes" : "no"
);
});
this.log(table.toString());
}
}
FunctionsListCommand.description = `list functions that exist locally
Helpful for making sure that you have formatted your functions correctly
NOT the same as listing the functions that have been deployed. For that info you need to go to your Netlify deploy log.
`;
FunctionsListCommand.aliases = ["function:list"];
FunctionsListCommand.flags = {
name: flags.string({
char: "n",
description: "name to print"
}),
functions: flags.string({
char: "f",
description: "Specify a functions folder to serve"
})
};
// TODO make visible once implementation complete
FunctionsListCommand.hidden = true;
module.exports = FunctionsListCommand;