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.

32 changes: 26 additions & 6 deletions templates/cli/lib/commands/deploy.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { Command } = require("commander");
const { localConfig } = require("../config");
const { questionsDeployFunctions, questionsGetEntrypoint, questionsDeployCollections } = require("../questions");
const { actionRunner, success, log, error, commandDescriptions } = require("../parser");
const { functionsGet, functionsCreate, functionsCreateDeployment, functionsUpdateDeployment } = require('./functions');
const { functionsGet, functionsCreate, functionsUpdate, functionsCreateDeployment, functionsUpdateDeployment } = require('./functions');
const {
databaseCreateBooleanAttribute,
databaseGetCollection,
Expand Down Expand Up @@ -154,19 +154,39 @@ const deployFunction = async () => {
log(`Deploying function ${func.name} ( ${func['$id']} )`)

try {
await functionsGet({
response = await functionsGet({
functionId: func['$id'],
parseOutput: false,
})
});

if(response.runtime !== func.runtime) {
throw new Error(`Runtime missmatch! (local=${func.runtime},remote=${response.runtime}) Please delete remote function or update your appwrite.json`);
}

response = await functionsUpdate({
functionId: func['$id'],
name: func.name,
execute: func.execute,
vars: func.vars,
events: func.events,
schedule: func.schedule,
timeout: func.timeout,
parseOutput: false
});
} catch (e) {
if (e.code == 404) {
log(`Function ${func.name} ( ${func['$id']} ) does not exist in the project. Creating ... `);
response = await functionsCreate({
functionId: 'unique()',
functionId: func.$id || 'unique()',
name: func.name,
runtime: func.runtime,
execute: func.execute,
vars: func.vars,
events: func.events,
schedule: func.schedule,
timeout: func.timeout,
parseOutput: false
})
});

localConfig.updateFunction(func['$id'], {
"$id": response['$id'],
Expand All @@ -191,7 +211,7 @@ const deployFunction = async () => {
functionId: func['$id'],
entrypoint: func.entrypoint,
code: func.path,
deploy: true,
activate: true,
parseOutput: false
})

Expand Down
21 changes: 13 additions & 8 deletions templates/cli/lib/commands/init.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const initProject = async () => {
const initFunction = async () => {
let answers = await inquirer.prompt(questionsInitFunction)

if (fs.existsSync(answers.name)) {
if (fs.existsSync(path.join(process.cwd(), 'functions', answers.name))) {
throw new Error(`( ${answers.name} ) already exists in the current directory. Please choose another name.`);
}

Expand All @@ -72,8 +72,8 @@ const initFunction = async () => {
})

let command = `
mkdir -m 777 -p '${answers.name}' && \
cd '${answers.name}' && \
mkdir -m 777 -p 'functions/${answers.name}' && \
cd 'functions/${answers.name}' && \
git init && \
git remote add -f origin https://github.com/{{ sdk.gitUserName }}/functions-starter && \
git config core.sparseCheckout true && \
Expand All @@ -87,7 +87,7 @@ const initFunction = async () => {
// 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 readmePath = path.join(process.cwd(), 'functions', answers.name, 'README.md');
const readmeFile = fs.readFileSync(readmePath).toString();
const newReadmeFile = readmeFile.split('\n');
newReadmeFile[0] = `# ${answers.name}`;
Expand All @@ -96,10 +96,15 @@ const initFunction = async () => {

let data = {
$id: response['$id'],
name: response['name'],
runtime: response['runtime'],
path: answers.name,
entrypoint: answers.runtime.entrypoint || ''
name: response.name,
runtime: response.runtime,
path: `functions/${answers.name}`,
entrypoint: answers.runtime.entrypoint || '',
execute: response.execute,
vars: response.vars,
events: response.events,
schedule: response.schedule,
timeout: response.timeout,
};

localConfig.addFunction(data);
Expand Down