1.0.16 • Published 2 years ago

@joyining/gsheet-helper v1.0.16

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

gsheet-helper

gsheet-helper generates multiple json files based on your Google sheets. It helps you to transfer data into json format.

Installation

npm i @joyining/gsheet-helper --save-dev

Usage from command line

Create a gsheet.config.js under root folder, following the below example:

module.exports = {
  docID: '',
  credentialsPath: '',
  sheets: [
    {
      sheetID: '',
      files: [
        {
          prefix: '',
          keyColumns: [],
          valueColumns: [],
          filePath: ''
        },
        {
          prefix: '',
          keyColumns: [],
          valueColumns: [],
          filePath: ''
        },
      ],
    },
  ],
}
KeyDescription
docIDrequired, Google sheet document ID.
credentialsPathoptional, the path for credential to access the Google sheet. It takes credentials.json under root folder as the default credential path.
sheetsrequired, specify the target sheets.
sheetIDrequired, Google sheet sheet ID.
filesrequired, specify expected results.
prefixoptional, the prefix before key string, default is empty string.
keyColumnsrequired, the columns to concatenate key.
valueColumnsoptional, the columns to concatenate value, default is empty string.
filePathrequired, the path and file name for the generated file.

Custom a script in package.json:

"scripts": {
  "sync": "gsheet-helper"
},

gsheet-helper will take gsheet.config.js under root folder as the default config. If your config is not named as gsheet.config.js, please specify the file name in the command, for example:

"scripts": {
  "sync": "gsheet-helper my.gsheet.config.js"
},

Run script and check if json files are generated.

npm run sync

Examples

Input

You have a 3-column Google sheet containing translations for some words: | en | zh | ja | | -------- | ------- | -------------- | | Engineer | 工程師 | エンジニア | | Homepage | 首頁 | ホームページ | | Frontend | 前端 | フロントエンド | | Backend | 後端 | バックエンド |

// gsheet.config.js
module.exports = {
  docID: 'XXXXX',
  credentialsPath: 'myCredential.json',
  sheets: [
    {
      sheetID: 'YYYYY',
      files: [
        {
          prefix: '_',
          keyColumns: ['en'],
          valueColumns: ['zh'],
          filePath: 'zh.json'
        },
        {
          prefix: '_',
          keyColumns: ['en'],
          valueColumns: ['ja'],
          filePath: 'ja.json'
        },
      ],
    },
  ],
}

Output

Two json files:

// zh.json
{
  "_Engineer": "工程師",
  "_Homepage": "首頁",
  "_Frontend": "前端",
  "_Backend": "後端"
}
// ja.json
{
  "_Engineer": "エンジニア",
  "_Homepage": "ホームページ",
  "_Frontend": "フロントエンド",
  "_Backend": "バックエンド"
}
1.0.16

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago