This repository was archived by the owner on Jun 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
47 lines (38 loc) · 1.56 KB
/
index.js
File metadata and controls
47 lines (38 loc) · 1.56 KB
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
#! /usr/bin/env node
const commander = require('commander');
const { writeFiles } = require('@stackbit/stackbit-pull-core');
const { pull } = require('./stackbit');
module.exports = {
pull
};
if (require.main === module) {
commander
.option('--stackbit-pull-api-url <stackbitPullApiUrl>', '[required] stackbit pull API URL')
.option(
'--stackbit-api-key <stackbitApiKey>',
'[required] stackbit API key, can be also specified through STACKBIT_API_KEY environment variable'
)
.option('--environment <environment>', '[optional] environment to pull data for')
.parse(process.argv);
const stackbitPullApiUrl = commander['stackbitPullApiUrl'];
const apiKey = process.env['STACKBIT_API_KEY'] || commander['stackbitApiKey'];
// Environment to pull data for, defaults to Netlify's BRANCH
const environment = commander['environment'] || process.env['BRANCH'];
if (!stackbitPullApiUrl) {
commander.help((helpText) => helpText + `\nError: '--stackbit-pull-api-url' argument must be specified\n\n`);
}
if (!apiKey) {
commander.help(
(helpText) => helpText + `\nError: either '--stackbit-api-key' argument or 'STACKBIT_API_KEY' must be specified\n\n`
);
}
console.log(`fetching data for project from ${stackbitPullApiUrl}`);
pull({ stackbitPullApiUrl, apiKey, environment })
.then((response) => {
return writeFiles(response);
})
.catch((err) => {
console.error(err);
process.exit(1);
});
}