8000 🚀 Feature: Function init via CLI with Typescript · Issue #5832 · appwrite/appwrite · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

🚀 Feature: Function init via CLI with Typescript #5832

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
2 tasks done
mbos2 opened this issue Jul 18, 2023 · 9 comments
Open
2 tasks done

🚀 Feature: Function init via CLI with Typescript #5832

mbos2 opened this issue Jul 18, 2023 · 9 comments
Labels
enhancement New feature or request

Comments

@mbos2
Copy link
Contributor
mbos2 commented Jul 18, 2023

🔖 Feature description

As a Typescript user, it would be nice to init a function with a typescript support so we can provide type safety for our appwrite functions.

When we do appwrite init function, add an option to initialize with Typescript.

🎤 Pitch

For all TS users, I guess a typescript support for introducing types and making cloud function error-free regarding types is pretty much desired.

Support for both require and import should be there.

TS files could live in dev folder, for example.
Npm scripts would be

  "scripts": {
    "build": "tsc --build",
    "clean": "tsc --build --clean"
  },

devDependencies in package.json

  "devDependencies": {
    "@types/node": "^20.4.2",
    "typescript": "^5.1.6"
  },

Some basic tsconfig.json example

{
  "compilerOptions": {
    "noImplicitAny": false,
    "noEmitOnError": true,
    "removeComments": false,
    "target": "ESNext",
    "outDir": "src"
  },
  "include": [
    "dev/**/*"
  ]
}

👀 Have you spent some time to check if this issue has been raised before?

  • I checked and didn't find similar issue

🏢 Have you read the Code of Conduct?

@mbos2
Copy link
Contributor Author
mbos2 commented Jul 18, 2023

Here's my tsconfig for imports/exports support

{
  "compilerOptions": {
    "target": "ES2022",
    "module": "CommonJS",
    "outDir": "./src",
    "rootDir": "./dev",
    "strict": true,
    "moduleResolution": "node",
    "esModuleInterop": true
  },
  "include": [
    "dev/**/*"
  ],
  "exclude": ["node_modules"]
}

@mariusbolik
Copy link

Don't forget to add "type": "module" to the package.json file or you get an ERR_REQUIRE_ESM error when using newer npm packages that are using esm imports.

@mbos2
Copy link
Contributor Author
mbos2 commented Jul 24, 2023

Don't forget to add "type": "module" to the package.json file or you get an ERR_REQUIRE_ESM error when using newer npm packages that are using esm imports.

My node version is 18.12.0
I do not have type: module in my package json in my example and it works just fine.

But good point, it should be optimized as best as it can be in case such issue can arise.

@JorensM
Copy link
JorensM commented Sep 6, 2023

I would love to have first-class TS support for Appwrite.

@mbos2
Copy link
Contributor Author
mbos2 commented Sep 23, 2023

Small update on this

With new 1.4.3 functions, I have adjusted my tsconfig.json file

{
  "compilerOptions": {
    "target": "ES2022",
    "module": "ES2022",
    "outDir": "./src",
    "rootDir": "./dev",
    "strict": true,
    "moduleResolution": "node",
    "esModuleInterop": true
  },
  "include": [
    "dev/**/*",
  ],
  "exclude": ["node_modules"]
}

@Ruboka
Copy link
Ruboka commented Nov 23, 2023

I do not understand how to get this to work . I am also not sure where the best place is to create the functions folder from appwrite init function.
Could you write me how your setup looks like and what order of commands is necessary to deploy a function from ts to js onto the server?

@mbos2
Copy link
Contributor Author
mbos2 commented Dec 23, 2023

I do not understand how to get this to work . I am also not sure where the best place is to create the functions folder from appwrite init function. Could you write me how your setup looks like and what order of commands is necessary to deploy a function from ts to js onto the server?

I pinged you on discord about it.
Send me a message there, I'll show you how steps.

My comment and TS stuff is a bit older than what I currently have.

You can check it out https://github.com/mbos2/url-shortener/tree/main/functions/url-shortener.

It's pretty straightforward.
Code inside functions/functonName/dev folder, in inside functions/functionName folder run npm build command, and then from the same root folder run cli command for publishing. Select function and it will publish whatever is in function/functionName/src folder

@mariusbolik
Copy link
mariusbolik commented Dec 24, 2023

For now, my favorite option to use Typescript with Appwrite is to use the Bun runtime.
With Bun there is no need to convert Typescript to JavaScript. You can upload the .ts file directly.

@stnguyen90 stnguyen90 added enhancement New feature or request and removed feature labels Mar 20, 2024
@pedrocarlos-ti
Copy link

Switching to Bun, just as I learn something new, it seems to work fine (hot reload), while Typescript is not doing the same. Thanks @mariusbolik

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

7 participants
0