# @dgcode/gscript

> Code and test in Node, deploy to Google Apps Script

Latest version **0.1.52** (published 2019-01-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install @dgcode/gscript
pnpm add @dgcode/gscript
yarn add @dgcode/gscript
bun add @dgcode/gscript
```

Provides the command `gscript`.

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.52 |
| Published | 2019-01-24 |
| First published | 2019-01-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 36 |
| Unpacked size | 602.2 KB |
| Known vulnerabilities | 0 (+6 in 1 direct dependencies) |
| Install scripts | no |
| Author | Aurelien Monasse |
| Maintainers | dgcoder |

## Links

- npm: https://www.npmjs.com/package/@dgcode/gscript
- npm.io page: https://npm.io/package/@dgcode/gscript

## Dependencies (36)

- [opn](https://npm.io/package/opn.md) ^5.4.0
- [ora](https://npm.io/package/ora.md) ^3.0.0
- [glob](https://npm.io/package/glob.md) ^7.1.3
- [yaml](https://npm.io/package/yaml.md) ^1.1.0
- [chalk](https://npm.io/package/chalk.md) ^2.4.1
- [debug](https://npm.io/package/debug.md) ^4.1.0
- [meant](https://npm.io/package/meant.md) ^1.0.1
- [core-js](https://npm.io/package/core-js.md) ^2.6.0
- [webpack](https://npm.io/package/webpack.md) ^4.27.0
- [fs-extra](https://npm.io/package/fs-extra.md) ^7.0.1
- [inquirer](https://npm.io/package/inquirer.md) ^6.2.1
- [progress](https://npm.io/package/progress.md) ^2.0.3
- [bootstrap](https://npm.io/package/bootstrap.md) ^4.2.1
- [commander](https://npm.io/package/commander.md) ^2.19.0
- [memory-fs](https://npm.io/package/memory-fs.md) ^0.4.1
- [ts-loader](https://npm.io/package/ts-loader.md) ^5.3.1
- [word-wrap](https://npm.io/package/word-wrap.md) ^1.2.3
- [superagent](https://npm.io/package/superagent.md) ^4.0.0
- [@babel/core](https://npm.io/package/@babel/core.md) ^7.1.0
- [null-loader](https://npm.io/package/null-loader.md) ^0.1.1
- [@dgcode/auth](https://npm.io/package/@dgcode/auth.md) ^0.1.42
- [babel-loader](https://npm.io/package/babel-loader.md) ^8.0.4
- [lodash.merge](https://npm.io/package/lodash.merge.md) ^4.6.1
- [webpack-merge](https://npm.io/package/webpack-merge.md) ^4.1.4
- [@dgcode/schema](https://npm.io/package/@dgcode/schema.md) ^0.1.21
- [setprototypeof](https://npm.io/package/setprototypeof.md) ^1.1.0
- [@babel/polyfill](https://npm.io/package/@babel/polyfill.md) ^7.0.0
- [webpack-sources](https://npm.io/package/webpack-sources.md) ^1.3.0
- [lodash.camelcase](https://npm.io/package/lodash.camelcase.md) ^4.3.0
- [lodash.startcase](https://npm.io/package/lodash.startcase.md) ^4.4.0
- [@babel/preset-env](https://npm.io/package/@babel/preset-env.md) ^7.2.0
- [webpack-dev-server](https://npm.io/package/webpack-dev-server.md) ^3.1.14
- [@babel/preset-react](https://npm.io/package/@babel/preset-react.md) ^7.0.0
- [html-webpack-plugin](https://npm.io/package/html-webpack-plugin.md) ^3.2.0
- [string-replace-loader](https://npm.io/package/string-replace-loader.md) ^2.1.1
- [terser-webpack-plugin](https://npm.io/package/terser-webpack-plugin.md) ^1.1.0

## Recent versions

- 0.1.52 (latest) — 2019-01-24
- 0.1.49 — 2019-01-21
- 0.1.48 — 2019-01-17
- 0.1.46 — 2019-01-17
- 0.1.45 — 2019-01-16
- 0.1.44 — 2019-01-16

## README

# `@dgcode/gscript`

Code and test in Node, deploy to Google Apps Script

# DISCLAIMER

This is a **highly experimental** tool! Use at your own risk. If you want a more official and battle-tested solution (with the caveats listed below), use [clasp](https://www.npmjs.com/package/@google/clasp) instead, keeping in mind both tools achieve very different purposes.

In its current state, consider this a "beta" project with few documentation and rough edge-cases - for the time being.

# Install

    $ npm install @dgcode/gscript

To get the command-line `gscript` tool instead, install the package globally:

    $ npm install @dgcode/gscript -g

# Usage

## From scratch

Print help, command usage and options:

    $ gscript help

Create a new project (follow prompt instructions):

    $ gscript create

If you'd rather generate a YAML configuration file instead for your project (which conveniently includes some documentation for customization):

    $ gscript create --format yaml

Code then deploy to Google Apps Script:

    $ gscript push

## Editing

Clone an existing Google Apps Script project (this will retrieve code and write files locally):

    $ gscript clone

Save current Apps Script code as new locked version:

    $ gscript bump

Retrieve current Apps Script code (in case local files are missing):

    $ gscript pull

Compile files locally to check what will eventually be pushed, based on your source files:

    $ gscript compile

## Workflow

Open current Apps Script UI to view final deployed code:

    $ gscript open

Run a local development server to preview your view files (React):

    $ gscript dev --port YOUR_PORT

# `gscript` vs Google's `clasp`

*gscript* is a more opinionated tool about how a project should be designed and coded, while *clasp* provides a thinner layer that merely keeps local and remote files synchronized.

**Building**

*[clasp](https://www.npmjs.com/package/@google/clasp)* maintains a one-to-one relationship between your local files and files in the Apps Script project, while *gscript* bundles your files into a single compiled one with help of [Webpack](https://www.npmjs.com/package/webpack).

Being powered by [Webpack](https://www.npmjs.com/package/webpack) enables *gscript* to compile into environment-agnostic code - notably one that understands `import {...} from ''` / `require('')` calls and includes all dependencies in a single wrapped Apps Script file without polluting the global namespace.

For example, if your local TypeScript code was made of:

```
// local file: main.ts

import { FooLogger } from './foo-logger';

export function sayHello() {
  const logger = new FooLogger();
  logger.print();
}
```
```
// local file: foo-logger.ts

export class FooLogger {
  public print() {
    console.log('Hello from Foo!');
  }
}
```

Then these will eventually be transformed and packed into a single file when sent to the Apps Script project, looking like:

```
// compiled Apps Script file: Entry.gs

function sayHello() {
  return entry.sayHello.apply(entry, arguments);
}

!(function webpackCompilation(global) {
  global['entry'] = (function() {
    // webpack-compiled magic goes here
    // ...
  })();
})(this);
```

**Local-first, transform later**

*gscript* is designed with local-first code in mind, letting you benefit from any IDE features you like (auto-completion, type checking) such as VSCode's. Moreover, *gscript* applies arbitrary code transforms that let you run your script locally first before publishing to Apps Script. For example:

    // in the local world:
    console.log('Hello, %s!', 'Joe');

... is compatible in classic JavaScript (both Node.js and browsers) but is unknown from Apps Script, which uses its own global `Logger` class instead. On compilation, *gscript* automatically transforms such code as:

    // same code, automatically transformed by gscript
    // once published on Apps Script:
    Logger.log('Hello, %s!', 'Joe');

# Entry points

Being compiled with [Webpack](https://www.npmjs.com/package/webpack), you code needs to specify known entry files.

By default, any file starting with `main-` or `Main` will be considered an entry point. Such file should *explicitly* expose functions, in the following form:

    export function someFunction() {...}

This will ensure AppsScript recognizes such function at top-level callables.

# Roadmap

> TODO more documentation to come in future versions

# License

MIT

---
_Source: https://npm.io/package/@dgcode/gscript · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
