“大型代码库”的定义是主观的,但即使是具有数百行代码的项目也可以从组织中受益。在 IDE 中,您有两个主要工具可用于帮助组织代码:文件和图书馆 https://developers.google.com/apps-script/guide_libraries.
该答案主要是指向其他答案的链接的集合,这些答案位于多个主题领域内,应解决您所表达的担忧。
代码组织和库
脚本项目可以有多个类型为“gs”(脚本)或“html”的文件。命名空间扩展到项目中的所有脚本文件。将方法分离到文件中是一种在项目中组织代码的简单方法(例如,将所有测试放在与生产代码分开的一个文件中),尽管它对于跨项目的可重用性作用很小。
图书馆 https://developers.google.com/apps-script/guide_libraries是为了让其他项目能够合并其功能而无需复制实际代码而发布的项目。看看著名的脚本库 https://developers.google.com/apps-script/notable-script-libraries作为一个开始。库从库名称中获取名称空间 - 例如,我有一个与 CSV 文件的输入和输出相关的实用程序库,我(巧妙地)将其命名为 CSVUtils。该库中的方法的访问方式为CSVUtils.example()
,并受自动完成功能的支持。库支持 jsdoc 的有限子集,并且在发布时提供指向生成的文档的链接。
在多个 *.gs 文件中组织电子表格代码 - 甚至可能吗? https://stackoverflow.com/questions/11725675/organizing-spreadsheet-code-in-several-gs-files-even-possible
是否可以为多个电子表格使用一个脚本? https://stackoverflow.com/questions/10500764/is-it-possible-to-have-one-script-for-multiple-spreadsheets
如何或在何处定义在多个电子表格中使用的函数? https://stackoverflow.com/questions/13082260/how-or-where-do-i-define-a-function-for-use-in-more-than-one-spreadsheet
google-apps-script 在一个电子表格中有多个脚本 https://stackoverflow.com/questions/10964932/google-apps-script-have-multiple-scripts-in-one-spreadsheet
在 Google Apps 脚本库中创建类似命名空间的组织 https://stackoverflow.com/questions/10890177/creating-a-namespace-like-organization-in-a-google-apps-script-library
发布 Google Apps 脚本库 https://stackoverflow.com/questions/10860533/publishing-a-google-apps-script-library
GAS 中库的设计模式? https://stackoverflow.com/questions/13575942/design-patterns-for-libraries-in-gas
WebApp 访问库中的 ScriptDb https://stackoverflow.com/questions/13113564/scriptdb-in-library-accessed-by-webapp
项目和多个 doGet() 脚本文件发布为 Web 应用程序 - 需要澄清 https://stackoverflow.com/questions/12268539/project-and-multiple-doget-script-files-published-as-web-apps-need-clarific
... 关于 Apps 脚本库的每个 SO 问题 https://stackoverflow.com/search?q=%5Bgoogle-apps-script%5D%20library.
使用外部 JavaScript 库:
从通读开始了解 Caja 消毒 https://developers.google.com/apps-script/html_service#Caja,特别是有关外部 JavaScript 库的部分。
Google Apps 脚本:如何在 HtmlService 中使用 js 库 https://stackoverflow.com/questions/13679377/google-apps-script-how-can-use-js-library-in-htmlservice
授权和所有权
授权 -Google Apps 脚本在首次运行时授予用户访问电子表格上的服务的权限,而无需打开脚本编辑器 https://stackoverflow.com/questions/13046705/google-apps-script-grant-user-permissions-access-services-on-spreadsheet-in-ther
https://stackoverflow.com/questions/15096379/google-app-scripts-how-to-let-shared-users-run-scripts-as-themselves https://stackoverflow.com/questions/15096379/google-app-scripts-how-to-let-shared-users-run-scripts-as-themselves
Google 何时需要重新验证? https://stackoverflow.com/questions/12354602/when-does-google-require-re-authentication
Google Apps 脚本库中的 OAuth https://stackoverflow.com/questions/11905481/oauth-in-google-apps-scripts-libraries
代码透明度
WebApps 使用的库的源代码对每个人都可见? https://stackoverflow.com/questions/13741173/source-code-of-libraries-used-by-webapps-visible-to-everybody
如何以Google方式隐藏库源代码? https://stackoverflow.com/questions/11915118/how-to-hide-library-source-code-in-google-way