# Local development

While you can accomplish all connector-related tasks using the online Apps
Script environment, some of them can become repetitive and error-prone over
time.

[`dscc-gen`](https://github.com/googledatastudio/dscc-gen) is an opinionated tool that's meant to address these repetitive
tasks so you can focus on solving your business problem instead of errors that
can be avoided through automation.

## Requirements

- [npm 5.2.0 or later](https://www.npmjs.com/get-npm)
- Some familiarity with the command-line.

## Using `dscc-gen`

`dscc-gen` can [create new community-connector projects](https://developers.google.com/data-studio/connector/local-development.md.txt#new_connectors) or be
[used with existing ones](https://developers.google.com/data-studio/connector/local-development.md.txt#existing_connectors).

### Existing connectors

`dscc-gen` can also be used with existing projects. First,
[copy your `scriptId`](https://developers.google.com/data-studio/connector/local-development.md.txt#get_your_script_id), then run the following command (replacing
`YOUR_SCRIPT_ID` with your `scriptId`.):

```bash
npx @google/dscc-gen connector --script_id YOUR_SCRIPT_ID
```

You'll be prompted for a few details for your connector. If you don't already
have a deployment called "Production", one will be created for you. None of your
existing code will be modified, but you will have access to
[everything `dscc-gen` can do](https://developers.google.com/data-studio/connector/local-development.md.txt#what_can_dscc-gen_do).

### New connectors

To create a new community-connector with `dscc-gen`, run the following command:

```bash
npx @google/dscc-gen connector
```

> [!NOTE]
> **Note:** [npx](https://medium.com/@maybekatz/introducing-npx-an-npm-package-runner-55f7d4bd282b) was added to npm 5.2.0. It runs one-off executables without modifying your `PATH`.

You'll be prompted for a few details for your new connector. First-time users
will be asked to authenticate `clasp`. [`clasp`](https://developers.google.com/apps-script/guides/clasp.md.txt) is a tool for creating \&
modifying Apps Script projects from the command-line.

After completing the prompts, `dscc-gen` will create a new Apps Script project
and print out [everything it can do](https://developers.google.com/data-studio/connector/local-development.md.txt#what_can_dscc-gen_do).

## What can `dscc-gen` do?

| Command | Description |
|---|---|
| `npm run open` | Open your project in Apps Script. |
| `npm run push` | Push your local changes to Apps Script. |
| `npm run watch` | Watch for local changes, and push them to Apps Script. |
| `npm run prettier` | Format your code using community standards. |
| `npm run try_latest` | Open the deployment with your latest code in Data Studio. |
| `npm run try_production` | Open your Production deployment in Data Studio. |
| `npm run update_production` | Update your production deployment to use your latest code. |

> [!NOTE]
> **Note:** All of these commands should be run from the top-level directory of your project.

## How should I Use it?

Using `dscc-gen` often goes a little like this:

1. Identify a feature you'd like to add to your connector.
2. Run `npm run watch`, so local changes will be pushed to Apps Script.
3. Make your code changes using your [favorite](https://code.visualstudio.com/) [JavaScript](https://www.sublimetext.com/) [editor](http://spacemacs.org/).
4. Run `npm run tryLatest` and check that your new feature is working as expected.
5. Run `npm run updateProduction` to update your production deployment to have your new feature.
6. Run `npm run tryProduction` and double check that the new feature works.

## Get your script Id

To get your `scriptId`, navigate to your existing project, then copy the section
of the url after `/d/` and before `/edit`. For example: the following url:

- Original Url: `https://script.google.com/a/google.com/d/example-script-id/edit`
- Script Id: `example-script-id`