Use command line to get spreadsheet data, sanitize it and save the result as a JSON file to google cloud storage.
We use this tool to update about us page.
- Make sure the target spreadsheet is publishly viewable to the web, using
File -> Publish To Web
in your Google Spreadsheet. - This package need google sheet api key & google cloud storage admin service account key file for auth.
- get google sheet api key from credentail page
- store api key in .env file with key name API_KEY
- get service account key file in GCP console
- store key file path in .env file with key name GOOGLE_APPLICATION_CREDENTIALS
- you can also auth cloud storage with other methods
// --help
$ about-us --help
Options:
--id <spreadsheet> google spreadsheet id (default: "16CVkhaSw5sxwjlSt1c0nLzxG7qzEmeO2gCymVsSY6PE"), required
--sheetName <name> target sheet name (default: "test"), required
--section <index> section index number (default: "5"), required
--branch <branch> git branch (one of "master", "staging", "release") (default: "master")
-h, --help display help for command
--section index will be used in two place:
- determine whether to group data or not (config-regulater)
- upload filename: section
..json
--section parameter should be corresbond with --sheetName parameter
$ about-us --section 2 --sheetName section-2 --branch master
When it is done, a new config file section2.master.json
will be uploaded to gcs and replace the old one.
This file is required by about us page.
$ about-us --section 3 --sheetName section-3 --branch release
When it is done, a new config file section3.release.json
will be uploaded to gcs and replace the old one.
There are one section to the returned data: Rows (containing each row of data as an object.)
{
rows: [
{
name: "Nick",
age: "21"
},
{
name: "Chris ",
age: "27"
},
{
name: "Barry",
age: "67"
}
]
}