Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion specs/swagger-appwrite-0.13.0.json

Large diffs are not rendered by default.

25 changes: 19 additions & 6 deletions templates/node-cli/lib/commands/init.js.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const fs = require("fs");
const path = require("path");
const childProcess = require('child_process');
const { Command } = require("commander");
const inquirer = require("inquirer");
Expand Down Expand Up @@ -59,10 +60,14 @@ const initFunction = async () => {
throw new Error(`( ${answers.name} ) already exists in the current directory. Please choose another name.`);
}

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

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

Expand All @@ -72,21 +77,29 @@ const initFunction = async () => {
git init && \
git remote add -f origin https://github.com/{{ sdk.gitUserName }}/functions-starter && \
git config core.sparseCheckout true && \
echo '${answers.runtime}' >> .git/info/sparse-checkout && \
git pull origin main && \
echo '${answers.runtime.id}' >> .git/info/sparse-checkout && \
git pull origin dev && \
git checkout dev && \
rm -rf .git && \
mv ${answers.runtime}/* . && \
rm -rf ${answers.runtime}`;
mv ${answers.runtime.id}/* . && \
rm -rf ${answers.runtime.id}`;

// Execute the child process but do not print any std output
childProcess.execSync(command, { stdio: 'pipe' });

const readmePath = path.join(process.cwd(), answers.name, 'README.md');
const readmeFile = fs.readFileSync(readmePath).toString();
const newReadmeFile = readmeFile.split('\n');
newReadmeFile[0] = `# ${answers.name}`;
newReadmeFile.splice(1, 2);
fs.writeFileSync(readmePath, newReadmeFile.join('\n'));

let data = {
$id: response['$id'],
name: response['name'],
runtime: response['runtime'],
path: answers.name,
command: ''
entrypoint: answers.runtime.entrypoint || ''
};

localConfig.addFunction(data);
Expand Down
27 changes: 26 additions & 1 deletion templates/node-cli/lib/questions.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,31 @@ const { localConfig } = require('./config');
const { projectsList } = require('./commands/projects');
const { functionsListRuntimes } = require('./commands/functions');

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

switch (languge) {
case 'dart':
return 'lib/main.dart';
case 'deno':
return 'src/mod.ts';
case 'node':
return 'src/index.js';
case 'php':
return 'src/index.php';
case 'python':
return 'src/index.py';
case 'ruby':
return 'src/index.rb';
case 'rust':
return 'main.rs';
case 'swift':
return 'Sources/swift-5.5/main.swift';
}

return undefined;
};

const questionsInitProject = [
{
type: "confirm",
Expand Down Expand Up @@ -92,7 +117,7 @@ const questionsInitFunction = [
let choices = runtimes.map((runtime, idx) => {
return {
name: `${runtime.name} (${runtime['$id']})`,
value: runtime['$id']
value: { id: runtime['$id'], entrypoint: getEntrypoint(runtime['$id'])}
}
})
return choices;
Expand Down