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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,4 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
.idea
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "polyapi",
"version": "0.23.8",
"version": "0.23.9",
"description": "Poly is a CLI tool to help create and manage your Poly definitions.",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ void yargs
return;
}
const { addOrUpdateCustomFunction } = await import('./commands/function');
await addOrUpdateCustomFunction(DEFAULT_POLY_PATH, context, name, description, file, server, logsEnabled, generateContexts, executionApiKey);
await addOrUpdateCustomFunction(DEFAULT_POLY_PATH, context, name, description, file, client, server, logsEnabled, generateContexts, executionApiKey);
},
);
})
Expand Down
24 changes: 19 additions & 5 deletions src/commands/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const addOrUpdateCustomFunction = async (
name: string,
description: string | null,
file: string,
client: boolean | undefined,
server: boolean | undefined,
logsEnabled: boolean | undefined,
generateContexts: string | undefined,
Expand All @@ -38,10 +39,21 @@ export const addOrUpdateCustomFunction = async (
const specs = await getSpecs([context], [name]);
const functionSpec = specs.find(spec => spec.name === name && spec.context === context);
const updating = !!functionSpec;
if (server === undefined && updating) {
server = functionSpec.type === 'serverFunction';
} else {
server = server ?? false;
if (updating) {
const isConflictingType =
(client === true && functionSpec.type === 'serverFunction') ||
(server === true && functionSpec.type === 'customFunction');

if (isConflictingType) {
const existingType = functionSpec.type === 'serverFunction' ? 'server' : 'client';
const targetType = existingType === 'server' ? 'client' : 'server';

shell.echo(
chalk.redBright(`ERROR: Function already exists as a ${existingType} function.`) + '\n' +
chalk.red(`Please delete it before deploying as a ${targetType} function.`),
);
return;
}
}

const typeSchemas = generateTypeSchemas(file, tsConfigBaseUrl, DeployableTypeEntries.map(d => d[0]));
Expand Down Expand Up @@ -69,7 +81,9 @@ export const addOrUpdateCustomFunction = async (
shell.echo(chalk.green('DEPLOYED'));

shell.echo(`Function ID: ${customFunction.id}`);
} else {
}

if (client) {
shell.echo('-n', `${updating ? 'Updating' : 'Adding'} Client Function to PolyAPI Catalog...`);
customFunction = await createOrUpdateClientFunction(context, name, description, code, typeSchemas);
shell.echo(chalk.green('DONE'));
Expand Down
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import dotenv from 'dotenv';

const getPolyConfigDirPath = (polyPath: string) =>
// If path does not start with `./` or `/` then we adjust!
/^\.?\/.*/.test(polyPath) ? polyPath : `${__dirname}/../../../../../${polyPath}`;
/^\.?\/.*/.test(polyPath) ? polyPath : `${__dirname}/../../../${polyPath}`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify the purpose of this one? I know we were doing this odd path munging to handle the difference when running locally vs running on the server. Just want to be sure we're not breaking something. 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously we have this client project under packages folder.

Then we need to go up 2 more steps.

Now We don't need this.

You can check it by publishing locally.

It's not find the .config.env file in that path

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!


const getPolyConfigFilePath = (polyPath: string) =>
`${getPolyConfigDirPath(polyPath)}/.config.env`;
Expand Down