Pages

Showing posts with label clasp. Show all posts
Showing posts with label clasp. Show all posts

Friday, January 3, 2020

Fedora 31 : Test Google locally Apps Script CLI.

The Apps Script CLI, or clasp, is a tool that lets you create, edit, and deploy Apps Script projects locally like Sheets, Docs, Forms, and Slides.
[mythcat@desk ~]$ mkdir google
[mythcat@desk ~]$ cd google
[mythcat@desk google]$ sudo dnf install nodejs
[sudo] password for mythcat: 
Last metadata expiration check: 2:03:50 ago on Fri 03 Jan 2020 11:37:12 AM EET.
Dependencies resolved.
================================================================================
 Package          Arch        Version                        Repository    Size
================================================================================
Installing:
 nodejs           x86_64      1:12.13.1-1.fc31               updates      413 k
Installing dependencies:
 nodejs-libs      x86_64      1:12.13.1-1.fc31               updates       19 M
 npm              x86_64      1:6.12.1-1.12.13.1.1.fc31      updates      3.4 M
Installing weak dependencies:
 nodejs-docs      noarch      1:12.13.1-1.fc31               updates      2.4 M

Transaction Summary
================================================================================
Install  4 Packages

Total download size: 25 M
Installed size: 132 M
Is this ok [y/N]: y
...
Complete!
The clasp uses requires Node.js >= v6.0.0. Let's install it:
[mythcat@desk google]$ sudo npm install n -g
/usr/local/bin/n -> /usr/local/lib/node_modules/n/bin/n
+ n@6.1.3
added 1 package from 4 contributors in 0.705s
[mythcat@desk google]$ sudo n latest

  installing : node-v13.5.0
       mkdir : /usr/local/n/versions/node/13.5.0
       fetch : https://nodejs.org/dist/v13.5.0/node-v13.5.0-linux-x64.tar.gz
   installed : v13.5.0 (with npm 6.13.4)

Note: the node command changed location and the old location may be remembered in your 
current shell.
         old : /usr/bin/node
         new : /usr/local/bin/node
To reset the command location hash either start a new shell, or execute PATH="$PATH"
[mythcat@desk google]$ sudo npm i @google/clasp -g
/usr/local/bin/clasp -> /usr/local/lib/node_modules/@google/clasp/src/index.js
npm WARN inquirer-autocomplete-prompt@1.0.1 requires a peer of inquirer@^5.0.0 || 
^6.0.0 but none is installed. You must install peer dependencies yourself.

+ @google/clasp@2.3.0
added 191 packages from 118 contributors in 53.457s 
The simple run of clasp command shows us all arguments:
[mythcat@desk google]$ clasp
Usage: clasp  [options]

clasp - The Apps Script CLI

Options:
  -v, --version                               
  -h, --help                                  output usage information

Commands:
  login [options]                             Log in to script.google.com
  logout                                      Log out
  create [options]                            Create a script
  clone [options] [scriptId] [versionNumber]  Clone a project
  pull [options]                              Fetch a remote project
  push [options]                              Update the remote project
  status [options]                            Lists files that will be pushed by clasp
  open [options] [scriptId]                   Open a script
  deployments                                 List deployment ids of a script
  deploy [options]                            Deploy a project
  undeploy [options] [deploymentId]           Undeploy a deployment of a project
  version [description]                       Creates an immutable version of the script
  versions                                    List versions of a script
  list                                        List App Scripts projects
  logs [options]                              Shows the StackDriver logs
  run [options] [functionName]                Run a function in your Apps Scripts project
  apis [options]                              List, enable, or disable APIs
    list
    enable 
    disable 
  help                                        Display help
  setting|settings [settingKey] [newValue]    Update  in .clasp.json
  *                                           Any other command is not supported
You can log in with this command
[mythcat@desk google]$ clasp login
Logging in globally...
...
This will open a webpage for authentification and ends with this text message: Logged in! You may close this page.
Now you can create a new folder for your project named clasp_code.
Use this command and arrows key to select the type of the project:
[mythcat@desk clasp_code]$ clasp create --title "my first project with clasp";
? Create which script? (Use arrow keys)
❯ standalone 
  docs 
  sheets 
  slides 
  forms 
  webapp 
  api 
...
User has not enabled the Apps Script API. Enable it by visiting 
https://script.google.com/home/usersettings then retry. 
If you enabled this API recently, wait a few minutes for the action to propagate 
to our systems and retry.
Open the URL to activate the API and run the command again to get the JSON file named appsscript.json.
You can clone an old project by script_ID.
Use this command into a new folder with the script_ID value from project menu File -> Project properties -> Info -> Script ID.
This will download the project in your current directory.
clasp clone script_ID 
To edit your project use this command:
[mythcat@desk clasp_code]$ clasp open
The next step is to pull and push operations:
[mythcat@desk clasp_code]$ clasp pull
Warning: files in subfolder are not accounted for unless you set a '.claspignore' file.
Cloned 2 files.
└─ appsscript.json
└─ Code.js
[mythcat@desk clasp_code]$ clasp push
└─ Code.js
└─ appsscript.json
Pushed 2 files.
The clasp allows you to manage versions and deployments with these commands:
[mythcat@desk clasp_code]$ clasp version "First version"
Created version 1.
[mythcat@desk clasp_code]$ clasp deploy 1 "First deployment"
Created version 2.
For more information see the GitHub webpage.