{"id":26403544,"url":"https://github.com/fossamagna/google-script-dts-generator","last_synced_at":"2025-03-17T15:34:21.178Z","repository":{"id":37951204,"uuid":"253370674","full_name":"fossamagna/google-script-dts-generator","owner":"fossamagna","description":"Generate TypeScript declaration (.d.ts) file for google.script.run(Client-side API).","archived":false,"fork":false,"pushed_at":"2025-01-03T06:59:03.000Z","size":897,"stargazers_count":6,"open_issues_count":13,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-04T14:52:53.541Z","etag":null,"topics":["apps-script","typescript"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fossamagna.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-06T01:48:21.000Z","updated_at":"2024-05-04T13:31:02.000Z","dependencies_parsed_at":"2023-10-03T03:52:41.822Z","dependency_job_id":"a64feb29-34e4-492f-a598-2551621812ea","html_url":"https://github.com/fossamagna/google-script-dts-generator","commit_stats":{"total_commits":183,"total_committers":5,"mean_commits":36.6,"dds":"0.24590163934426235","last_synced_commit":"7e3b7f0d03e4e631316b8379124baf7c500466ad"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fossamagna%2Fgoogle-script-dts-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fossamagna%2Fgoogle-script-dts-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fossamagna%2Fgoogle-script-dts-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fossamagna%2Fgoogle-script-dts-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fossamagna","download_url":"https://codeload.github.com/fossamagna/google-script-dts-generator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244058701,"owners_count":20391151,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["apps-script","typescript"],"created_at":"2025-03-17T15:34:18.530Z","updated_at":"2025-03-17T15:34:21.173Z","avatar_url":"https://github.com/fossamagna.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# google-script-dts-generator [![NPM version][npm-image]][npm-url]\n\nGenerate TypeScript declaration (.d.ts) file for [google.script.run](https://developers.google.com/apps-script/guides/html/reference/run)(Client-side API).\n\n## About\n\n`google-script-dts-generator` generates a client-side TypeScript declaration (.d.ts) for the Apps Script function from a server-side TypeScript source that matchs the following conditions:\n\n* function assignment expressions to `global` object. \n* named export functions (when using `namedExportsFiles` option)\n\n## Example\n\nSee [example](./example).\n\nserver.ts:\n```ts\nglobal.echo = (message: string) =\u003e {\n  return message;\n};\n```\n\ngenerate:\n\n```sh\n$ google-script-dts-generator --sourcesDir server/ --outputDir client/\n```\n\ngenerated `google-script.d.ts`:\n```ts\ndeclare namespace google {\n    /**\n     * Methods available to Google Apps Script\n     */\n    namespace script {\n        interface IRun {\n            echo(message: string): void;\n            /**\n             * Sets a callback function to run if the server-side function throws an exception. Without a failure handler, failures are logged to the JavaScript console. To override this, call withFailureHandler(null) or supply a failure handler that does nothing.\n             * @param callback a client-side callback function to run if the server-side function throws an exception; the Error object is passed to the function as the first argument, and the user object (if any) is passed as a second argument\n             */\n            withFailureHandler(callback: (error: Error, object?: any)=\u003evoid): IRun;\n            /**\n             * Sets a callback function to run if the server-side function returns successfully.\n             * @param callback a client-side callback function to run if the server-side function returns successfully; the server's return value is passed to the function as the first argument, and the user object (if any) is passed as a second argument\n             */\n            withSuccessHandler(callback: (value: any, object?: any)=\u003evoid): IRun;\n            /**\n             * Sets an object to pass as a second parameter to the success and failure handlers.\n             * @param {Object} object an object to pass as a second parameter to the success and failure handlers; because user objects are not sent to the server, they are not subject to the restrictions on parameters and return values for server calls. User objects cannot, however, be objects constructed with the new operator\n             */\n            withUserObject(object: object): IRun;\n        }\n        \n        const run: IRun;\n\n        // omitted below\n}\n```\n\n## Installation\n\n```sh\n$ npm install google-script-dts-generator --save-dev\n```\n\nor \n\n```\n$ yarn add google-script-dts-generator\n```\n\n## Usage\n\n### CLI\n\n```sh\n$ google-script-dts-generator --sourcesDir server --outputDir client\n```\n\n### Options\n\n* [`--sourcesDir \u003csources\u003e`](#--sourcesDir-sources)\n* [`--outputDir \u003coutputDir\u003e`](#--outputDir-outputDir)\n* [`--namedExportsFiles \u003cglob\u003e`](#--namedExportsFiles-glob)\n* [`--endpointsOnly`](#--endpointsOnly)\n* [`--nonVoidReturnType`](#--nonVoidReturnType)\n\n#### `--sourcesDir \u003csources\u003e`\n\nPath to TypeScript sources directory.\n\n```sh\n$ google-script-dts-generator --outputDir ./example/client --sourcesDir ./example/server\n```\n\n#### `--outputDir \u003coutputDir\u003e`\n\nPath to a generated `d.ts` file output directory.\n\n```sh\n$ google-script-dts-generator --outputDir ./example/client --sourcesDir ./example/server\n```\n\n#### `--namedExportsFiles \u003cglob\u003e`\n\nA glob path pattern to generates a client-side TypeScript declaration (.d.ts) from named exports.  \n**Note**: Glob patterns should always use / as a path separator, even on Windows systems\n\n```sh\n$ google-script-dts-generator --outputDir ./example/client --sourcesDir ./example/server --namedExportsFiles './example/server/**/*.ts'\n```\n\n#### `--endpointsOnly`\n\nWhen use [@types/google.script.client-side](https://www.npmjs.com/package/@types/google.script.client-side), User needs define specify functions as PublicEndpoints.\ngoogle-script-dts-generator support generate only PublicEndpoint interfaces.\n\n```\nyarn google-script-dts-generator -s ./src/server/ -o ./src/client/ --namedExportsFiles \"./src/server/**/*.ts\" --endpointsOnly\n```\n\nOutput:\n```ts\ndeclare namespace google {\n  namespace script {\n    interface PublicEndpoints {\n        doGet(): void;\n        myFunction(param1: string, param2: boolean): void;\n    }\n  }\n}\n```\n\n#### `--nonVoidReturnType`\n\ngenerate return type of server-side function as return type of client-side function.\nThis option assumed that using in combination with [gas-client](https://www.npmjs.com/package/gas-client).\n\n\u003e Note: Use gas-client@1.0.0-pr.2 or later\n\n```\nyarn google-script-dts-generator -s ./src/server/ -o ./src/client/ --namedExportsFiles \"./src/server/**/*.ts\" --endpointsOnly --nonVoidReturnType\n```\n\nOutput:\n```ts\ndeclare namespace google {\n    /**\n     * Methods available to Google Apps Script\n     */\n    namespace script {\n        interface PublicEndpoints {\n            helloWorld(): string;\n            echo(message: string): string;\n        }\n    }\n}\n```\n\nclient.ts\n```ts\nimport { GASClient } from 'gas-client';\n\nconst { serverFunctions } = new GASClient\u003cgoogle.script.PublicEndpoints\u003e();\nserverFunctions.echo(\"hello gas\")\n    .then((s) =\u003e console.log(s))\n    .catch(e =\u003e console.error(e));\n```\n\n[npm-image]: https://badge.fury.io/js/google-script-dts-generator.svg\n[npm-url]: https://npmjs.org/package/google-script-dts-generator","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffossamagna%2Fgoogle-script-dts-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffossamagna%2Fgoogle-script-dts-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffossamagna%2Fgoogle-script-dts-generator/lists"}