@@ -97,65 +97,70 @@ const pullFunctions = async ({ code, withVariables }) => {
9797
9898 if (code === false) {
9999 warn("Source code download skipped.");
100- } else if (!func['deployment']) {
101- warn("Source code download skipped because function doesn't have active deployment.");
102- } else {
103- if (allowCodePull === null) {
104- const codeAnswer = await inquirer.prompt(questionsPullFunctionsCode);
105- allowCodePull = codeAnswer.override;
100+ continue;
101+ }
102+
103+ if (allowCodePull === null) {
104+ const codeAnswer = await inquirer.prompt(questionsPullFunctionsCode);
105+ allowCodePull = codeAnswer.override;
106+ }
107+
108+ if (!allowCodePull) {
109+ continue;
110+ }
111+
112+ let deploymentId = null;
113+
114+ try {
115+ const fetchResponse = await functionsListDeployments({
116+ functionId: func['$id'],
117+ queries: [
118+ JSON.stringify({ method: 'limit', values: [1] }),
119+ JSON.stringify({ method: 'orderDesc', values: ['$id'] })
120+ ],
121+ parseOutput: false
122+ });
123+
124+ if (fetchResponse['total'] > 0) {
125+ deploymentId = fetchResponse['deployments'][0]['$id'];
106126 }
107127
108- if (allowCodePull) {
109- log("Pulling active deployment's code ...");
110-
111- let deploymentId = func['deployment'];
112-
113- try {
114- const fetchResponse = await functionsListDeployments({
115- functionId: func['$id'],
116- queries: [
117- JSON.stringify({ method: 'limit', values: [1] }),
118- JSON.stringify({ method: 'orderDesc', values: [''] })
119- ],
120- parseOutput: false
121- });
122-
123- if (fetchResponse['total'] > 0) {
124- deploymentId = fetchResponse['deployments'][0]['$id'];
125- }
126-
127- } catch (e) {
128- log("Can't get last deployment ID, using local value instead")
129- }
130-
131- const compressedFileName = `${func['$id']}-${+new Date()}.tar.gz`
132- await functionsDownloadDeployment({
133- functionId: func['$id'],
134- deploymentId,
135- destination: compressedFileName,
136- overrideForCli: true,
137- parseOutput: false
138- });
139-
140- tar.extract({
141- sync: true,
142- cwd: func['path'],
143- file: compressedFileName,
144- strict: false,
145- });
146-
147- fs.rmSync(compressedFileName);
148-
149- if (withVariables) {
150- const envFileLocation = `${func['path']}/.env`
151- try {
152- fs.rmSync(envFileLocation);
153- } catch {
154- }
155-
156- fs.writeFileSync(envFileLocation, func['vars'].map(r => `${r.key}=${r.value}\n`).join(''))
157- }
128+ } catch {
129+ }
130+
131+ if (deploymentId === null) {
132+ log("Source code download skipped because function doesn't have any available deployment");
133+ continue;
134+ }
135+
136+ log("Pulling latest deployment code ...");
137+
138+ const compressedFileName = `${func['$id']}-${+new Date()}.tar.gz`
139+ await functionsDownloadDeployment({
140+ functionId: func['$id'],
141+ deploymentId,
142+ destination: compressedFileName,
143+ overrideForCli: true,
144+ parseOutput: false
145+ });
146+
147+ tar.extract({
148+ sync: true,
149+ cwd: func['path'],
150+ file: compressedFileName,
151+ strict: false,
152+ });
153+
154+ fs.rmSync(compressedFileName);
155+
156+ if (withVariables) {
157+ const envFileLocation = `${func['path']}/.env`
158+ try {
159+ fs.rmSync(envFileLocation);
160+ } catch {
158161 }
162+
163+ fs.writeFileSync(envFileLocation, func['vars'].map(r => `${r.key}=${r.value}\n`).join(''))
159164 }
160165 }
161166
0 commit comments