Skip to content

Commit

Permalink
fix: updates for functions g4
Browse files Browse the repository at this point in the history
  • Loading branch information
christyjacob4 committed Sep 8, 2023
1 parent 8edf1b8 commit daa1981
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 15 deletions.
13 changes: 11 additions & 2 deletions lib/commands/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,14 @@ const deployFunction = async ({ functionId, all, yes } = {}) => {
functionId: func['$id'],
name: func.name,
execute: func.execute,
vars: JSON.stringify(response.vars),
events: func.events,
schedule: func.schedule,
timeout: func.timeout,
enabled: func.enabled,
logging: func.logging,
entrypoint: func.entrypoint,
commands: func.commands,
vars: JSON.stringify(response.vars),
parseOutput: false
});
} catch (e) {
Expand All @@ -220,10 +224,14 @@ const deployFunction = async ({ functionId, all, yes } = {}) => {
name: func.name,
runtime: func.runtime,
execute: func.execute,
vars: JSON.stringify(func.vars),
events: func.events,
schedule: func.schedule,
timeout: func.timeout,
enabled: func.enabled,
logging: func.logging,
entrypoint: func.entrypoint,
commands: func.commands,
vars: JSON.stringify(func.vars),
parseOutput: false
});

Expand Down Expand Up @@ -292,6 +300,7 @@ const deployFunction = async ({ functionId, all, yes } = {}) => {
response = await functionsCreateDeployment({
functionId: func['$id'],
entrypoint: func.entrypoint,
commands: func.commands,
code: func.path,
activate: true,
parseOutput: false
Expand Down
15 changes: 12 additions & 3 deletions lib/commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,16 @@ const initFunction = async () => {
log(`Entrypoint for this runtime not found. You will be asked to configure entrypoint when you first deploy the function.`);
}

if (!answers.runtime.commands) {
log(`Installation command for this runtime not found. You will be asked to configure the install command when you first deploy the function.`);
}

let response = await functionsCreate({
functionId: answers.id,
name: answers.name,
runtime: answers.runtime.id,
entrypoint: answers.runtime.entrypoint || '',
commands: answers.runtime.commands || '',
parseOutput: false
})

Expand Down Expand Up @@ -138,13 +144,16 @@ const initFunction = async () => {
$id: response['$id'],
name: response.name,
runtime: response.runtime,
path: `functions/${answers.name}`,
entrypoint: answers.runtime.entrypoint || '',
ignore: answers.runtime.ignore || null,
execute: response.execute,
events: response.events,
schedule: response.schedule,
timeout: response.timeout,
enabled: response.enabled,
logging: response.logging,
entrypoint: response.entrypoint,
commands: response.commands,
ignore: answers.runtime.ignore || null,
path: `functions/${answers.name}`,
};

localConfig.addFunction(data);
Expand Down
55 changes: 45 additions & 10 deletions lib/questions.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,57 @@ const getEntrypoint = (runtime) => {
case 'dart':
return 'lib/main.dart';
case 'deno':
return 'src/mod.ts';
return 'src/main.ts';
case 'node':
return 'src/index.js';
return 'src/main.js';
case 'php':
return 'src/index.php';
case 'python':
return 'src/index.py';
return 'src/main.py';
case 'ruby':
return 'src/index.rb';
return 'lib/main.rb';
case 'rust':
return 'main.rs';
case 'swift':
return 'Sources/swift-5.5/main.swift';
return 'Sources/index.swift';
case 'cpp':
return 'src/index.cc';
return 'src/main.cc';
case 'dotnet':
return 'src/Index.cs';
case 'java':
return 'src/Index.java';
return 'src/Main.java';
case 'kotlin':
return 'src/Index.kt';
return 'src/Main.kt';
}

return undefined;
};

const getInstallCommand = (runtime) => {
const languge = runtime.split('-')[0];

switch (languge) {
case 'dart':
return 'dart pub get';
case 'deno':
return "deno install";
case 'node':
return 'npm install';
case 'php':
return 'composer install';
case 'python':
return 'pip install -r requirements.txt';
case 'ruby':
return 'bundle install';
case 'rust':
return 'cargo install';
case 'dotnet':
return 'dotnet restore';
case 'swift':
case 'java':
case 'kotlin':
case 'cpp':
return '';
}

return undefined;
Expand Down Expand Up @@ -171,10 +201,15 @@ const questionsInitFunction = [
parseOutput: false
})
let runtimes = response["runtimes"]
let choices = runtimes.map((runtime, idx) => {
let choices = runtimes.map((runtime, idx) => {
return {
name: `${runtime.name} (${runtime['$id']})`,
value: { id: runtime['$id'], entrypoint: getEntrypoint(runtime['$id']), ignore: getIgnores(runtime['$id']) },
value: {
id: runtime['$id'],
entrypoint: getEntrypoint(runtime['$id']),
ignore: getIgnores(runtime['$id']),
commands : getInstallCommand(runtime['$id'])
},
}
})
return choices;
Expand Down

0 comments on commit daa1981

Please sign in to comment.