1
- const fs = require("fs");
2
- const path = require("path");
3
- const childProcess = require('child_process');
4
1
const { Command } = require("commander");
5
2
const inquirer = require("inquirer");
6
3
const { teamsCreate, teamsList } = require("./teams");
7
4
const { projectsCreate } = require("./projects");
8
- const { functionsCreate } = require("./functions");
9
5
const { databasesGet, databasesListCollections, databasesList } = require("./databases");
10
6
const { storageListBuckets } = require("./storage");
11
7
const { sdkForConsole } = require("../sdks");
12
8
const { localConfig } = require("../config");
13
9
const ID = require("../id");
14
10
const { paginate } = require("../paginate");
15
- const { questionsPullProject, questionsPullFunction, questionsPullCollection } = require("../questions");
11
+ const { questionsPullProject, questionsPullCollection } = require("../questions");
16
12
const { success, log, actionRunner, commandDescriptions } = require("../parser");
17
13
18
14
const pull = new Command("pull")
@@ -32,116 +28,6 @@ const pullProject = async () => {
32
28
success();
33
29
}
34
30
35
- const pullFunction = async () => {
36
- // TODO: Add CI/CD support (ID, name, runtime)
37
- const answers = await inquirer.prompt(questionsPullFunction)
38
- const functionFolder = path.join(process.cwd(), 'functions');
39
-
40
- if (!fs.existsSync(functionFolder)) {
41
- fs.mkdirSync(functionFolder, {
42
- recursive: true
43
- });
44
- }
45
-
46
- const functionId = answers.id === 'unique()' ? ID.unique() : answers.id;
47
- const functionDir = path.join(functionFolder, functionId);
48
-
49
- if (fs.existsSync(functionDir)) {
50
- throw new Error(`( ${functionId} ) already exists in the current directory. Please choose another name.`);
51
- }
52
-
53
- if (!answers.runtime.entrypoint) {
54
- log(`Entrypoint for this runtime not found. You will be asked to configure entrypoint when you first push the function.`);
55
- }
56
-
57
- if (!answers.runtime.commands) {
58
- log(`Installation command for this runtime not found. You will be asked to configure the install command when you first push the function.`);
59
- }
60
-
61
- let response = await functionsCreate({
62
- functionId,
63
- name: answers.name,
64
- runtime: answers.runtime.id,
65
- entrypoint: answers.runtime.entrypoint || '',
66
- commands: answers.runtime.commands || '',
67
- parseOutput: false
68
- })
69
-
70
- fs.mkdirSync(functionDir, "777");
71
-
72
- let gitInitCommands = "git clone -b v3 --single-branch --depth 1 --sparse https://github.com/{{ sdk .gitUserName }}/functions-starter ."; // depth prevents fetching older commits reducing the amount fetched
73
-
74
- let gitPullCommands = `git sparse-checkout add ${answers.runtime.id}`;
75
-
76
- /* Force use CMD as powershell does not support && */
77
- if (process.platform === 'win32') {
78
- gitInitCommands = 'cmd /c "' + gitInitCommands + '"';
79
- gitPullCommands = 'cmd /c "' + gitPullCommands + '"';
80
- }
81
-
82
- /* Execute the child process but do not print any std output */
83
- try {
84
- childProcess.execSync(gitInitCommands, { stdio: 'pipe', cwd: functionDir });
85
- childProcess.execSync(gitPullCommands, { stdio: 'pipe', cwd: functionDir });
86
- } catch (error) {
87
- /* Specialised errors with recommended actions to take */
88
- if (error.message.includes('error: unknown option')) {
89
- throw new Error(`${error.message} \n\nSuggestion: Try updating your git to the latest version, then trying to run this command again.`)
90
- } else if (error.message.includes('is not recognized as an internal or external command,') || error.message.includes('command not found')) {
91
- throw new Error(`${error.message} \n\nSuggestion: It appears that git is not installed, try installing git then trying to run this command again.`)
92
- } else {
93
- throw error;
94
- }
95
- }
96
-
97
- fs.rmSync(path.join(functionDir, ".git"), { recursive: true });
98
- const copyRecursiveSync = (src, dest) => {
99
- let exists = fs.existsSync(src);
100
- let stats = exists && fs.statSync(src);
101
- let isDirectory = exists && stats.isDirectory();
102
- if (isDirectory) {
103
- if (!fs.existsSync(dest)) {
104
- fs.mkdirSync(dest);
105
- }
106
-
107
- fs.readdirSync(src).forEach(function (childItemName) {
108
- copyRecursiveSync(path.join(src, childItemName), path.join(dest, childItemName));
109
- });
110
- } else {
111
- fs.copyFileSync(src, dest);
112
- }
113
- };
114
- copyRecursiveSync(path.join(functionDir, answers.runtime.id), functionDir);
115
-
116
- fs.rmSync(`${functionDir}/${answers.runtime.id}`, { recursive: true, force: true });
117
-
118
- const readmePath = path.join(process.cwd(), 'functions', functionId, 'README.md');
119
- const readmeFile = fs.readFileSync(readmePath).toString();
120
- const newReadmeFile = readmeFile.split('\n');
121
- newReadmeFile[0] = `# ${answers.name}`;
122
- newReadmeFile.splice(1, 2);
123
- fs.writeFileSync(readmePath, newReadmeFile.join('\n'));
124
-
125
- let data = {
126
- $id: response['$id'],
127
- name: response.name,
128
- runtime: response.runtime,
129
- execute: response.execute,
130
- events: response.events,
131
- schedule: response.schedule,
132
- timeout: response.timeout,
133
- enabled: response.enabled,
134
- logging: response.logging,
135
- entrypoint: response.entrypoint,
136
- commands: response.commands,
137
- ignore: answers.runtime.ignore || null,
138
- path: `functions/${functionId}`,
139
- };
140
-
141
- localConfig.addFunction(data);
142
- success();
143
- }
144
-
145
31
const pullCollection = async ({ all, databaseId } = {}) => {
146
32
const databaseIds = [];
147
33
@@ -221,11 +107,6 @@ pull
221
107
.description("Pulling your {{ spec .title | caseUcfirst }} project")
222
108
.action(actionRunner(pullProject));
223
109
224
- pull
225
- .command("function")
226
- .description("Pulling your {{ spec .title | caseUcfirst }} cloud function")
227
- .action(actionRunner(pullFunction))
228
-
229
110
pull
230
111
.command("collection")
231
112
.description("Pulling your {{ spec .title | caseUcfirst }} collections")
0 commit comments