-
Notifications
You must be signed in to change notification settings - Fork 0
Information for Developers
This page is for the owner/developer of the web app.
- A Github account (create a free account) with a username
- Your organisation's domain-specific settings
- Read and write access to the app code repository
This is required to manage access to the app.
- Open https://console.cloud.google.com/cloud-resource-manager?walkthrough_id=resource-manager--create-project
- Select Create project
-
Project name:
Gsheet Compost Collections
-
Project ID (edit):
gsheet-compost-collections-2
(I use-2
after migrating from my company Google account to a personal Google account)
This involves setting up clasp
then deploying the application code for the project. You can then use this code as-is, or edit it to meet your needs.
- Open the SPREADSHEET
- Open GCC Help > Code > Open Code Repository
- Clone this repository to your local machine: Code > Download ZIP
- Open a Terminal > Navigate to the downloaded folder >
npm install
Application files are stored in this Github repository and hosted in Google Apps Script.
- https://script.google.com/ > Start scripting > Log in
- https://script.google.com/ > New project > Untitled project > type Gsheet Compost Collections
- Project Settings (cog icon) > Show "appsscript.json" manifest file in editor
-
Project Settings (cog icon) > Script ID > Copy (this is the same ID as shown in the URL i.e.
https://script.google.com/home/projects/{ID}
)
The web app reads and writes from a Google Sheet. Google Apps Script offers the choice of a 'container-bound' (spreadsheet linked) or 'standalone' project.
The main script is authored as a 'standalone' project (created at script.google.com
rather than via sheets.google.com
). This facilitates testing across different spreadsheets and allows the project to be reused as an Apps Script library.
Additional container-bound scripts are used for configuration purposes.
Application code may be edited and deployed using the Apps Script project IDE (https://script.google.com/ > My Projects > Gsheet Search > Editor), which is similar to VSCode.
However it is recommended to use a local development environment in conjunction with Clasp (Command Line Apps Script Projects), via the NPM scripts. This simplifies some aspects of development, allows the code to be checked into version control (i.e. this repo) and ensures that any changes are packaged correctly (using the NPM scripts to run additional scripts before the clasp
scripts).
This Medium article about clasp outlines the benefits of using Clasp.
- Open
.clasp.json
(the Clasp configuration file)- set the
scriptId
to the value copied from the Project Settings in 2b. Create an Apps Script project - set the
projectId
to the value used in 1. Set up a Google Cloud Project (npx clasp setting projectId YOUR_PROJECT_ID
does the same thing)
- set the
- Enable the Apps Script API: https://script.google.com/home/usersettings
- Open https://console.developers.google.com/apis/credentials/consent?project=YOUR_PROJECT_ID (Edit app registration: OAuth consent screen)
-
App information
-
User Type:
External
(orInternal
if that suits you better, see alsoInformation-for-Administrators.md > App users - share the GCP PROJECT
) -
App name:
Gsheet Compost Collections
(this would be seen by any end user trying to load the library Web App URL directly, for the first time) - User support email: select your email from the list
- App logo: - (no logo to upload)
-
User Type:
-
App domain
-
Application home page:
https://github.com/dotherightthing/gsheet-compost-collections
-
Application privacy policy link:
https://github.com/dotherightthing/gsheet-compost-collections
-
Application Terms of Service link:
https://github.com/dotherightthing/gsheet-compost-collections
-
Authorised domains:
github.com
-
Application home page:
- Developer contact information: enter your email
-
App information
- Project Settings (cog icon) > Google Cloud Platform (GCP) Project > Change project > (Enter GCP project number) > Set project (if you lose your Project number you can retrieve it from https://console.cloud.google.com/home/dashboard?project=YOUR_PROJECT_ID)
- Open https://console.cloud.google.com/apis/credentials?project=YOUR_PROJECT_ID > Create credentials > OAuth client ID
-
Application type:
Desktop App
-
Name:
Gsheet Compost Collections OAuth Client
- Download the JSON credentials file to the project directory as
creds.json
-
Application type:
- Open a Terminal, navigate to the folder downloaded in 2a. Download the app files then run
npx clasp login
(this will log you in globally - don't runnpx clasp login --creds creds.json
) - Open
package.json
and changeconfig.headDeploymentId
to the value of Deploy > Test deployments > Head Deployment ID
npm run push
- At
? Manifest file has been updated. Do you want to push and overwrite? (y/N)
typey
(Yes)
The main application code is consumed as a library rather than accessed directly from a URL.
Deployment allows new versions to be added to the standalone library.
Container-bound scripts can then choose to load the development version of the library (HEAD
) or a specific numbered version.
This protects users by allowing them to use an older version of the app library while new features are being developed.
The initial deployment must be done from the IDE:
- Deploy > New deployment
- Select type:
Web app
- Description:
Initial deployment
- Execute as:
User accessing the web app
- Who has access:
Only myself
- Deploy
Thereafter, deployments can be managed from the commandline:
# Update the STABLE BUILD
npm run publish --gccmessage="VERSION_DESCRIPTION"
This updates and opens the latest STABLE APP (TODO using the old version of the library).
- Open the container-bound Apps Script project (see 4. Set up the container-bound Apps Script project)
- Open
appsscript.json
- Change
dependencies.libraries.version
to the deployed library version (integer) - Save changes
- Open spreadsheet (see 3. Create a spreadsheet) > GCC Help > Mobile App > Open STABLE App
The app uses a spreadsheet as its database and for limited configuration.
- Spreadsheet > Settings > Locale > United Kingdom
Specific Named Ranges must be added to demarcate rows and cells for processing by the script.
This is attached to the spreadsheet.
It loads the standalone Apps Script project as a library.
It is used to configure the standalone application.
It provides a custom spreadsheet menu and access to the Web App.
- See instructions in https://github.com/dotherightthing/gsheet-compost-collections/tree/main/demo
Get the latest code from the server, to capture changes from any developers not using the Github repo.
Note: You will need to manually copy the internals of src/Htmlified
files to the corresponding originals in src/Classes
.
npx clasp pull
Code execution can be tested by directly calling the serverside functions contained in Main
and Middleware.js
.
This is a great way to get developer-friendly error messages, rather than the user-friendly ones provided in-app.
Due to issue #1, this requires jumping over to the online development environment.
npm run openEditor
# 'Select function to run' from the dropdown:
# doGet - tests the template generation
# Click 'Run'
A Husky Git Hook triggers the following tasks whenever code is pushed to Github:
- linting of CSS files
- linting of JavaScript files
- rebuild of the JavaScript documentation (MANual)
Tests can't be run from the standalone app, as they require a data source (spreadsheet) and associated app configuration (Apps Script project).
Tests should be run from the spreadsheet menu instead:
- Frontend tests: GCC Help > Code > Run Unit Tests
- Backend tests: GCC Help > Code > Run Integration Tests
Both will run tests on the latest code (aka the TEST BUILD).
Testing on different data sources can be performed by adding additional spreadsheets, each with their own container-bound Apps Script configuration.
Data manipulation can be verified by viewing the SPREADSHEET.
Visual and interactive testing requires viewing the web app.
# EITHER: Update the TEST BUILD then automatically open the web app
npm run openPreview
# OR: Update the TEST BUILD then manually open/refresh the web app
# Note! Do not run `npx clasp push` directly, as this bypasses extra steps which the app must perform on push
npm run push
This updates and opens the latest DEV APP.
This allows changes to be tested without impacting the STABLE APP.
Note: In the online IDE, this Web app URL is accessed under Test deployments.
- Set
appConfig.debug: true
inMain.js
- Use
console.log
to temporarily output strings and variable values - Or for permanent logging:
const { debug } = KrmCache.settings; if (debug) { console.log('foo'); }
- Open the APPS SCRIPT PROJECT > Click Executions > Click on any script execution to view its logs
- Or open the DEV APP > Click DEBUG in the footer
The initial deployment must be done from the IDE: Deploy > New deployment.
Thereafter, deployments can be managed from the commandline:
# Update the STABLE BUILD
npm run publish --gccmessage="VERSION_DESCRIPTION"
This removes the QUnitGS2 integration testing dependency, then updates and opens the latest STABLE APP.
- Open the APPS SCRIPT PROJECT
- Open
appsscript.json
- Change
dependencies.libraries.version
to the deployed version (integer) - Save changes
The MANual is generated from JSDoc comments in the sourcecode (Local development only).
The good functioning of the app is dependent on the structure of the source spreadsheet being maintained.
Brittleness is mitigated somewhat by referencing Named Ranges and strings/labels:
- Column headers - Row and column containing header strings
- Run range - e.g. Row containing "MT VIC RUN", down to the row containing "MT COOK RUN"
When a test fails to load, or fails to run, or fails unexpectedly, Qunit won't usually offer any useful feedback. In this case:
- run unit and integration tests
- check that the tested static method doesn't access
this
- check that the test targets the correct testing function (i.e. that the method exists for a particular class)
- navigate through the app and watch for load error messages
- open the web browser's developer console and watch for errors there
- wait a minute then refresh the page
- run the tests from Tests/Integration.gs - then view the Executions log